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

105 lines, 42 significant
1## our_shell: ysh
2## oils_failures_allowed: 3
3
4#### global frame doesn't contain builtins like len(), dict(), io
5
6try {
7 pp frame_vars_ | grep -o len
8}
9pp test_ (_pipeline_status)
10
11try {
12 pp frame_vars_ | grep -o dict
13}
14pp test_ (_pipeline_status)
15
16try {
17 pp frame_vars_ | grep -o -w io
18}
19pp test_ (_pipeline_status)
20
21## STDOUT:
22(List) [0,1]
23(List) [0,1]
24(List) [0,1]
25## END
26
27#### global frame doesn't contain env vars
28
29#pp frame_vars_
30
31try {
32 pp frame_vars_ | grep -o TMP
33}
34pp test_ (_pipeline_status)
35
36
37## STDOUT:
38(List) [0,1]
39## END
40
41#### global frame doesn't have PWD, IFS
42
43echo "IFS=[$IFS]"
44echo "PWD=[$PWD]"
45
46## STDOUT:
47## END
48
49#### __defaults__ is a Dict, showing default PATH, PS1
50
51pp test_ (type(__defaults__))
52
53pp test_ (__defaults__)
54
55## STDOUT:
56(Str) "Dict"
57## END
58
59
60#### __builtins__ module
61
62var b = len(propView(__builtins__))
63
64# more than 30 builtins
65assert [b > 30]
66
67var mylist = :| a b |
68
69setvar len = 4 # overwrite
70setvar len = __builtins__.len(mylist)
71assert [2 === len]
72
73## STDOUT:
74## END
75
76
77#### cd builtin respects ENV.HOME, not HOME
78
79try { cd }
80echo code=$[_error.code]
81echo
82
83setglobal ENV.HOME = '/tmp'
84
85# Now it's respected
86try { cd }
87echo code=$[_error.code]
88
89pwd
90
91## STDOUT:
92code=1
93
94code=0
95/tmp
96## END
97
98#### compgen -c respects ENV.PATH, not PATH
99
100# grep is required by posix
101compgen -c | grep -w ls
102
103## STDOUT:
104## END
105