Skip to content

Commit

Permalink
Raise the default warning level in tests (#47077)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Oct 17, 2020
1 parent 21d2208 commit b43d165
Show file tree
Hide file tree
Showing 44 changed files with 239 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ class Test<T> where T : unmanaged
{
}";

CreateCompilation(text, options: new CSharpCompilationOptions(outputKind)).VerifyDiagnostics(
CreateCompilation(text, options: TestOptions.DebugDll.WithOutputKind(outputKind)).VerifyDiagnostics(
// (9,12): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsUnmanagedAttribute..ctor'
// class Test<T> where T : unmanaged
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "T").WithArguments("System.Runtime.CompilerServices.IsUnmanagedAttribute", ".ctor").WithLocation(9, 12));
Expand All @@ -792,7 +792,7 @@ class Test<T> where T : unmanaged
{
}";

CreateCompilation(text, options: new CSharpCompilationOptions(outputKind)).VerifyDiagnostics(
CreateCompilation(text, options: TestOptions.DebugDll.WithOutputKind(outputKind)).VerifyDiagnostics(
// (9,12): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsUnmanagedAttribute..ctor'
// class Test<T> where T : unmanaged
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "T").WithArguments("System.Runtime.CompilerServices.IsUnmanagedAttribute", ".ctor").WithLocation(9, 12));
Expand All @@ -812,7 +812,7 @@ class Test<T> where T : unmanaged
{
}";

CreateCompilation(text, options: new CSharpCompilationOptions(outputKind)).VerifyDiagnostics(
CreateCompilation(text, options: TestOptions.DebugDll.WithOutputKind(outputKind)).VerifyDiagnostics(
// (6,12): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsUnmanagedAttribute..ctor'
// class Test<T> where T : unmanaged
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "T").WithArguments("System.Runtime.CompilerServices.IsUnmanagedAttribute", ".ctor").WithLocation(6, 12));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,8 @@ public void Bug1095618(CSharpParseOptions parseOptions)
[MemberData(nameof(AllProviderParseOptions))]
public void ConsistentErrorMessageWhenProvidingNullKeyFile(CSharpParseOptions parseOptions)
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: null);
var options = TestOptions.DebugDll;
Assert.Null(options.CryptoKeyFile);
var compilation = CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics();

VerifySignedBitSetAfterEmit(compilation, expectedToBeSigned: false);
Expand All @@ -2637,7 +2638,7 @@ public void ConsistentErrorMessageWhenProvidingNullKeyFile(CSharpParseOptions pa
[MemberData(nameof(AllProviderParseOptions))]
public void ConsistentErrorMessageWhenProvidingEmptyKeyFile(CSharpParseOptions parseOptions)
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: string.Empty);
var options = TestOptions.DebugDll.WithCryptoKeyFile(string.Empty);
var compilation = CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics();

VerifySignedBitSetAfterEmit(compilation, expectedToBeSigned: false);
Expand All @@ -2648,7 +2649,8 @@ public void ConsistentErrorMessageWhenProvidingEmptyKeyFile(CSharpParseOptions p
[MemberData(nameof(AllProviderParseOptions))]
public void ConsistentErrorMessageWhenProvidingNullKeyFile_PublicSign(CSharpParseOptions parseOptions)
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: null, publicSign: true);
var options = TestOptions.DebugDll.WithPublicSign(true);
Assert.Null(options.CryptoKeyFile);
CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics(
// error CS8102: Public signing was specified and requires a public key, but no public key was specified.
Diagnostic(ErrorCode.ERR_PublicSignButNoKey).WithLocation(1, 1));
Expand All @@ -2659,7 +2661,7 @@ public void ConsistentErrorMessageWhenProvidingNullKeyFile_PublicSign(CSharpPars
[MemberData(nameof(AllProviderParseOptions))]
public void ConsistentErrorMessageWhenProvidingEmptyKeyFile_PublicSign(CSharpParseOptions parseOptions)
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: string.Empty, publicSign: true);
var options = TestOptions.DebugDll.WithCryptoKeyFile(string.Empty).WithPublicSign(true);
CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics(
// error CS8102: Public signing was specified and requires a public key, but no public key was specified.
Diagnostic(ErrorCode.ERR_PublicSignButNoKey).WithLocation(1, 1));
Expand Down
11 changes: 9 additions & 2 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,11 @@ async static Task Main(string[] args)
System.Console.WriteLine(""Task Main"");
}
}";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics();
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics(
// (10,23): warning CS8892: Method 'A.Main(string[])' will not be used as an entry point because a synchronous entry point 'A.Main()' was found.
// async static Task Main(string[] args)
Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("A.Main(string[])", "A.Main()").WithLocation(10, 23)
);
CompileAndVerify(compilation, expectedOutput: "Non Task Main", expectedReturnCode: 0);
}

Expand Down Expand Up @@ -1239,7 +1243,10 @@ async static Task Main(string[] args)
System.Console.WriteLine(""Task Main"");
}
}";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithMainTypeName("A")).VerifyDiagnostics();
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithMainTypeName("A")).VerifyDiagnostics(
// (10,23): warning CS8892: Method 'A.Main(string[])' will not be used as an entry point because a synchronous entry point 'A.Main()' was found.
// async static Task Main(string[] args)
Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("A.Main(string[])", "A.Main()").WithLocation(10, 23));
CompileAndVerify(compilation, expectedOutput: "Non Task Main", expectedReturnCode: 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void Main()
}
}
}";
var compilation = CompileAndVerify(source, expectedOutput: @"3", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release));
var compilation = CompileAndVerify(source, expectedOutput: @"3", options: TestOptions.ReleaseExe);

VerifyTypeIL(compilation, "Program", @"
.class public auto ansi abstract sealed beforefieldinit Program
Expand Down Expand Up @@ -126,7 +126,7 @@ public static void Main()
}
}
}";
var compilation = CompileAndVerify(source, expectedOutput: @"3", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug));
var compilation = CompileAndVerify(source, expectedOutput: @"3", options: TestOptions.DebugExe);

VerifyTypeIL(compilation, "Program", @"
.class public auto ansi abstract sealed beforefieldinit Program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9524,6 +9524,9 @@ public static async Task Main() {}
// (11,25): error CS8894: Cannot use 'Task' as a return type on a method attributed with 'UnmanagedCallersOnly'.
// public static async Task Main() {}
Diagnostic(ErrorCode.ERR_CannotUseManagedTypeInUnmanagedCallersOnly, "Task").WithArguments("System.Threading.Tasks.Task", "return").WithLocation(11, 25),
// (11,30): warning CS8892: Method 'D.Main()' will not be used as an entry point because a synchronous entry point 'C.Main()' was found.
// public static async Task Main() {}
Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("D.Main()", "C.Main()").WithLocation(11, 30),
// (11,30): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
// public static async Task Main() {}
Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(11, 30)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ .maxstack 1
}";
string expectedIL6 = expectedIL4;

CompileAndVerify(source, expectedOutput: expectedOutput).VerifyDiagnostics(
CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.ReleaseExe.WithWarningLevel(4)).VerifyDiagnostics(
// (21,16): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'short?'
// return new int?(N1()) == new short?();
Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "new int?(N1()) == new short?()").WithArguments("false", "int", "short?").WithLocation(21, 16),
Expand All @@ -1111,7 +1111,7 @@ .maxstack 1
// return ((S?)null) < new S?(N4());
Diagnostic(ErrorCode.WRN_CmpAlwaysFalse, "((S?)null) < new S?(N4())").WithArguments("S?").WithLocation(41, 16)
);
var comp = CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.ReleaseExe.WithWarningLevel(5));
var comp = CompileAndVerify(source, expectedOutput: expectedOutput);
comp.VerifyDiagnostics(
// (21,16): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'short?'
// return new int?(N1()) == new short?();
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27055,7 +27055,7 @@ public static string GetFromExternal()
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true));
var compilation = CreateCompilationWithMscorlib45(source, null, TestOptions.UnsafeDebugExe);
CompileAndVerify(compilation, expectedOutput:
"MessageType x MessageType").VerifyDiagnostics();
}
Expand Down
16 changes: 8 additions & 8 deletions src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3214,7 +3214,7 @@ public static void Main()
}
}";
var compilation = CreateCompilation(source,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.X86));
options: TestOptions.DebugDll.WithPlatform(Platform.X86));

var peHeaders = new PEHeaders(compilation.EmitToStream());

Expand Down Expand Up @@ -3248,7 +3248,7 @@ public static void Main()
}
}";
var compilation = CreateCompilation(source,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.X64));
options: TestOptions.DebugDll.WithPlatform(Platform.X64));

var peHeaders = new PEHeaders(compilation.EmitToStream());

Expand Down Expand Up @@ -3298,7 +3298,7 @@ public static void Main()
}
}";
var compilation = CreateCompilation(source,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.Arm));
options: TestOptions.DebugDll.WithPlatform(Platform.Arm));

var peHeaders = new PEHeaders(compilation.EmitToStream());

Expand Down Expand Up @@ -3429,7 +3429,7 @@ public static void Main()
{
}
}";
var compilation = CreateCompilation(source, options: new CSharpCompilationOptions(OutputKind.WindowsRuntimeApplication));
var compilation = CreateCompilation(source, options: TestOptions.CreateTestOptions(OutputKind.WindowsRuntimeApplication, OptimizationLevel.Debug));
var peHeaders = new PEHeaders(compilation.EmitToStream());

//interesting COFF bits
Expand Down Expand Up @@ -5247,15 +5247,15 @@ public void CompileAndVerifyModuleIncludesAllModules()
[WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")]
public void WarnAsErrorDoesNotEmit_GeneralDiagnosticOption()
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, generalDiagnosticOption: ReportDiagnostic.Error);
var options = TestOptions.DebugDll.WithGeneralDiagnosticOption(ReportDiagnostic.Error);
TestWarnAsErrorDoesNotEmitCore(options);
}

[Fact]
[WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")]
public void WarnAsErrorDoesNotEmit_SpecificDiagnosticOption()
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithSpecificDiagnosticOptions("CS0169", ReportDiagnostic.Error);
var options = TestOptions.DebugDll.WithSpecificDiagnosticOptions("CS0169", ReportDiagnostic.Error);
TestWarnAsErrorDoesNotEmitCore(options);
}

Expand Down Expand Up @@ -5292,15 +5292,15 @@ class X
[WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")]
public void WarnAsErrorWithMetadataOnlyImageDoesEmit_GeneralDiagnosticOption()
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, generalDiagnosticOption: ReportDiagnostic.Error);
var options = TestOptions.DebugDll.WithGeneralDiagnosticOption(ReportDiagnostic.Error);
TestWarnAsErrorWithMetadataOnlyImageDoesEmitCore(options);
}

[Fact]
[WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")]
public void WarnAsErrorWithMetadataOnlyImageDoesEmit_SpecificDiagnosticOptions()
{
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithSpecificDiagnosticOptions("CS0612", ReportDiagnostic.Error);
var options = TestOptions.DebugDll.WithSpecificDiagnosticOptions("CS0612", ReportDiagnostic.Error);
TestWarnAsErrorWithMetadataOnlyImageDoesEmitCore(options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void TestWriteOnlyStream()
var compilation = CSharpCompilation.Create("Program",
new[] { tree },
new[] { MetadataReference.CreateFromAssemblyInternal(typeof(object).Assembly) },
new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithDeterministic(true));
TestOptions.DebugExe.WithDeterministic(true));
var output = new WriteOnlyStream();
compilation.Emit(output);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void M2() {
var source = builder.ToString();
RunInThread(() =>
{
var options = new CSharpCompilationOptions(outputKind: OutputKind.DynamicallyLinkedLibrary, concurrentBuild: false);
var options = TestOptions.DebugDll.WithConcurrentBuild(false);
var compilation = CreateCompilation(source, options: options);
compilation.VerifyDiagnostics();
compilation.EmitToArray();
Expand Down
14 changes: 7 additions & 7 deletions src/Compilers/CSharp/Test/Semantic/FlowAnalysis/StructTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ public static void Main()
Diagnostic(ErrorCode.ERR_UseDefViolation, "v1").WithArguments("v1").WithLocation(9, 18)
);
CreateCompilation(source2,
options: TestOptions.ReleaseDll,
options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel),
references: new MetadataReference[] { sourceReference }).VerifyDiagnostics(
// (9,18): error CS0165: Use of unassigned local variable 'v1'
// var v2 = v1;
Diagnostic(ErrorCode.ERR_UseDefViolation, "v1").WithArguments("v1").WithLocation(9, 18)
);
CreateCompilation(source2,
options: TestOptions.ReleaseDll,
options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel),
references: new MetadataReference[] { metadataReference }).VerifyDiagnostics(
// (9,18): error CS0165: Use of unassigned local variable 'v1'
// var v2 = v1;
Expand Down Expand Up @@ -336,9 +336,9 @@ public static void Main()
var r2 = r1;
}
}";
CreateCompilation(source2, references: new MetadataReference[] { sourceReference }).VerifyDiagnostics(
CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(
);
CreateCompilation(source2, references: new MetadataReference[] { metadataReference }).VerifyDiagnostics(
CreateCompilation(source2, references: new MetadataReference[] { metadataReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(
);
CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics(
// (6,18): warning CS8829: Use of unassigned local variable 'r1'
Expand Down Expand Up @@ -381,9 +381,9 @@ public static void Main()
var r2 = r1;
}
}";
CreateCompilation(source2, references: new MetadataReference[] { sourceReference }).VerifyDiagnostics(
CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(
);
CreateCompilation(source2, references: new MetadataReference[] { metadataReference }).VerifyDiagnostics(
CreateCompilation(source2, references: new MetadataReference[] { metadataReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(
);
CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics(
// (6,18): warning CS8829: Use of unassigned local variable 'r1'
Expand Down Expand Up @@ -501,7 +501,7 @@ public static void Main()
var r2 = r1;
}
}";
CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics(
CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(
);
CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics(
// (6,18): warning CS8829: Use of unassigned local variable 'r1'
Expand Down
Loading

0 comments on commit b43d165

Please sign in to comment.