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

77 lines, 44 significant
1#!/usr/bin/env bash
2
3: ${LIB_OSH=stdlib/osh}
4
5source $LIB_OSH/no-quotes.sh # module under test
6
7source $LIB_OSH/two.sh
8source $LIB_OSH/task-five.sh
9
10set -o nounset
11set -o pipefail
12set -o errexit
13
14_demo-stderr() {
15 echo zzz "$@" >& 2
16 return 99
17}
18
19test-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
51test-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
581
592
603
61EOF
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
72hi
73there
74EOF
75}
76
77task-five "$@"