dotnet: improve language coverage of passthru.tests for dotnet sdks (#370789)

Changed files
+124 -87
pkgs
development
compilers
dotnet
+124 -87
pkgs/development/compilers/dotnet/wrapper.nix
···
postFixup = lib.optionalString (unwrapped ? man) ''
ln -s ${unwrapped.man} "$man"
'';
+
passthru = unwrapped.passthru // {
inherit unwrapped;
tests =
···
name,
stdenv ? stdenvNoCC,
template,
+
lang ? null,
usePackageSource ? false,
build,
buildInputs ? [ ],
···
let
sdk = finalAttrs.finalPackage;
built = stdenv.mkDerivation {
-
name = "dotnet-test-${name}";
+
name = "${sdk.name}-test-${name}";
buildInputs = [ sdk ] ++ buildInputs ++ lib.optional (usePackageSource) sdk.packages;
# make sure ICU works in a sandbox
propagatedSandboxProfile = toString sdk.__propagatedSandboxProfile;
-
unpackPhase = ''
-
mkdir test
-
cd test
-
dotnet new ${template} -o . --no-restore
-
'';
+
unpackPhase =
+
let
+
unpackArgs =
+
[ template ]
+
++ lib.optionals (lang != null) [
+
"-lang"
+
lang
+
];
+
in
+
''
+
mkdir test
+
cd test
+
dotnet new ${lib.escapeShellArgs unpackArgs} -o . --no-restore
+
'';
buildPhase = build;
dontPatchELF = true;
};
in
-
if run == null then
+
# older SDKs don't include an embedded FSharp.Core package
+
if lang == "F#" && lib.versionOlder sdk.version "6.0.400" then
+
null
+
else if run == null then
built
else
runCommand "${built.name}-run"
···
+ run
);
-
# Setting LANG to something other than 'C' forces the runtime to search
-
# for ICU, which will be required in most user environments.
-
checkConsoleOutput = command: ''
-
output="$(LANG=C.UTF-8 ${command})"
-
# yes, older SDKs omit the comma
-
[[ "$output" =~ Hello,?\ World! ]] && touch "$out"
-
'';
-
in
-
unwrapped.passthru.tests or { }
-
// {
-
version = testers.testVersion (
-
{
-
package = finalAttrs.finalPackage;
-
}
-
// lib.optionalAttrs (type != "sdk") {
-
command = "dotnet --info";
-
}
-
);
-
}
-
// lib.optionalAttrs (type == "sdk") (
-
{
-
console = mkDotnetTest {
-
name = "console";
-
template = "console";
-
build = checkConsoleOutput "dotnet run";
-
};
+
mkConsoleTests =
+
lang: suffix: output:
+
let
+
# Setting LANG to something other than 'C' forces the runtime to search
+
# for ICU, which will be required in most user environments.
+
checkConsoleOutput = command: ''
+
output="$(LANG=C.UTF-8 ${command})"
+
[[ "$output" =~ ${output} ]] && touch "$out"
+
'';
+
+
mkConsoleTest =
+
{ name, ... }@args:
+
mkDotnetTest (
+
args
+
// {
+
name = "console-${name}-${suffix}";
+
template = "console";
+
inherit lang;
+
}
+
);
+
in
+
lib.recurseIntoAttrs {
+
run = mkConsoleTest {
+
name = "run";
+
build = checkConsoleOutput "dotnet run";
+
};
-
publish = mkDotnetTest {
-
name = "publish";
-
template = "console";
-
build = "dotnet publish -o $out/bin";
-
run = checkConsoleOutput "$src/bin/test";
-
};
+
publish = mkConsoleTest {
+
name = "publish";
+
build = "dotnet publish -o $out/bin";
+
run = checkConsoleOutput "$src/bin/test";
+
};
-
self-contained = mkDotnetTest {
-
name = "self-contained";
-
template = "console";
-
usePackageSource = true;
-
build = "dotnet publish --use-current-runtime --sc -o $out";
-
runtime = null;
-
run = checkConsoleOutput "$src/test";
-
};
+
self-contained = mkConsoleTest {
+
name = "self-contained";
+
usePackageSource = true;
+
build = "dotnet publish --use-current-runtime --sc -o $out";
+
runtime = null;
+
run = checkConsoleOutput "$src/test";
+
};
-
single-file = mkDotnetTest {
-
name = "single-file";
-
template = "console";
-
usePackageSource = true;
-
build = "dotnet publish --use-current-runtime -p:PublishSingleFile=true -o $out/bin";
-
runtime = null;
-
run = checkConsoleOutput "$src/bin/test";
+
single-file = mkConsoleTest {
+
name = "single-file";
+
usePackageSource = true;
+
build = "dotnet publish --use-current-runtime -p:PublishSingleFile=true -o $out/bin";
+
runtime = null;
+
run = checkConsoleOutput "$src/bin/test";
+
};
+
}
+
// lib.optionalAttrs finalAttrs.finalPackage.hasILCompiler {
+
aot = mkConsoleTest {
+
name = "aot";
+
stdenv = if stdenv.hostPlatform.isDarwin then swiftPackages.stdenv else stdenv;
+
usePackageSource = true;
+
buildInputs =
+
[
+
zlib
+
]
+
++ lib.optional stdenv.hostPlatform.isDarwin (
+
with darwin;
+
with apple_sdk.frameworks;
+
[
+
swiftPackages.swift
+
Foundation
+
CryptoKit
+
GSS
+
ICU
+
]
+
);
+
build = ''
+
dotnet restore -p:PublishAot=true
+
dotnet publish -p:PublishAot=true -o $out/bin
+
'';
+
runtime = null;
+
run = checkConsoleOutput "$src/bin/test";
+
};
};
-
web = mkDotnetTest {
-
name = "web";
+
mkWebTest =
+
lang: suffix:
+
mkDotnetTest {
+
name = "web-${suffix}";
template = "web";
+
inherit lang;
build = "dotnet publish -o $out/bin";
runtime = finalAttrs.finalPackage.aspnetcore;
runInputs = [
···
'';
runAllowNetworking = true;
};
-
}
-
// lib.optionalAttrs finalAttrs.finalPackage.hasILCompiler {
-
aot = mkDotnetTest {
-
name = "aot";
-
stdenv = if stdenv.hostPlatform.isDarwin then swiftPackages.stdenv else stdenv;
-
template = "console";
-
usePackageSource = true;
-
buildInputs =
-
[
-
zlib
-
]
-
++ lib.optional stdenv.hostPlatform.isDarwin (
-
with darwin;
-
with apple_sdk.frameworks;
-
[
-
swiftPackages.swift
-
Foundation
-
CryptoKit
-
GSS
-
ICU
-
]
-
);
-
build = ''
-
dotnet restore -p:PublishAot=true
-
dotnet publish -p:PublishAot=true -o $out/bin
-
'';
-
runtime = null;
-
run = checkConsoleOutput "$src/bin/test";
-
};
-
}
-
);
+
in
+
unwrapped.passthru.tests or { }
+
// {
+
version = testers.testVersion (
+
{
+
package = finalAttrs.finalPackage;
+
}
+
// lib.optionalAttrs (type != "sdk") {
+
command = "dotnet --info";
+
}
+
);
+
}
+
// lib.optionalAttrs (type == "sdk") ({
+
console = lib.recurseIntoAttrs {
+
# yes, older SDKs omit the comma
+
cs = mkConsoleTests "C#" "cs" "Hello,?\\ World!";
+
fs = mkConsoleTests "F#" "fs" "Hello\\ from\\ F#";
+
vb = mkConsoleTests "VB" "vb" "Hello,?\\ World!";
+
};
+
+
web = lib.recurseIntoAttrs {
+
cs = mkWebTest "C#" "cs";
+
fs = mkWebTest "F#" "fs";
+
};
+
});
};
})