Skip to content

Commit ecd810c

Browse files
authored
dotnet: improve language coverage of passthru.tests for dotnet sdks (NixOS#370789)
2 parents c14d641 + 4e5ba7e commit ecd810c

File tree

1 file changed

+124
-87
lines changed

1 file changed

+124
-87
lines changed

pkgs/development/compilers/dotnet/wrapper.nix

Lines changed: 124 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
8282
postFixup = lib.optionalString (unwrapped ? man) ''
8383
ln -s ${unwrapped.man} "$man"
8484
'';
85+
8586
passthru = unwrapped.passthru // {
8687
inherit unwrapped;
8788
tests =
@@ -91,6 +92,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
9192
name,
9293
stdenv ? stdenvNoCC,
9394
template,
95+
lang ? null,
9496
usePackageSource ? false,
9597
build,
9698
buildInputs ? [ ],
@@ -102,20 +104,32 @@ stdenvNoCC.mkDerivation (finalAttrs: {
102104
let
103105
sdk = finalAttrs.finalPackage;
104106
built = stdenv.mkDerivation {
105-
name = "dotnet-test-${name}";
107+
name = "${sdk.name}-test-${name}";
106108
buildInputs = [ sdk ] ++ buildInputs ++ lib.optional (usePackageSource) sdk.packages;
107109
# make sure ICU works in a sandbox
108110
propagatedSandboxProfile = toString sdk.__propagatedSandboxProfile;
109-
unpackPhase = ''
110-
mkdir test
111-
cd test
112-
dotnet new ${template} -o . --no-restore
113-
'';
111+
unpackPhase =
112+
let
113+
unpackArgs =
114+
[ template ]
115+
++ lib.optionals (lang != null) [
116+
"-lang"
117+
lang
118+
];
119+
in
120+
''
121+
mkdir test
122+
cd test
123+
dotnet new ${lib.escapeShellArgs unpackArgs} -o . --no-restore
124+
'';
114125
buildPhase = build;
115126
dontPatchELF = true;
116127
};
117128
in
118-
if run == null then
129+
# older SDKs don't include an embedded FSharp.Core package
130+
if lang == "F#" && lib.versionOlder sdk.version "6.0.400" then
131+
null
132+
else if run == null then
119133
built
120134
else
121135
runCommand "${built.name}-run"
@@ -142,61 +156,90 @@ stdenvNoCC.mkDerivation (finalAttrs: {
142156
+ run
143157
);
144158

145-
# Setting LANG to something other than 'C' forces the runtime to search
146-
# for ICU, which will be required in most user environments.
147-
checkConsoleOutput = command: ''
148-
output="$(LANG=C.UTF-8 ${command})"
149-
# yes, older SDKs omit the comma
150-
[[ "$output" =~ Hello,?\ World! ]] && touch "$out"
151-
'';
152-
in
153-
unwrapped.passthru.tests or { }
154-
// {
155-
version = testers.testVersion (
156-
{
157-
package = finalAttrs.finalPackage;
158-
}
159-
// lib.optionalAttrs (type != "sdk") {
160-
command = "dotnet --info";
161-
}
162-
);
163-
}
164-
// lib.optionalAttrs (type == "sdk") (
165-
{
166-
console = mkDotnetTest {
167-
name = "console";
168-
template = "console";
169-
build = checkConsoleOutput "dotnet run";
170-
};
159+
mkConsoleTests =
160+
lang: suffix: output:
161+
let
162+
# Setting LANG to something other than 'C' forces the runtime to search
163+
# for ICU, which will be required in most user environments.
164+
checkConsoleOutput = command: ''
165+
output="$(LANG=C.UTF-8 ${command})"
166+
[[ "$output" =~ ${output} ]] && touch "$out"
167+
'';
171168

172-
publish = mkDotnetTest {
173-
name = "publish";
174-
template = "console";
175-
build = "dotnet publish -o $out/bin";
176-
run = checkConsoleOutput "$src/bin/test";
177-
};
169+
mkConsoleTest =
170+
{ name, ... }@args:
171+
mkDotnetTest (
172+
args
173+
// {
174+
name = "console-${name}-${suffix}";
175+
template = "console";
176+
inherit lang;
177+
}
178+
);
179+
in
180+
lib.recurseIntoAttrs {
181+
run = mkConsoleTest {
182+
name = "run";
183+
build = checkConsoleOutput "dotnet run";
184+
};
178185

179-
self-contained = mkDotnetTest {
180-
name = "self-contained";
181-
template = "console";
182-
usePackageSource = true;
183-
build = "dotnet publish --use-current-runtime --sc -o $out";
184-
runtime = null;
185-
run = checkConsoleOutput "$src/test";
186-
};
186+
publish = mkConsoleTest {
187+
name = "publish";
188+
build = "dotnet publish -o $out/bin";
189+
run = checkConsoleOutput "$src/bin/test";
190+
};
187191

188-
single-file = mkDotnetTest {
189-
name = "single-file";
190-
template = "console";
191-
usePackageSource = true;
192-
build = "dotnet publish --use-current-runtime -p:PublishSingleFile=true -o $out/bin";
193-
runtime = null;
194-
run = checkConsoleOutput "$src/bin/test";
192+
self-contained = mkConsoleTest {
193+
name = "self-contained";
194+
usePackageSource = true;
195+
build = "dotnet publish --use-current-runtime --sc -o $out";
196+
runtime = null;
197+
run = checkConsoleOutput "$src/test";
198+
};
199+
200+
single-file = mkConsoleTest {
201+
name = "single-file";
202+
usePackageSource = true;
203+
build = "dotnet publish --use-current-runtime -p:PublishSingleFile=true -o $out/bin";
204+
runtime = null;
205+
run = checkConsoleOutput "$src/bin/test";
206+
};
207+
}
208+
// lib.optionalAttrs finalAttrs.finalPackage.hasILCompiler {
209+
aot = mkConsoleTest {
210+
name = "aot";
211+
stdenv = if stdenv.hostPlatform.isDarwin then swiftPackages.stdenv else stdenv;
212+
usePackageSource = true;
213+
buildInputs =
214+
[
215+
zlib
216+
]
217+
++ lib.optional stdenv.hostPlatform.isDarwin (
218+
with darwin;
219+
with apple_sdk.frameworks;
220+
[
221+
swiftPackages.swift
222+
Foundation
223+
CryptoKit
224+
GSS
225+
ICU
226+
]
227+
);
228+
build = ''
229+
dotnet restore -p:PublishAot=true
230+
dotnet publish -p:PublishAot=true -o $out/bin
231+
'';
232+
runtime = null;
233+
run = checkConsoleOutput "$src/bin/test";
234+
};
195235
};
196236

197-
web = mkDotnetTest {
198-
name = "web";
237+
mkWebTest =
238+
lang: suffix:
239+
mkDotnetTest {
240+
name = "web-${suffix}";
199241
template = "web";
242+
inherit lang;
200243
build = "dotnet publish -o $out/bin";
201244
runtime = finalAttrs.finalPackage.aspnetcore;
202245
runInputs = [
@@ -228,36 +271,30 @@ stdenvNoCC.mkDerivation (finalAttrs: {
228271
'';
229272
runAllowNetworking = true;
230273
};
231-
}
232-
// lib.optionalAttrs finalAttrs.finalPackage.hasILCompiler {
233-
aot = mkDotnetTest {
234-
name = "aot";
235-
stdenv = if stdenv.hostPlatform.isDarwin then swiftPackages.stdenv else stdenv;
236-
template = "console";
237-
usePackageSource = true;
238-
buildInputs =
239-
[
240-
zlib
241-
]
242-
++ lib.optional stdenv.hostPlatform.isDarwin (
243-
with darwin;
244-
with apple_sdk.frameworks;
245-
[
246-
swiftPackages.swift
247-
Foundation
248-
CryptoKit
249-
GSS
250-
ICU
251-
]
252-
);
253-
build = ''
254-
dotnet restore -p:PublishAot=true
255-
dotnet publish -p:PublishAot=true -o $out/bin
256-
'';
257-
runtime = null;
258-
run = checkConsoleOutput "$src/bin/test";
259-
};
260-
}
261-
);
274+
in
275+
unwrapped.passthru.tests or { }
276+
// {
277+
version = testers.testVersion (
278+
{
279+
package = finalAttrs.finalPackage;
280+
}
281+
// lib.optionalAttrs (type != "sdk") {
282+
command = "dotnet --info";
283+
}
284+
);
285+
}
286+
// lib.optionalAttrs (type == "sdk") ({
287+
console = lib.recurseIntoAttrs {
288+
# yes, older SDKs omit the comma
289+
cs = mkConsoleTests "C#" "cs" "Hello,?\\ World!";
290+
fs = mkConsoleTests "F#" "fs" "Hello\\ from\\ F#";
291+
vb = mkConsoleTests "VB" "vb" "Hello,?\\ World!";
292+
};
293+
294+
web = lib.recurseIntoAttrs {
295+
cs = mkWebTest "C#" "cs";
296+
fs = mkWebTest "F#" "fs";
297+
};
298+
});
262299
};
263300
})

0 commit comments

Comments
 (0)