summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh
blob: a0ac1df9d3c1c5261698738cf8519632771099e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# shellcheck shell=bash disable=SC2154,SC2164

cargoNextestHook() {
    echo "Executing cargoNextestHook"

    runHook preCheck

    if [[ -n "${buildAndTestSubdir-}" ]]; then
        pushd "${buildAndTestSubdir}"
    fi

    local flagsArray=(
        "--target" "@rustcTargetSpec@"
        "--offline"
        "--show-progress=none"
    )

    if [[ -z ${dontUseCargoParallelTests-} ]]; then
        flagsArray+=("-j" "$NIX_BUILD_CORES")
    else
        flagsArray+=("-j" "1")
    fi

    if [ "${cargoCheckType}" != "debug" ]; then
        flagsArray+=("--cargo-profile" "${cargoCheckType}")
    fi

    if [ -n "${cargoCheckNoDefaultFeatures-}" ]; then
        flagsArray+=("--no-default-features")
    fi

    if [ -n "${cargoCheckFeatures-}" ]; then
        flagsArray+=("--features=$(concatStringsSep "," cargoCheckFeatures)")
    fi

    prependToVar checkFlags "--"
    concatTo flagsArray cargoTestFlags checkFlags checkFlagsArray

    echoCmd 'cargoNextestHook flags' "${flagsArray[@]}"
    cargo nextest run "${flagsArray[@]}"

    if [[ -n "${buildAndTestSubdir-}" ]]; then
        popd
    fi

    echo "Finished cargoNextestHook"

    runHook postCheck
}

if [ -z "${dontCargoCheck-}" ] && [ -z "${checkPhase-}" ]; then
  checkPhase=cargoNextestHook
fi