Skip to content

Commit 8968ec5

Browse files
authored
Cleanup how code is executed in our unit tests (#78112)
As part of #78024 I needed to change how output was handled by our unit tests. In looking at the test execution code I noticed that it was in need of a bit of a cleanup. The responsibilities of the layers was not clear and this lead to a lot of code duplication as well as subtle behavior differences between .NET Core and Framework. This change does the following: - Changes the responsibility of `IRuntimeEnvironment` to be _only_ about how code is executed. No more emitting code, calling into `Assert`, etc ... This is just about running code in a specific environment. - Moves the responsibility of verifying the output is as expected to `CompilationVerifier` - Moves the responsibility of emitting the code to be `CompilationVerifier` - Enables NRT in several places to better track how `null` is handled. There is so much implicit `null` usage in the low test layers that it was making the hard to follow. Decided to just turn on NRT there and work through the problems.
2 parents e7069f2 + 0b626fe commit 8968ec5

25 files changed

+1095
-1323
lines changed

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLockTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ public void Write(T newItem)
17711771
17721772
item = newItem;
17731773
empty = false;
1774-
Console.Error.WriteLine(""{0} wrote {1}"", Thread.CurrentThread.Name, newItem);
1774+
Console.WriteLine(""{0} wrote {1}"", Thread.CurrentThread.Name, newItem);
17751775
Monitor.PulseAll(bufferLock);
17761776
}
17771777
}
@@ -1784,7 +1784,7 @@ public T Read()
17841784
17851785
empty = true;
17861786
T result = item;
1787-
Console.Error.WriteLine(""{0} read {1}"", Thread.CurrentThread.Name, result);
1787+
Console.WriteLine(""{0} read {1}"", Thread.CurrentThread.Name, result);
17881788
Monitor.PulseAll(bufferLock);
17891789
return result;
17901790
}

src/Compilers/CSharp/Test/Symbol/Symbols/CSharpCompilerFeatureRequiredTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected override CSharpTestSource GetUsage() => """
5050
_ = new OnThisIndexerParameter()[1];
5151
""";
5252

53-
internal override string VisualizeRealIL(IModuleSymbol peModule, CompilationTestData.MethodData methodData, IReadOnlyDictionary<int, string> markers, bool areLocalsZeroed)
53+
internal override string VisualizeRealIL(IModuleSymbol peModule, CompilationTestData.MethodData methodData, IReadOnlyDictionary<int, string>? markers, bool areLocalsZeroed)
5454
{
5555
return _csharpTest.VisualizeRealIL(peModule, methodData, markers, areLocalsZeroed);
5656
}

src/Compilers/CSharp/Test/Symbol/Symbols/FunctionPointerTypeSymbolTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ unsafe void M()
11651165
Assert.NotNull(a);
11661166
Assert.Equal("System.Int32 a", a.ToTestDisplayString());
11671167

1168+
Assert.NotNull(functionPointerTypeSyntax.Parent);
11681169
VerifyOperationTreeForNode(comp, model, functionPointerTypeSyntax.Parent, expectedOperationTree: @"
11691170
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null, IsInvalid) (Syntax: 'delegate*<int[a]> local')
11701171
Ignored Dimensions(1):
@@ -1271,6 +1272,7 @@ unsafe void M()
12711272
Assert.Equal("C.D", nestedTypeInfo.Type!.ToTestDisplayString());
12721273
Assert.False(nestedTypeInfo.Type!.IsErrorType());
12731274

1275+
Assert.NotNull(functionPointerTypeSyntax.Parent);
12741276
VerifyOperationTreeForNode(comp, model, functionPointerTypeSyntax.Parent, expectedOperationTree: @"
12751277
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null, IsInvalid) (Syntax: 'delegate*<C.D> d')
12761278
Declarators:

src/Compilers/Core/CodeAnalysisTest/Symbols/DocumentationCommentIdTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ unsafe void M({{type}} i)
186186
}
187187

188188
internal override string VisualizeRealIL(
189-
IModuleSymbol peModule, CompilationTestData.MethodData methodData, IReadOnlyDictionary<int, string> markers, bool areLocalsZeroed)
189+
IModuleSymbol peModule, CompilationTestData.MethodData methodData, IReadOnlyDictionary<int, string>? markers, bool areLocalsZeroed)
190190
=> throw new NotImplementedException();
191191
}
192192
}

src/Compilers/Test/Core/CommonTestBase.cs

Lines changed: 90 additions & 89 deletions
Large diffs are not rendered by default.

src/Compilers/Test/Core/Compilation/Exceptions.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)