-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.cake
154 lines (132 loc) · 5.6 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
#tool nuget:?package=NUnit.ConsoleRunner&version=3.15.5
#tool nuget:?package=NUnit.ConsoleRunner&version=3.17.0
#tool nuget:?package=NUnit.ConsoleRunner&version=3.18.0-dev00037
#tool nuget:?package=NUnit.ConsoleRunner.NetCore&version=3.18.0-dev00037
// Load the recipe
#load nuget:?package=NUnit.Cake.Recipe&version=1.0.1-dev00001
// 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",
"Run mock-assembly",
$"net462/mock-assembly.dll --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
new ExpectedResult("Failed")
{
Assemblies = new[] { new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2") }
} ),
new PackageTest(
1, "SingleAssembly_NetCoreRunner",
"Run mock-assembly under NetCore runner",
$"net6.0/mock-assembly.dll --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
new ExpectedResult("Failed")
{
Assemblies = new[] { new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0") }
},
new IPackageTestRunner[] { (IPackageTestRunner)new NUnitNetCoreConsoleRunner("3.18.0-dev00037") } ),
new PackageTest(
1, "TwoAssembliesTogether",
"Run two copies of mock-assembly",
$"net462/mock-assembly.dll net6.0/mock-assembly.dll --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
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",
"Run NUnit project with two assemblies",
$"../../TwoMockAssemblies.nunit --result={NUNIT3_RESULT_FILE} --result={NUNIT2_RESULT_FILE};format=nunit2",
new ExpectedResult("Failed")
{
Assemblies = new[] {
new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"),
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0")
}
},
KnownExtensions.NUnitProjectLoader.SetVersion("3.8.0") )
};
//////////////////////////////////////////////////////////////////////
// NUGET PACKAGE
//////////////////////////////////////////////////////////////////////
private TestRunnerSource DEFAULT_TEST_RUNNER_SOURCE = new TestRunnerSource (
new NUnitConsoleRunner("3.17.0"), new NUnitConsoleRunner("3.15.5"), new NUnitConsoleRunner("3.18.0-dev00037") );
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,
testRunnerSource: DEFAULT_TEST_RUNNER_SOURCE
));
//////////////////////////////////////////////////////////////////////
// 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,
testRunnerSource: DEFAULT_TEST_RUNNER_SOURCE
));
//////////////////////////////////////////////////////////////////////
// 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();