summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/languages-frameworks/dotnet.section.md6
-rw-r--r--pkgs/build-support/build-dotnet-module/default.nix28
-rw-r--r--pkgs/tools/games/opentracker/default.nix6
3 files changed, 38 insertions, 2 deletions
diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md
index 9bf96f3198a..f2a5efd05db 100644
--- a/doc/languages-frameworks/dotnet.section.md
+++ b/doc/languages-frameworks/dotnet.section.md
@@ -77,9 +77,13 @@ To package Dotnet applications, you can use `buildDotnetModule`. This has simila
 * `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies.
 * `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`.
 * `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used.
-* `dotnet-runtime` is useful in cases where you need to change what dotnet runtime is being used.
+* `dotnet-runtime` is useful in cases where you need to change what dotnet runtime is being used. This can be either a regular dotnet runtime, or an aspnetcore.
+* `dotnet-test-sdk` is useful in cases where unit tests expect a different dotnet SDK. By default, this is set to the `dotnet-sdk` attribute.
+* `testProjectFile` is useful in cases where the regular project file does not contain the unit tests. By default, this is set to the `projectFile` attribute.
+* `disabledTests` is used to disable running specific unit tests. This gets passed as: `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all unit test frameworks.
 * `dotnetRestoreFlags` can be used to pass flags to `dotnet restore`.
 * `dotnetBuildFlags` can be used to pass flags to `dotnet build`.
+* `dotnetTestFlags` can be used to pass flags to `dotnet test`.
 * `dotnetInstallFlags` can be used to pass flags to `dotnet install`.
 * `dotnetFlags` can be used to pass flags to all of the above phases.
 
diff --git a/pkgs/build-support/build-dotnet-module/default.nix b/pkgs/build-support/build-dotnet-module/default.nix
index b6330b90775..6a7b70e070b 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 a191a90b17b..d774fcb8f1f 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