-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.cake
More file actions
158 lines (136 loc) · 5.9 KB
/
build.cake
File metadata and controls
158 lines (136 loc) · 5.9 KB
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
#tool nuget:?package=NUnit.ConsoleRunner&version=4.0.0-beta.1.1
#tool dotnet:?package=NUnit.ConsoleRunner.NetCore&version=4.0.0-beta.1
// Load the recipe
#load nuget:?package=NUnit.Cake.Recipe&version=1.5.1-alpha.1
// 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";
IPackageTestRunner StandardRunner = new NUnitConsoleRunner("NUnit.ConsoleRunner", "4.0.0-beta.1.1");
IPackageTestRunner DotNetRunner = new NUnit4DotNetRunner("NUnit.ConsoleRunner.NetCore", "4.0.0-beta.1");
PackageTest[] PackageTests = new PackageTest[]
{
new PackageTest(1, "SingleAssembly_Net462")
{
Description = "Run mock-assembly targeting .NET Framework 4.6.2",
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") }
},
TestRunner = StandardRunner
},
new PackageTest(1, "SingleAssembly_Net60")
{
Description = "Run mock-assembly targeting .NET 6.0",
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") }
}
},
new PackageTest(1, "TwoAssemblies_Net462_plus_Net60")
{
Description = "Run two copies of mock-assembly targeting .NET 4.6.2 and .NET 6.0",
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")
}
},
TestRunner = StandardRunner
},
// Not currently working... need to fix in version 3.9.0 of NUnitProjectLoader
//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: [StandardRunner, DotNetRunner]
));
//////////////////////////////////////////////////////////////////////
// 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: [StandardRunner, DotNetRunner]
));
//////////////////////////////////////////////////////////////////////
// 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();