nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 149 lines 4.1 kB view raw
1{ 2 emptyDirectory, 3 hello, 4 lib, 5 overrideStructuredAttrs, 6 runCommand, 7 stdenvNoCC, 8 testers, 9}: 10let 11 inherit (lib.attrsets) recurseIntoAttrs; 12 final = { 13 # NOTE: This example is used in the docs. 14 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailurePrime 15 # or doc/build-helpers/testers.chapter.md 16 doc-example = testers.testBuildFailure' { 17 drv = runCommand "doc-example" { } '' 18 echo ok-ish >"$out" 19 echo failing though 20 exit 3 21 ''; 22 expectedBuilderExitCode = 3; 23 expectedBuilderLogEntries = [ "failing though" ]; 24 script = '' 25 grep --silent -F 'ok-ish' "$failed/result" 26 ''; 27 }; 28 29 happy = testers.testBuildFailure' { 30 drv = runCommand "happy" { } '' 31 echo ok-ish >$out 32 33 echo failing though 34 echo also stderr 1>&2 35 echo 'line\nwith-\bbackslashes' 36 printf "incomplete line - no newline" 37 38 exit 3 39 ''; 40 expectedBuilderExitCode = 3; 41 expectedBuilderLogEntries = [ 42 "failing though" 43 "also stderr" 44 ''line\nwith-\bbackslashes'' 45 "incomplete line - no newline" 46 ]; 47 script = '' 48 grep --silent -F 'ok-ish' "$failed/result" 49 ''; 50 }; 51 52 happyStructuredAttrs = overrideStructuredAttrs true final.happy; 53 54 helloDoesNotFail = testers.testBuildFailure' { 55 drv = testers.testBuildFailure hello; 56 expectedBuilderLogEntries = [ 57 "testBuildFailure: The builder did not fail, but a failure was expected" 58 ]; 59 }; 60 61 multiOutput = testers.testBuildFailure' { 62 drv = 63 runCommand "multiOutput" 64 { 65 # dev will be the default output 66 outputs = [ 67 "dev" 68 "doc" 69 "out" 70 ]; 71 } 72 '' 73 echo i am failing 74 exit 1 75 ''; 76 expectedBuilderLogEntries = [ 77 "i am failing" 78 ]; 79 script = '' 80 # Checking our note that dev is the default output 81 echo $failed/_ | grep -- '-dev/_' >/dev/null 82 echo 'All good.' 83 ''; 84 }; 85 86 multiOutputStructuredAttrs = overrideStructuredAttrs true final.multiOutput; 87 88 sideEffects = testers.testBuildFailure' { 89 drv = stdenvNoCC.mkDerivation { 90 name = "fail-with-side-effects"; 91 src = emptyDirectory; 92 93 postHook = '' 94 echo touching side-effect... 95 # Assert that the side-effect doesn't exist yet... 96 # We're checking that this hook isn't run by expect-failure.sh 97 if [[ -e side-effect ]]; then 98 echo "side-effect already exists" 99 exit 1 100 fi 101 touch side-effect 102 ''; 103 104 buildPhase = '' 105 echo i am failing 106 exit 1 107 ''; 108 }; 109 expectedBuilderLogEntries = [ 110 "touching side-effect..." 111 "i am failing" 112 ]; 113 script = '' 114 [[ ! -e side-effect ]] 115 ''; 116 }; 117 118 sideEffectsStructuredAttrs = overrideStructuredAttrs true final.sideEffects; 119 120 exitCodeNegativeTest = testers.testBuildFailure' { 121 drv = testers.testBuildFailure' { 122 drv = runCommand "exit-code" { } "exit 3"; 123 # Default expected exit code is 1 124 }; 125 expectedBuilderLogEntries = [ 126 "ERROR: testBuilderExitCode: original builder produced exit code 3 but was expected to produce 1" 127 ]; 128 }; 129 130 exitCodeNegativeTestStructuredAttrs = overrideStructuredAttrs true final.exitCodeNegativeTest; 131 132 logNegativeTest = testers.testBuildFailure' { 133 drv = testers.testBuildFailure' { 134 drv = runCommand "exit-code" { } '' 135 nixLog "apples" 136 exit 3 137 ''; 138 expectedBuilderExitCode = 3; 139 expectedBuilderLogEntries = [ "bees" ]; 140 }; 141 expectedBuilderLogEntries = [ 142 "ERROR: testBuilderLogEntries: original builder log does not contain 'bees'" 143 ]; 144 }; 145 146 logNegativeTestStructuredAttrs = overrideStructuredAttrs true final.logNegativeTest; 147 }; 148in 149recurseIntoAttrs final