OILS / spec / word-eval.test.sh View on Github | oils.pub

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