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

105 lines, 38 significant
1## oils_failures_allowed: 3
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
57pp test_ (ENV)
58
59#export PYTHONPATH=zz
60
61# execute POSIX shell
62sh -c 'echo pythonpath=$PYTHONPATH'
63
64## STDOUT:
65## END
66
67#### export builtin still works
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