OILS / spec / ysh-usage.test.sh View on Github | oils.pub

107 lines, 50 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
79
80#### --tool syntax-tree respects frontend/syntax_abbrev.py
81
82$[ENV.SH] --tool syntax-tree <<< '''
83echo 'sq'
84'''
85
86$[ENV.SH] --tool syntax-tree <<< '''
87echo "hi $x ${y}"
88'''
89
90$[ENV.SH] --tool syntax-tree <<< '''
91var x = 42 + a
92'''
93
94# this reflects the default width
95
96## STDOUT:
97(C (w <Lit_Chars echo>) (w (SQ sq)))
98(C
99 (w <Lit_Chars echo>)
100 (w (DQ <Lit_Chars "hi "> ($ x) <Lit_Chars " "> (${ VSub_Name y)))
101)
102(command.VarDecl
103 keyword:<KW_Var var>
104 lhs:[(NameType left:<Expr_Name x> name:x)]
105 rhs:(expr.Binary op:<Arith_Plus "+"> left:(Const Expr_DecInt _) right:(Var a))
106)
107## END