about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid McFarland2024-09-02 07:09:06 -0700
committerGitHub2024-09-02 07:09:06 -0700
commit7bc85af0c5da0cd45a47256180af6969a21d8814 (patch)
tree315bee342171e64729926d93c8af6911fcb39724
parent41ac9a8729c3b55174d8d2b02712e9c9dfc176b4 (diff)
parenta177c637b91c7d40531327a04dfdc3e1035d293b (diff)
buildDotnetModule: add `testFilters` arg (#336571)
-rw-r--r--doc/languages-frameworks/dotnet.section.md1
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix6
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh8
-rw-r--r--pkgs/by-name/ne/nexusmods-app/package.nix32
4 files changed, 29 insertions, 18 deletions
diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md
index 546b451f3117..cdacec1c3a5e 100644
--- a/doc/languages-frameworks/dotnet.section.md
+++ b/doc/languages-frameworks/dotnet.section.md
@@ -118,6 +118,7 @@ For more detail about managing the `deps.nix` file, see [Generating and updating
 * `dotnet-sdk` is useful in cases where you need to change what dotnet SDK is being used. You can also set this to the result of `dotnetSdkPackages.combinePackages`, if the project uses multiple SDKs to build.
 * `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.
 * `testProjectFile` is useful in cases where the regular project file does not contain the unit tests. It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this. Note that if set, only tests from this project are executed.
+* `testFilters` is used to disable running unit tests based on various [filters](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details). This gets passed as: `dotnet test --filter "{}"`, with each filter being concatenated using `"&"`.
 * `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`.
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index c8ad6a174ce5..418c90c64899 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -67,7 +67,12 @@ let
       # platforms in meta.platforms which are supported by the sdk.
       runtimeId ? null,
 
+      # Test filters. This gets passed to `dotnet test --filter`, concatenated using `&`.
+      # You may also use `disabledTests` to filter tests based on their name.
+      # See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
+      testFilters ? [ ],
       # Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
+      # You may also use `testFilters` to pass more generic filters to `dotnet test --filter`.
       # 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 referenced in the regular project file, but sometimes it needs to be manually set.
@@ -132,6 +137,7 @@ let
       dotnetBuildType = buildType;
       dotnetProjectFiles = projectFiles;
       dotnetTestProjectFiles = testProjectFiles;
+      dotnetTestFilters = testFilters;
       dotnetDisabledTests = disabledTests;
       dotnetRuntimeIds = lib.singleton (
         if runtimeId != null then runtimeId else systemToDotnetRid stdenvNoCC.hostPlatform.system
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
index 4dc8b5a97a1f..21ebbbe5381e 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
@@ -9,6 +9,7 @@ dotnetCheckHook() {
         local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
         local dotnetTestProjectFilesArray=( "${dotnetTestProjectFiles[@]}" )
         local dotnetTestFlagsArray=( "${dotnetTestFlags[@]}" )
+        local dotnetTestFiltersArray=( "${dotnetTestFilters[@]}" )
         local dotnetDisabledTestsArray=( "${dotnetDisabledTests[@]}" )
         local dotnetRuntimeDepsArray=( "${dotnetRuntimeDeps[@]}" )
         local dotnetRuntimeIdsArray=( "${dotnetRuntimeIds[@]}" )
@@ -16,6 +17,7 @@ dotnetCheckHook() {
         local dotnetProjectFilesArray=($dotnetProjectFiles)
         local dotnetTestProjectFilesArray=($dotnetTestProjectFiles)
         local dotnetTestFlagsArray=($dotnetTestFlags)
+        local dotnetTestFiltersArray=($dotnetTestFilters)
         local dotnetDisabledTestsArray=($dotnetDisabledTests)
         local dotnetRuntimeDepsArray=($dotnetRuntimeDeps)
         local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
@@ -23,8 +25,12 @@ dotnetCheckHook() {
 
     if (( ${#dotnetDisabledTestsArray[@]} > 0 )); then
         local disabledTestsFilters=("${dotnetDisabledTestsArray[@]/#/FullyQualifiedName!=}")
+        dotnetTestFiltersArray=( "${dotnetTestFiltersArray[@]}" "${disabledTestsFilters[@]//,/%2C}" )
+    fi
+
+    if (( ${#dotnetTestFiltersArray[@]} > 0 )); then
         local OLDIFS="$IFS" IFS='&'
-        dotnetTestFlagsArray+=("--filter:${disabledTestsFilters[*]//,/%2C}")
+        dotnetTestFlagsArray+=("--filter:${dotnetTestFiltersArray[*]}")
         IFS="$OLDIFS"
     fi
 
diff --git a/pkgs/by-name/ne/nexusmods-app/package.nix b/pkgs/by-name/ne/nexusmods-app/package.nix
index 9d4c3947d97a..03784eeb34c3 100644
--- a/pkgs/by-name/ne/nexusmods-app/package.nix
+++ b/pkgs/by-name/ne/nexusmods-app/package.nix
@@ -71,25 +71,23 @@ buildDotnetModule (finalAttrs: {
 
   doCheck = true;
 
-  dotnetTestFlags = [
-    "--environment=USER=nobody"
-    (
-      "--filter="
-      + lib.strings.concatStringsSep "&" (
-        [
-          "Category!=Disabled"
-          "FlakeyTest!=True"
-          "RequiresNetworking!=True"
-          "FullyQualifiedName!=NexusMods.UI.Tests.ImageCacheTests.Test_LoadAndCache_RemoteImage"
-          "FullyQualifiedName!=NexusMods.UI.Tests.ImageCacheTests.Test_LoadAndCache_ImageStoredFile"
-        ]
-        ++ lib.optionals (!_7zz.meta.unfree) [
-          "FullyQualifiedName!=NexusMods.Games.FOMOD.Tests.FomodXmlInstallerTests.InstallsFilesSimple_UsingRar"
-        ]
-      )
-    )
+  dotnetTestFlags = [ "--environment=USER=nobody" ];
+
+  testFilters = [
+    "Category!=Disabled"
+    "FlakeyTest!=True"
+    "RequiresNetworking!=True"
   ];
 
+  disabledTests =
+    [
+      "NexusMods.UI.Tests.ImageCacheTests.Test_LoadAndCache_RemoteImage"
+      "NexusMods.UI.Tests.ImageCacheTests.Test_LoadAndCache_ImageStoredFile"
+    ]
+    ++ lib.optionals (!_7zz.meta.unfree) [
+      "NexusMods.Games.FOMOD.Tests.FomodXmlInstallerTests.InstallsFilesSimple_UsingRar"
+    ];
+
   passthru = {
     tests =
       let