| 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 | proc _check (; val) { # TODO: assert
|
| 13 | if (not val) {
|
| 14 | pp line (val)
|
| 15 | error "Failed:"
|
| 16 | }
|
| 17 | }
|
| 18 |
|
| 19 | _demo-stderr() {
|
| 20 | echo zzz "$@" >& 2
|
| 21 | return 99
|
| 22 | }
|
| 23 |
|
| 24 | proc test-nq-capture {
|
| 25 |
|
| 26 | nq-capture (&r) {
|
| 27 | write --end '' hi
|
| 28 | }
|
| 29 | _check (0 === r.status)
|
| 30 | _check ('hi' === r.stdout)
|
| 31 |
|
| 32 | #return
|
| 33 |
|
| 34 | nq-capture (&r) {
|
| 35 | echo hi
|
| 36 | }
|
| 37 | #pp line (r)
|
| 38 | _check (0 === r.status)
|
| 39 | _check (u'hi\n' === r.stdout)
|
| 40 |
|
| 41 | # TODO: _demo-stderr fails - we catch this earlier though!
|
| 42 | nq-capture-2 (&r) {
|
| 43 | _demo-stderr yyy
|
| 44 | }
|
| 45 | _check (99 === r.status)
|
| 46 | _check (u'zzz yyy\n' === r.stderr)
|
| 47 |
|
| 48 | nq-capture (&r) {
|
| 49 | _demo-stderr aaa
|
| 50 | }
|
| 51 | _check (99 === r.status)
|
| 52 | _check ('' === r.stdout)
|
| 53 | }
|
| 54 |
|
| 55 | proc test-nq-redir {
|
| 56 | local status stdout_file
|
| 57 |
|
| 58 | nq-redir status stdout_file \
|
| 59 | seq 3
|
| 60 | nq-assert 0 = "$status"
|
| 61 | diff -u $stdout_file - << EOF
|
| 62 | 1
|
| 63 | 2
|
| 64 | 3
|
| 65 | EOF
|
| 66 |
|
| 67 | local stderr_file
|
| 68 | nq-redir-2 status stderr_file \
|
| 69 | log $'hi\nthere'
|
| 70 | nq-assert 0 = "$status"
|
| 71 |
|
| 72 | # TODO: nq-diff - this can diff files and show LINE number of error
|
| 73 |
|
| 74 | set +o errexit
|
| 75 | diff -u $stderr_file - << EOF
|
| 76 | hi
|
| 77 | there
|
| 78 | EOF
|
| 79 | }
|
| 80 |
|
| 81 | task-five "$@"
|