Skip to content

Remove extraneous support in the test runner generator for referencing corelib directly. #62154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/tests/Common/XUnitWrapperGenerator/OptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace XUnitWrapperGenerator;

public static class OptionsHelper
{
private const string ReferenceSystemPrivateCoreLibOption = "build_property.ReferenceSystemPrivateCoreLib";
private const string IsMergedTestRunnerAssemblyOption = "build_property.IsMergedTestRunnerAssembly";
private const string PriorityOption = "build_property.Priority";
private const string RuntimeFlavorOption = "build_property.RuntimeFlavor";
Expand All @@ -29,8 +28,6 @@ private static bool GetBoolOption(this AnalyzerConfigOptions options, string key
? result : 0;
}

internal static bool ReferenceSystemPrivateCoreLib(this AnalyzerConfigOptions options) => options.GetBoolOption(ReferenceSystemPrivateCoreLibOption);

internal static bool IsMergedTestRunnerAssembly(this AnalyzerConfigOptions options) => options.GetBoolOption(IsMergedTestRunnerAssemblyOption);

internal static int? Priority(this AnalyzerConfigOptions options) => options.GetIntOption(PriorityOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,16 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
return;
}

bool referenceCoreLib = configOptions.GlobalOptions.ReferenceSystemPrivateCoreLib();

bool isMergedTestRunnerAssembly = configOptions.GlobalOptions.IsMergedTestRunnerAssembly();

// TODO: add error (maybe in MSBuild that referencing CoreLib directly from a merged test runner is not supported)
if (isMergedTestRunnerAssembly && !referenceCoreLib)
if (isMergedTestRunnerAssembly)
{
context.AddSource("FullRunner.g.cs", GenerateFullTestRunner(methods, aliasMap, assemblyName));
}
else
{
string consoleType = referenceCoreLib ? "Internal.Console" : "System.Console";
string consoleType = "System.Console";
context.AddSource("SimpleRunner.g.cs", GenerateStandaloneSimpleTestRunner(methods, aliasMap, consoleType));
}
});
Expand Down Expand Up @@ -144,7 +142,7 @@ private static string GenerateStandaloneSimpleTestRunner(ImmutableArray<ITestInf
builder.AppendLine(string.Join("\n", aliasMap.Values.Where(alias => alias != "global").Select(alias => $"extern alias {alias};")));
builder.AppendLine("try {");
builder.AppendLine(string.Join("\n", testInfos.Select(m => m.GenerateTestExecution(reporter))));
builder.AppendLine($"}} catch(System.Exception ex) {{ {consoleType}.WriteLine(ex.ToString()); return 101; }}");
builder.AppendLine("} catch(System.Exception ex) { System.Console.WriteLine(ex.ToString()); return 101; }");
builder.AppendLine("return 100;");
return builder.ToString();
}
Expand Down