-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathProgram.cs
91 lines (74 loc) · 2.67 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Commands;
#pragma warning disable SA1205 // Partial elements should declare access
partial class Program
#pragma warning restore SA1205 // Partial elements should declare access
{
public static int Main(string[] args)
{
var testCommandLine = TestCommandLine.HandleCommandLine(args);
List<string> newArgs = testCommandLine.RemainingArgs?.ToList() ?? new List<string>();
// Help argument needs to be the first one to xunit, so don't insert assembly location in that case
if (testCommandLine.ShouldShowHelp)
{
newArgs.Insert(0, "-?");
}
else
{
newArgs.Insert(0, typeof(Program).Assembly.Location);
}
if (!testCommandLine.ShouldShowHelp)
{
newArgs.AddRange(testCommandLine.GetXunitArgsFromTestConfig());
BeforeTestRun(newArgs);
}
int returnCode = 0;
if (testCommandLine.ShowSdkInfo)
{
returnCode = ShowSdkInfo();
}
else
{
var xunitReturnCode = Xunit.ConsoleClient.Program.Main(newArgs.ToArray());
if (Environment.GetEnvironmentVariable("HELIX_WORKITEM_PAYLOAD") != null)
{
// If we are running in Helix, we want the test work item to return 0 unless there's a crash
Console.WriteLine($"Xunit return code: {xunitReturnCode}");
}
else
{
// If we are running locally, we to return the xunit return code
returnCode = xunitReturnCode;
}
}
if (testCommandLine.ShouldShowHelp)
{
TestCommandLine.ShowHelp();
ShowAdditionalHelp();
}
else
{
AfterTestRun();
}
return returnCode;
}
private static int ShowSdkInfo()
{
var log = new StringTestLogger();
var command = new DotnetCommand(log, "--info");
var testDirectory = TestDirectory.Create(Path.Combine(TestContext.Current.TestExecutionDirectory, "sdkinfo"));
command.WorkingDirectory = testDirectory.Path;
var result = command.Execute();
Console.WriteLine(result.StdOut);
if (result.ExitCode != 0)
{
Console.WriteLine(log.ToString());
}
return result.ExitCode;
}
static partial void BeforeTestRun(List<string> args);
static partial void AfterTestRun();
static partial void ShowAdditionalHelp();
}