about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorKevin Cox <kevincox@kevincox.ca>2021-11-01 07:42:55 -0400
committerGitHub <noreply@github.com>2021-11-01 07:42:55 -0400
commit4559160c4f4eb55f9eee0cb6015e2a0f3fa80462 (patch)
treeba8a2da55b03227e4c63c3f70088afbafeb2d029 /pkgs
parent42e9ec0c3962c4070a13ff7c403d5cde0b6237ae (diff)
parent7bee2fb2b706ee7fab1c98c4f2ceff323999007d (diff)
Merge pull request #144062 from IvarWithoutBones/dotnet-module/tests
buildDotnetModule: add support for running unit tests
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/build-dotnet-module/default.nix28
-rw-r--r--pkgs/tools/games/opentracker/default.nix6
2 files changed, 33 insertions, 1 deletions
diff --git a/pkgs/build-support/build-dotnet-module/default.nix b/pkgs/build-support/build-dotnet-module/default.nix
index b6330b90775c5..6a7b70e070b0c 100644
--- a/pkgs/build-support/build-dotnet-module/default.nix
+++ b/pkgs/build-support/build-dotnet-module/default.nix
@@ -2,6 +2,7 @@
 
 { name ? "${args.pname}-${args.version}"
 , enableParallelBuilding ? true
+, doCheck ? false
 # Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
 , makeWrapperArgs ? []
 
@@ -9,6 +10,8 @@
 , dotnetRestoreFlags ? []
 # Flags to pass to `dotnet build`.
 , dotnetBuildFlags ? []
+# Flags to pass to `dotnet test`, if running tests is enabled.
+, dotnetTestFlags ? []
 # Flags to pass to `dotnet install`.
 , dotnetInstallFlags ? []
 # Flags to pass to dotnet in all phases.
@@ -27,12 +30,20 @@
 # These get wrapped into `LD_LIBRARY_PATH`.
 , runtimeDeps ? []
 
+# Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
+# See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
+, disabledTests ? []
+# The project file to run unit tests against. This is usually the regular project file, but sometimes it needs to be manually set.
+, testProjectFile ? projectFile
+
 # The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
 , buildType ? "Release"
 # The dotnet SDK to use.
 , dotnet-sdk ? dotnetCorePackages.sdk_5_0
 # The dotnet runtime to use.
 , dotnet-runtime ? dotnetCorePackages.runtime_5_0
+# The dotnet SDK to run tests against. This can differentiate from the SDK compiled against.
+, dotnet-test-sdk ? dotnet-sdk
 , ... } @ args:
 
 assert projectFile == null -> throw "Defining the `projectFile` attribute is required. This is usually an `.csproj`, or `.sln` file.";
@@ -119,6 +130,23 @@ let
       runHook postBuild
     '';
 
+    checkPhase = args.checkPhase or ''
+      runHook preCheck
+
+      ${lib.getBin dotnet-test-sdk}/bin/dotnet test "$testProjectFile" \
+        -maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
+        -p:ContinuousIntegrationBuild=true \
+        -p:Deterministic=true \
+        --configuration "$buildType" \
+        --no-build \
+        --logger "console;verbosity=normal" \
+        ${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "|FullyQualifiedName!=" disabledTests}\""} \
+        "''${dotnetTestFlags[@]}"  \
+        "''${dotnetFlags[@]}"
+
+      runHook postCheck
+    '';
+
     installPhase = args.installPhase or ''
       runHook preInstall
 
diff --git a/pkgs/tools/games/opentracker/default.nix b/pkgs/tools/games/opentracker/default.nix
index a191a90b17ba6..d774fcb8f1f00 100644
--- a/pkgs/tools/games/opentracker/default.nix
+++ b/pkgs/tools/games/opentracker/default.nix
@@ -25,10 +25,14 @@ buildDotnetModule rec {
   };
 
   dotnet-runtime = dotnetCorePackages.runtime_3_1;
-  projectFile = "OpenTracker.sln";
   nugetDeps = ./deps.nix;
+
+  projectFile = "OpenTracker.sln";
   executables = [ "OpenTracker" ];
 
+  doCheck = true;
+  dotnet-test-sdk = dotnetCorePackages.sdk_3_1;
+
   nativeBuildInputs = [
     autoPatchelfHook
     wrapGAppsHook