| 1 | # |
| 2 | # Usage: |
| 3 | # ./sh-usage.test.sh <function name> |
| 4 | |
| 5 | #### sh -c |
| 6 | $SH -c 'echo hi' |
| 7 | ## stdout: hi |
| 8 | ## status: 0 |
| 9 | |
| 10 | #### empty -c input |
| 11 | # had a bug here |
| 12 | $SH -c '' |
| 13 | ## stdout-json: "" |
| 14 | ## status: 0 |
| 15 | |
| 16 | #### sh +c is accepted |
| 17 | $SH +c 'echo hi' |
| 18 | ## stdout: hi |
| 19 | ## status: 0 |
| 20 | ## N-I mksh/yash stdout-json: "" |
| 21 | ## N-I mksh/yash status: 127 |
| 22 | |
| 23 | #### empty stdin |
| 24 | # had a bug here |
| 25 | echo -n '' | $SH |
| 26 | ## stdout-json: "" |
| 27 | ## status: 0 |
| 28 | |
| 29 | #### shell obeys --help (regression for OSH) |
| 30 | n=$($SH --help | wc -l) |
| 31 | if test $n -gt 0; then |
| 32 | echo yes |
| 33 | fi |
| 34 | ## STDOUT: |
| 35 | yes |
| 36 | ## END |
| 37 | ## N-I dash/mksh stdout-json: "" |
| 38 | |
| 39 | #### args are passed |
| 40 | $SH -c 'argv.py "$@"' dummy a b |
| 41 | ## stdout: ['a', 'b'] |
| 42 | |
| 43 | #### args that look like flags are passed after script |
| 44 | script=$TMP/sh1.sh |
| 45 | echo 'argv.py "$@"' > $script |
| 46 | chmod +x $script |
| 47 | $SH $script --help --help -h |
| 48 | ## stdout: ['--help', '--help', '-h'] |
| 49 | |
| 50 | #### args that look like flags are passed after -c |
| 51 | $SH -c 'argv.py "$@"' --help --help -h |
| 52 | ## stdout: ['--help', '-h'] |
| 53 | |
| 54 | #### exit with explicit arg |
| 55 | exit 42 |
| 56 | ## status: 42 |
| 57 | |
| 58 | #### exit with no args |
| 59 | false |
| 60 | exit |
| 61 | ## status: 1 |
| 62 | |
| 63 | #### --rcfile in non-interactive shell prints warnings |
| 64 | echo 'echo rc' > rc |
| 65 | |
| 66 | $SH --rcfile rc -i </dev/null 2>interactive.txt |
| 67 | grep -q 'warning' interactive.txt |
| 68 | echo warned=$? >&2 |
| 69 | |
| 70 | $SH --rcfile rc </dev/null 2>non-interactive.txt |
| 71 | grep -q 'warning' non-interactive.txt |
| 72 | echo warned=$? >&2 |
| 73 | |
| 74 | head *interactive.txt |
| 75 | |
| 76 | ## STDERR: |
| 77 | warned=1 |
| 78 | warned=0 |
| 79 | ## END |
| 80 | ## N-I bash/dash/mksh STDERR: |
| 81 | warned=1 |
| 82 | warned=1 |
| 83 | ## END |