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

80 lines, 51 significant
1#!bin/ysh
2
3shopt -s parse_sh_arith # ${BASH_SOURCE[0]}
4
5source ///ysh/yblocks.ysh # module under test
6
7: ${LIB_OSH=stdlib/osh}
8source $LIB_OSH/two.sh
9source $LIB_OSH/task-five.sh
10
11proc _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
23proc 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
54proc 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
611
622
633
64EOF
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
75hi
76there
77EOF
78}
79
80task-five "$@"