Unverified Commit ecd810c4 authored by David McFarland's avatar David McFarland Committed by GitHub
Browse files

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

parents c14d641d 4e5ba7e9
Loading
Loading
Loading
Loading
+124 −87
Original line number Diff line number Diff line
@@ -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 ? [ ],
@@ -102,20 +104,32 @@ 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;
              unpackPhase = ''
              unpackPhase =
                let
                  unpackArgs =
                    [ template ]
                    ++ lib.optionals (lang != null) [
                      "-lang"
                      lang
                    ];
                in
                ''
                  mkdir test
                  cd test
                dotnet new ${template} -o . --no-restore
                  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
              );

        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})"
          # yes, older SDKs omit the comma
          [[ "$output" =~ Hello,?\ World! ]] && touch "$out"
              [[ "$output" =~ ${output} ]] && touch "$out"
            '';
      in
      unwrapped.passthru.tests or { }

            mkConsoleTest =
              { name, ... }@args:
              mkDotnetTest (
                args
                // {
        version = testers.testVersion (
          {
            package = finalAttrs.finalPackage;
          }
          // lib.optionalAttrs (type != "sdk") {
            command = "dotnet --info";
                  name = "console-${name}-${suffix}";
                  template = "console";
                  inherit lang;
                }
              );
      }
      // lib.optionalAttrs (type == "sdk") (
        {
          console = mkDotnetTest {
            name = "console";
            template = "console";
          in
          lib.recurseIntoAttrs {
            run = mkConsoleTest {
              name = "run";
              build = checkConsoleOutput "dotnet run";
            };

          publish = mkDotnetTest {
            publish = mkConsoleTest {
              name = "publish";
            template = "console";
              build = "dotnet publish -o $out/bin";
              run = checkConsoleOutput "$src/bin/test";
            };

          self-contained = mkDotnetTest {
            self-contained = mkConsoleTest {
              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 {
            single-file = mkConsoleTest {
              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";
            };
          }
          // 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 = [
@@ -228,36 +271,30 @@ stdenvNoCC.mkDerivation (finalAttrs: {
            '';
            runAllowNetworking = true;
          };
      in
      unwrapped.passthru.tests or { }
      // {
        version = testers.testVersion (
          {
            package = finalAttrs.finalPackage;
          }
        // 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";
          };
          // 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";
        };
      });
  };
})