OILS / spec / ysh-usage.test.sh View on Github | oilshell.org

77 lines, 35 significant
1## our_shell: ysh
2
3#### ysh usage
4
5set +o errexit
6
7$SH --location-str foo.hay --location-start-line 42 -c 'echo ()' 2>err.txt
8
9cat err.txt | grep -o -- '-- foo.hay:42: Unexpected'
10
11
12# common idiom is to use -- to say it came from a file
13$SH --location-str '[ stdin ]' --location-start-line 10 -c 'echo "line 10";
14echo ()' 2>err.txt
15
16cat err.txt | fgrep -o -- '-- [ stdin ]:11: Unexpected'
17
18## STDOUT:
19-- foo.hay:42: Unexpected
20line 10
21-- [ stdin ]:11: Unexpected
22## END
23
24#### --debug-file
25$SH --debug-file $TMP/debug.txt -c 'true'
26grep 'Oils started with' $TMP/debug.txt >/dev/null && echo yes
27## stdout: yes
28
29#### Filename quoting
30
31echo '(BAD' > no-quoting
32echo '(BAD' > 'with spaces.sh'
33echo '(BAD' > $'bad \xff'
34
35write -n '' > err.txt
36
37$SH no-quoting 2>>err.txt || true
38$SH 'with spaces.sh' 2>>err.txt || true
39$SH $'bad \xff' 2>>err.txt || true
40
41egrep --only-matching '^.*:1' err.txt
42
43## STDOUT:
44no-quoting:1
45"with spaces.sh":1
46b'bad \yff':1
47## END
48
49
50#### shopt --set verbose_errexit
51
52try {
53 $SH -c '/bin/false' 2>on.txt
54}
55
56try {
57 $SH +o verbose_errexit -c '/bin/false' 2>off.txt
58}
59
60wc -l on.txt off.txt
61#echo
62#cat on.txt off.txt
63
64## STDOUT:
65 3 on.txt
66 0 off.txt
67 3 total
68## END
69
70#### YSH shows options correctly (bug fix)
71
72$SH -o | egrep 'errexit|pipefail'
73
74## STDOUT:
75set -o errexit
76set -o pipefail
77## END