OILS / spec / builtin-type.test.sh View on Github | oilshell.org

117 lines, 46 significant
1## oils_failures_allowed: 0
2## compare_shells: bash zsh mksh dash ash
3
4#### type -> keyword builtin
5
6type while cd
7
8## STDOUT:
9while is a shell keyword
10cd is a shell builtin
11## END
12## OK zsh/mksh STDOUT:
13while is a reserved word
14cd is a shell builtin
15## END
16
17#### type -> alias function external
18
19shopt -s expand_aliases || true # bash
20
21alias ll='ls -l'
22
23f() { echo hi; }
24
25touch _tmp/date
26chmod +x _tmp/date
27PATH=_tmp:/bin
28
29# ignore quotes and backticks
30# bash prints a left backtick
31quotes='"`'\'
32
33type ll f date | sed "s/[$quotes]//g"
34
35# Note: both procs and funcs go in var namespace? So they don't respond to
36# 'type'?
37
38## STDOUT:
39ll is an alias for ls -l
40f is a shell function
41date is _tmp/date
42## END
43## OK ash STDOUT:
44ll is an alias for ls -l
45f is a function
46date is _tmp/date
47## END
48## OK mksh STDOUT:
49ll is an alias for ls -l
50f is a function
51date is a tracked alias for _tmp/date
52## END
53## OK bash STDOUT:
54ll is aliased to ls -l
55f is a function
56f ()
57{
58 echo hi
59}
60date is _tmp/date
61## END
62
63#### type of relative path
64
65touch _tmp/file _tmp/ex
66chmod +x _tmp/ex
67
68type _tmp/file _tmp/ex
69
70# dash and ash don't care if it's executable
71# mksh
72
73## status: 1
74## STDOUT:
75_tmp/ex is _tmp/ex
76## END
77
78## OK mksh/zsh STDOUT:
79_tmp/file not found
80_tmp/ex is _tmp/ex
81## END
82
83## BUG dash/ash status: 0
84## BUG dash/ash STDOUT:
85_tmp/file is _tmp/file
86_tmp/ex is _tmp/ex
87## END
88
89#### type -> not found
90
91type zz 2>err.txt
92echo status=$?
93
94# for bash and OSH: print to stderr
95fgrep -o 'zz: not found' err.txt || true
96
97# zsh and mksh behave the same - status 1
98# dash and ash behave the same - status 127
99
100## STDOUT:
101status=1
102zz: not found
103## END
104
105## OK mksh/zsh STDOUT:
106zz not found
107status=1
108## END
109## STDERR:
110## END
111
112## BUG dash/ash STDOUT:
113zz: not found
114status=127
115## END
116## BUG dash/ash STDERR:
117## END