1 |
#!/usr/bin/env bash |
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 |
15 |
argv.py bare 'sq' |
16 |
## stdout: ['bare', 'sq'] |
17 |
|
18 |
#### Evaluation of each part |
19 |
#set -o noglob |
20 |
HOME=/home/bob |
21 |
str=s |
22 |
array=(a1 a2) |
23 |
argv.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 |
29 |
s1='1 2' |
30 |
s2='3 4' |
31 |
s3='5 6' |
32 |
argv.py $s1$s2 "$s3" |
33 |
## stdout: ['1', '23', '4', '5 6'] |
34 |
|
35 |
#### Word joining |
36 |
set -- x y z |
37 |
s1='1 2' |
38 |
array=(a1 a2) |
39 |
argv.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 |
45 |
s1='' |
46 |
argv.py $s1 - "$s1" |
47 |
## stdout: ['-', ''] |
48 |
|
49 |
#### Default values -- more cases |
50 |
argv.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 |
54 |
touch _tmp/foo.gg _tmp/bar.gg _tmp/foo.hh |
55 |
pat='_tmp/*.hh _tmp/*.gg' |
56 |
argv.py $pat |
57 |
## stdout: ['_tmp/foo.hh', '_tmp/bar.gg', '_tmp/foo.gg'] |
58 |
|
59 |
#### Globbing escaping |
60 |
touch '_tmp/[bc]ar.mm' # file that looks like a glob pattern |
61 |
touch _tmp/bar.mm _tmp/car.mm |
62 |
argv.py '_tmp/[bc]'*.mm - _tmp/?ar.mm |
63 |
## stdout: ['_tmp/[bc]ar.mm', '-', '_tmp/bar.mm', '_tmp/car.mm'] |