OILS / spec / word-eval.test.sh View on Github | oilshell.org

62 lines, 22 significant
1#
2# word-eval.test.sh: Test the word evaluation pipeline in order.
3#
4# Part evaluation, splitting, joining, elision, globbing.
5
6# TODO: Rename word-eval-smoke.test.sh?
7# Word sequence evaluation.
8# This is more like a vertical slice. For exhaustive tests, see:
9#
10# word-split.test.sh (perhaps rename word-reframe?)
11# glob.test.sh
12
13#### Evaluation of constant parts
14argv.py bare 'sq'
15## stdout: ['bare', 'sq']
16
17#### Evaluation of each part
18#set -o noglob
19HOME=/home/bob
20str=s
21array=(a1 a2)
22argv.py bare 'sq' ~ $str "-${str}-" "${array[@]}" $((1+2)) $(echo c) `echo c`
23## stdout: ['bare', 'sq', '/home/bob', 's', '-s-', 'a1', 'a2', '3', 'c', 'c']
24## N-I dash stdout-json: ""
25## N-I dash status: 2
26
27#### Word splitting
28s1='1 2'
29s2='3 4'
30s3='5 6'
31argv.py $s1$s2 "$s3"
32## stdout: ['1', '23', '4', '5 6']
33
34#### Word joining
35set -- x y z
36s1='1 2'
37array=(a1 a2)
38argv.py $s1"${array[@]}"_"$@"
39## stdout: ['1', '2a1', 'a2_x', 'y', 'z']
40## N-I dash stdout-json: ""
41## N-I dash status: 2
42
43#### Word elision
44s1=''
45argv.py $s1 - "$s1"
46## stdout: ['-', '']
47
48#### Default values -- more cases
49argv.py ${undef:-hi} ${undef:-'a b'} "${undef:-c d}" "${un:-"e f"}" "${un:-'g h'}"
50## stdout: ['hi', 'a b', 'c d', 'e f', "'g h'"]
51
52#### Globbing after splitting
53touch _tmp/foo.gg _tmp/bar.gg _tmp/foo.hh
54pat='_tmp/*.hh _tmp/*.gg'
55argv.py $pat
56## stdout: ['_tmp/foo.hh', '_tmp/bar.gg', '_tmp/foo.gg']
57
58#### Globbing escaping
59touch '_tmp/[bc]ar.mm' # file that looks like a glob pattern
60touch _tmp/bar.mm _tmp/car.mm
61argv.py '_tmp/[bc]'*.mm - _tmp/?ar.mm
62## stdout: ['_tmp/[bc]ar.mm', '-', '_tmp/bar.mm', '_tmp/car.mm']