| 1 | #!bin/ysh
|
| 2 |
|
| 3 | shopt -s redefine_proc_func # log
|
| 4 | shopt -s parse_sh_arith # ${BASH_SOURCE[0]}
|
| 5 |
|
| 6 | source ///ysh/no-quotes.ysh # module under test
|
| 7 |
|
| 8 | : ${LIB_OSH=stdlib/osh}
|
| 9 | source $LIB_OSH/two.sh
|
| 10 | source $LIB_OSH/task-five.sh
|
| 11 |
|
| 12 | _demo-stderr() {
|
| 13 | echo zzz "$@" >& 2
|
| 14 | return 99
|
| 15 | }
|
| 16 |
|
| 17 | test-nq-capture() {
|
| 18 | local status stdout
|
| 19 |
|
| 20 | nq-capture status stdout \
|
| 21 | echo hi
|
| 22 | nq-assert 0 = "$status"
|
| 23 | nq-assert 'hi' = "$stdout"
|
| 24 |
|
| 25 | nq-capture status stdout \
|
| 26 | echo hi
|
| 27 | nq-assert 0 = "$status"
|
| 28 | # Note that we LOSE the last newline!
|
| 29 | #nq-assert $'hi\n' = "$stdout"
|
| 30 |
|
| 31 | # TODO: _demo-stderr fails - we catch this earlier though!
|
| 32 | local stderr
|
| 33 | nq-capture-2 status stderr \
|
| 34 | _demo-stderr yyy
|
| 35 |
|
| 36 | #echo "stderr: [$stderr]"
|
| 37 |
|
| 38 | nq-assert 99 = "$status"
|
| 39 | nq-assert 'zzz yyy' = "$stderr"
|
| 40 |
|
| 41 | nq-capture status stdout \
|
| 42 | _demo-stderr aaa
|
| 43 |
|
| 44 | #echo "stderr: [$stderr]"
|
| 45 |
|
| 46 | nq-assert 99 = "$status"
|
| 47 | nq-assert '' = "$stdout"
|
| 48 | }
|
| 49 |
|
| 50 | test-nq-redir() {
|
| 51 | local status stdout_file
|
| 52 |
|
| 53 | nq-redir status stdout_file \
|
| 54 | seq 3
|
| 55 | nq-assert 0 = "$status"
|
| 56 | diff -u $stdout_file - << EOF
|
| 57 | 1
|
| 58 | 2
|
| 59 | 3
|
| 60 | EOF
|
| 61 |
|
| 62 | local stderr_file
|
| 63 | nq-redir-2 status stderr_file \
|
| 64 | log $'hi\nthere'
|
| 65 | nq-assert 0 = "$status"
|
| 66 |
|
| 67 | # TODO: nq-diff - this can diff files and show LINE number of error
|
| 68 |
|
| 69 | set +o errexit
|
| 70 | diff -u $stderr_file - << EOF
|
| 71 | hi
|
| 72 | there
|
| 73 | EOF
|
| 74 | }
|
| 75 |
|
| 76 | task-five "$@"
|