Skip to content

Commit

Permalink
Remove extraneous support in the test runner generator for referencin…
Browse files Browse the repository at this point in the history
…g corelib directly. (#62154)
  • Loading branch information
jkoritzinsky committed Nov 30, 2021
1 parent b5bb3c9 commit 13c8988
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/tests/Common/XUnitWrapperGenerator/OptionsHelper.cs
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
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

0 comments on commit 13c8988

Please sign in to comment.