OILS / stdlib / ysh / yblocks-test.ysh View on Github | oilshell.org

72 lines, 44 significant
1#!bin/ysh
2
3source $LIB_YSH/yblocks.ysh # module under test
4
5: ${LIB_OSH=stdlib/osh}
6source $LIB_OSH/two.sh
7source $LIB_OSH/task-five.sh
8
9proc _demo-stderr {
10 echo zzz @ARGV >& 2
11 return 99
12}
13
14proc 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
44proc 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
561
572
583
59EOF
60
61 try 2>$tmp {
62 log $'hi\nthere'
63 }
64 assert [0 === _error.code]
65
66 diff -u $tmp - << EOF
67hi
68there
69EOF
70}
71
72task-five @ARGV