Skip to content

Commit 6888cd6

Browse files
authored
Document ROSLYN_TEST_USEDASSEMBLIES (#60478)
1 parent 764dcd0 commit 6888cd6

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

docs/contributing/Building, Debugging, and Testing on Windows.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ See more details in the [IOperation test hook](https://github.com/dotnet/roslyn/
196196
`C:\Source\roslyn> cd ..`
197197
`C:\Source> dotnet-format analyzers .\roslyn\Compilers.sln --diagnostics=RS0016 --no-restore --include-generated -v diag`
198198

199+
## Replicating Failures in the Used Assemblies leg
200+
201+
In order to replicate test failures in that leg, there are a few options:
202+
203+
1. Uncomment `src/Compilers/Test/Core/Compilation/CompilationExtensions.cs:9`, which defines `ROSLYN_TEST_USEDASSEMBLIES`, and run your tests. Do _not_ check this in, as it
204+
will enable the test hook for every test in every project and significantly slow down regular test runs.
205+
2. Set the `ROSLYN_TEST_USEDASSEMBLIES` environment variable and restart VS with it set.
206+
3. Set a breakpoint at the start of `CSharpTestBase.VerifyUsedAssemblyReferences` in `src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs`. When it breaks, use VS's jump to location or
207+
drag the instruction pointer past the early check and return on `EnableVerifyUsedAssemblies`.
208+
209+
When a test failure is isolated, please add a _dedicated_ test for this (ie. failing even when the Used Assemblies validation isn't enabled) to make it easier to avoid future regressions.
210+
Preferrably, don't replicate the entire original test, just enough to hit the bug to ensure that it's protected against regressions.
211+
Before pushing a relevant fix to CI, you can validate locally using the `-testUsedAssemblies` command-line option for `build.cmd`. For example: `build.cmd -testCoreClr -testCompilerOnly -testUsedAssemblies`.
212+
199213
## Contributing
200214

201215
Please see [Contributing Code](https://github.com/dotnet/roslyn/blob/main/CONTRIBUTING.md) for details on contributing changes back to the code.

eng/build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function Print-Usage() {
9898
Write-Host " -testCompilerOnly Run only the compiler unit tests"
9999
Write-Host " -testVsi Run all integration tests"
100100
Write-Host " -testIOperation Run extra checks to validate IOperations"
101-
Write-Host " -testUsedAssemblies Run extra checks to validate used assemblies feature"
101+
Write-Host " -testUsedAssemblies Run extra checks to validate used assemblies feature (see ROSLYN_TEST_USEDASSEMBLIES in codebase)"
102102
Write-Host ""
103103
Write-Host "Advanced settings:"
104104
Write-Host " -ci Set when running on CI server"

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@
66
// Uncomment to enable the IOperation test hook on all test runs. Do not commit this uncommented.
77
//#define ROSLYN_TEST_IOPERATION
88

9+
// Uncomment to enable the Used Assemblies test hook on all test runs. Do not commit this uncommented.
10+
//#define ROSLYN_TEST_USEDASSEMBLIES
11+
912
using System;
1013
using System.Collections.Generic;
1114
using System.Collections.Immutable;
1215
using System.Diagnostics;
1316
using System.IO;
1417
using System.Linq;
15-
using System.Reflection.Metadata;
1618
using System.Text;
17-
using System.Text.RegularExpressions;
1819
using System.Threading;
1920
using Microsoft.CodeAnalysis.CodeGen;
2021
using Microsoft.CodeAnalysis.CSharp;
2122
using Microsoft.CodeAnalysis.Emit;
2223
using Microsoft.CodeAnalysis.FlowAnalysis;
2324
using Microsoft.CodeAnalysis.Operations;
2425
using Microsoft.CodeAnalysis.PooledObjects;
25-
using Microsoft.CodeAnalysis.Symbols;
2626
using Roslyn.Test.Utilities;
2727
using Roslyn.Utilities;
2828
using Xunit;
29-
using Xunit.Sdk;
3029

3130
namespace Microsoft.CodeAnalysis.Test.Utilities
3231
{
@@ -39,7 +38,12 @@ public static class CompilationExtensions
3938
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ROSLYN_TEST_IOPERATION"));
4039
#endif
4140

42-
internal static bool EnableVerifyUsedAssemblies { get; } = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ROSLYN_TEST_USEDASSEMBLIES"));
41+
internal static bool EnableVerifyUsedAssemblies { get; } =
42+
#if ROSLYN_TEST_USEDASSEMBLIES
43+
true;
44+
#else
45+
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ROSLYN_TEST_USEDASSEMBLIES"));
46+
#endif
4347

4448
internal static ImmutableArray<byte> EmitToArray(
4549
this Compilation compilation,

src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ private static void ValidateCompilation(Func<CSharpCompilation> createCompilatio
12101210

12111211
private static void VerifyUsedAssemblyReferences(Func<CSharpCompilation> createCompilationLambda)
12121212
{
1213+
// To run the additional validation below, comment this out or define ROSLYN_TEST_USEDASSEMBLIES
12131214
if (!CompilationExtensions.EnableVerifyUsedAssemblies)
12141215
{
12151216
return;

0 commit comments

Comments
 (0)