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