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

133 lines, 43 significant
1## our_shell: ysh
2
3#### promptVal() with various values
4
5shopt -s ysh:upgrade
6
7var x = io.promptVal('$')
8
9# We're not root, so it should be $
10echo x=$x
11
12var x = io.promptVal('w')
13if (x === PWD) {
14 echo pass
15} else {
16 echo fail
17}
18
19## STDOUT:
20x=$
21pass
22## END
23
24#### promptVal() with invalid chars
25
26# \D{} will be supported with date and time functions
27var x = io.promptVal('D')
28echo x=$x
29
30# something else
31var x = io.promptVal('/')
32echo x=$x
33
34var x = io.promptVal('ZZ')
35echo x=$x
36
37## status: 3
38## STDOUT:
39x=<Error: \D{} not in promptVal()>
40x=<Error: \/ is invalid or unimplemented in $PS1>
41## END
42
43
44#### ysh respects PS1
45
46export PS1='myprompt\$ '
47echo 'echo hi' | $SH -i
48
49## STDOUT:
50hi
51^D
52## END
53## stderr-json: "ysh myprompt$ ysh myprompt$ "
54
55#### ysh respects renderPrompt() over PS1
56
57export PS1='myprompt\$ '
58
59cat >yshrc <<'EOF'
60func renderPrompt(io) {
61 var parts = []
62 call parts->append('hi')
63 call parts->append(io.promptVal('$'))
64 call parts->append(' ')
65 return (join(parts))
66}
67EOF
68
69echo 'echo hi' | $SH -i --rcfile yshrc
70
71## STDOUT:
72hi
73^D
74## END
75## stderr-json: "hi$ hi$ "
76
77#### renderPrompt() doesn't return string
78
79export PS1='myprompt\$ '
80
81cat >yshrc <<'EOF'
82func renderPrompt(io) {
83 return ([42, 43])
84}
85EOF
86
87echo 'echo hi' | $SH -i --rcfile yshrc
88
89## STDOUT:
90hi
91^D
92## END
93## stderr-json: "<Error: renderPrompt() should return Str, got List> <Error: renderPrompt() should return Str, got List> "
94
95
96#### renderPrompt() raises error
97
98export PS1='myprompt\$ '
99
100cat >yshrc <<'EOF'
101func renderPrompt(io) {
102 error 'oops'
103}
104EOF
105
106echo 'echo hi' | $SH -i --rcfile yshrc
107
108## STDOUT:
109hi
110^D
111## END
112## stderr-json: "<Runtime error: oops><Runtime error: oops>"
113
114
115#### renderPrompt() has wrong signature
116
117export PS1='myprompt\$ '
118
119cat >yshrc <<'EOF'
120func renderPrompt() {
121 error 'oops'
122}
123EOF
124
125echo 'echo hi' | $SH -i --rcfile yshrc
126
127## STDOUT:
128hi
129^D
130## END
131## stderr-json: "<Runtime error: Func 'renderPrompt' takes no positional args, but got 1><Runtime error: Func 'renderPrompt' takes no positional args, but got 1>"
132
133