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

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