diff options
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/dotnet/default.nix | 4 | ||||
-rw-r--r-- | pkgs/test/dotnet/project-references/default.nix | 10 | ||||
-rw-r--r-- | pkgs/test/dotnet/structured-attrs/default.nix | 36 | ||||
-rw-r--r-- | pkgs/test/dotnet/structured-attrs/nuget-deps.nix | 5 | ||||
-rw-r--r-- | pkgs/test/dotnet/structured-attrs/src/Application.cs | 10 | ||||
-rw-r--r-- | pkgs/test/dotnet/structured-attrs/src/Application.csproj | 5 | ||||
-rw-r--r-- | pkgs/test/dotnet/use-dotnet-from-env/default.nix | 60 | ||||
-rw-r--r-- | pkgs/test/dotnet/use-dotnet-from-env/nuget-deps.nix | 5 | ||||
-rw-r--r-- | pkgs/test/dotnet/use-dotnet-from-env/src/Application.cs | 3 | ||||
-rw-r--r-- | pkgs/test/dotnet/use-dotnet-from-env/src/Application.csproj | 5 |
10 files changed, 139 insertions, 4 deletions
diff --git a/pkgs/test/dotnet/default.nix b/pkgs/test/dotnet/default.nix index 7592b09d76e3c..d70850c05fdb0 100644 --- a/pkgs/test/dotnet/default.nix +++ b/pkgs/test/dotnet/default.nix @@ -1,5 +1,7 @@ -{ callPackage }: +{ lib, callPackage }: { project-references = callPackage ./project-references { }; + use-dotnet-from-env = lib.recurseIntoAttrs (callPackage ./use-dotnet-from-env { }); + structured-attrs = lib.recurseIntoAttrs (callPackage ./structured-attrs { }); } diff --git a/pkgs/test/dotnet/project-references/default.nix b/pkgs/test/dotnet/project-references/default.nix index 0736cedc9096b..762686a7d01ff 100644 --- a/pkgs/test/dotnet/project-references/default.nix +++ b/pkgs/test/dotnet/project-references/default.nix @@ -4,11 +4,13 @@ { lib , dotnet-sdk -, buildDotnetModule +, buildPackages # buildDotnetModule , runCommand }: let + inherit (buildPackages) buildDotnetModule; + nugetDeps = ./nuget-deps.nix; # Specify the TargetFramework via an environment variable so that we don't @@ -18,7 +20,8 @@ let library = buildDotnetModule { name = "project-references-test-library"; src = ./library; - inherit nugetDeps TargetFramework; + inherit nugetDeps; + env.TargetFramework = TargetFramework; packNupkg = true; }; @@ -26,7 +29,8 @@ let application = buildDotnetModule { name = "project-references-test-application"; src = ./application; - inherit nugetDeps TargetFramework; + inherit nugetDeps; + env.TargetFramework = TargetFramework; projectReferences = [ library ]; }; diff --git a/pkgs/test/dotnet/structured-attrs/default.nix b/pkgs/test/dotnet/structured-attrs/default.nix new file mode 100644 index 0000000000000..cf96fef8dbdcc --- /dev/null +++ b/pkgs/test/dotnet/structured-attrs/default.nix @@ -0,0 +1,36 @@ +{ lib +, dotnet-sdk +, buildPackages # buildDotnetModule +, testers +, runCommand +}: +let + # Note: without structured attributes, we can’t use derivation arguments that + # contain spaces unambiguously because arguments are passed as space-separated + # environment variables. + copyrightString = "Public domain 🅮"; + + inherit (buildPackages) buildDotnetModule; + + app = buildDotnetModule { + name = "structured-attrs-test-application"; + src = ./src; + nugetDeps = ./nuget-deps.nix; + dotnetFlags = [ "--property:Copyright=${copyrightString}" ]; + env.TargetFramework = "net${lib.versions.majorMinor (lib.getVersion dotnet-sdk)}"; + __structuredAttrs = true; + }; +in +{ + no-structured-attrs = testers.testBuildFailure (app.overrideAttrs { + __structuredAttrs = false; + }); + + check-output = testers.testEqualContents { + assertion = "buildDotnetModule sets AssemblyCopyrightAttribute with structured attributes"; + expected = builtins.toFile "expected-copyright.txt" copyrightString; + actual = runCommand "dotnet-structured-attrs-test" { } '' + ${app}/bin/Application >"$out" + ''; + }; +} diff --git a/pkgs/test/dotnet/structured-attrs/nuget-deps.nix b/pkgs/test/dotnet/structured-attrs/nuget-deps.nix new file mode 100644 index 0000000000000..f3a17967e25c8 --- /dev/null +++ b/pkgs/test/dotnet/structured-attrs/nuget-deps.nix @@ -0,0 +1,5 @@ +# This file was automatically generated by passthru.fetch-deps. +# Please dont edit it manually, your changes might get overwritten! + +{ fetchNuGet }: [ +] diff --git a/pkgs/test/dotnet/structured-attrs/src/Application.cs b/pkgs/test/dotnet/structured-attrs/src/Application.cs new file mode 100644 index 0000000000000..3bc548105c2b4 --- /dev/null +++ b/pkgs/test/dotnet/structured-attrs/src/Application.cs @@ -0,0 +1,10 @@ +using System; +using System.Reflection; + +Console.Write( + ( + (AssemblyCopyrightAttribute)Assembly + .GetExecutingAssembly() + .GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true)[0] + ).Copyright +); diff --git a/pkgs/test/dotnet/structured-attrs/src/Application.csproj b/pkgs/test/dotnet/structured-attrs/src/Application.csproj new file mode 100644 index 0000000000000..decaa6d961aab --- /dev/null +++ b/pkgs/test/dotnet/structured-attrs/src/Application.csproj @@ -0,0 +1,5 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>exe</OutputType> + </PropertyGroup> +</Project> diff --git a/pkgs/test/dotnet/use-dotnet-from-env/default.nix b/pkgs/test/dotnet/use-dotnet-from-env/default.nix new file mode 100644 index 0000000000000..711a98eb0c29d --- /dev/null +++ b/pkgs/test/dotnet/use-dotnet-from-env/default.nix @@ -0,0 +1,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" + ''; + }; +} diff --git a/pkgs/test/dotnet/use-dotnet-from-env/nuget-deps.nix b/pkgs/test/dotnet/use-dotnet-from-env/nuget-deps.nix new file mode 100644 index 0000000000000..f3a17967e25c8 --- /dev/null +++ b/pkgs/test/dotnet/use-dotnet-from-env/nuget-deps.nix @@ -0,0 +1,5 @@ +# This file was automatically generated by passthru.fetch-deps. +# Please dont edit it manually, your changes might get overwritten! + +{ fetchNuGet }: [ +] diff --git a/pkgs/test/dotnet/use-dotnet-from-env/src/Application.cs b/pkgs/test/dotnet/use-dotnet-from-env/src/Application.cs new file mode 100644 index 0000000000000..5efc571ca9a3e --- /dev/null +++ b/pkgs/test/dotnet/use-dotnet-from-env/src/Application.cs @@ -0,0 +1,3 @@ +using System; + +Console.Write(Environment.Version.ToString()); diff --git a/pkgs/test/dotnet/use-dotnet-from-env/src/Application.csproj b/pkgs/test/dotnet/use-dotnet-from-env/src/Application.csproj new file mode 100644 index 0000000000000..decaa6d961aab --- /dev/null +++ b/pkgs/test/dotnet/use-dotnet-from-env/src/Application.csproj @@ -0,0 +1,5 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>exe</OutputType> + </PropertyGroup> +</Project> |