From b93c5fc48098e582656e8308c04600707a3a0d04 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Tue, 21 Jun 2022 17:35:24 -0700 Subject: [PATCH] Test failure --- .../Test/CommandLine/CommandLineTests.cs | 47 +++++++++++++++++-- .../Utilities/CSharp/MockCSharpCompiler.cs | 10 ++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index a9004a8c5849b..b52599fd5d943 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -9240,16 +9240,55 @@ public void SkipAnalyzersParse() Assert.False(parsedArgs.SkipAnalyzers); } - [Theory, CombinatorialData] + [Fact] [WorkItem(40926, "https://github.com/dotnet/roslyn/issues/40926")] - public void SkipAnalyzersSemantics(bool skipAnalyzers) + public void SkipAnalyzersFlagFiltersAnalyzers() + { + var srcFile = Temp.CreateFile().WriteAllText(@"class C {}"); + var srcDirectory = Path.GetDirectoryName(srcFile.Path); + + var args = new List() { "/reportanalyzer", "/t:library", "/a:" + Assembly.GetExecutingAssembly().Location, srcFile.Path }; + var csc = CreateCSharpCompiler( + responseFile: null, + srcDirectory, + args.ToArray()); + + csc.ResolveAnalyzersFromArguments( + skipAnalyzers: false, + out _, + out var analyzers, + out var generators); + Assert.NotEmpty(analyzers); + Assert.NotEmpty(generators); + + csc.ResolveAnalyzersFromArguments( + skipAnalyzers: true, + out _, + out analyzers, + out generators); + Assert.Empty(analyzers); + Assert.NotEmpty(generators); + + CleanupAllGeneratedFiles(srcFile.Path); + } + + [Theory] + [CombinatorialData] + [WorkItem(40926, "https://github.com/dotnet/roslyn/issues/40926")] + public void NoAnalyzersReportSemantics(bool skipAnalyzers) { var srcFile = Temp.CreateFile().WriteAllText(@"class C {}"); var srcDirectory = Path.GetDirectoryName(srcFile.Path); var outWriter = new StringWriter(CultureInfo.InvariantCulture); - var skipAnalyzersFlag = "/skipanalyzers" + (skipAnalyzers ? "+" : "-"); - var csc = CreateCSharpCompiler(null, srcDirectory, new[] { skipAnalyzersFlag, "/reportanalyzer", "/t:library", "/a:" + Assembly.GetExecutingAssembly().Location, srcFile.Path }); + var analyzers = skipAnalyzers + ? ImmutableArray.Empty + : ImmutableArray.Create(new HiddenDiagnosticAnalyzer(), new WarningDiagnosticAnalyzer()); + var csc = CreateCSharpCompiler( + responseFile: null, + srcDirectory, + new[] { "/reportanalyzer", "/t:library", srcFile.Path }, + analyzers: analyzers); var exitCode = csc.Run(outWriter); Assert.Equal(0, exitCode); var output = outWriter.ToString(); diff --git a/src/Compilers/Test/Utilities/CSharp/MockCSharpCompiler.cs b/src/Compilers/Test/Utilities/CSharp/MockCSharpCompiler.cs index be90ad0ef1d3b..059b14b1b08b3 100644 --- a/src/Compilers/Test/Utilities/CSharp/MockCSharpCompiler.cs +++ b/src/Compilers/Test/Utilities/CSharp/MockCSharpCompiler.cs @@ -53,6 +53,16 @@ protected override void ResolveAnalyzersFromArguments( } } + public void ResolveAnalyzersFromArguments( + bool skipAnalyzers, + out List diagnostics, + out ImmutableArray analyzers, + out ImmutableArray generators) + { + diagnostics = new List(); + ResolveAnalyzersFromArguments(diagnostics, this.MessageProvider, skipAnalyzers, out analyzers, out generators); + } + public Compilation CreateCompilation( TextWriter consoleOutput, TouchedFileLogger touchedFilesLogger,