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

56 lines, 28 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
14#### cdable_vars: fails when shopt is off
15shopt -u cdable_vars
16TARGET_DIR='/tmp'
17cd TARGET_DIR
18## status: 1
19
20#### cdable_vars: normal path still works when cdable_vars is set
21shopt -s cdable_vars
22cd /tmp
23pwd
24## status: 0
25## STDOUT:
26/tmp
27## END
28
29#### cdable_vars: path takes priority over variable with same name
30shopt -s cdable_vars
31mkdir -p /tmp/testdir
32cd /tmp/testdir
33pwd
34## status: 0
35## STDOUT:
36/tmp/testdir
37## END
38
39#### cdable_vars: fails if variable points to a file not a directory
40shopt -s cdable_vars
41touch /tmp/my_file
42VAR_NAME='my_file'
43cd VAR_NAME
44## status: 1
45
46#### cdable_vars: fails if variable is unset
47shopt -s cdable_vars
48unset TARGET_DIR
49cd TARGET_DIR
50## status: 1
51
52#### cdable_vars: array variable resolves to first element
53shopt -s cdable_vars
54TARGET_DIR=('/tmp' '/home')
55cd TARGET_DIR
56## status: 0