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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#!/bin/sh
export "PATH=.:$PATH"
printf '1..16\n'
printf '# error handling\n'
tap3 'exit code on success' <<'EOF'
xe
>>>= 0
EOF
tap3 'exit code on other error' <<'EOF'
true | xe -j NaN
>>>= 1
EOF
tap3 'exit code on when command fails with 1-125' <<'EOF'
xe -s 'exit 42'
<<<
a
>>>= 123
EOF
tap3 'exit code on when command fails with 126' <<'EOF'
xe -s 'exit 126'
<<<
a
>>>= 123
EOF
tap3 'exit code on when command fails with 127' <<'EOF'
xe -s 'exit 127'
<<<
a
>>>= 123
EOF
tap3 'exit code on when command fails with 250' <<'EOF'
xe -s 'exit 250'
<<<
a
>>>= 123
EOF
tap3 'exit code on when command fails with 255' <<'EOF'
xe -s 'exit 255'
<<<
a
>>>= 124
EOF
tap3 'exit code when process was killed' <<'EOF'
xe perl -e 'kill "KILL", $$'
<<<
a
>>>= 125
EOF
# possible false positive result when exec returns ENOENT instead of ENOTDIR here
tap3 'exit code when command cannot be run' <<'EOF'
xe /dev/null/calc.exe
<<<
a
>>>= 126
EOF
tap3 'exit code when command was not found' <<'EOF'
xe /bin/calc.exe
<<<
a
>>>= 127
EOF
tap3 'exit code on empty input when run with -R' <<'EOF'
xe -R echo a
>>>= 122
EOF
tap3 'doesn'\''t stop on errors by default' <<'EOF'
xe -s 'if [ b = $1 ]; then false; else echo $1; fi'
<<<
a
b
c
>>>
a
c
>>>= 123
EOF
tap3 'stops on first error with -F' <<'EOF'
xe -F -s 'if [ b = $1 ]; then false; else echo $1; fi'
<<<
a
b
c
>>>
a
>>>= 123
EOF
tap3 'should close stdin when arguments were read from it' <<'EOF'
xe -s 'sed q'
<<<
a
b
c
>>>
EOF
tap3 'should not close stdin when arguments were read from command line' <<'EOF'
yes | xe -a -s "sed q" -- 1 2 3
>>>
y
y
y
EOF
tap3 'should not close stdin when arguments were read from file' <<'EOF'
yes | xe -f NEWS.md -s 'sed q' 2>&1 | sed 3q
>>>
y
y
y
EOF
|