-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fixed_v1.2.2.bash
More file actions
executable file
·159 lines (123 loc) · 3.03 KB
/
test_fixed_v1.2.2.bash
File metadata and controls
executable file
·159 lines (123 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash -xv
# SPDX-FileCopyrightText: 2023 Ryuichi Ueda ryuichiueda@gmail.com
# SPDX-License-Identifier: GPL-3.0-or-later
err () {
echo $0 >> ./error
echo "ERROR!" FILE: $0, LINENO: $1
rm -f $tmp-*
exit 1
}
repo_dir=${2:-~/GIT/rusty_bash}
test_dir="$PWD"
com="$repo_dir/target/debug/sush"
cd "$repo_dir"
tmp=/tmp/$$
[ "$1" == "nobuild" ] || cargo build || err $LINENO
cd "$test_dir"
res=$($com << 'EOF' | tr -dc a-z\\n
a=$'ab\001cd\001ef'
IFS=$'\001'
b=$'uv\177wx\177yz'
for w in ab${b}y${a}z ; do echo $w ; done
EOF
)
[ "$res" == 'abuvwxyzyab
cd
efz' ] || err $LINENO
res=$($com <<< 'x=" a" ; set $x ; echo @$1@')
[ "$res" == '@a@' ] || err $LINENO
res=$($com <<< 'IFS=": "; x=" a" ; set $x ; echo @$1@')
[ "$res" == '@a@' ] || err $LINENO
res=$($com <<< 'IFS=": "; x=" a" ;echo @$x@')
[ "$res" == '@ a@' ] || err $LINENO
res=$($com <<< 'set x - ; echo $2')
[ "$res" == '-' ] || err $LINENO
res=$($com <<< 'str="-"; set x $str ; echo $2')
[ "$res" == '-' ] || err $LINENO
res=$($com << 'EOF'
c=(outside)
f() { readonly c=(3) ; }
f
declare -p c
EOF
)
[ "$res" == 'declare -ar c=([0]="3")' ] || err $LINENO
res=$($com << 'EOF'
c=(outside)
f() { readonly 'c=(3)' ; }
f
declare -p c
EOF
)
[ "$res" == 'declare -ar c=([0]="(3)")' ] || err $LINENO
res=$($com << 'EOF'
r=(1)
f() { export r='(5)' ; }
f
declare -p r
EOF
)
[ "$res" == 'declare -ax r=([0]="(5)")' ] || err $LINENO
res=$($com <<< 'set "" ""; f() { echo $# ; } ; f "$@"')
[ "$res" == '2' ] || err $LINENO
res=$($com <<< 'set "" ; f() { echo $# ; } ; f "$@"')
[ "$res" == '1' ] || err $LINENO
res=$($com <<< 'set "" ; f() { echo $# ; } ; f "${@}"')
[ "$res" == '1' ] || err $LINENO
res=$($com -c 'printf "%#x\n" 12')
[ "$res" == '0xc' ] || err $LINENO
res=$($com << 'EOF'
printf "%#x\n" "'1"
printf "%#x\n" "'あ"
EOF
)
[ "$res" == '0x31
0x3042' ] || err $LINENO
res=$($com << "EOF"
tmp=$'\x7f'
printf "%#1x\n" "'$tmp"
EOF
)
[ "$res" == '0x7f' ] || err $LINENO
res=$($com <<< 'for i in a b c; do echo $i; continue; echo bad-$i ; done; echo end-1')
[ "$res" == 'a
b
c
end-1' ] || err $LINENO
res=$($com <<< 'f() { echo "-${*-x}-" ; } ; f ""')
[ "$res" == '--' ] || err $LINENO
res=$($com -c 'echo F=~')
[ "$res" != 'F=~' ] || err $LINENO
res=$($com -c 'echo ${A:-\a}')
[ "$res" == 'a' ] || err $LINENO
res=$($com -c 'echo "${A:-\a}"')
[ "$res" == '\a' ] || err $LINENO
res=$($com -c 'echo ${A:-~}')
[ "$res" != '~' ] || err $LINENO
res=$($com -c 'echo "${A:-~}"')
[ "$res" = '~' ] || err $LINENO
res=$($com -c '
cat << !
~
!
')
echo "$res" | grep '~' || err $LINENO
res=$($com -c '
cat << !
~/bin
!
')
echo "$res" | grep '~/bin' || err $LINENO
res=$($com -c ': ${A:=~}; echo $A')
echo "$res" | grep '^/' || err $LINENO
res=$($com -c ': ${A:=~:aa}; echo $A')
echo "$res" | grep '^/' || err $LINENO
res=$($com -c ': ${A:=~/bin:~/bin2}; echo $A')
echo "$res" | grep '^/.*~' || err $LINENO
res=$($com -c ': ${A:=B=~/bin:~/bin2}; echo $A')
[ "$res" = 'B=~/bin:~/bin2' ] || err $LINENO
res=$($com -c 'B=aaa;C=D=~/bin:$B; echo $C')
[ "$res" = 'D=~/bin:aaa' ] || err $LINENO
rm -f $tmp-*
echo $0 >> ./ok
exit