本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Test.Utilities.MockCSharpCompiler类的典型用法代码示例。如果您正苦于以下问题:C# MockCSharpCompiler类的具体用法?C# MockCSharpCompiler怎么用?C# MockCSharpCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockCSharpCompiler类属于Microsoft.CodeAnalysis.CSharp.Test.Utilities命名空间,在下文中一共展示了MockCSharpCompiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TrivialSourceFileOnlyCsc
public void TrivialSourceFileOnlyCsc()
{
var hello = Temp.CreateFile().WriteAllText(helloWorldCS).Path;
var touchedDir = Temp.CreateDirectory();
var touchedBase = Path.Combine(touchedDir.Path, "touched");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", hello,
string.Format(@"/touchedfiles:""{0}""", touchedBase) });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
List<string> expectedReads;
List<string> expectedWrites;
BuildTouchedFiles(cmd,
Path.ChangeExtension(hello, "exe"),
out expectedReads,
out expectedWrites);
var exitCode = cmd.Run(outWriter);
Assert.Equal("", outWriter.ToString().Trim());
Assert.Equal(0, exitCode);
AssertTouchedFilesEqual(expectedReads,
expectedWrites,
touchedBase);
CleanupAllGeneratedFiles(hello);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:26,代码来源:TouchedFileLoggingTests.cs
示例2: AppConfigCsc
public void AppConfigCsc()
{
var hello = Temp.CreateFile().WriteAllText(helloWorldCS).Path;
var touchedDir = Temp.CreateDirectory();
var touchedBase = Path.Combine(touchedDir.Path, "touched");
var appConfigPath = Temp.CreateFile().WriteAllText(
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<supportPortability PKT=""7cec85d7bea7798e"" enable=""false""/>
</assemblyBinding>
</runtime>
</configuration>").Path;
var silverlight = Temp.CreateFile().WriteAllBytes(ProprietaryTestResources.NetFX.silverlight_v5_0_5_0.System_v5_0_5_0_silverlight).Path;
var net4_0dll = Temp.CreateFile().WriteAllBytes(ProprietaryTestResources.NetFX.v4_0_30319.System).Path;
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var cmd = new MockCSharpCompiler(null, _baseDirectory,
new[] { "/nologo",
"/r:" + silverlight,
"/r:" + net4_0dll,
"/appconfig:" + appConfigPath,
"/touchedfiles:" + touchedBase,
hello });
List<string> expectedReads;
List<string> expectedWrites;
BuildTouchedFiles(cmd,
Path.ChangeExtension(hello, "exe"),
out expectedReads,
out expectedWrites);
expectedReads.Add(appConfigPath);
var exitCode = cmd.Run(outWriter);
Assert.Equal("", outWriter.ToString().Trim());
Assert.Equal(0, exitCode);
AssertTouchedFilesEqual(expectedReads,
expectedWrites,
touchedBase);
CleanupAllGeneratedFiles(hello);
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:44,代码来源:TouchedFileLoggingTests.cs
示例3: NoDiagnostics
public void NoDiagnostics()
{
var helloWorldCS = @"using System;
class C
{
public static void Main(string[] args)
{
Console.WriteLine(""Hello, world"");
}
}";
var hello = Temp.CreateFile().WriteAllText(helloWorldCS).Path;
var errorLogDir = Temp.CreateDirectory();
var errorLogFile = Path.Combine(errorLogDir.Path, "ErrorLog.txt");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", hello,
$"/errorlog:{errorLogFile}" });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var exitCode = cmd.Run(outWriter);
Assert.Equal("", outWriter.ToString().Trim());
Assert.Equal(0, exitCode);
var actualOutput = File.ReadAllText(errorLogFile).Trim();
var expectedHeader = GetExpectedErrorLogHeader(actualOutput, cmd);
var expectedIssues = @"
""issues"": [
]
}
]
}";
var expectedText = expectedHeader + expectedIssues;
Assert.Equal(expectedText, actualOutput);
CleanupAllGeneratedFiles(hello);
CleanupAllGeneratedFiles(errorLogFile);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:39,代码来源:ErrorLoggerTests.cs
示例4: VerifyOutput
private static string VerifyOutput(TempDirectory sourceDir, TempFile sourceFile,
bool includeCurrentAssemblyAsAnalyzerReference = true,
string[] additionalFlags = null,
int expectedInfoCount = 0,
int expectedWarningCount = 0,
int expectedErrorCount = 0)
{
var args = new[] {
"/nologo", "/preferreduilang:en", "/t:library",
sourceFile.Path
};
if (includeCurrentAssemblyAsAnalyzerReference)
{
args = args.Append("/a:" + Assembly.GetExecutingAssembly().Location);
}
if (additionalFlags != null)
{
args = args.Append(additionalFlags);
}
var csc = new MockCSharpCompiler(null, sourceDir.Path, args);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var exitCode = csc.Run(outWriter);
var output = outWriter.ToString();
var expectedExitCode = expectedErrorCount > 0 ? 1 : 0;
Assert.True(
expectedExitCode == exitCode,
string.Format("Expected exit code to be '{0}' was '{1}'.{2} Output:{3}{4}",
expectedExitCode, exitCode, Environment.NewLine, Environment.NewLine, output));
Assert.DoesNotContain("hidden", output, StringComparison.Ordinal);
if (expectedInfoCount == 0)
{
Assert.DoesNotContain("info", output, StringComparison.Ordinal);
}
else
{
Assert.Equal(expectedInfoCount, OccurrenceCount(output, "info"));
}
if (expectedWarningCount == 0)
{
Assert.DoesNotContain("warning", output, StringComparison.Ordinal);
}
else
{
Assert.Equal(expectedWarningCount, OccurrenceCount(output, "warning"));
}
if (expectedErrorCount == 0)
{
Assert.DoesNotContain("error", output, StringComparison.Ordinal);
}
else
{
Assert.Equal(expectedErrorCount, OccurrenceCount(output, "error"));
}
return output;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:62,代码来源:CommandLineTests.cs
示例5: NoInfoDiagnostics
public void NoInfoDiagnostics()
{
string filePath = Temp.CreateFile().WriteAllText(@"
using System.Diagnostics; // Unused.
").Path;
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", "/target:library", filePath });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var exitCode = cmd.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Equal("", outWriter.ToString().Trim());
CleanupAllGeneratedFiles(filePath);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:13,代码来源:CommandLineTests.cs
示例6: PreferredUILang
public void PreferredUILang()
{
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Contains("CS2006", outWriter.ToString(), StringComparison.Ordinal);
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang:" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Contains("CS2006", outWriter.ToString(), StringComparison.Ordinal);
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang:zz" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Contains("CS2038", outWriter.ToString(), StringComparison.Ordinal);
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang:en-zz" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Contains("CS2038", outWriter.ToString(), StringComparison.Ordinal);
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang:en-US" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.DoesNotContain("CS2038", outWriter.ToString(), StringComparison.Ordinal);
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang:de" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.DoesNotContain("CS2038", outWriter.ToString(), StringComparison.Ordinal);
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/preferreduilang:de-AT" }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.DoesNotContain("CS2038", outWriter.ToString(), StringComparison.Ordinal);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:37,代码来源:CommandLineTests.cs
示例7: AnalyzerReportsMisformattedDiagnostic
public void AnalyzerReportsMisformattedDiagnostic()
{
var srcFile = Temp.CreateFile().WriteAllText(@"class C {}");
var srcDirectory = Path.GetDirectoryName(srcFile.Path);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var csc = new MockCSharpCompiler(null, _baseDirectory, new[] { "/t:library", srcFile.Path },
analyzer: new AnalyzerReportingMisformattedDiagnostic());
var exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
var output = outWriter.ToString();
// Verify that the diagnostic reported by AnalyzerReportingMisformattedDiagnostic is reported with the message format string, instead of the formatted message.
Assert.Contains(AnalyzerThatThrowsInGetMessage.Rule.Id, output, StringComparison.Ordinal);
Assert.Contains(AnalyzerThatThrowsInGetMessage.Rule.MessageFormat.ToString(CultureInfo.InvariantCulture), output, StringComparison.Ordinal);
CleanupAllGeneratedFiles(srcFile.Path);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:CommandLineTests.cs
示例8: ReportAnalyzerOutput
public void ReportAnalyzerOutput()
{
var srcFile = Temp.CreateFile().WriteAllText(@"class C {}");
var srcDirectory = Path.GetDirectoryName(srcFile.Path);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var csc = new MockCSharpCompiler(null, srcDirectory, new[] { "/reportanalyzer", "/t:library", "/a:" + Assembly.GetExecutingAssembly().Location, srcFile.Path });
var exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
var output = outWriter.ToString();
Assert.Contains(CodeAnalysisResources.AnalyzerExecutionTimeColumnHeader, output, StringComparison.Ordinal);
Assert.Contains(new WarningDiagnosticAnalyzer().ToString(), output, StringComparison.Ordinal);
CleanupAllGeneratedFiles(srcFile.Path);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:14,代码来源:CommandLineTests.cs
示例9: TestCS2002
private static void TestCS2002(string[] commandLineArgs, string baseDirectory, int expectedExitCode, string[] compileDiagnostics, params DiagnosticDescription[] parseDiagnostics)
{
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var allCommandLineArgs = new[] { "/nologo", "/preferreduilang:en", "/t:library" }.Concat(commandLineArgs).ToArray();
// Verify command line parser diagnostics.
DefaultParse(allCommandLineArgs, baseDirectory).Errors.Verify(parseDiagnostics);
// Verify compile.
int exitCode = new MockCSharpCompiler(null, baseDirectory, allCommandLineArgs).Run(outWriter);
Assert.Equal(expectedExitCode, exitCode);
if (parseDiagnostics.IsEmpty())
{
// Verify compile diagnostics.
string outString = String.Empty;
for (int i = 0; i < compileDiagnostics.Length; i++)
{
if (i != 0)
{
outString += @"
";
}
outString += compileDiagnostics[i];
}
Assert.Equal(outString, outWriter.ToString().Trim());
}
else
{
Assert.Null(compileDiagnostics);
}
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:34,代码来源:CommandLineTests.cs
示例10: TestWarnAsError_CS1522
public void TestWarnAsError_CS1522()
{
string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@"
public class Test
{
// CS0169 (level 3)
private int x;
// CS0109 (level 4)
public new void Method() { }
public static int Main()
{
int i = 5;
// CS1522 (level 1)
switch (i) { }
return 0;
// CS0162 (level 2)
i = 6;
}
}
").Path;
var baseDir = Path.GetDirectoryName(source);
var fileName = Path.GetFileName(source);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, baseDir, new[] { "/nologo", "/preferreduilang:en", "/warn:3", "/warnaserror", source.ToString() }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Equal(fileName + "(12,20): error CS1522: Empty switch block", outWriter.ToString().Trim());
CleanupAllGeneratedFiles(source);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:31,代码来源:CommandLineTests.cs
示例11: TestNoWarnParseDiagnostics
public void TestNoWarnParseDiagnostics()
{
string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@"
class Test
{
static void Main()
{
//Generates warning CS1522: Empty switch block
switch (1) { }
//Generates warning CS0642: Possible mistaken empty statement
while (false) ;
{ }
}
}
").Path;
var baseDir = Path.GetDirectoryName(source);
var fileName = Path.GetFileName(source);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", "/nowarn:1522,642", source.ToString() }).Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Equal("", outWriter.ToString().Trim());
CleanupAllGeneratedFiles(source);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:27,代码来源:CommandLineTests.cs
示例12: TestFilterParseDiagnostics
public void TestFilterParseDiagnostics()
{
string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@"
#pragma warning disable 440
using global = A; // CS0440
class A
{
static void Main() {
#pragma warning suppress 440
}
}").Path;
var baseDir = Path.GetDirectoryName(source);
var fileName = Path.GetFileName(source);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, baseDir, new[] { "/nologo", "/preferreduilang:en", source.ToString() }).Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Equal(Path.GetFileName(source) + "(7,17): warning CS1634: Expected disable or restore", outWriter.ToString().Trim());
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, baseDir, new[] { "/nologo", "/nowarn:1634", source.ToString() }).Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Equal("", outWriter.ToString().Trim());
outWriter = new StringWriter(CultureInfo.InvariantCulture);
exitCode = new MockCSharpCompiler(null, baseDir, new[] { "/nologo", "/preferreduilang:en", Path.Combine(baseDir, "nonexistent.cs"), source.ToString() }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Equal("error CS2001: Source file '" + Path.Combine(baseDir, "nonexistent.cs") + "' could not be found.", outWriter.ToString().Trim());
CleanupAllGeneratedFiles(source);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:32,代码来源:CommandLineTests.cs
示例13: DefaultResponseFileNoConfig
public void DefaultResponseFileNoConfig()
{
MockCSharpCompiler csc = new MockCSharpCompiler(GetDefaultResponseFilePath(), _baseDirectory, new[] { "/noconfig" });
Assert.Equal(csc.Arguments.MetadataReferences.Select(r => r.Reference), new string[]
{
typeof(object).Assembly.Location,
}, StringComparer.OrdinalIgnoreCase);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:8,代码来源:CommandLineTests.cs
示例14: DefaultResponseFile
public void DefaultResponseFile()
{
MockCSharpCompiler csc = new MockCSharpCompiler(GetDefaultResponseFilePath(), _baseDirectory, new string[0]);
AssertEx.Equal(csc.Arguments.MetadataReferences.Select(r => r.Reference), new string[]
{
typeof(object).Assembly.Location,
"Accessibility.dll",
"Microsoft.CSharp.dll",
"System.Configuration.dll",
"System.Configuration.Install.dll",
"System.Core.dll",
"System.Data.dll",
"System.Data.DataSetExtensions.dll",
"System.Data.Linq.dll",
"System.Data.OracleClient.dll",
"System.Deployment.dll",
"System.Design.dll",
"System.DirectoryServices.dll",
"System.dll",
"System.Drawing.Design.dll",
"System.Drawing.dll",
"System.EnterpriseServices.dll",
"System.Management.dll",
"System.Messaging.dll",
"System.Runtime.Remoting.dll",
"System.Runtime.Serialization.dll",
"System.Runtime.Serialization.Formatters.Soap.dll",
"System.Security.dll",
"System.ServiceModel.dll",
"System.ServiceModel.Web.dll",
"System.ServiceProcess.dll",
"System.Transactions.dll",
"System.Web.dll",
"System.Web.Extensions.Design.dll",
"System.Web.Extensions.dll",
"System.Web.Mobile.dll",
"System.Web.RegularExpressions.dll",
"System.Web.Services.dll",
"System.Windows.Forms.dll",
"System.Workflow.Activities.dll",
"System.Workflow.ComponentModel.dll",
"System.Workflow.Runtime.dll",
"System.Xml.dll",
"System.Xml.Linq.dll",
}, StringComparer.OrdinalIgnoreCase);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:46,代码来源:CommandLineTests.cs
示例15: CheckFullpaths
public void CheckFullpaths()
{
string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@"
public class C
{
public static void Main()
{
string x;
}
}").Path;
var baseDir = Path.GetDirectoryName(source);
var fileName = Path.GetFileName(source);
// Checks the base case without /fullpaths (expect to see relative path name)
// c:\temp> csc.exe c:\temp\a.cs
// a.cs(6,16): warning CS0168: The variable 'x' is declared but never used
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var csc = new MockCSharpCompiler(null, baseDir, new[] { source, "/preferreduilang:en" });
int exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Contains(fileName + "(6,16): warning CS0168: The variable 'x' is declared but never used", outWriter.ToString(), StringComparison.Ordinal);
// Checks the base case without /fullpaths when the file is located in the sub-folder (expect to see relative path name)
// c:\temp> csc.exe c:\temp\example\a.cs
// example\a.cs(6,16): warning CS0168: The variable 'x' is declared but never used
outWriter = new StringWriter(CultureInfo.InvariantCulture);
csc = new MockCSharpCompiler(null, Directory.GetParent(baseDir).FullName, new[] { source, "/preferreduilang:en" });
exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Contains(fileName + "(6,16): warning CS0168: The variable 'x' is declared but never used", outWriter.ToString(), StringComparison.Ordinal);
Assert.DoesNotContain(source, outWriter.ToString(), StringComparison.Ordinal);
// Checks the base case without /fullpaths when the file is not located under the base directory (expect to see the full path name)
// c:\temp> csc.exe c:\test\a.cs
// c:\test\a.cs(6,16): warning CS0168: The variable 'x' is declared but never used
outWriter = new StringWriter(CultureInfo.InvariantCulture);
csc = new MockCSharpCompiler(null, Temp.CreateDirectory().Path, new[] { source, "/preferreduilang:en" });
exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Contains(source + "(6,16): warning CS0168: The variable 'x' is declared but never used", outWriter.ToString(), StringComparison.Ordinal);
// Checks the case with /fullpaths (expect to see the full paths)
// c:\temp> csc.exe c:\temp\a.cs /fullpaths
// c:\temp\a.cs(6,16): warning CS0168: The variable 'x' is declared but never used
outWriter = new StringWriter(CultureInfo.InvariantCulture);
csc = new MockCSharpCompiler(null, baseDir, new[] { source, "/fullpaths", "/preferreduilang:en" });
exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Contains(source + @"(6,16): warning CS0168: The variable 'x' is declared but never used", outWriter.ToString(), StringComparison.Ordinal);
// Checks the base case without /fullpaths when the file is located in the sub-folder (expect to see the full path name)
// c:\temp> csc.exe c:\temp\example\a.cs /fullpaths
// c:\temp\example\a.cs(6,16): warning CS0168: The variable 'x' is declared but never used
outWriter = new StringWriter(CultureInfo.InvariantCulture);
csc = new MockCSharpCompiler(null, Directory.GetParent(baseDir).FullName, new[] { source, "/preferreduilang:en", "/fullpaths" });
exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Contains(source + "(6,16): warning CS0168: The variable 'x' is declared but never used", outWriter.ToString(), StringComparison.Ordinal);
// Checks the base case without /fullpaths when the file is not located under the base directory (expect to see the full path name)
// c:\temp> csc.exe c:\test\a.cs /fullpaths
// c:\test\a.cs(6,16): warning CS0168: The variable 'x' is declared but never used
outWriter = new StringWriter(CultureInfo.InvariantCulture);
csc = new MockCSharpCompiler(null, Temp.CreateDirectory().Path, new[] { source, "/preferreduilang:en", "/fullpaths" });
exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Contains(source + "(6,16): warning CS0168: The variable 'x' is declared but never used", outWriter.ToString(), StringComparison.Ordinal);
CleanupAllGeneratedFiles(source);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:71,代码来源:CommandLineTests.cs
示例16: Test
private void Test(string source, int startErrorCode, int endErrorCode)
{
string sourcePath = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(source).Path;
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", sourcePath }).Run(outWriter);
Assert.Equal(0, exitCode);
var cscOutput = outWriter.ToString().Trim();
for (int errorCode = startErrorCode; errorCode < endErrorCode; errorCode++)
{
Assert.True(cscOutput == string.Empty, "Failed at error code: " + errorCode);
}
CleanupAllGeneratedFiles(sourcePath);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:16,代码来源:CommandLineTests.cs
示例17: WriteXml
public void WriteXml()
{
var source = @"
/// <summary>
/// A subtype of <see cref=""object""/>.
/// </summary>
public class C { }
";
var sourcePath = Temp.CreateFile(directory: _baseDirectory, extension: ".cs").WriteAllText(source).Path;
string xmlPath = Path.Combine(_baseDirectory, "Test.xml");
var csc = new MockCSharpCompiler(null, _baseDirectory, new[] { "/target:library", "/out:Test.dll", "/doc:" + xmlPath, sourcePath });
var writer = new StringWriter(CultureInfo.InvariantCulture);
var exitCode = csc.Run(writer);
if (exitCode != 0)
{
Console.WriteLine(writer.ToString());
Assert.Equal(0, exitCode);
}
var bytes = File.ReadAllBytes(xmlPath);
var actual = new string(Encoding.UTF8.GetChars(bytes));
var expected = @"
<?xml version=""1.0""?>
<doc>
<assembly>
<name>Test</name>
</assembly>
<members>
<member name=""T:C"">
<summary>
A subtype of <see cref=""T:System.Object""/>.
</summary>
</member>
</members>
</doc>
";
Assert.Equal(expected.Trim(), actual.Trim());
System.IO.File.Delete(xmlPath);
System.IO.File.Delete(sourcePath);
CleanupAllGeneratedFiles(sourcePath);
CleanupAllGeneratedFiles(xmlPath);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:46,代码来源:CommandLineTests.cs
示例18: TestWin32ResWithBadResFile_CS1583ERR_BadWin32Res
public void TestWin32ResWithBadResFile_CS1583ERR_BadWin32Res()
{
string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@"class Test { static void Main() {} }").Path;
string badres = Temp.CreateFile().WriteAllBytes(TestResources.DiagnosticTests.badresfile).Path;
var baseDir = Path.GetDirectoryName(source);
var fileName = Path.GetFileName(source);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, baseDir, new[]
{
"/nologo",
"/preferreduilang:en",
"/win32res:" + badres,
source
}).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Equal("error CS1583: Error reading Win32 resources -- Image is too small.", outWriter.ToString().Trim());
CleanupAllGeneratedFiles(source);
CleanupAllGeneratedFiles(badres);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:23,代码来源:CommandLineTests.cs
示例19: ErrorLineEnd
public void ErrorLineEnd()
{
var tree = SyntaxFactory.ParseSyntaxTree("class C public { }", path: "foo");
var comp = new MockCSharpCompiler(null, _baseDirectory, new[] { "/errorendlocation" });
var loc = new SourceLocation(tree.GetCompilationUnitRoot().FindToken(6));
var diag = new CSDiagnostic(new DiagnosticInfo(MessageProvider.Instance, (int)ErrorCode.ERR_MetadataNameTooLong), loc);
var text = comp.DiagnosticFormatter.Format(diag);
string stringStart = "foo(1,7,1,8)";
Assert.Equal(stringStart, text.Substring(0, stringStart.Length));
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:13,代码来源:CommandLineTests.cs
示例20: TestFilterCommandLineDiagnostics
public void TestFilterCommandLineDiagnostics()
{
string source = Temp.CreateFile(prefix: "", extension: ".cs").WriteAllText(@"
class A
{
static void Main() { }
}").Path;
var baseDir = Path.GetDirectoryName(source);
var fileName = Path.GetFileName(source);
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", "/target:library", "/out:foo.dll", "/nowarn:2008" }).Run(outWriter);
Assert.Equal(0, exitCode);
Assert.Equal("", outWriter.ToString().Trim());
System.IO.File.Delete(System.IO.Path.Combine(baseDir, "foo.dll"));
CleanupAllGeneratedFiles(source);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:18,代码来源:CommandLineTests.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Test.Utilities.MockCSharpCompiler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论