OILS / spec / whitespace.test.sh View on Github | oilshell.org

114 lines, 59 significant
1## compare_shells: dash bash mksh zsh ash
2
3#### Parsing shell words \r \v
4
5# frontend/lexer_def.py has rules for this
6
7tab=$(python2 -c 'print "argv.py -\t-"')
8cr=$(python2 -c 'print "argv.py -\r-"')
9vert=$(python2 -c 'print "argv.py -\v-"')
10ff=$(python2 -c 'print "argv.py -\f-"')
11
12$SH -c "$tab"
13$SH -c "$cr"
14$SH -c "$vert"
15$SH -c "$ff"
16
17## STDOUT:
18['-', '-']
19['-\r-']
20['-\x0b-']
21['-\x0c-']
22## END
23
24#### \r in arith expression is allowed by some shells, but not most!
25
26arith=$(python2 -c 'print "argv.py $(( 1 +\n2))"')
27arith_cr=$(python2 -c 'print "argv.py $(( 1 +\r\n2))"')
28
29$SH -c "$arith"
30if test $? -ne 0; then
31 echo 'failed'
32fi
33
34$SH -c "$arith_cr"
35if test $? -ne 0; then
36 echo 'failed'
37fi
38
39## STDOUT:
40['3']
41failed
42## END
43
44## OK mksh/ash/osh STDOUT:
45['3']
46['3']
47## END
48
49#### whitespace in string to integer conversion
50
51tab=$(python2 -c 'print "\t42\t"')
52cr=$(python2 -c 'print "\r42\r"')
53
54$SH -c 'echo $(( $1 + 1 ))' dummy0 "$tab"
55if test $? -ne 0; then
56 echo 'failed'
57fi
58
59$SH -c 'echo $(( $1 + 1 ))' dummy0 "$cr"
60if test $? -ne 0; then
61 echo 'failed'
62fi
63
64## STDOUT:
6543
66failed
67## END
68
69## OK mksh/ash/osh STDOUT:
7043
7143
72## END
73
74#### \r at end of line is not special
75
76# hm I wonder if Windows ports have rules for this?
77
78cr=$(python2 -c 'print "argv.py -\r"')
79
80$SH -c "$cr"
81
82## STDOUT:
83['-\r']
84## END
85
86#### Default IFS does not include \r \v \f
87
88# dash and zsh don't have echo -e
89tab=$(python2 -c 'print "-\t-"')
90cr=$(python2 -c 'print "-\r-"')
91vert=$(python2 -c 'print "-\v-"')
92ff=$(python2 -c 'print "-\f-"')
93
94$SH -c 'argv.py $1' dummy0 "$tab"
95$SH -c 'argv.py $1' dummy0 "$cr"
96$SH -c 'argv.py $1' dummy0 "$vert"
97$SH -c 'argv.py $1' dummy0 "$ff"
98
99## STDOUT:
100['-', '-']
101['-\r-']
102['-\x0b-']
103['-\x0c-']
104## END
105
106# No word splitting in zsh
107
108## OK zsh STDOUT:
109['-\t-']
110['-\r-']
111['-\x0b-']
112['-\x0c-']
113## END
114