about summary refs log tree commit diff
path: root/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/rust/hooks/cargo-nextest-hook.sh')
-rw-r--r--pkgs/build-support/rust/hooks/cargo-nextest-hook.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh b/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh
new file mode 100644
index 0000000000000..de85683ead2ac
--- /dev/null
+++ b/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh
@@ -0,0 +1,54 @@
+declare -a checkFlags
+declare -a cargoTestFlags
+
+cargoNextestHook() {
+    echo "Executing cargoNextestHook"
+
+    runHook preCheck
+
+    if [[ -n "${buildAndTestSubdir-}" ]]; then
+        pushd "${buildAndTestSubdir}"
+    fi
+
+    if [[ -z ${dontUseCargoParallelTests-} ]]; then
+        threads=$NIX_BUILD_CORES
+    else
+        threads=1
+    fi
+
+    if [ "${cargoCheckType}" != "debug" ]; then
+        cargoCheckProfileFlag="--${cargoCheckType}"
+    fi
+
+    if [ -n "${cargoCheckNoDefaultFeatures-}" ]; then
+        cargoCheckNoDefaultFeaturesFlag=--no-default-features
+    fi
+
+    if [ -n "${cargoCheckFeatures-}" ]; then
+        cargoCheckFeaturesFlag="--features=${cargoCheckFeatures// /,}"
+    fi
+
+    argstr="${cargoCheckProfileFlag} ${cargoCheckNoDefaultFeaturesFlag} ${cargoCheckFeaturesFlag}
+        --target @rustTargetPlatformSpec@ --frozen ${cargoTestFlags}"
+
+    (
+        set -x
+        cargo nextest run \
+              -j ${threads} \
+              ${argstr} -- \
+              ${checkFlags} \
+              ${checkFlagsArray+"${checkFlagsArray[@]}"}
+    )
+
+    if [[ -n "${buildAndTestSubdir-}" ]]; then
+        popd
+    fi
+
+    echo "Finished cargoNextestHook"
+
+    runHook postCheck
+}
+
+if [ -z "${dontCargoCheck-}" ] && [ -z "${checkPhase-}" ]; then
+  checkPhase=cargoNextestHook
+fi