OILS / spec / cdable-vars.test.sh View on Github | oils.pub

60 lines, 29 significant
1## compare_shells: bash
2
3#### cdable_vars: resolve variable to path
4shopt -s cdable_vars
5export TARGET_DIR='/tmp'
6cd TARGET_DIR
7pwd
8## status: 0
9## STDOUT:
10/tmp
11/tmp
12## END
13## OK osh STDOUT:
14/tmp
15## END
16
17#### cdable_vars: fails when shopt is off
18shopt -u cdable_vars
19TARGET_DIR='/tmp'
20cd TARGET_DIR
21## status: 1
22
23#### cdable_vars: normal path still works when cdable_vars is set
24shopt -s cdable_vars
25cd /tmp
26pwd
27## status: 0
28## STDOUT:
29/tmp
30## END
31
32#### cdable_vars: path takes priority over variable with same name
33shopt -s cdable_vars
34mkdir -p /tmp/testdir
35cd /tmp/testdir
36pwd
37## status: 0
38## STDOUT:
39/tmp/testdir
40## END
41
42#### cdable_vars: fails if variable points to a file not a directory
43shopt -s cdable_vars
44touch /tmp/my_file
45VAR_NAME='my_file'
46cd VAR_NAME
47## status: 1
48
49#### cdable_vars: fails if variable is unset
50shopt -s cdable_vars
51unset TARGET_DIR
52cd TARGET_DIR
53## status: 1
54
55#### cdable_vars: array variable resolves to first element
56shopt -s cdable_vars
57TARGET_DIR=('/tmp' '/home')
58cd TARGET_DIR
59## status: 0
60## BUG osh status: 1