Skip to content

Commit 3d9c377

Browse files
authored
[tests] Collect and zip up the .NET unit tests for execution on Windows. (#11850)
1 parent 9dc24c7 commit 3d9c377

File tree

7 files changed

+80
-7
lines changed

7 files changed

+80
-7
lines changed

tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ Makefile.inc
2929
test.config
3030
test-system.config
3131
mac-test-package
32+
dotnet-test-package
3233
.nuget
3334
logs
3435
*.mSYM
3536
*.generated.cs
3637
x86
3738
bcl-test/templates
39+
*.7z

tests/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ mac-test-package.zip:
288288
@echo Not enabled
289289
endif
290290

291+
ifdef INCLUDE_DOTNET
292+
dotnet-test-package.7z:
293+
./package-dotnet-tests.sh
294+
else
295+
dotnet-test-package.7z:
296+
@echo Not enabled
297+
endif
298+
291299
#XI
292300
ifdef INCLUDE_IOS
293301
wrench-mtouch:

tests/common/Configuration.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void ParseConfigFile (string file)
187187
}
188188
}
189189

190-
static string GetVariable (string variable, string @default)
190+
internal static string GetVariable (string variable, string @default)
191191
{
192192
var result = Environment.GetEnvironmentVariable (variable);
193193
if (string.IsNullOrEmpty (result))
@@ -305,11 +305,13 @@ public static string RootPath {
305305
var path = Path.Combine (dir, ".git");
306306
while (!Directory.Exists (path) && path.Length > 3) {
307307
dir = Path.GetDirectoryName (dir);
308+
if (dir == null)
309+
throw new Exception ($"Could not find the xamarin-macios repo given the test assembly directory {TestAssemblyDirectory}");
308310
path = Path.Combine (dir, ".git");
309311
}
310312
path = Path.GetDirectoryName (path);
311313
if (!Directory.Exists (path))
312-
throw new Exception ("Could not find the xamarin-macios repo");
314+
throw new Exception ($"Could not find the xamarin-macios repo given the test assembly directory {TestAssemblyDirectory}");
313315
return path;
314316
}
315317
}

tests/common/DotNet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class DotNet {
1414
public static string Executable {
1515
get {
1616
if (dotnet_executable == null) {
17-
dotnet_executable = Configuration.EvaluateVariable ("DOTNET6");
17+
dotnet_executable = Configuration.GetVariable ("DOTNET6", null);
1818
if (string.IsNullOrEmpty (dotnet_executable))
1919
throw new Exception ($"Could not find the dotnet executable.");
2020
if (!File.Exists (dotnet_executable))

tests/dotnet/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ TARGETS += \
3030
../bgen/NuGet.config \
3131
../bgen/global.json \
3232

33-
# Example TEST_FILTER:
34-
# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp"
35-
# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details
3633
run-unit-tests:
37-
cd UnitTests && $(DOTNET) test DotNetUnitTests.csproj $(TEST_FILTER)
34+
$(MAKE) -C UnitTests $@
3835

3936
all-local:: $(TARGETS)
4037

tests/dotnet/UnitTests/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
TOP=../../..
2+
3+
include $(TOP)/Make.config
4+
5+
6+
build:
7+
$(DOTNET) build DotNetUnitTests.csproj
8+
9+
publish:
10+
$(DOTNET) publish DotNetUnitTests.csproj
11+
12+
# Example TEST_FILTER:
13+
# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp"
14+
# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details
15+
run-unit-tests:
16+
$(DOTNET) test DotNetUnitTests.csproj $(TEST_FILTER)
17+
18+
run-published:
19+
$(DOTNET) test bin/Debug/net5.0/publish/DotNetUnitTests.dll $(TEST_FILTER)

tests/package-dotnet-tests.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash -ex
2+
3+
cd "$(dirname "${BASH_SOURCE[0]}")"
4+
5+
# Clone files instead of copying them on APFS file systems. Much faster.
6+
CP="cp"
7+
if df -t apfs / >/dev/null 2>&1; then
8+
CP="cp -c"
9+
fi
10+
11+
#git clean -xfdq
12+
13+
rm -Rf "$(pwd)/dotnet-test-package"
14+
DIR=$(pwd)/dotnet-test-package/xamarin-macios
15+
ZIP=$DIR.7z
16+
mkdir -p $DIR
17+
mkdir -p $DIR/tests/dotnet/UnitTests/bin/Debug/net5.0/
18+
mkdir -p $DIR/.git
19+
20+
make -j8
21+
make -C dotnet/UnitTests publish
22+
23+
$CP -r dotnet $DIR/tests/
24+
rm -Rf $DIR/tests/dotnet/packages
25+
26+
# Various files to make 'make' work
27+
$CP -p ../Make.config $DIR
28+
$CP -p ../Make.versions $DIR
29+
$CP -p ../Make.config $DIR
30+
mkdir -p $DIR/mk
31+
$CP -p ../Make.config $DIR
32+
$CP -p ../mk/subdirs.mk $DIR/mk
33+
$CP -p ../mk/rules.mk $DIR/mk
34+
$CP -p ../mk/quiet.mk $DIR/mk
35+
$CP -p ../mk/mono.mk "$DIR/mk"
36+
37+
# Files to make the unit tests run
38+
$CP -p dotnet/global.json $DIR/tests/global.json
39+
$CP -p ../NuGet.config $DIR
40+
$CP -p test.config $DIR/tests
41+
42+
# Zip it all up
43+
rm -f dotnet-test-package.7z
44+
cd dotnet-test-package
45+
7z a ../dotnet-test-package.7z *

0 commit comments

Comments
 (0)