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

80 lines, 50 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 _check (; val) { # TODO: assert
10 if (not val) {
11 pp line (val)
12 error "Failed:"
13 }
14}
15
16_demo-stderr() {
17 echo zzz "$@" >& 2
18 return 99
19}
20
21proc test-yb-capture {
22
23 yb-capture (&r) {
24 write --end '' hi
25 }
26 _check (0 === r.status)
27 _check ('hi' === r.stdout)
28
29 #return
30
31 yb-capture (&r) {
32 echo hi
33 }
34 #pp line (r)
35 _check (0 === r.status)
36 _check (u'hi\n' === r.stdout)
37
38 # TODO: _demo-stderr fails - we catch this earlier though!
39 yb-capture-2 (&r) {
40 _demo-stderr yyy
41 }
42 _check (99 === r.status)
43 _check (u'zzz yyy\n' === r.stderr)
44
45 yb-capture (&r) {
46 _demo-stderr aaa
47 }
48 _check (99 === r.status)
49 _check ('' === r.stdout)
50}
51
52proc test-yb-redir-not-needed {
53 # TODO: need $BYO_TEMP_DIR maybe? Or is that implicit with 'cd'? We don't
54 # always have a temp dir
55
56 var tmp = "${BYO_TEMP_DIR:-/tmp}/$$"
57
58 try > $tmp {
59 seq 3
60 }
61 _check (0 === _error.code)
62
63 diff -u $tmp - << EOF
641
652
663
67EOF
68
69 try 2>$tmp {
70 log $'hi\nthere'
71 }
72 _check (0 === _error.code)
73
74 diff -u $tmp - << EOF
75hi
76there
77EOF
78}
79
80task-five "$@"