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

78 lines, 36 significant
1## our_shell: ysh
2
3#### ysh usage
4
5set +o errexit
6
7$[ENV.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$[ENV.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
25var TMP = ENV.TMP
26$[ENV.SH] --debug-file $TMP/debug.txt -c 'true'
27grep 'Oils started with' $TMP/debug.txt >/dev/null && echo yes
28## stdout: yes
29
30#### Filename quoting
31
32echo '(BAD' > no-quoting
33echo '(BAD' > 'with spaces.sh'
34echo '(BAD' > $'bad \xff'
35
36write -n '' > err.txt
37
38$[ENV.SH] no-quoting 2>>err.txt || true
39$[ENV.SH] 'with spaces.sh' 2>>err.txt || true
40$[ENV.SH] $'bad \xff' 2>>err.txt || true
41
42egrep --only-matching '^.*:1' err.txt
43
44## STDOUT:
45no-quoting:1
46"with spaces.sh":1
47b'bad \yff':1
48## END
49
50
51#### shopt --set verbose_errexit
52
53try {
54 $[ENV.SH] -c '/bin/false' 2>on.txt
55}
56
57try {
58 $[ENV.SH] +o verbose_errexit -c '/bin/false' 2>off.txt
59}
60
61wc -l on.txt off.txt
62#echo
63#cat on.txt off.txt
64
65## STDOUT:
66 3 on.txt
67 0 off.txt
68 3 total
69## END
70
71#### YSH shows options correctly (bug fix)
72
73$[ENV.SH] -o | egrep 'errexit|pipefail'
74
75## STDOUT:
76set -o errexit
77set -o pipefail
78## END