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