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