OILS / test / ysh-every-string.sh View on Github | oilshell.org

192 lines, 42 significant
1#!/usr/bin/env bash
2#
3# Use every kind of YSH string
4#
5# Usage:
6# test/ysh-every-string.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12OSH=${OSH:-bin/osh}
13YSH=${YSH:-bin/ysh}
14
15# Disable for YSH
16#shopt -s parse_sh_arith
17source test/common.sh # run-test-funcs
18
19# OSH and YSH
20test-legacy-osh-ysh() {
21 for sh in $OSH $YSH; do
22 log " test-legacy with $sh"
23
24 $sh <<'EOF'
25 echo 'foo \ "
26---'
27
28 echo "foo \\ \" '
29---"
30
31 echo $'fo\x6f \\ \" \'
32---'
33EOF
34 done
35}
36
37test-legacy-expr() {
38 for sh in $YSH; do
39 $sh <<'EOF'
40 # can't have backslash without r, and can't have single quote
41 var x = 'foo "
42---'
43 echo $x
44
45 var x = "foo \\ \" '
46---"
47 echo $x
48
49 # I guess this is useful for refactoring
50 var x = $'f\u006f\x6f \\ \" \'
51---'
52 echo $x
53
54EOF
55done
56}
57
58test-legacy-multiline() {
59 ### double-quoted is allowed to be multi-line in YSH
60
61 for sh in $YSH; do
62 $sh <<'EOF'
63 echo """
64 foo \\ \" '
65 ---
66 """
67
68 var x = """
69 foo \\ \" '
70 ---
71 """
72 echo $x
73EOF
74done
75}
76
77test-raw() {
78 ### r prefix for raw is allowed in YSH
79
80 #for sh in $OSH $YSH; do
81 for sh in $YSH; do
82 $sh <<'EOF'
83 # Command mode
84
85 echo 'foo
86---'
87
88 echo r'foo
89---'
90
91 echo '''
92 foo
93 ---
94 '''
95
96 echo r'''
97 foo
98 ---
99 '''
100
101 # Expression mode
102
103 var x = 'foo
104---'
105 echo $x
106
107 var x = r'foo
108---'
109 echo $x
110
111 var x = '''
112 foo
113 ---
114 '''
115 echo $x
116
117 var x = r'''
118 foo
119 ---
120 '''
121 echo $x
122
123EOF
124 done
125}
126
127test-j8() {
128 ### J8 strings are allowed in YSH
129
130 #for sh in $OSH $YSH; do
131 for sh in $YSH; do
132 $sh <<'EOF'
133
134 # Command mode
135
136 echo u'fo\u{6f} \\ " \'
137---'
138
139 echo b'f\u{6f}\y6f \\ " \'
140---'
141
142 # Leading indent of ---
143 echo u'''
144 fo\u{6f} \\ " \'
145 ---
146 '''
147
148 echo b'''
149 f\u{6f}\y6f \\ " \'
150 ---
151 '''
152
153 # Expression mode
154
155 var x = u'fo\u{6f} \\ " \'
156---'
157 echo $x
158
159 var x = b'f\u{6f}\y6f \\ " \'
160---'
161 echo $x
162
163 var x = u'''
164 fo\u{6f} \\ " \'
165 ---
166 '''
167 echo $x
168
169 var x = b'''
170 f\u{6f}\y6f \\ " \'
171 ---
172 '''
173 echo $x
174
175EOF
176 done
177}
178
179soil-run-py() {
180 run-test-funcs
181}
182
183soil-run-cpp() {
184 ninja _bin/cxx-asan/osh
185 SH=_bin/cxx-asan/osh run-test-funcs
186}
187
188run-for-release() {
189 run-other-suite-for-release ysh-every-string run-test-funcs
190}
191
192"$@"