1 | #!/usr/bin/env bash
|
2 |
|
3 | : ${LIB_OSH=stdlib/osh}
|
4 |
|
5 | source $LIB_OSH/no-quotes.sh # module under test
|
6 |
|
7 | source $LIB_OSH/bash-strict.sh
|
8 | source $LIB_OSH/two.sh
|
9 | source $LIB_OSH/task-five.sh
|
10 |
|
11 | _demo-stderr() {
|
12 | echo zzz "$@" >& 2
|
13 | return 99
|
14 | }
|
15 |
|
16 | test-nq-run() {
|
17 | local status
|
18 |
|
19 | nq-run status \
|
20 | false
|
21 | nq-assert 1 = "$status"
|
22 | }
|
23 |
|
24 | test-nq-capture() {
|
25 | local status stdout
|
26 |
|
27 | nq-capture status stdout \
|
28 | echo -n hi
|
29 | nq-assert 0 = "$status"
|
30 | nq-assert 'hi' = "$stdout"
|
31 |
|
32 | nq-capture status stdout \
|
33 | echo hi
|
34 | nq-assert 0 = "$status"
|
35 | # Note that we LOSE the last newline!
|
36 | #nq-assert $'hi\n' = "$stdout"
|
37 |
|
38 | local stderr
|
39 | nq-capture-2 status stderr \
|
40 | _demo-stderr yyy
|
41 |
|
42 | #echo "stderr: [$stderr]"
|
43 |
|
44 | nq-assert 99 = "$status"
|
45 | nq-assert 'zzz yyy' = "$stderr"
|
46 |
|
47 | nq-capture status stdout \
|
48 | _demo-stderr aaa
|
49 |
|
50 | #echo "stderr: [$stderr]"
|
51 |
|
52 | nq-assert 99 = "$status"
|
53 | nq-assert '' = "$stdout"
|
54 | }
|
55 |
|
56 | test-nq-redir() {
|
57 | local status stdout_file
|
58 |
|
59 | nq-redir status stdout_file \
|
60 | seq 3
|
61 | nq-assert 0 = "$status"
|
62 | diff -u $stdout_file - << EOF
|
63 | 1
|
64 | 2
|
65 | 3
|
66 | EOF
|
67 |
|
68 | local stderr_file
|
69 | nq-redir-2 status stderr_file \
|
70 | log $'hi\nthere'
|
71 | nq-assert 0 = "$status"
|
72 |
|
73 | # TODO: nq-diff - this can diff files and show LINE number of error
|
74 |
|
75 | set +o errexit
|
76 | diff -u $stderr_file - << EOF
|
77 | hi
|
78 | there
|
79 | EOF
|
80 | }
|
81 |
|
82 | task-five "$@"
|