about summary refs log tree commit diff
path: root/pkgs/test/dotnet/use-dotnet-from-env/default.nix
blob: 711a98eb0c29d750a79b9303011216bea121183e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ lib
, dotnet-sdk
, buildPackages # buildDotnetModule, dotnet-runtime
, testers
, runCommand
, removeReferencesTo
}:
let
  inherit (buildPackages) buildDotnetModule dotnet-runtime;

  app = buildDotnetModule {
    name = "use-dotnet-from-env-test-application";
    src = ./src;
    nugetDeps = ./nuget-deps.nix;
    useDotnetFromEnv = true;
    env.TargetFramework = "net${lib.versions.majorMinor (lib.getVersion dotnet-sdk)}";
  };

  appWithoutFallback = app.overrideAttrs (oldAttrs: {
    nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [
      removeReferencesTo
    ];
    postFixup = (oldAttrs.postFixup or "") + ''
      remove-references-to -t ${dotnet-runtime} "$out/bin/Application"
    '';
  });

  runtimeVersion = lib.getVersion dotnet-runtime;
  runtimeVersionFile = builtins.toFile "dotnet-version.txt" runtimeVersion;
in
{
  fallback = testers.testEqualContents {
    assertion = "buildDotnetModule sets fallback DOTNET_ROOT in wrapper";
    expected = runtimeVersionFile;
    actual = runCommand "use-dotnet-from-env-fallback-test" { } ''
      ${app}/bin/Application >"$out"
    '';
  };

  # Check that appWithoutFallback does not use fallback .NET runtime.
  without-fallback = testers.testBuildFailure (runCommand "use-dotnet-from-env-without-fallback-test" { } ''
    ${appWithoutFallback}/bin/Application >"$out"
  '');

  # NB assumes that without-fallback above to passes.
  use-dotnet-root-env = testers.testEqualContents {
    assertion = "buildDotnetModule uses DOTNET_ROOT from environment in wrapper";
    expected = runtimeVersionFile;
    actual = runCommand "use-dotnet-from-env-root-test" { env.DOTNET_ROOT = dotnet-runtime; } ''
      ${appWithoutFallback}/bin/Application >"$out"
    '';
  };
  use-dotnet-path-env = testers.testEqualContents {
    assertion = "buildDotnetModule uses DOTNET_ROOT from dotnet in PATH in wrapper";
    expected = runtimeVersionFile;
    actual = runCommand "use-dotnet-from-env-path-test" { dotnetRuntime = dotnet-runtime; } ''
      PATH=$dotnetRuntime''${PATH+:}$PATH ${appWithoutFallback}/bin/Application >"$out"
    '';
  };
}