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