-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.cake
184 lines (159 loc) · 7.27 KB
/
build.cake
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#tool nuget:?package=NUnit.ConsoleRunner&version=3.19.2
#tool nuget:?package=NUnit.ConsoleRunner&version=3.18.3
#tool nuget:?package=NUnit.ConsoleRUnner&version=3.17.0
#tool nuget:?package=NUnit.ConsoleRunner&version=3.15.5
#tool nuget:?package=NUnit.ConsoleRunner.NetCore&version=3.19.2
#tool nuget:?package=NUnit.ConsoleRunner.NetCore&version=3.18.3
#tool nuget:?package=NUnit.ConsoleRunner.NetCore&version=3.17.0
#tool nuget:?package=NUnit.ConsoleRunner.NetCore&version=3.15.5
// NOTE: Because of permission issues in installing the chocolatey
// versions of the NUnit console runner, all tests use the nuget
// packages. The test runners included in the recipe adjust the
// search path for extensions accordingly.
// StandardRunners is used as the default setting for our tests,
// since the standard runner can execute all of them
var StandardRunners = new IPackageTestRunner[] {
new NUnitConsoleRunner("NUnit.ConsoleRunner", "3.19.2"),
new NUnitConsoleRunner("NUnit.ConsoleRunner", "3.18.3"),
new NUnitConsoleRunner("NUnit.ConsoleRunner", "3.17.0"),
new NUnitConsoleRunner("NUnit.ConsoleRunner", "3.15.5"),
};
var NetCoreRunners = new IPackageTestRunner[] {
new NUnit3NetCoreConsoleRunner("NUnit.ConsoleRunner.NetCore", "3.19.2", "tools/net8.0/any/nunit3-console.exe"),
new NUnit3NetCoreConsoleRunner("NUnit.ConsoleRunner.NetCore", "3.18.3", "tools/net6.0/any/nunit3-console.exe"),
new NUnit3NetCoreConsoleRunner("NUnit.ConsoleRunner.NetCore", "3.17.0", "tools/net6.0/any/nunit3-console.exe"),
new NUnit3NetCoreConsoleRunner("NUnit.ConsoleRunner.NetCore", "3.15.5", "tools/net6.0/any/nunit3-console.exe")
};
// For .NET Core tests, we override the default and use AllRunners,
// since both the standard and netcore runners can execute them.
var AllRunners = new List<IPackageTestRunner>(StandardRunners.Concat(NetCoreRunners)).ToArray();
// Load the recipe
#load nuget:?package=NUnit.Cake.Recipe&version=1.4.0-alpha.5
// Comment out above line and uncomment below for local tests of recipe changes
//#load ../NUnit.Cake.Recipe/recipe/*.cake
// Initialize BuildSettings
BuildSettings.Initialize(
Context,
"NUnit Project Loader",
"nunit-v2-result-writer",
solutionFile: "nunit-v2-result-writer.sln",
unitTestRunner: new NUnitLiteRunner(),
unitTests: "**/*.tests.exe");
const string NUNIT3_RESULT_FILE = "TestResult.xml";
const string NUNIT2_RESULT_FILE = "NUnit2TestResult.xml";
PackageTest[] PackageTests = new PackageTest[]
{
new PackageTest(1, "SingleAssembly")
{
Description = "Run mock-assembly",
Arguments = $"net462/mock-assembly.dll --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
ExpectedResult = new ExpectedResult("Failed")
{
Assemblies = new[] { new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2") }
}
},
new PackageTest(1, "SingleAssembly_NetCoreRunner")
{
Description = "Run mock-assembly under NetCore runner",
Arguments = $"net6.0/mock-assembly.dll --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
ExpectedResult = new ExpectedResult("Failed")
{
Assemblies = new[] { new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0") }
},
TestRunners = AllRunners
},
new PackageTest(1, "TwoAssembliesTogether")
{
Description = "Run two copies of mock-assembly",
Arguments = $"net462/mock-assembly.dll net6.0/mock-assembly.dll --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
ExpectedResult =new ExpectedResult("Failed") {
Assemblies = new[] {
new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"),
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0")
}
}
},
new PackageTest(1, "NUnitProject")
{
Description = "Run NUnit project with two assemblies",
Arguments = $"../../TwoMockAssemblies.nunit --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
ExpectedResult = new ExpectedResult("Failed")
{
Assemblies = new[] {
new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"),
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0")
}
},
ExtensionsNeeded = new[] { KnownExtensions.NUnitProjectLoader.SetVersion("3.8.0") }
}
};
//////////////////////////////////////////////////////////////////////
// NUGET PACKAGE
//////////////////////////////////////////////////////////////////////
BuildSettings.Packages.Add(
new NuGetPackage(
"NUnit.Extension.NUnitV2ResultWriter",
"nuget/nunit-v2-result-writer.nuspec",
checks: new PackageCheck[] {
HasFiles("LICENSE.txt", "nunit_256.png"),
HasDirectory("tools/net462").WithFile("nunit-v2-result-writer.dll"),
HasDirectory("tools/net462").WithFile("nunit.engine.api.dll"),
HasDirectory("tools/net6.0").WithFile("nunit-v2-result-writer.dll"),
HasDirectory("tools/net6.0").WithFile("nunit.engine.api.dll") },
tests: PackageTests,
testRunners: StandardRunners
));
//////////////////////////////////////////////////////////////////////
// CHOCOLATEY PACKAGE
//////////////////////////////////////////////////////////////////////
BuildSettings.Packages.Add(
new ChocolateyPackage(
"nunit-extension-nunit-v2-result-writer",
"choco/nunit-v2-result-writer.nuspec",
checks: new PackageCheck[] {
HasDirectory("tools").WithFiles("LICENSE.txt", "VERIFICATION.txt", "nunit_256.png", "nunit-v2-result-writer.legacy.addins"),
HasDirectory("tools/net462").WithFile("nunit.engine.api.dll"),
HasDirectory("tools/net6.0").WithFile("nunit-v2-result-writer.dll"),
HasDirectory("tools/net6.0").WithFile("nunit.engine.api.dll") },
tests: PackageTests,
testRunners: StandardRunners
));
//////////////////////////////////////////////////////////////////////
// FINAL CHECK AFTER PACKAGE TESTS HAVE RUN
//////////////////////////////////////////////////////////////////////
// The recipe handles checking the standard nunit3 test result file but
// not the nunit2 format file we produce in the package tests. We handle
// that check in a TaskTeardown event. Currently, we only check that the
// file exists.
// TODO: Perform this check for each test as it is run rather than
// after the Package task completes. This requires changes to the
// recipe itself.
// TODO: Check the internal format of the files.
TaskTeardown(teardownContext =>
{
if (teardownContext.Task.Name == "Package")
{
Banner.Display("Check the NUnit2 format result files", '=', 78);
foreach(var package in BuildSettings.Packages)
{
Banner.Display( package.PackageFileName );
//Console.WriteLine( package.PackageResultDirectory);
int index = 0;
foreach (var dir in teardownContext.GetDirectories(package.PackageResultDirectory + "*"))
{
var nunit2ResultFile = dir.CombineWithFilePath("NUnit2TestResult.xml");
Console.WriteLine($"{++index}. {dir.GetDirectoryName()}");
Console.WriteLine();
if (SIO.File.Exists($"{nunit2ResultFile}"))
Console.WriteLine(" SUCCESS: NUnit2 Test Result FOUND");
else
Console.WriteLine(" FAILED: NUnit2 TestResult NOT FOUND");
Console.WriteLine();
}
}
}
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
Build.Run();