sdrangel: fix build on x86_64-darwin
[NixPkgs.git] / pkgs / build-support / testers / expect-failure.sh
blob9c725d48bf34251f35d9a5f54c393231553a341b
1 # Run a builder, flip exit code, save log and fix outputs
3 # Sub-goals:
4 # - Delegate to another original builder passed via args
5 # - Save the build log to output for further checks
6 # - Make the derivation succeed if the original builder fails
7 # - Make the derivation fail if the original builder returns exit code 0
9 # Requirements:
10 # This runs before, without and after stdenv. Do not modify the environment;
11 # especially not before invoking the original builder. For example, use
12 # "@" substitutions instead of PATH.
13 # Do not export any variables.
15 # Stricter bash
16 set -eu
18 # ------------------------
19 # Run the original builder
21 echo "testBuildFailure: Expecting non-zero exit from builder and args: ${*@Q}"
23 ("$@" 2>&1) | @coreutils@/bin/tee $TMPDIR/testBuildFailure.log \
24 | while IFS= read -r ln; do
25 echo "original builder: $ln"
26 done
28 r=${PIPESTATUS[0]}
29 if [[ $r = 0 ]]; then
30 echo "testBuildFailure: The builder did not fail, but a failure was expected!"
31 exit 1
33 echo "testBuildFailure: Original builder produced exit code: $r"
35 # -----------------------------------------
36 # Write the build log to the default output
38 # # from stdenv setup.sh
39 getAllOutputNames() {
40 if [ -n "$__structuredAttrs" ]; then
41 echo "${!outputs[*]}"
42 else
43 echo "$outputs"
47 outs=( $(getAllOutputNames) )
48 defOut=${outs[0]}
49 defOutPath=${!defOut}
51 if [[ ! -d $defOutPath ]]; then
52 if [[ -e $defOutPath ]]; then
53 @coreutils@/bin/mv $defOutPath $TMPDIR/out-node
54 @coreutils@/bin/mkdir $defOutPath
55 @coreutils@/bin/mv $TMPDIR/out-node $defOutPath/result
59 @coreutils@/bin/mkdir -p $defOutPath
60 @coreutils@/bin/mv $TMPDIR/testBuildFailure.log $defOutPath/testBuildFailure.log
61 echo $r >$defOutPath/testBuildFailure.exit
63 # ------------------------------------------------------
64 # Put empty directories in place for any missing outputs
66 for outputName in ${outputs:-out}; do
67 outputPath="${!outputName}"
68 if [[ ! -e "${outputPath}" ]]; then
69 @coreutils@/bin/mkdir "${outputPath}";
71 done