提交 6efa39ed 编写于 作者: V vsadov

Do not autodisable verification based on unsafe compilation option.

上级 1d28ff9b
......@@ -98,7 +98,7 @@ public void TestCompileDynamicAttributes()
{
var comp = CreateCompilationWithMscorlibAndSystemCore(s_dynamicTestSource, options: TestOptions.UnsafeReleaseDll, references: new[] { SystemCoreRef, ValueTupleRef, SystemRuntimeFacadeRef });
CompileAndVerify(comp, symbolValidator: module =>
CompileAndVerify(comp, verify: Verification.Passes, symbolValidator: module =>
{
DynamicAttributeValidator.ValidateDynamicAttributes(module);
});
......
......@@ -1214,7 +1214,7 @@ public class C
}
";
var compilation = CreateStandardCompilation(source, options: TestOptions.UnsafeReleaseDll);
CompileAndVerify(compilation, symbolValidator: module =>
CompileAndVerify(compilation, verify: Verification.Passes,symbolValidator: module =>
{
ValidateDeclSecurity(module, new DeclSecurityEntry
{
......@@ -1294,7 +1294,7 @@ public class C
";
var compilation = CreateStandardCompilation(source, options: TestOptions.UnsafeReleaseDll);
CompileAndVerify(compilation, symbolValidator: module =>
CompileAndVerify(compilation, verify: Verification.Passes, symbolValidator: module =>
{
ValidateDeclSecurity(module, new DeclSecurityEntry
{
......
......@@ -1185,7 +1185,8 @@ public static void Main()
optimizationLevel: OptimizationLevel.Release,
allowUnsafe: true));
CompileAndVerify(compilation, symbolValidator: module =>
//Skipped because PeVerify fails to run with "The module was expected to contain an assembly manifest."
CompileAndVerify(compilation, verify: Verification.Skipped, symbolValidator: module =>
{
var unverifiableCode = module.GetAttributes().Single();
......@@ -1198,7 +1199,7 @@ public static void Main()
{
// Modules security attributes are copied to assemblies they're included in
var moduleReference = ModuleMetadata.CreateFromImage(compilation.EmitToArray()).GetReference();
CompileAndVerify("", additionalRefs: new[] { moduleReference }, symbolValidator: validateSecurity);
CompileAndVerify("", additionalRefs: new[] { moduleReference }, symbolValidator: validateSecurity, verify: Verification.Skipped);
}
else
{
......
......@@ -113,7 +113,7 @@ public void TestTupleAttributes()
options: TestOptions.UnsafeReleaseDll,
references: s_attributeRefs);
CompileAndVerify(comp, symbolValidator: module =>
CompileAndVerify(comp, verify: Verification.Passes, symbolValidator: module =>
{
TupleAttributeValidator.ValidateTupleAttributes(module);
});
......@@ -230,6 +230,7 @@ public void RoundTrip()
CompileAndVerify(s_tuplesTestSource,
options: TestOptions.UnsafeReleaseDll,
additionalRefs: s_attributeRefs,
verify: Verification.Passes,
sourceSymbolValidator: m => sourceModule = m,
symbolValidator: m => peModule = m);
......
......@@ -21,10 +21,10 @@ public CodeGenAsyncLocalsTests()
{
}
private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable<MetadataReference> references = null, CSharpCompilationOptions options = null)
private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null, IEnumerable<MetadataReference> 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)
......@@ -1293,7 +1293,7 @@ static void Main()
Console.Write(i);
}
}";
var verifier = CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: @"1");
var verifier = CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: @"1", verify: Verification.Fails);
verifier.VerifyIL("C.<F>d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()",
@"
{
......@@ -1398,7 +1398,7 @@ .maxstack 3
IL_00c0: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder<int>.SetResult(int)""
IL_00c5: ret
}");
verifier = CompileAndVerify(text, options: TestOptions.UnsafeDebugExe, expectedOutput: @"1");
verifier = CompileAndVerify(text, options: TestOptions.UnsafeDebugExe, expectedOutput: @"1", verify: Verification.Fails);
verifier.VerifyIL("C.<F>d__0.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext()",
@"
{
......
......@@ -24,10 +24,10 @@ private static CSharpCompilation CreateCompilation(string source, IEnumerable<Me
return CreateCompilationWithMscorlib45(source, options: options, references: references);
}
private CompilationVerifier CompileAndVerify(string source, string expectedOutput, IEnumerable<MetadataReference> references = null, CSharpCompilationOptions options = null)
private CompilationVerifier CompileAndVerify(string source, string expectedOutput, IEnumerable<MetadataReference> references = null, CSharpCompilationOptions options = null, Verification verify = Verification.Passes)
{
var compilation = CreateCompilation(source, references: references, options: options);
return base.CompileAndVerify(compilation, expectedOutput: expectedOutput);
return base.CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: verify);
}
[Fact]
......@@ -865,7 +865,7 @@ public static void Main()
Console.WriteLine(Result);
}
}";
CompileAndVerify(source, "0", options: TestOptions.UnsafeReleaseExe);
CompileAndVerify(source, expectedOutput: "0", options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails);
}
[Fact]
......@@ -937,7 +937,7 @@ static void Main()
Console.WriteLine(Driver.Result);
}
}";
CompileAndVerify(source, "0", options: TestOptions.UnsafeDebugExe);
CompileAndVerify(source, expectedOutput: "0", options: TestOptions.UnsafeDebugExe, verify: Verification.Passes);
}
[Fact]
......@@ -998,7 +998,7 @@ static void Main()
Console.Write(Driver.Result);
}
}";
CompileAndVerify(source, "0", options: TestOptions.UnsafeDebugExe);
CompileAndVerify(source, expectedOutput: "0", options: TestOptions.UnsafeDebugExe, verify: Verification.Passes);
}
[Fact]
......@@ -1039,7 +1039,7 @@ public static void Main()
public static int Result = -1;
}";
CompileAndVerify(source, "0", options: TestOptions.UnsafeDebugExe);
CompileAndVerify(source, expectedOutput: "0", options: TestOptions.UnsafeDebugExe, verify: Verification.Passes);
}
[Fact]
......
......@@ -383,7 +383,7 @@ public static long Sub_Ptr(C* a, C* b)
}
}
";
var verifier = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll);
var verifier = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails);
// NOTE: unsigned addition
verifier.VerifyIL("C.Add_Int1", @"
......
......@@ -2518,7 +2518,7 @@ public static void Main(string[] args)
d();
}
}";
CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: "F");
CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: "F", verify: Verification.Passes);
}
[Fact]
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -2431,7 +2432,7 @@ unsafe static void Main()
";
string expectedOutput = @"1
1";
CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.UnsafeReleaseExe);
CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails);
}
[Fact, WorkItem(17756, "https://github.com/dotnet/roslyn/issues/17756")]
......
......@@ -28,7 +28,8 @@ public class CodeGen_DynamicTests : CSharpTestBase
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 @@ public class CodeGen_DynamicTests : CSharpTestBase
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)
......@@ -9358,7 +9359,7 @@ .maxstack 9
IL_0063: callvirt ""void <>A{00000002}<System.Runtime.CompilerServices.CallSite, S, object>.Invoke(System.Runtime.CompilerServices.CallSite, ref S, object)""
IL_0068: ret
}
", allowUnsafe: true);
", allowUnsafe: true, verify: Verification.Fails);
}
[Fact]
......@@ -9427,7 +9428,7 @@ .maxstack 9
IL_0063: callvirt ""void <>A{00000002}<System.Runtime.CompilerServices.CallSite, S, object>.Invoke(System.Runtime.CompilerServices.CallSite, ref S, object)""
IL_0068: ret
}
", allowUnsafe: true);
", allowUnsafe: true, verify: Verification.Fails);
}
[Fact]
......@@ -9497,7 +9498,7 @@ .maxstack 9
IL_006a: callvirt ""void <>A{00000002}<System.Runtime.CompilerServices.CallSite, S, object>.Invoke(System.Runtime.CompilerServices.CallSite, ref S, object)""
IL_006f: ret
}
", allowUnsafe: true);
", allowUnsafe: true, verify: Verification.Fails);
}
[Fact]
......
......@@ -2312,7 +2312,7 @@ static void Main()
}";
string expectedOutput = @"x => G(x)";
CompileAndVerify(text, new[] { ExpressionAssemblyRef }, options: TestOptions.UnsafeReleaseExe, expectedOutput: TrimExpectedOutput(expectedOutput));
CompileAndVerify(text, new[] { ExpressionAssemblyRef }, options: TestOptions.UnsafeReleaseExe, expectedOutput: TrimExpectedOutput(expectedOutput), verify: Verification.Fails);
}
[WorkItem(544246, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544246")]
......@@ -3052,7 +3052,7 @@ public static void Main()
var c = CompileAndVerify(text,
additionalRefs: new[] { SystemCoreRef },
options: TestOptions.UnsafeReleaseDll,
verify: Verification.Passes);
verify: Verification.Fails);
c.VerifyDiagnostics();
}
......
......@@ -4484,7 +4484,7 @@ static void Main(string[] args)
2
2
";
VerifyOutput(source, output, TestOptions.ReleaseExe.WithAllowUnsafe(true).WithWarningLevel(0));
VerifyOutput(source, output, TestOptions.ReleaseExe.WithAllowUnsafe(true).WithWarningLevel(0), verify: Verification.Passes);
}
[Fact]
......@@ -4510,7 +4510,7 @@ static void Main(string[] args)
}
}
";
VerifyOutput(source, "2", TestOptions.ReleaseExe.WithAllowUnsafe(true));
VerifyOutput(source, "2", TestOptions.ReleaseExe.WithAllowUnsafe(true), verify: Verification.Fails);
}
[Fact]
......@@ -4536,7 +4536,7 @@ static void Main(string[] args)
}
}
";
VerifyOutput(source, "2", TestOptions.ReleaseExe.WithAllowUnsafe(true));
VerifyOutput(source, "2", TestOptions.ReleaseExe.WithAllowUnsafe(true), verify: Verification.Fails);
}
[Fact]
......@@ -4563,7 +4563,7 @@ static void Main(string[] args)
}
}
";
VerifyOutput(source, "2", TestOptions.ReleaseExe.WithAllowUnsafe(true));
VerifyOutput(source, "2", TestOptions.ReleaseExe.WithAllowUnsafe(true), verify: Verification.Fails);
}
[Fact]
......@@ -4603,7 +4603,7 @@ unsafe void Local(ref int x2)
Console.WriteLine(y);
}
}";
VerifyOutput(src, "10\r\n4", TestOptions.ReleaseExe.WithAllowUnsafe(true));
VerifyOutput(src, "10\r\n4", TestOptions.ReleaseExe.WithAllowUnsafe(true), verify: Verification.Fails);
}
[Fact]
......@@ -5072,10 +5072,10 @@ .maxstack 3
");
}
internal CompilationVerifier VerifyOutput(string source, string output, CSharpCompilationOptions options)
internal CompilationVerifier VerifyOutput(string source, string output, CSharpCompilationOptions options, Verification verify = Verification.Passes)
{
var comp = CreateCompilationWithMscorlib45AndCSruntime(source, options: options);
return CompileAndVerify(comp, expectedOutput: output).VerifyDiagnostics(); // no diagnostics
return CompileAndVerify(comp, expectedOutput: output, verify: verify).VerifyDiagnostics(); // no diagnostics
}
internal CompilationVerifier VerifyOutput(string source, string output)
......
......@@ -1058,7 +1058,7 @@ unsafe public static void Main()
}
}", TestOptions.UnsafeReleaseExe);
CompileAndVerify(comp, expectedOutput: "24");
CompileAndVerify(comp, expectedOutput: "24", verify: Verification.Fails);
}
[Fact]
......
......@@ -1469,7 +1469,7 @@ static unsafe void Main()
}
";
CompileAndVerify(text, options: TestOptions.UnsafeDebugDll).VerifyIL("Program.Main()", @"
CompileAndVerify(text, options: TestOptions.UnsafeDebugDll, verify: Verification.Fails).VerifyIL("Program.Main()", @"
{
// Code size 54 (0x36)
.maxstack 3
......@@ -1542,7 +1542,7 @@ static unsafe int Main()
}
";
CompileAndVerify(text, options: TestOptions.UnsafeDebugDll).VerifyIL("Program.Main()", @"
CompileAndVerify(text, options: TestOptions.UnsafeDebugDll, verify: Verification.Passes).VerifyIL("Program.Main()", @"
{
// Code size 41 (0x29)
.maxstack 2
......
......@@ -1261,7 +1261,7 @@ static unsafe void Main()
}
";
CompileAndVerifyRef(text, options: TestOptions.UnsafeReleaseDll).VerifyIL("Program.Main()", @"
CompileAndVerifyRef(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyIL("Program.Main()", @"
{
// Code size 291 (0x123)
.maxstack 4
......@@ -1450,7 +1450,7 @@ static unsafe int Main()
}
";
CompileAndVerifyRef(text, options: TestOptions.UnsafeReleaseDll).VerifyIL("Program.Main()", @"
CompileAndVerifyRef(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyIL("Program.Main()", @"
{
// Code size 168 (0xa8)
.maxstack 4
......
......@@ -5152,7 +5152,7 @@ static void Goo(C x)
}
}
";
var verifier = CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"---
var verifier = CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), verify: Verification.Fails, expectedOutput: @"---
M
---
---");
......@@ -5513,7 +5513,7 @@ static public void F1(C c)
}
}
";
var verifier = CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: @"---
var verifier = CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), verify: Verification.Fails, expectedOutput: @"---
F1
---
F1
......
......@@ -14606,7 +14606,7 @@ unsafe static bool[] AllOnesBool()
}
";
CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: @""
CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails, expectedOutput: @""
).VerifyIL("Program.TestArrElement(bool[])",
@"
{
......@@ -15917,7 +15917,7 @@ unsafe public static void Main()
}
}", TestOptions.UnsafeReleaseExe);
CompileAndVerify(comp, expectedOutput: "24");
CompileAndVerify(comp, expectedOutput: "24", verify: Verification.Fails);
}
[Fact]
......
......@@ -39,7 +39,7 @@ static void Main()
S t = s;
}
}";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "12")
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "12", verify: Verification.Fails)
.VerifyIL("Program.Main",
@"{
// Code size 58 (0x3a)
......@@ -102,7 +102,7 @@ unsafe static void Main()
}
}
}";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "12")
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "12", verify: Verification.Fails)
.VerifyIL("Program.Main",
@"
{
......@@ -167,12 +167,12 @@ static void Main()
S t = s;
}
}";
var comp1 = CompileAndVerify(s1, options: TestOptions.UnsafeReleaseDll).Compilation;
var comp1 = CompileAndVerify(s1, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).Compilation;
var comp2 = CompileAndVerify(s2,
options: TestOptions.UnsafeReleaseExe,
additionalRefs: new MetadataReference[] { MetadataReference.CreateFromStream(comp1.EmitToStream()) },
expectedOutput: "12").Compilation;
expectedOutput: "12", verify: Verification.Fails).Compilation;
var f = (FieldSymbol)comp2.GlobalNamespace.GetTypeMembers("S")[0].GetMembers("x")[0];
Assert.Equal("x", f.Name);
......@@ -205,7 +205,7 @@ static void Main()
}
}
}";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "12")
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "12", verify: Verification.Fails)
.VerifyIL("Program.Main",
@"{
// Code size 36 (0x24)
......@@ -357,7 +357,7 @@ private static unsafe uint Test( AssemblyRecord* pStruct )
}
}
";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "133")
CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, expectedOutput: "133", verify: Verification.Fails)
.VerifyIL("Program.Test",
@"{
// Code size 20 (0x14)
......@@ -578,7 +578,7 @@ public unsafe struct Test
" + (layout == LayoutKind.Explicit ? "[FieldOffset(0)]" : "") + @"public fixed UInt32 Field[ 16 ];
}
";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll,
CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes,
symbolValidator: (m) =>
{
var test = m.GlobalNamespace.GetTypeMember("Test");
......@@ -610,7 +610,7 @@ public unsafe struct Test
" + (layout == LayoutKind.Explicit ? "[FieldOffset(0)]" : "") + @"public fixed UInt32 Field[ 16 ];
}
";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll,
CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes,
symbolValidator: (m) =>
{
var test = m.GlobalNamespace.GetTypeMember("Test");
......
......@@ -59,7 +59,7 @@ public static void Main(string[] args)
foreach (var x in new int*[] { y }) { }
}
}
}", options: TestOptions.UnsafeReleaseDll).VerifyIL("Test.Main", @"
}", options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails).VerifyIL("Test.Main", @"
{
// Code size 33 (0x21)
.maxstack 4
......
......@@ -3362,7 +3362,7 @@ static void Main()
X = x;
}
}";
CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: "1");
CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput: "1", verify: Verification.Fails);
}
[Fact, WorkItem(1089276, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1089276")]
......@@ -3404,7 +3404,7 @@ static int Index
X = x;
}
}";
CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), expectedOutput:
CompileAndVerify(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), verify: Verification.Fails, expectedOutput:
@"get_Index
2
3");
......
......@@ -3724,7 +3724,7 @@ public static void Main()
}";
// Setting the CompilationOption.AllowUnsafe causes an entry to be inserted into the DeclSecurity table
var compilation = CreateStandardCompilation(source, options: TestOptions.UnsafeReleaseDll);
CompileAndVerify(compilation, symbolValidator: module =>
CompileAndVerify(compilation, verify: Verification.Passes, symbolValidator: module =>
{
ValidateDeclSecurity(module, new DeclSecurityEntry
{
......@@ -3967,7 +3967,7 @@ public static void Main()
// [assembly: SecurityPermission(SecurityAction.RequestMinimum, RemotingConfiguration = true)]
Diagnostic(ErrorCode.WRN_DeprecatedSymbolStr, "SecurityAction.RequestMinimum").WithArguments("System.Security.Permissions.SecurityAction.RequestMinimum", "Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information."));
CompileAndVerify(compilation, symbolValidator: module =>
CompileAndVerify(compilation, verify: Verification.Passes, symbolValidator: module =>
{
ValidateDeclSecurity(module, new DeclSecurityEntry
{
......@@ -4024,7 +4024,7 @@ public static void Main()
// [assembly: SecurityPermission(SecurityAction.RequestOptional, RemotingConfiguration = true)]
Diagnostic(ErrorCode.WRN_DeprecatedSymbolStr, "SecurityAction.RequestOptional").WithArguments("System.Security.Permissions.SecurityAction.RequestOptional", "Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information."));
CompileAndVerify(compilation, symbolValidator: module =>
CompileAndVerify(compilation, verify: Verification.Passes, symbolValidator: module =>
{
ValidateDeclSecurity(module, new DeclSecurityEntry
{
......
......@@ -1225,7 +1225,7 @@ File 1
True
";
CompilationVerifier verifier = CompileAndVerify(source + InstrumentationHelperSource, options: TestOptions.UnsafeDebugExe, expectedOutput: expectedOutput);
CompilationVerifier verifier = CompileAndVerify(source + InstrumentationHelperSource, options: TestOptions.UnsafeDebugExe, expectedOutput: expectedOutput, verify: Verification.Fails);
verifier.VerifyDiagnostics();
}
......@@ -3211,9 +3211,9 @@ 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)
......
......@@ -39,7 +39,7 @@ unsafe public static void Main()
new[] { TestReferences.SymbolsTests.CustomModifiers.Modifiers.dll },
options: TestOptions.UnsafeReleaseExe);
CompileAndVerify(c, expectedOutput:
CompileAndVerify(c, verify: Verification.Passes, expectedOutput:
@"F1
F2
F3
......@@ -701,7 +701,7 @@ static void Main()
}";
var compilation = CreateCompilationWithCustomILSource(source, ilSource, options: TestOptions.UnsafeReleaseExe);
compilation.VerifyDiagnostics();
CompileAndVerify(compilation);
CompileAndVerify(compilation, verify: Verification.Fails);
}
[Fact]
......@@ -735,7 +735,7 @@ static void Main()
}";
var compilation = CreateCompilationWithCustomILSource(source, ilSource, options: TestOptions.UnsafeReleaseExe);
compilation.VerifyDiagnostics();
CompileAndVerify(compilation);
CompileAndVerify(compilation, verify: Verification.Fails);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis.CSharp.Symbols;
......@@ -3398,7 +3398,7 @@ unsafe static void Main()
static T Goo<T>(Action<T, T> x) { throw null; }
}
";
var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true)).VerifyDiagnostics();
var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.Fails).VerifyDiagnostics();
var tree = verifier.Compilation.SyntaxTrees.Single();
var model = verifier.Compilation.GetSemanticModel(tree);
......@@ -3425,7 +3425,7 @@ unsafe static void Main()
static T Goo<T>(Action<T, T> x) { throw null; }
}
";
var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true)).VerifyDiagnostics();
var verifier = CompileAndVerify(source, options: TestOptions.DebugDll.WithAllowUnsafe(true), verify: Verification.Fails).VerifyDiagnostics();
var tree = verifier.Compilation.SyntaxTrees.Single();
var model = verifier.Compilation.GetSemanticModel(tree);
......
......@@ -765,7 +765,7 @@ static void Main()
// default(IntPtr) as "load zero, convert to type", rather than making a stack slot and calling
// init on it.
var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll);
var c = CompileAndVerify(source, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails);
c.VerifyIL("C.Main", @"{
// Code size 13 (0xd)
......
......@@ -5690,7 +5690,7 @@ static bool TakeOutParam(string y, out string x)
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), parseOptions: TestOptions.Regular);
CompileAndVerify(compilation, expectedOutput:
CompileAndVerify(compilation, verify: Verification.Fails, expectedOutput:
@"fixed
fixed");
}
......@@ -5724,7 +5724,7 @@ static bool TakeOutParam(string y, out string x)
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe.WithAllowUnsafe(true), parseOptions: TestOptions.Regular);
CompileAndVerify(compilation, expectedOutput:
CompileAndVerify(compilation, verify: Verification.Fails, expectedOutput:
@"fixed
fixed");
}
......@@ -2622,7 +2622,7 @@ public static int Main()
}
}
";
CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, expectedOutput: @"2
CompileAndVerify(source, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails, expectedOutput: @"2
True
3
3
......
......@@ -2630,7 +2630,7 @@ static int[] Dummy(object y, object z)
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe.WithAllowUnsafe(true));
CompileAndVerify(compilation, expectedOutput:
CompileAndVerify(compilation, verify: Verification.Fails, expectedOutput:
@"fixed
fixed");
}
......@@ -6476,7 +6476,7 @@ unsafe static void Main()
False";
var compilation = CreateStandardCompilation(source, options: TestOptions.UnsafeReleaseExe);
compilation.VerifyDiagnostics();
CompileAndVerify(compilation, expectedOutput: expectedOutput);
CompileAndVerify(compilation, expectedOutput: expectedOutput, verify: Verification.Fails);
}
[Fact]
......
......@@ -8129,7 +8129,7 @@ unsafe static void Load()
}
";
var compilation = CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe);
var compilation = CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails);
compilation.VerifyIL("Program.Store", @"
{
......@@ -8246,7 +8246,7 @@ unsafe static void Load()
//IL Baseline rather than execute because I'm intentionally writing outside of bounds of buffer
// This will compile without warning but runtime behavior is unpredictable.
var compilation = CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe);
var compilation = CompileAndVerify(text, options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails);
compilation.VerifyIL("Program.Load", @"
{
// Code size 47 (0x2f)
......@@ -8325,7 +8325,7 @@ void Error_UsingFixedBuffersWithThis()
}
";
CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll);
CompileAndVerify(text, options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails);
}
[Fact]
......@@ -8406,10 +8406,10 @@ unsafe static void Load()
}
}";
var comp1 = CompileAndVerify(s1, options: TestOptions.UnsafeReleaseDll).Compilation;
var comp1 = CompileAndVerify(s1, options: TestOptions.UnsafeReleaseDll, verify: Verification.Passes).Compilation;
var comp2 = CompileAndVerify(s2,
options: TestOptions.UnsafeReleaseExe,
options: TestOptions.UnsafeReleaseExe, verify: Verification.Fails,
additionalRefs: new MetadataReference[] { MetadataReference.CreateFromImage(comp1.EmitToArray()) },
expectedOutput: "TrueFalse").Compilation;
......@@ -8461,7 +8461,7 @@ unsafe static void Load()
// Only compile this as its intentionally writing outside of fixed buffer boundaries and
// this doesn't warn but causes flakiness when executed.
var comp3 = CompileAndVerify(s3,
options: TestOptions.UnsafeReleaseDll,
options: TestOptions.UnsafeReleaseDll, verify: Verification.Fails,
additionalRefs: new MetadataReference[] { MetadataReference.CreateFromImage(comp1.EmitToArray()) }).Compilation;
}
......
......@@ -626,17 +626,17 @@ public static MetadataReference CreateMetadataReferenceFromIlSource(string ilSou
/// <typeparam name="T">Expected type of the exception.</typeparam>
/// <param name="source">Program to compile and execute.</param>
/// <param name="expectedMessage">Ignored if null.</param>
internal CompilationVerifier CompileAndVerifyException<T>(string source, string expectedMessage = null, bool allowUnsafe = false) where T : Exception
internal CompilationVerifier CompileAndVerifyException<T>(string source, string expectedMessage = null, bool allowUnsafe = false, Verification verify = Verification.Passes) where T : Exception
{
var comp = CreateStandardCompilation(source, options: TestOptions.ReleaseExe.WithAllowUnsafe(allowUnsafe));
return CompileAndVerifyException<T>(comp, expectedMessage);
return CompileAndVerifyException<T>(comp, expectedMessage, verify);
}
internal CompilationVerifier CompileAndVerifyException<T>(CSharpCompilation comp, string expectedMessage = null) where T : Exception
internal CompilationVerifier CompileAndVerifyException<T>(CSharpCompilation comp, string expectedMessage = null, Verification verify = Verification.Passes) where T : Exception
{
try
{
CompileAndVerify(comp, expectedOutput: ""); //need expected output to force execution
CompileAndVerify(comp, expectedOutput: "", verify: verify); //need expected output to force execution
Assert.False(true, string.Format("Expected exception {0}({1})", typeof(T).Name, expectedMessage));
}
catch (ExecutionException x)
......@@ -649,7 +649,7 @@ public static MetadataReference CreateMetadataReferenceFromIlSource(string ilSou
}
}
return CompileAndVerify(comp);
return CompileAndVerify(comp, verify: verify);
}
protected static List<SyntaxNode> GetSyntaxNodeList(SyntaxTree syntaxTree)
......
......@@ -131,13 +131,6 @@ public abstract partial class CommonTestBase : TestBase
(compilation.Options.OutputKind == OutputKind.ConsoleApplication || compilation.Options.OutputKind == OutputKind.WindowsApplication),
"Compilation must be executable if output is expected.");
if (verify == Verification.Passes)
{
// Unsafe code might not verify, so don't try.
var csharpOptions = compilation.Options as CSharp.CSharpCompilationOptions;
verify = (csharpOptions == null || !csharpOptions.AllowUnsafe) ? Verification.Passes : Verification.Skipped;
}
if (sourceSymbolValidator != null)
{
var module = compilation.Assembly.Modules.First();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册