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

139 lines, 47 significant
1## oils_failures_allowed: 4
2
3#### Can read from ENV Dict
4shopt -s ysh:upgrade
5
6pp test_ (type(ENV))
7#pp test_ (ENV)
8
9# Set by the spec test harness
10
11if (ENV.SH ~~ '*osh') {
12 echo ok
13}
14
15#echo SH=$[ENV.SH]
16
17## STDOUT:
18(Str) "Dict"
19ok
20## END
21
22#### YSH doesn't have exported vars (declare -x)
23
24osh=$SH # this file is run by OSH
25
26case $osh in
27 *osh)
28 echo 'OSH ok'
29 ;;
30esac
31
32var ysh = osh.replace('osh', 'ysh')
33
34# NOT exported
35$ysh -c 'echo sh=$[getVar("SH")]'
36
37## STDOUT:
38OSH ok
39sh=null
40## END
41
42#### Temp bindings A=a B=b my-command push to ENV dict
43shopt -s ysh:upgrade
44
45_A=a _B=b env | grep '^_' | sort
46
47## STDOUT:
48_A=a
49_B=b
50## END
51
52#### setglobal ENV.PYTHONPATH = 'foo' changes child process state
53shopt -s ysh:upgrade
54
55setglobal ENV.PYTHONPATH = 'foo'
56
57#pp test_ (ENV)
58#export PYTHONPATH=zz
59
60# execute POSIX shell
61sh -c 'echo pythonpath=$PYTHONPATH'
62
63## STDOUT:
64pythonpath=foo
65## END
66
67#### export builtin is disabled, in favor of setglobal
68shopt -s ysh:upgrade
69
70export PYTHONPATH='foo'
71
72#pp test_ (ENV)
73
74# execute POSIX shell
75sh -c 'echo pythonpath=$PYTHONPATH'
76
77## STDOUT:
78pythonpath=foo
79## END
80
81
82#### PS4 environment variable is respected
83shopt -s ysh:upgrade
84
85setglobal ENV.PS4 = '%%% '
86
87$[ENV.SH] -c 'set -x; echo 1; echo 2'
88
89## STDOUT:
90TODO
91## END
92
93
94#### ENV works in different modules
95shopt -s ysh:upgrade
96
97setglobal ENV.PS4 = '%%% '
98
99use $[ENV.REPO_ROOT]/spec/testdata/module2/env.ysh
100
101## STDOUT:
102env.ysh
103OSH ok
104## END
105
106
107#### HOME var
108shopt --set ysh:upgrade
109
110#setvar HOME = 'yo'
111
112# TODO: this should consult ENV.HOME
113echo ~
114
115# not set by spec test framework
116echo $[ENV.HOME]
117
118#echo ~root
119
120#echo ~bob/
121
122## STDOUT:
123## END
124
125#### exec builtin respects ENV
126
127shopt --set ysh:upgrade
128
129#export ZZ=zzz
130setglobal ENV.ZZ = 'zz'
131
132env sh -c 'echo child ZZ=$ZZ'
133
134exec env sh -c 'echo exec ZZ=$ZZ'
135
136## STDOUT:
137child ZZ=zz
138exec ZZ=zz
139## END