1
2 #### sh -i
3 # Notes:
4 # - OSH prompt goes to stdout and bash goes to stderr
5 # - This test seems to fail on the system bash, but succeeds with
6 # _deps/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 status=$?
10 ## STDOUT:
11 status=0
12 ## END
13
14 #### \[\] are non-printing
15 PS1='\[foo\]\$'
16 echo "${PS1@P}"
17 ## STDOUT:
18 foo$
19 ## END
20
21 #### literal escapes
22 PS1='\a\e\r\n'
23 echo "${PS1@P}"
24 ## stdout-json: "\u0007\u001b\r\n\n"
25
26 #### special case for $
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 #### PS1 evaluation order
48 x='\'
49 y='h'
50 PS1='$x$y'
51 echo "${PS1@P}"
52 ## STDOUT:
53 \h
54 ## END
55
56 #### PS1 evaluation order 2
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 #### \1004
69 PS1='\1004$'
70 echo "${PS1@P}"
71 ## STDOUT:
72 @4$
73 ## END
74
75 #### \001 octal literals are supported
76 PS1='[\045]'
77 echo "${PS1@P}"
78 ## STDOUT:
79 [%]
80 ## END
81
82 #### \555 is beyond max octal byte of \377 and wrapped to m
83 PS1='\555$'
84 echo "${PS1@P}"
85 ## STDOUT:
86 m$
87 ## END
88
89 #### \x55 hex literals not supported
90 PS1='[\x55]'
91 echo "${PS1@P}"
92 ## STDOUT:
93 [\x55]
94 ## END
95
96 #### Single backslash
97 PS1='\'
98 echo "${PS1@P}"
99 ## BUG bash stdout-json: "\\\u0002\n"
100 ## STDOUT:
101 \
102 ## END
103
104 #### Escaped backslash
105 PS1='\\'
106 echo "${PS1@P}"
107 ## BUG bash stdout-json: "\\\u0002\n"
108 ## STDOUT:
109 \
110 ## END
111
112 #### \0001 octal literals are not supported
113 PS1='[\0455]'
114 echo "${PS1@P}"
115 ## STDOUT:
116 [%5]
117 ## END
118
119 #### \u0001 unicode literals not supported
120 PS1='[\u0001]'
121 USER=$(whoami)
122 test "${PS1@P}" = "[${USER}0001]"
123 echo status=$?
124 ## STDOUT:
125 status=0
126 ## END
127
128 #### constant string
129 PS1='$ '
130 echo "${PS1@P}"
131 ## STDOUT:
132 $
133 ## END
134
135 #### hostname
136
137 # NOTE: This test is not hermetic. On my machine the short and long host name
138 # are the same.
139
140 PS1='\h '
141 test "${PS1@P}" = "$(hostname -s) " # short name
142 echo status=$?
143 PS1='\H '
144 test "${PS1@P}" = "$(hostname) "
145 echo status=$?
146 ## STDOUT:
147 status=0
148 status=0
149 ## END
150
151 #### username
152 PS1='\u '
153 USER=$(whoami)
154 test "${PS1@P}" = "${USER} "
155 echo status=$?
156 ## STDOUT:
157 status=0
158 ## END
159
160 #### current working dir
161 PS1='\w '
162 test "${PS1@P}" = "${PWD} "
163 echo status=$?
164 ## STDOUT:
165 status=0
166 ## END
167
168 #### \W is basename of working dir
169 PS1='\W '
170 test "${PS1@P}" = "$(basename $PWD) "
171 echo status=$?
172 ## STDOUT:
173 status=0
174 ## END
175
176 #### @P with array
177 $SH -c 'echo ${@@P}' dummy a b c
178 echo status=$?
179 $SH -c 'echo ${*@P}' dummy a b c
180 echo status=$?
181 $SH -c 'a=(x y); echo ${a@P}' dummy a b c
182 echo status=$?
183 ## STDOUT:
184 a b c
185 status=0
186 a b c
187 status=0
188 x
189 status=0
190 ## END
191 ## OK osh STDOUT:
192 status=1
193 status=1
194 status=1
195 ## END