From e982e95b9a2f12bcc5d9cdb6a88de9f10ef02e1f Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Jan 2025 22:50:10 -0400 Subject: [PATCH 1/3] dotnet: extend tests to cover F# in addition to C# --- pkgs/development/compilers/dotnet/wrapper.nix | 212 ++++++++++-------- 1 file changed, 124 insertions(+), 88 deletions(-) diff --git a/pkgs/development/compilers/dotnet/wrapper.nix b/pkgs/development/compilers/dotnet/wrapper.nix index 90b520519f94..add81d1087c5 100644 --- a/pkgs/development/compilers/dotnet/wrapper.nix +++ b/pkgs/development/compilers/dotnet/wrapper.nix @@ -82,6 +82,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { postFixup = lib.optionalString (unwrapped ? man) '' ln -s ${unwrapped.man} "$man" ''; + passthru = unwrapped.passthru // { inherit unwrapped; tests = @@ -91,6 +92,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { name, stdenv ? stdenvNoCC, template, + lang ? null, usePackageSource ? false, build, buildInputs ? [ ], @@ -106,16 +108,28 @@ stdenvNoCC.mkDerivation (finalAttrs: { 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" @@ -142,61 +156,90 @@ stdenvNoCC.mkDerivation (finalAttrs: { + 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; + 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 = mkConsoleTest { + name = "publish"; + build = "dotnet publish -o $out/bin"; + run = checkConsoleOutput "$src/bin/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 = 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 (type != "sdk") { - command = "dotnet --info"; - } - ); - } - // lib.optionalAttrs (type == "sdk") ( - { - console = mkDotnetTest { - name = "console"; - template = "console"; - build = checkConsoleOutput "dotnet run"; + // 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"; + }; }; - publish = mkDotnetTest { - name = "publish"; - template = "console"; - 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"; - }; - - 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"; - }; - - 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 = [ @@ -228,36 +271,29 @@ stdenvNoCC.mkDerivation (finalAttrs: { ''; 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#"; + }; + + web = lib.recurseIntoAttrs { + cs = mkWebTest "C#" "cs"; + fs = mkWebTest "F#" "fs"; + }; + }); }; }) From 3cc71777af4917899605469927dd2d8a476f08a5 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Jan 2025 22:58:21 -0400 Subject: [PATCH 2/3] dotnet: add VB console tests --- pkgs/development/compilers/dotnet/wrapper.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/compilers/dotnet/wrapper.nix b/pkgs/development/compilers/dotnet/wrapper.nix index add81d1087c5..0c97ea6af39b 100644 --- a/pkgs/development/compilers/dotnet/wrapper.nix +++ b/pkgs/development/compilers/dotnet/wrapper.nix @@ -288,6 +288,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { # 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 { From 4e5ba7e9971020bcd147d25c31f7e85cddafa8bd Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 4 Jan 2025 21:05:32 -0400 Subject: [PATCH 3/3] dotnet: include sdk name in test names --- pkgs/development/compilers/dotnet/wrapper.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/compilers/dotnet/wrapper.nix b/pkgs/development/compilers/dotnet/wrapper.nix index 0c97ea6af39b..d328dbf97b7e 100644 --- a/pkgs/development/compilers/dotnet/wrapper.nix +++ b/pkgs/development/compilers/dotnet/wrapper.nix @@ -104,7 +104,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { 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;