-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fixed_v1.2.4.bash
More file actions
executable file
·175 lines (134 loc) · 3.82 KB
/
test_fixed_v1.2.4.bash
File metadata and controls
executable file
·175 lines (134 loc) · 3.82 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/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 <<< 'declare -n a=b; a=3; echo $b')
[ "$res" = '3' ] || err $LINENO
res=$($com <<< '
bar=one
foo=bar
typeset -n foo
echo ${foo}
echo ${!foo}
')
[ "$res" = 'one
bar' ] || err $LINENO
res=$($com <<< 'declare -n a=b ; declare -r a ; b=3')
[ $? -eq 1 ] || err $LINENO
res=$($com <<< '
bar=one
typeset -n foo=bar
unset foo
echo ${bar-unset}
echo ${foo-unset}
echo ${!foo}
')
[ "$res" = 'unset
unset
bar' ] || err $LINENO
res=$($com <<< 'declare -n a=b ; declare -p a')
[ $? -eq 0 ] || err $LINENO
res=$($com <<< 'declare -n a=b ; unset a ; declare -p a')
[ $? -eq 0 ] || err $LINENO
res=$($com <<< 'declare -n a=b ; unset -n a ; declare -p a')
[ $? -eq 1 ] || err $LINENO
res=$($com <<< 'echo ${!aaa}')
[ $? -eq 1 ] || err $LINENO
res=$($com <<< 'echo ${!aaa-unset}')
[ $? -eq 1 ] || err $LINENO
[ "$res" != 'unset' ] || err $LINENO
res=$($com <<< 'b=x; readonly b; declare -n a=b ; unset a')
[ $? -eq 1 ] || err $LINENO
res=$($com <<< 'qux=three; typeset -n ref=; ref=qux; echo $ref')
[ $? -eq 1 ] || err $LINENO
res=$($com <<< 'qux=three; typeset -n ref; ref=qux; echo $ref')
[ "$res" = 'three' ] || err $LINENO
res=$($com <<< 'declare -ai a
a[0]=4
declare -n b='a[0]'
b+=1
declare -p b')
[ "$res" = 'declare -n b="a[0]"' ] || err $LINENO
res=$($com <<< 'declare -ai a
a[0]=4
declare -n b='a[0]'
b+=1
declare -p a')
[ "$res" = 'declare -ai a=([0]="5")' ] || err $LINENO
res=$($com <<< 'declare -ai a; a=(); echo ${a[42]=4+3}')
[ "$res" = '7' ] || err $LINENO
res=$($com <<< 'A=(a); echo ${A[@]@k}')
[ "$res" = '0 a' ] || err $LINENO
res=$($com <<< 'A=(1 2 3); declare "A=(1 2 3)" ; echo ${A[@]}')
[ "$res" = '1 2 3' ] || err $LINENO
res=$($com <<< 'set - a b c; echo $1 $3')
[ "$res" = 'a c' ] || err $LINENO
res=$($com <<< 'arr=(a b c); IFS=+; a=${arr[@]} ; echo "$a"; b=${arr[@]/a/x}; echo "$b"')
[ "$res" = 'a b c
x b c' ] || err $LINENO
res=$($com <<< 'A=( a b c d ) ; N=${#A[@]} ; unset A[N-1] ; echo ${A[@]}')
[ "$res" = 'a b c' ] || err $LINENO
res=$($com <<< 'declare -r c
declare -p c')
[ "$res" = 'declare -r c' ] || err $LINENO
res=$($com <<< 'declare -r c[100]
c[-2]=4
declare -p c')
[ "$res" = 'declare -ar c' ] || err $LINENO
res=$($com <<< 'declare -n b='a[0]' ; a=(1 2 3) ; b=x ; declare -p a')
[ "$res" = 'declare -a a=([0]="x" [1]="2" [2]="3")' ] || err $LINENO
res=$($com <<< 'command declare a=b; echo $a')
[ "$res" = 'b' ] || err $LINENO
res=$($com <<< 'typeset -n ref ; echo ${ref-unset}')
[ "$res" = 'unset' ] || err $LINENO
res=$($com <<< 'typeset -n a='b[1]' ; b=(a B c) ; echo ${a}')
[ "$res" = 'B' ] || err $LINENO
res=$($com <<< 'typeset -n a='b[1]' ; b=(a B c) ; echo $a')
[ "$res" = 'B' ] || err $LINENO
echo 'a() { echo ${FUNCNAME[0]} ; echo ${FUNCNAME[1]} ; }; a' > $tmp-script
res=$($com $tmp-script)
[ "$res" = 'a
main' ] || err $LINENO
echo 'a() { echo ${FUNCNAME[@]} ; }; a' > $tmp-script
res=$($com $tmp-script)
[ "$res" = 'a main' ] || err $LINENO
res=$($com <<< 'f () { caller ; }
f')
[ "$res" = '2 NULL' ] || err $LINENO
res=$($com <<< 'f () { echo ${BASH_LINENO[@]} ; echo ${FUNCNAME[@]}; }
g () { f ; }
g')
[ "$res" = '2 3
f g' ] || err $LINENO
res=$($com <<< 'f () { caller ; }
g () { caller; f ; }
g')
[ "$res" = '3 NULL
2 main' ] || err $LINENO
res=$($com <<< 'f () { caller 0 ; }
g () { f ; }
g')
[ "$res" = '2 g main' ] || err $LINENO
res=$($com <<< '
coproc a { echo a b c ; }
sleep 0.1
coproc b { echo a b c ; sleep 0.4; }
sleep 0.1
echo ${b[@]}
')
[ "$res" = '63 60' ] || err $LINENO
rm -f $tmp-*
echo $0 >> ./ok
exit