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