diff --git a/NuGet.Config b/NuGet.Config index fbfe5f6d92f2b..f2fccda461daf 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -29,5 +29,8 @@ + + + diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs index 6454e007c84c0..5e8a77dfe2b41 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs @@ -6296,7 +6296,7 @@ class X: Attribute { } "; - CompileAndVerify(source5, additionalRefs: new[] { comp1, comp2 }); + CompileAndVerify(source5, additionalRefs: new[] { comp1, comp2 }, verify: Verification.ClassLoadGeneral); // Multiple from PE, multiple from Source var source6 = @" diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs index 39ed75abd7c0d..93af62be4e1e2 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Assembly.cs @@ -297,7 +297,7 @@ public void MismatchedSurrogateInAssemblyCultureAttribute() string s = @"[assembly: System.Reflection.AssemblyCultureAttribute(""\uD800"")]"; var comp = CreateStandardCompilation(s, options: TestOptions.ReleaseDll); - CompileAndVerify(comp, verify: Verification.Fails, symbolValidator: m => + CompileAndVerify(comp, verify: Verification.InvalidLocale, symbolValidator: m => { var utf8 = new System.Text.UTF8Encoding(false, false); Assert.Equal(utf8.GetString(utf8.GetBytes("\uD800")), m.ContainingAssembly.Identity.CultureName); @@ -655,7 +655,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Fails, + CompileAndVerify(compilation, verify: Verification.Skipped, manifestResources: hash_resources, validator: (peAssembly) => { @@ -684,7 +684,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Fails, + CompileAndVerify(compilation, verify: Verification.Skipped, manifestResources: hash_resources, validator: (peAssembly) => { @@ -717,7 +717,7 @@ void M(Test x) {} } ", options: TestOptions.ReleaseDll, references: new[] { MscorlibRef_v4_0_30316_17626, hash_module }); - CompileAndVerify(compilation, verify: Verification.Fails, + CompileAndVerify(compilation, verify: Verification.Skipped, manifestResources: hash_resources, validator: (peAssembly) => { diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs index 32015e4e96af0..0a1810be6b5bc 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs @@ -959,7 +959,7 @@ public ref struct NotTypedReference { } }"; var compilation1 = CreateCompilation(source1, assemblyName: GetUniqueName()); - CompileAndVerify(compilation1, verify: Verification.Fails, symbolValidator: module => + CompileAndVerify(compilation1, verify: Verification.FailsPeVerify, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("System.TypedReference"); AssertReferencedIsByRefLikeAttributes(Accessibility.Internal, type, module.ContainingAssembly.Name, hasObsolete: false); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs index cab3e39500ef7..72e1fff3ff8cd 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_StructLayout.cs @@ -211,10 +211,10 @@ class Structs }; CompileAndVerify(verifiable, assemblyValidator: validator); - CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.Fails); + CompileAndVerify(unverifiable, assemblyValidator: validator, verify: Verification.ClassLayout); // CLR limitation on type size, not a RefEmit bug: - CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.Fails); + CompileAndVerify(unloadable, assemblyValidator: validator, verify: Verification.ClassLayout); } [Fact] @@ -332,7 +332,7 @@ public class C : B } "; // type C can't be loaded - CompileAndVerify(source, verify: Verification.Fails); + CompileAndVerify(source, verify: Verification.TypeLoadFailed); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs index 4f7194840c021..198a4f88f1bb2 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs @@ -3539,7 +3539,7 @@ public static int Main () // the resulting code does not need to verify // This is consistent with Dev10 behavior - CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.Fails, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); + CompileAndVerify(source, options: TestOptions.ReleaseDll, verify: Verification.UnableToResolveToken, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator); } [Fact, WorkItem(544507, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544507")] @@ -5341,7 +5341,7 @@ public static void Main() {} // Dev10 Runtime Exception: // Unhandled Exception: System.TypeLoadException: Windows Runtime types can only be declared in Windows Runtime assemblies. - var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.Fails); + var verifier = CompileAndVerify(source, sourceSymbolValidator: sourceValidator, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); } #endregion diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index d2aa591f1ce08..f16c5a4816c98 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -1086,7 +1086,7 @@ public static void Main() .WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile) .WithStrongNameProvider(s_defaultDesktopProvider)); - CompileAndVerify(comp2, expectedOutput: "Called M"); + CompileAndVerify(comp2, expectedOutput: "Called M", verify: Verification.Passes); Assert.Equal(TestResources.General.snMaxSizePublicKey, comp2.Assembly.Identity.PublicKey); Assert.Equal(pubKeyTokenBytes, comp2.Assembly.Identity.PublicKeyToken); @@ -1097,7 +1097,7 @@ public static void Main() .WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile) .WithStrongNameProvider(s_defaultDesktopProvider)); - CompileAndVerify(comp3, expectedOutput: "Called M"); + CompileAndVerify(comp3, expectedOutput: "Called M", verify: Verification.Passes); Assert.Equal(TestResources.General.snMaxSizePublicKey, comp3.Assembly.Identity.PublicKey); Assert.Equal(pubKeyTokenBytes, comp3.Assembly.Identity.PublicKeyToken); } @@ -2391,7 +2391,7 @@ static void Main() CompileAndVerify(ca); var cb = CreateStandardCompilation(sourceB, options: TestOptions.ReleaseExe, assemblyName: "X", references: new[] { new CSharpCompilationReference(ca) }); - CompileAndVerify(cb, expectedOutput: "42").Diagnostics.Verify(); + CompileAndVerify(cb, expectedOutput: "42", verify: Verification.Passes).Diagnostics.Verify(); } [Fact, WorkItem(1072339, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1072339")] @@ -2417,7 +2417,7 @@ static void Main() CompileAndVerify(ca); var cb = CreateStandardCompilation(sourceB, options: TestOptions.ReleaseExe, assemblyName: "X", references: new[] { new CSharpCompilationReference(ca) }); - CompileAndVerify(cb, expectedOutput: "42").Diagnostics.Verify(); + CompileAndVerify(cb, expectedOutput: "42", verify: Verification.IVT).Diagnostics.Verify(); } [Fact, WorkItem(1095618, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095618")] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs index bd67211613e97..c3e0023ad97f3 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs @@ -21,10 +21,10 @@ public CodeGenAsyncEHTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) { references = (references != null) ? references.Concat(s_asyncRefs) : s_asyncRefs; - return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: references, options: options); + return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: references, options: options, verify: verify); } [Fact] @@ -936,7 +936,8 @@ public static void Main() var expected = @" 2 "; - var v = CompileAndVerify(source, s_asyncRefs, options: TestOptions.DebugExe.WithMetadataImportOptions(MetadataImportOptions.All), expectedOutput: expected, symbolValidator: module => + var v = CompileAndVerify(source, s_asyncRefs, options: TestOptions.DebugExe.WithMetadataImportOptions(MetadataImportOptions.All), + expectedOutput: expected, symbolValidator: module => { Assert.Equal(new[] { @@ -1841,7 +1842,7 @@ public static void Main() hello 2 "; - CompileAndVerify(source, expectedOutput: expected); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.LeaveIntoTry); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncLocalsTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncLocalsTests.cs index b7e80504ea4ec..fd63cbd3d723b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncLocalsTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncLocalsTests.cs @@ -21,10 +21,10 @@ public CodeGenAsyncLocalsTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) { references = (references != null) ? references.Concat(s_asyncRefs) : s_asyncRefs; - return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: references, options: options); + return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: references, options: options, verify: verify); } private string GetFieldLoadsAndStores(CompilationVerifier c, string qualifiedMethodName) @@ -231,7 +231,8 @@ public static async Task M(int x, int y, int z) y = 1; } }"; - CompileAndVerify(source, additionalRefs: s_asyncRefs, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => + CompileAndVerify(source, additionalRefs: s_asyncRefs, + options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { AssertEx.Equal(new[] { @@ -244,7 +245,8 @@ public static async Task M(int x, int y, int z) }, module.GetFieldNames("C.d__1")); }); - CompileAndVerify(source, additionalRefs: s_asyncRefs, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => + CompileAndVerify(source, additionalRefs: s_asyncRefs, + options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { AssertEx.Equal(new[] { @@ -283,7 +285,8 @@ public async Task M(IDisposable disposable) lock (this) { } } }"; - CompileAndVerify(source, s_asyncRefs, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => + CompileAndVerify(source, s_asyncRefs, + options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { AssertEx.Equal(new[] { @@ -301,7 +304,8 @@ public async Task M(IDisposable disposable) }, module.GetFieldNames("C.d__3")); }); - var vd = CompileAndVerify(source, s_asyncRefs, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => + var vd = CompileAndVerify(source, s_asyncRefs, + options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { AssertEx.Equal(new[] { @@ -1239,7 +1243,8 @@ public async Task F() var b8 = await Task.FromResult(default(Tuple)); } }"; - CompileAndVerify(source, additionalRefs: s_asyncRefs, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => + CompileAndVerify(source, additionalRefs: s_asyncRefs, + options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { AssertEx.Equal(new[] { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs index 12e0205e37dde..d6b9e84c30cb7 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncSpillTests.cs @@ -21,10 +21,10 @@ public CodeGenAsyncSpillTests() { } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes) { references = (references != null) ? references.Concat(s_asyncRefs) : s_asyncRefs; - return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: references, options: options); + return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: references, options: options, verify: verify); } [Fact] @@ -967,7 +967,7 @@ public static async Task F(int[] array) }, module.GetFieldNames("C.d__3")); }); - CompileAndVerify(source, additionalRefs: s_asyncRefs, verify: Verification.Passes, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => + CompileAndVerify(source, additionalRefs: s_asyncRefs, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { AssertEx.Equal(new[] { @@ -2490,7 +2490,7 @@ public static void Main() 2 0 "; - CompileAndVerify(source, expectedOutput: expected); + CompileAndVerify(source, expectedOutput: expected, verify: Verification.RuntimeArgumentHandle); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs index f06489bad8b79..7290319510fc8 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs @@ -92,11 +92,11 @@ public void Deconstruct(out int a, out string b) var lhs = tree.GetRoot().DescendantNodes().OfType().First(); Assert.Equal(@"(x, y)", lhs.ToString()); Assert.Equal("(System.Int64 x, System.String y)", model.GetTypeInfo(lhs).Type.ToTestDisplayString()); + Assert.Equal("(System.Int64 x, System.String y)", model.GetTypeInfo(lhs).ConvertedType.ToTestDisplayString()); var right = tree.GetRoot().DescendantNodes().OfType().Single(); Assert.Equal(@"new C()", right.ToString()); Assert.Equal("C", model.GetTypeInfo(right).Type.ToTestDisplayString()); - Assert.Equal("C", model.GetTypeInfo(right).ConvertedType.ToTestDisplayString()); Assert.Equal(ConversionKind.Identity, model.GetConversion(right).Kind); }; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs index d397e64f66610..13ef2ad5194d2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs @@ -28,7 +28,8 @@ private CompilationVerifier CompileAndVerifyIL( bool allowUnsafe = false, [CallerFilePath]string callerPath = null, [CallerLineNumber]int callerLine = 0, - CSharpParseOptions parseOptions = null) + CSharpParseOptions parseOptions = null, + Verification verify = Verification.Passes) { references = references ?? new[] { SystemCoreRef, CSharpRef }; @@ -36,8 +37,8 @@ private CompilationVerifier CompileAndVerifyIL( var unoptimizedCompilation = CreateCompilationWithMscorlib45(source, references, parseOptions: parseOptions, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All).WithAllowUnsafe(allowUnsafe)); var optimizedCompilation = CreateCompilationWithMscorlib45(source, references, parseOptions: parseOptions, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All).WithAllowUnsafe(allowUnsafe)); - var unoptimizedVerifier = CompileAndVerify(unoptimizedCompilation); - var optimizedVerifier = CompileAndVerify(optimizedCompilation); + var unoptimizedVerifier = CompileAndVerify(unoptimizedCompilation, verify: verify); + var optimizedVerifier = CompileAndVerify(optimizedCompilation, verify: verify); // check what IL we emit exactly: if (expectedUnoptimizedIL != null) @@ -9550,7 +9551,7 @@ .locals init (int V_0, //a IL_0066: callvirt ""void <>A{00000002}.Invoke(System.Runtime.CompilerServices.CallSite, ref int, object)"" IL_006b: ret } -"); +", verify: Verification.TypedReference); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs index d56ba267265fd..ab99b9cf3406d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIncrementTests.cs @@ -3,6 +3,7 @@ using System; using System.Globalization; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; @@ -1028,7 +1029,7 @@ public static void Main() } } "; - base.CompileAndVerify(source, expectedOutput: "12"). + base.CompileAndVerify(source, verify: Verification.TypedReference, expectedOutput: "12"). VerifyIL("Test.Main", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs index 98e2cda53e5bd..d4f372154ee8c 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs @@ -2382,7 +2382,7 @@ public System.Collections.IEnumerable SomeNumbers() }"; // The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available. var compilation = CreateCompilation(new[] { Parse(source), Parse(corlib) }); - var verifier = CompileAndVerify(compilation, verify: Verification.Fails); + var verifier = CompileAndVerify(compilation, verify: Verification.TypeLoadFailed); verifier.VerifyDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs index 18d4e70f7b86c..d29e07c66beee 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOverridingAndHiding.cs @@ -2452,7 +2452,7 @@ public static void Main() // from assembly 'Dev10, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' // is overriding a method that is not visible from that assembly. - CompileAndVerify(outerCompilation, verify: Verification.Fails).VerifyIL("Test.Main", @" + CompileAndVerify(outerCompilation, verify: Verification.UnableToResolveToken).VerifyIL("Test.Main", @" { // Code size 65 (0x41) .maxstack 4 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs index 28c3a3ad59ab0..ef83b62ba655a 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenScriptTests.cs @@ -552,7 +552,7 @@ public void SubmissionEntryPoint() "s0.dll", SyntaxFactory.ParseSyntaxTree(source0, options: TestOptions.Script), references); - var verifier = CompileAndVerify(s0, verify: Verification.Fails); + var verifier = CompileAndVerify(s0, verify: Verification.BadName); var methodData = verifier.TestData.GetMethodData(""); Assert.Equal("System.Threading.Tasks.Task", methodData.Method.ReturnType.ToDisplayString()); methodData.VerifyIL( diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index 5bff14e6df103..cdd8d41158cd2 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -1277,7 +1277,7 @@ public static void Main() } "; - var compilation = CompileAndVerify(source, expectedOutput: "11"); + var compilation = CompileAndVerify(source, expectedOutput: "11", verify: Verification.InvalidProgramVararg); compilation.VerifyIL("D.Main", @" diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index ff2b2c17a5596..26fd83ae8020e 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -4326,7 +4326,7 @@ public static void M() Callee3(default(T), default(T)); } } -", verify: Verification.Fails, options: TestOptions.ReleaseExe); +", verify: Verification.TypeDevNotNil, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 297 (0x129) @@ -4459,7 +4459,7 @@ public static void M() Callee3(); } } -", verify: Verification.Fails, options: TestOptions.ReleaseExe); +", verify: Verification.TypeDevNotNil, options: TestOptions.ReleaseExe); verifier.VerifyIL("Program.M()", @"{ // Code size 34 (0x22) @@ -5140,7 +5140,7 @@ static void Test(in object r) } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"hi", verify: Verification.Fails); + var compilation = CompileAndVerify(source, expectedOutput: @"hi", verify: Verification.UnexpectedTypeOnStack); compilation.VerifyIL("Program.Main(string[])", @" @@ -5226,7 +5226,7 @@ static void Test(in T r) } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.Fails); + var compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.UnexpectedTypeOnStack); var expectedIL = @" { @@ -5247,7 +5247,7 @@ .maxstack 2 compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); // expect the same IL in the compat case since direct references are required and must be emitted with "readonly.", even though unverifiable - compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.Fails, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); + compilation = CompileAndVerify(source, expectedOutput: @"hihi", verify: Verification.UnexpectedTypeOnStack, parseOptions: TestOptions.Regular.WithPEVerifyCompatFeature()); compilation.VerifyIL("Program.GetElementRef(T[])", expectedIL); } @@ -10423,7 +10423,7 @@ static void Main() Diagnostic(ErrorCode.WRN_ExternMethodNoImplementation, "Goo").WithArguments("Test.Goo()")); // NOTE: the resulting IL is unverifiable, but not an error for compat reasons - CompileAndVerify(comp, verify: Verification.Fails).VerifyIL("Test.Main", + CompileAndVerify(comp, verify: Verification.TypeLoadFailed).VerifyIL("Test.Main", @" { // Code size 11 (0xb) @@ -13267,6 +13267,7 @@ private void PrintArgList(ArgIterator args) "; var compilation = CompileAndVerify( source, + verify: Verification.InvalidProgramVararg, expectedOutput: @"Inside - TestVarArgs::ctor (__arglist) Inside - TestVarArgs::ctor (__arglist) System.Int32 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index eb6c4ed58b9b5..4126fa0ec6ae6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Linq; using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; using System.Text; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -2786,7 +2787,7 @@ public static async Task Test(T a) } " + trivial2uple + trivial3uple + trivialRemainingTuples + tupleattributes_cs; - CompileAndVerify(source, expectedOutput: @"42", additionalRefs: new[] { MscorlibRef_v46 }, options: TestOptions.ReleaseExe); + CompileAndVerify(source, expectedOutput: @"42", additionalRefs: new[] { MscorlibRef_v46 }, verify: Verification.Passes, options: TestOptions.ReleaseExe); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs index 356542f0ed7be..d911cfc5e43f9 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/DestructorTests.cs @@ -694,7 +694,7 @@ public class B : A Diagnostic(ErrorCode.WRN_FinalizeMethod, "Finalize")); // We produce unverifiable code here as per bug resolution (compat concerns, not common case). - CompileAndVerify(compilation, verify: Verification.Fails).VerifyIL("B.Finalize", + CompileAndVerify(compilation, verify: Verification.TypeLoadFailed).VerifyIL("B.Finalize", @" { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs index f625b31cae15a..703d4679c5167 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/UnsafeTests.cs @@ -8714,7 +8714,7 @@ public static void Main() } } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails).VerifyDiagnostics(); + CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Passes).VerifyDiagnostics(); } [WorkItem(545026, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545026")] @@ -8728,7 +8728,7 @@ class C unsafe int* p = (int*)2; } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).VerifyDiagnostics( // (4,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); @@ -8745,7 +8745,7 @@ class C int x = 1; } "; - CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyDiagnostics( + CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).VerifyDiagnostics( // (5,9): warning CS0414: The field 'C.x' is assigned but its value is never used // int x = 1; Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "x").WithArguments("C.x")); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 8309dfd57d10d..cb0c75e560f9d 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -4492,7 +4492,7 @@ public void Bug769741() { var comp = CreateCompilation("", new[] { TestReferences.SymbolsTests.netModule.x64COFF }, options: TestOptions.DebugDll); // modules not supported in ref emit - CompileAndVerify(comp, verify: Verification.Fails); + CompileAndVerify(comp, verify: Verification.BadFormat); Assert.NotSame(comp.Assembly.CorLibrary, comp.Assembly); comp.GetSpecialType(SpecialType.System_Int32); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs index 58d63291b64f7..6fce937f19c7b 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs @@ -3211,9 +3211,12 @@ private static void AssertInstrumented(CompilationVerifier verifier, string qual Assert.True(expected == instrumented, $"Method '{qualifiedMethodName}' should {(expected ? "be" : "not be")} instrumented. Actual IL:{Environment.NewLine}{il}"); } - private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, CompilationOptions options = null) + private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, CompilationOptions options = null, Verification verify = Verification.Passes) { - return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: s_refs, options: (options ?? TestOptions.ReleaseExe).WithDeterministic(true), emitOptions: EmitOptions.Default.WithInstrumentationKinds(ImmutableArray.Create(InstrumentationKind.TestCoverage))); + return base.CompileAndVerify(source, expectedOutput: expectedOutput, additionalRefs: s_refs, + options: (options ?? TestOptions.ReleaseExe).WithDeterministic(true), + emitOptions: EmitOptions.Default.WithInstrumentationKinds(ImmutableArray.Create(InstrumentationKind.TestCoverage)), + verify: verify); } private CompilationVerifier CompileAndVerify((string Path, string Content)[] sources, string expectedOutput = null, CSharpCompilationOptions options = null) diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs index 938d6edc5bdf1..fddfb87ee1e0a 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/AssemblyReferencesTests.cs @@ -473,7 +473,7 @@ class C var compilation0 = CreateCompilation(src0, new[] { MscorlibRef, ref01, ref11 }, assemblyName: "C", options: TestOptions.DebugDll); var compilation1 = compilation0.WithSource(src1).WithReferences(new[] { MscorlibRef, ref02, ref12 }); - var v0 = CompileAndVerify(compilation0); + var v0 = CompileAndVerify(compilation0, verify: Verification.FullNames); var f0 = compilation0.GetMember("C.F"); var f1 = compilation1.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs index 0318a24d7f518..24f3fb07f10ee 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs @@ -4981,7 +4981,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); @@ -5040,7 +5040,7 @@ public async Task F() // older versions of mscorlib don't contain IteratorStateMachineAttribute Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5104,7 +5104,7 @@ public async Task F() Assert.NotNull(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); v0.VerifyDiagnostics(); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); @@ -5205,7 +5205,7 @@ public async Task F() Assert.Null(compilation0.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor)); - var v0 = CompileAndVerify(compilation0, verify: Verification.Fails); + var v0 = CompileAndVerify(compilation0, verify: Verification.TypeLoadFailed); var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData); var f0 = compilation0.GetMember("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs index 2446af63d1744..912c00a32d1f0 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EmitMetadataTests.cs @@ -174,7 +174,7 @@ public class Test : Class2 { } "; - CompileAndVerify(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, assemblyValidator: (assembly) => + CompileAndVerify(sources, new[] { TestReferences.SymbolsTests.MultiModule.Assembly }, verify: Verification.NotImplemented, assemblyValidator: (assembly) => { var refs2 = assembly.Modules[0].ReferencedAssemblies.Select(r => r.Name); Assert.Equal(2, refs2.Count()); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs index c13542c01e4c5..67d7aba32cad3 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs @@ -1649,12 +1649,12 @@ .maxstack 2 } "; - var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator); + var verifier = CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.InvalidProgramVararg); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); - verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator); + verifier = CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.InvalidProgramVararg); verifier.VerifyIL("UsePia4.M5", expected_M5); verifier.VerifyIL("UsePia4.M6", expected_M6); @@ -1763,9 +1763,9 @@ interface UsePia5 : ITest29 Assert.Equal(VarianceKind.None, t7.Variance); }; - CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.Fails); + CompileAndVerify(compilation1, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); - CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.Fails); + CompileAndVerify(compilation2, symbolValidator: metadataValidator, verify: Verification.TypeLoadFailed); } [Fact] @@ -4692,11 +4692,11 @@ public void M1() var compilation3 = CreateStandardCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.Fails); + CompileAndVerify(compilation3, verify: Verification.TypeLoadFailed); var compilation4 = CreateStandardCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.Fails); + CompileAndVerify(compilation4, verify: Verification.TypeLoadFailed); } [Fact] @@ -5169,11 +5169,11 @@ public void M1() var compilation3 = CreateStandardCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { new CSharpCompilationReference(piaCompilation2) }); - CompileAndVerify(compilation3, verify: Verification.Fails); + CompileAndVerify(compilation3, verify: Verification.TypeLoadFailed); var compilation4 = CreateStandardCompilation(consumer, options: TestOptions.DebugExe, references: new MetadataReference[] { MetadataReference.CreateFromStream(piaCompilation2.EmitToStream()) }); - CompileAndVerify(compilation4, verify: Verification.Fails); + CompileAndVerify(compilation4, verify: Verification.TypeLoadFailed); } [Fact, WorkItem(611578, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/611578")] @@ -5390,7 +5390,7 @@ static string MyEvent02Handler(string arg) { var app_compilation = CreateStandardCompilation(App_cs, new[] { NetImpl_ref, IEvent_ref, CSharpRef, SystemCoreRef }, options: TestOptions.ReleaseExe, assemblyName: "App"); - CompileAndVerify(app_compilation, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, + CompileAndVerify(app_compilation, verify: Verification.NoPia, symbolValidator: IEvent_ref.Properties.EmbedInteropTypes ? metadataValidator : null, expectedOutput: @"E01 E02"); } diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index 9fd04e97f295b..7fbde554f3035 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -1962,7 +1962,8 @@ public static async void Test() } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[]{ MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[]{ MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { @@ -2158,7 +2159,8 @@ public static async void Test() } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { @@ -2290,7 +2292,8 @@ public static async void Test() } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { @@ -7908,7 +7911,8 @@ public static async void Test() } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { @@ -7987,7 +7991,8 @@ public static async void Test() } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { @@ -8068,7 +8073,8 @@ public static async void Test() } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { @@ -8160,7 +8166,8 @@ public static async void Test() public static int M(out int x) { x = 0; return 0; } } "; - var v = CompileAndVerify(source, options: TestOptions.DebugDll, additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); + var v = CompileAndVerify(source, options: TestOptions.DebugDll, + additionalRefs: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef, CSharpRef }); v.VerifyIL("Program.d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()", @" { diff --git a/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs b/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs index f4682b994f424..2ce0a16522f6b 100644 --- a/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs @@ -22,6 +22,51 @@ private CompilationUnitSyntax ParseFile(string text) return SyntaxFactory.ParseCompilationUnit(text); } + [Fact] + public void TestILVerify() + { + var source = +@" +class Program +{ + static void Main() + { + var obj = new C1(); + System.Console.WriteLine(obj.field.ToString()); + } +} + +class C1 +{ + public readonly S1 field; +} + +struct S1 +{ +} +"; + CompileAndVerify(source); + // PEVerify catches the problem, but not ILVerify + } + + [Fact] + public void TestILVerify2() + { + var source = +@" +unsafe class C +{ + public int* M(int* x) + { + return x; + } +} +"; + CompileAndVerify(source, options: TestOptions.UnsafeDebugDll); + // IlVerify failed for assembly '17962445-862f-4904-8dd9-9625c43bc81d': + // [IL]: Error: [17962445-862f-4904-8dd9-9625c43bc81d : C::M([mscorlib]System.Int32*)][offset 0x00000001] Unmanaged pointers are not a verifiable type. + } + [Fact] public void TestSimpleDeclarations() { diff --git a/src/Test/Utilities/Portable/CommonTestBase.cs b/src/Test/Utilities/Portable/CommonTestBase.cs index 060eafcd1f907..f6fe9ec8c9ce7 100644 --- a/src/Test/Utilities/Portable/CommonTestBase.cs +++ b/src/Test/Utilities/Portable/CommonTestBase.cs @@ -22,11 +22,37 @@ namespace Microsoft.CodeAnalysis.Test.Utilities { + [Flags] public enum Verification { - Passes = 0, - Fails, - Skipped + Skipped = 0, + + PassesPeVerify = 1 << 0, + PassesIlVerify = 1 << 1, + FailsPeVerify = 1 << 2, + FailsIlVerify = 1 << 3, + + Passes = PassesPeVerify | PassesIlVerify, + Fails = FailsPeVerify | FailsIlVerify, + + IVT = PassesPeVerify | FailsIlVerify, // ILVerify is case-sensitive in IVT + FullNames = PassesPeVerify, // ILVerify uses simple names instead of full names + TypedReference = PassesPeVerify | FailsIlVerify, // ILVerify doesn't support TypedReference + InvalidProgramVararg = PassesPeVerify | FailsIlVerify, // ILVerify complains about InvalidProgramVararg + ClassLoadGeneral = PassesPeVerify | FailsIlVerify, // ILVerify complains about ClassLoadGeneral + NotImplemented = PassesPeVerify | FailsIlVerify, // ILVerify has some un-implemented cases in EcmaModule.GetType + NoPia = PassesPeVerify | FailsIlVerify, // ILVerify doesn't do NoPia unification + RuntimeArgumentHandle = PassesPeVerify | FailsIlVerify, // ILVerify reports: RuntimeArgumentHandle not supported in .NET Core + LeaveIntoTry = PassesPeVerify | FailsIlVerify, // ILVerify reports: Leave into try block. + + TypeLoadFailed = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain type load failed + UnexpectedTypeOnStack = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: Unexpected type on the stack. + InvalidLocale = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about invalid locale string + UnableToResolveToken = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about "unable to resolve token" + TypeDevNotNil = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: TypeDef for Object class extends token=0x01000005 which is not nil. + ClassLayout = FailsPeVerify | PassesIlVerify, // ILVerify doesn't complain about: ClassLayout has parent TypeDef token=0x0200000f marked AutoLayout. + BadName = FailsPeVerify | PassesIlVerify, // PEVerify complains about: Assembly name contains leading spaces or path or extension. + BadFormat = FailsPeVerify | PassesIlVerify, // PEVerify complains about: An attempt was made to load a program with an incorrect format. } /// diff --git a/src/Test/Utilities/Portable/Compilation/Exceptions.cs b/src/Test/Utilities/Portable/Compilation/Exceptions.cs index b25aea985e436..dd8047150306a 100644 --- a/src/Test/Utilities/Portable/Compilation/Exceptions.cs +++ b/src/Test/Utilities/Portable/Compilation/Exceptions.cs @@ -25,6 +25,12 @@ public PeVerifyException(string output, string exePath) } + public class IlVerifyException : Exception + { + public IlVerifyException(string output, string assemblyName) + : base(GetMessageFromResult(output, assemblyName, isIlVerify: true)) { } + } + public class ExecutionException : Exception { public ExecutionException(string expectedOutput, string actualOutput, string exePath) diff --git a/src/Test/Utilities/Portable/Compilation/IRuntimeEnvironment.cs b/src/Test/Utilities/Portable/Compilation/IRuntimeEnvironment.cs index 144c8c7b86610..b5ac180f32e34 100644 --- a/src/Test/Utilities/Portable/Compilation/IRuntimeEnvironment.cs +++ b/src/Test/Utilities/Portable/Compilation/IRuntimeEnvironment.cs @@ -348,6 +348,7 @@ public interface IRuntimeEnvironment : IDisposable ImmutableArray GetDiagnostics(); SortedSet GetMemberSignaturesFromMetadata(string fullyQualifiedTypeName, string memberName); IList GetAllModuleData(); + void IlVerify(); void PeVerify(); string[] PeVerifyModules(string[] modulesToVerify, bool throwOnError = true); void CaptureOutput(Action action, int expectedLength, out string output, out string errorOutput); diff --git a/src/Test/Utilities/Portable/CompilationVerifier.cs b/src/Test/Utilities/Portable/CompilationVerifier.cs index 72d47d8820504..87b071882c957 100644 --- a/src/Test/Utilities/Portable/CompilationVerifier.cs +++ b/src/Test/Utilities/Portable/CompilationVerifier.cs @@ -73,15 +73,24 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions); _allModuleData = testEnvironment.GetAllModuleData(); - if (peVerify == Verification.Passes) + if ((peVerify & Verification.PassesPeVerify) != 0) { testEnvironment.PeVerify(); } - else if (peVerify == Verification.Fails) + else if ((peVerify & Verification.FailsPeVerify) != 0) { Assert.Throws(() => testEnvironment.PeVerify()); } + if ((peVerify & Verification.PassesIlVerify) != 0) + { + testEnvironment.IlVerify(); + } + else if ((peVerify & Verification.FailsIlVerify) != 0) + { + Assert.Throws(() => testEnvironment.IlVerify()); + } + if (expectedSignatures != null) { MetadataSignatureUnitTestHelper.VerifyMemberSignatures(testEnvironment, expectedSignatures); diff --git a/src/Test/Utilities/Portable/ExceptionHelper.cs b/src/Test/Utilities/Portable/ExceptionHelper.cs index 4c6c768dd87d1..a0e5f725d30b9 100644 --- a/src/Test/Utilities/Portable/ExceptionHelper.cs +++ b/src/Test/Utilities/Portable/ExceptionHelper.cs @@ -21,11 +21,12 @@ internal static string GetMessageFromResult(IEnumerable diagnostics, return sb.ToString(); } - internal static string GetMessageFromResult(string output, string exePath) + internal static string GetMessageFromResult(string output, string exePath, bool isIlVerify = false) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); - sb.Append("PeVerify failed for assembly '"); + string tool = isIlVerify ? "IlVerify" : "PeVerify"; + sb.Append($"{tool} failed for assembly '"); sb.Append(exePath); sb.AppendLine("':"); sb.AppendLine(output); diff --git a/src/Test/Utilities/Portable/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs b/src/Test/Utilities/Portable/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs index 9cab04fc6e22d..237f6db90c7d8 100644 --- a/src/Test/Utilities/Portable/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs +++ b/src/Test/Utilities/Portable/Platform/CoreClr/CoreCLRRuntimeEnvironment.cs @@ -99,6 +99,11 @@ public SortedSet GetMemberSignaturesFromMetadata(string fullyQualifiedTy throw new NotImplementedException(); } + public void IlVerify() + { + throw new NotImplementedException(); + } + public void PeVerify() { var emitData = GetEmitData(); diff --git a/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs b/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs index ef3d30189d883..0ab36d5115ed5 100644 --- a/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs +++ b/src/Test/Utilities/Portable/Platform/Desktop/DesktopRuntimeEnvironment.cs @@ -5,17 +5,20 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Reflection.PortableExecutable; using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.Emit; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Roslyn.Utilities; -using static Roslyn.Test.Utilities.RuntimeUtilities; +using static Roslyn.Test.Utilities.RuntimeUtilities; namespace Roslyn.Test.Utilities.Desktop { @@ -237,7 +240,7 @@ public int Execute(string moduleName, string[] args, string expectedOutput) { var emitData = GetEmitData(); emitData.RuntimeData.ExecuteRequested = true; - var resultCode = emitData.Manager.Execute(moduleName, args, expectedOutput?.Length, out var output); + var resultCode = emitData.Manager.Execute(moduleName, args, expectedOutputLength: expectedOutput?.Length, out var output); if (expectedOutput != null && expectedOutput.Trim() != output.Trim()) { @@ -289,11 +292,62 @@ public IList GetAllModuleData() return GetEmitData().AllModuleData; } +#if NET461 + private class Resolver : ILVerify.ResolverBase + { + private Dictionary> imagesByName = new Dictionary>(); + + internal Resolver(EmitData emitData) + { + foreach (var module in emitData.AllModuleData) + { + string name = module.SimpleName; + + var image = name == "mscorlib" + ? TestResources.NetFX.v4_6_1038_0.mscorlib.AsImmutable() + : module.Image; + + imagesByName.Add(name, image); + } + } + + protected override PEReader ResolveCore(AssemblyName name) + { + if (imagesByName.TryGetValue(name.Name, out var image)) + { + return new PEReader(image); + } + + return null; + } + } +#endif + + public void IlVerify() + { +#if NET461 + var emitData = GetEmitData(); + + var resolver = new Resolver(emitData); + var verifier = new ILVerify.Verifier(resolver); + if (emitData.AllModuleData.Any(m => m.SimpleName == "mscorlib")) + { + verifier.SetSystemModuleName(new AssemblyName("mscorlib")); + } + + var result = verifier.Verify(resolver.Resolve(new AssemblyName(emitData.MainModule.FullName))); + if (result.Count() > 0) + { + throw new IlVerifyException("ILVerify error PROTOTYPE(ILVerify)", emitData.MainModule.SimpleName); + } +#endif + } + public void PeVerify() { + var emitData = GetEmitData(); try { - var emitData = GetEmitData(); emitData.RuntimeData.PeverifyRequested = true; emitData.Manager.PeVerifyModules(new[] { emitData.MainModule.FullName }); } diff --git a/src/Test/Utilities/Portable/TestUtilities.csproj b/src/Test/Utilities/Portable/TestUtilities.csproj index 82bb32e51fe63..061b09a55d670 100644 --- a/src/Test/Utilities/Portable/TestUtilities.csproj +++ b/src/Test/Utilities/Portable/TestUtilities.csproj @@ -112,6 +112,7 @@ +