1 |
## compare_shells: bash
|
2 |
|
3 |
|
4 |
# Notes:
|
5 |
# - OSH prompt goes to stdout and bash goes to stderr
|
6 |
# - This test seems to fail on the system bash, but succeeds with spec-bin/bash
|
7 |
echo 'echo foo' | PS1='[prompt] ' $SH --rcfile /dev/null -i >out.txt 2>err.txt
|
8 |
fgrep -q '[prompt]' out.txt err.txt
|
9 |
echo match=$?
|
10 |
## STDOUT:
|
11 |
match=0
|
12 |
## END
|
13 |
|
14 |
|
15 |
PS1='\[foo\]\$'
|
16 |
echo "${PS1@P}"
|
17 |
## STDOUT:
|
18 |
foo$
|
19 |
## END
|
20 |
|
21 |
|
22 |
PS1='\a\e\r\n'
|
23 |
echo "${PS1@P}"
|
24 |
## stdout-json: "\u0007\u001b\r\n\n"
|
25 |
|
26 |
|
27 |
# NOTE: This might be broken for # but it's hard to tell since we don't have
|
28 |
# root. Could inject __TEST_EUID or something.
|
29 |
PS1='$'
|
30 |
echo "${PS1@P}"
|
31 |
PS1='\$'
|
32 |
echo "${PS1@P}"
|
33 |
PS1='\\$'
|
34 |
echo "${PS1@P}"
|
35 |
PS1='\\\$'
|
36 |
echo "${PS1@P}"
|
37 |
PS1='\\\\$'
|
38 |
echo "${PS1@P}"
|
39 |
## STDOUT:
|
40 |
$
|
41 |
$
|
42 |
$
|
43 |
\$
|
44 |
\$
|
45 |
## END
|
46 |
|
47 |
|
48 |
x='\'
|
49 |
y='h'
|
50 |
PS1='$x$y'
|
51 |
echo "${PS1@P}"
|
52 |
## STDOUT:
|
53 |
\h
|
54 |
## END
|
55 |
|
56 |
|
57 |
foo=foo_value
|
58 |
dir=$TMP/'$foo' # Directory name with a dollar!
|
59 |
mkdir -p $dir
|
60 |
cd $dir
|
61 |
PS1='\w $foo'
|
62 |
test "${PS1@P}" = "$PWD foo_value"
|
63 |
echo status=$?
|
64 |
## STDOUT:
|
65 |
status=0
|
66 |
## END
|
67 |
|
68 |
|
69 |
PS1='\1004$'
|
70 |
echo "${PS1@P}"
|
71 |
## STDOUT:
|
72 |
@4$
|
73 |
## END
|
74 |
|
75 |
|
76 |
PS1='[\045]'
|
77 |
echo "${PS1@P}"
|
78 |
## STDOUT:
|
79 |
[%]
|
80 |
## END
|
81 |
|
82 |
|
83 |
PS1='\555$'
|
84 |
echo "${PS1@P}"
|
85 |
## STDOUT:
|
86 |
m$
|
87 |
## END
|
88 |
|
89 |
|
90 |
PS1='[\x55]'
|
91 |
echo "${PS1@P}"
|
92 |
## STDOUT:
|
93 |
[\x55]
|
94 |
## END
|
95 |
|
96 |
|
97 |
PS1='\'
|
98 |
echo "${PS1@P}"
|
99 |
## STDOUT:
|
100 |
\
|
101 |
## END
|
102 |
|
103 |
|
104 |
PS1='\\'
|
105 |
echo "${PS1@P}"
|
106 |
## STDOUT:
|
107 |
\
|
108 |
## END
|
109 |
|
110 |
|
111 |
PS1='[\0455]'
|
112 |
echo "${PS1@P}"
|
113 |
## STDOUT:
|
114 |
[%5]
|
115 |
## END
|
116 |
|
117 |
|
118 |
PS1='[\u0001]'
|
119 |
USER=$(whoami)
|
120 |
test "${PS1@P}" = "[${USER}0001]"
|
121 |
echo status=$?
|
122 |
## STDOUT:
|
123 |
status=0
|
124 |
## END
|
125 |
|
126 |
|
127 |
PS1='$ '
|
128 |
echo "${PS1@P}"
|
129 |
## STDOUT:
|
130 |
$
|
131 |
## END
|
132 |
|
133 |
|
134 |
|
135 |
# NOTE: This test is not hermetic. On my machine the short and long host name
|
136 |
# are the same.
|
137 |
|
138 |
PS1='\h '
|
139 |
test "${PS1@P}" = "$(hostname -s) " # short name
|
140 |
echo status=$?
|
141 |
PS1='\H '
|
142 |
test "${PS1@P}" = "$(hostname) "
|
143 |
echo status=$?
|
144 |
## STDOUT:
|
145 |
status=0
|
146 |
status=0
|
147 |
## END
|
148 |
|
149 |
|
150 |
PS1='\u '
|
151 |
USER=$(whoami)
|
152 |
test "${PS1@P}" = "${USER} "
|
153 |
echo status=$?
|
154 |
## STDOUT:
|
155 |
status=0
|
156 |
## END
|
157 |
|
158 |
|
159 |
PS1='\w '
|
160 |
test "${PS1@P}" = "${PWD} "
|
161 |
echo status=$?
|
162 |
## STDOUT:
|
163 |
status=0
|
164 |
## END
|
165 |
|
166 |
|
167 |
PS1='\W '
|
168 |
test "${PS1@P}" = "$(basename $PWD) "
|
169 |
echo status=$?
|
170 |
## STDOUT:
|
171 |
status=0
|
172 |
## END
|
173 |
|
174 |
|
175 |
PS1='foo \A bar'
|
176 |
echo "${PS1@P}" | egrep -q 'foo [0-9][0-9]:[0-9][0-9] bar'
|
177 |
echo matched=$?
|
178 |
## STDOUT:
|
179 |
matched=0
|
180 |
## END
|
181 |
|
182 |
|
183 |
PS1='foo \D{%H:%M} bar'
|
184 |
echo "${PS1@P}" | egrep -q 'foo [0-9][0-9]:[0-9][0-9] bar'
|
185 |
echo matched=$?
|
186 |
|
187 |
PS1='foo \D{%H:%M:%S} bar'
|
188 |
echo "${PS1@P}" | egrep -q 'foo [0-9][0-9]:[0-9][0-9]:[0-9][0-9] bar'
|
189 |
echo matched=$?
|
190 |
|
191 |
## STDOUT:
|
192 |
matched=0
|
193 |
matched=0
|
194 |
## END
|
195 |
|
196 |
|
197 |
|
198 |
# In bash y.tab.c uses %X when string is empty
|
199 |
# This doesn't seem to match exactly, but meh for now.
|
200 |
|
201 |
PS1='foo \D{} bar'
|
202 |
echo "${PS1@P}" | egrep -q '^foo [0-9][0-9]:[0-9][0-9]:[0-9][0-9]( ..)? bar$'
|
203 |
echo matched=$?
|
204 |
## STDOUT:
|
205 |
matched=0
|
206 |
## END
|
207 |
|
208 |
|
209 |
PS1='foo \s bar'
|
210 |
echo "${PS1@P}" | egrep -q '^foo (bash|osh) bar$'
|
211 |
echo match=$?
|
212 |
|
213 |
PS1='foo \v bar'
|
214 |
echo "${PS1@P}" | egrep -q '^foo [0-9.]+ bar$'
|
215 |
echo match=$?
|
216 |
|
217 |
## STDOUT:
|
218 |
match=0
|
219 |
match=0
|
220 |
## END
|
221 |
|
222 |
|
223 |
$SH -c 'echo ${@@P}' dummy a b c
|
224 |
echo status=$?
|
225 |
$SH -c 'echo ${*@P}' dummy a b c
|
226 |
echo status=$?
|
227 |
$SH -c 'a=(x y); echo ${a@P}' dummy a b c
|
228 |
echo status=$?
|
229 |
## STDOUT:
|
230 |
a b c
|
231 |
status=0
|
232 |
a b c
|
233 |
status=0
|
234 |
x
|
235 |
status=0
|
236 |
## END
|
237 |
## OK osh STDOUT:
|
238 |
status=1
|
239 |
status=1
|
240 |
x
|
241 |
status=0
|
242 |
## END
|
243 |
|
244 |
|
245 |
#flags='--norc --noprofile'
|
246 |
flags='--rcfile /dev/null'
|
247 |
|
248 |
$SH $flags -i -c 'echo "_${PS1}_"'
|
249 |
|
250 |
## STDOUT:
|
251 |
_\s-\v\$ _
|
252 |
## END
|
253 |
|