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

74 lines, 42 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/bash-strict.sh
8source $LIB_OSH/two.sh
9source $LIB_OSH/task-five.sh
10
11_demo-stderr() {
12 echo zzz "$@" >& 2
13 return 99
14}
15
16test-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
48test-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
551
562
573
58EOF
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
69hi
70there
71EOF
72}
73
74task-five "$@"