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

76 lines, 43 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
12_demo-stderr() {
13 echo zzz "$@" >& 2
14 return 99
15}
16
17test-nq-capture() {
18 local status stdout
19
20 nq-capture status stdout \
21 echo hi
22 nq-assert 0 = "$status"
23 nq-assert 'hi' = "$stdout"
24
25 nq-capture status stdout \
26 echo hi
27 nq-assert 0 = "$status"
28 # Note that we LOSE the last newline!
29 #nq-assert $'hi\n' = "$stdout"
30
31 # TODO: _demo-stderr fails - we catch this earlier though!
32 local stderr
33 nq-capture-2 status stderr \
34 _demo-stderr yyy
35
36 #echo "stderr: [$stderr]"
37
38 nq-assert 99 = "$status"
39 nq-assert 'zzz yyy' = "$stderr"
40
41 nq-capture status stdout \
42 _demo-stderr aaa
43
44 #echo "stderr: [$stderr]"
45
46 nq-assert 99 = "$status"
47 nq-assert '' = "$stdout"
48}
49
50test-nq-redir() {
51 local status stdout_file
52
53 nq-redir status stdout_file \
54 seq 3
55 nq-assert 0 = "$status"
56 diff -u $stdout_file - << EOF
571
582
593
60EOF
61
62 local stderr_file
63 nq-redir-2 status stderr_file \
64 log $'hi\nthere'
65 nq-assert 0 = "$status"
66
67 # TODO: nq-diff - this can diff files and show LINE number of error
68
69 set +o errexit
70 diff -u $stderr_file - << EOF
71hi
72there
73EOF
74}
75
76task-five "$@"