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

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