| 1 | #!bin/ysh
|
| 2 |
|
| 3 | source $LIB_YSH/yblocks.ysh # module under test
|
| 4 |
|
| 5 | : ${LIB_OSH=stdlib/osh}
|
| 6 | source $LIB_OSH/two.sh
|
| 7 | source $LIB_OSH/task-five.sh
|
| 8 |
|
| 9 | proc _demo-stderr {
|
| 10 | echo zzz @ARGV >& 2
|
| 11 | return 99
|
| 12 | }
|
| 13 |
|
| 14 | proc test-yb-capture {
|
| 15 |
|
| 16 | yb-capture (&r) {
|
| 17 | write --end '' hi
|
| 18 | }
|
| 19 | assert [0 === r.status]
|
| 20 | assert ['hi' === r.stdout]
|
| 21 |
|
| 22 | #return
|
| 23 |
|
| 24 | yb-capture (&r) {
|
| 25 | echo hi
|
| 26 | }
|
| 27 | #pp test_ (r)
|
| 28 | assert [0 === r.status]
|
| 29 | assert [u'hi\n' === r.stdout]
|
| 30 |
|
| 31 | yb-capture-2 (&r) {
|
| 32 | _demo-stderr yyy
|
| 33 | }
|
| 34 | assert [99 === r.status]
|
| 35 | assert [u'zzz yyy\n' === r.stderr]
|
| 36 |
|
| 37 | yb-capture (&r) {
|
| 38 | _demo-stderr aaa
|
| 39 | }
|
| 40 | assert [99 === r.status]
|
| 41 | assert ['' === r.stdout]
|
| 42 | }
|
| 43 |
|
| 44 | proc test-yb-redir-not-needed {
|
| 45 | # TODO: need $BYO_TEMP_DIR maybe? Or is that implicit with 'cd'? We don't
|
| 46 | # always have a temp dir
|
| 47 |
|
| 48 | var tmp = "${BYO_TEMP_DIR:-/tmp}/$$"
|
| 49 |
|
| 50 | try > $tmp {
|
| 51 | seq 3
|
| 52 | }
|
| 53 | assert [0 === _error.code]
|
| 54 |
|
| 55 | diff -u $tmp - << EOF
|
| 56 | 1
|
| 57 | 2
|
| 58 | 3
|
| 59 | EOF
|
| 60 |
|
| 61 | try 2>$tmp {
|
| 62 | log $'hi\nthere'
|
| 63 | }
|
| 64 | assert [0 === _error.code]
|
| 65 |
|
| 66 | diff -u $tmp - << EOF
|
| 67 | hi
|
| 68 | there
|
| 69 | EOF
|
| 70 | }
|
| 71 |
|
| 72 | task-five @ARGV
|