-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fixed_v1.2.7.bash
More file actions
executable file
·109 lines (84 loc) · 2.43 KB
/
test_fixed_v1.2.7.bash
File metadata and controls
executable file
·109 lines (84 loc) · 2.43 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
#!/bin/bash -xv
# SPDX-FileCopyrightText: 2025 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 <<< '
f () { echo aho ; }
g () { local f=3 ; echo $f ; f ; unset f; echo $f ; f ; }
g
')
[ "$res" = "3
aho
aho" ] || err $LINENO
res=$($com <<< ' typeset -i ivar; typeset -n iref=ivar; (( iref=17 )); echo $iref' )
[ "$res" = "17" ] || err $LINENO
res=$($com <<< 'a=b; typeset -n c=a; c=2; echo $a; typeset +n c; c=3; echo $a' )
[ "$res" = "2
2" ] || err $LINENO
res=$($com <<< 'bar=4; typeset -n foo=bar; typeset -n one=foo; echo one:$one foo:$foo bar:$bar')
[ "$res" = "one:4 foo:4 bar:4" ] || err $LINENO
res=$($com <<< 'bar=4; typeset -n foo='bar[0]'; echo foo:$foo bar:$bar')
[ "$res" = "foo:4 bar:4" ] || err $LINENO
res=$($com <<< 'bar=4; typeset -n foo='bar[hoge]'; typeset -n one=foo; echo one:$one foo:$foo bar:$bar')
[ "$res" = "one:4 foo:4 bar:4" ] || err $LINENO
res=$($com <<< 'bar=4; typeset -n foo='bar[0]'; typeset -n one=foo; echo one:$one foo:$foo bar:$bar')
[ "$res" = "one:4 foo:4 bar:4" ] || err $LINENO
res=$($com <<< 'typeset -n b=a ; a=3 ; echo $a')
[ "$res" = "3" ] || err $LINENO
res=$($com <<< 'typeset -n b=a ; a=3 ; typeset -n b=a ; echo $a')
[ "$res" = "3" ] || err $LINENO
res=$($com <<< '
v1=1
v2=2
typeset -n v=v1
for v in v1 v2; do
declare -p v v1 v2
echo "${!v}: $v"
done
declare -p v
')
[ "$res" = 'declare -n v="v1"
declare -- v1="1"
declare -- v2="2"
v1: 1
declare -n v="v2"
declare -- v1="1"
declare -- v2="2"
v2: 2
declare -n v="v2"' ] || err $LINENO
res=$($com <<< '
x=(X)
y=(Y)
typeset -n x=y
echo $x -- $?
')
[ "$res" = "X -- 1" ] || err $LINENO
res=$($com <<< 'f () { local a=bbb ; unset a ; } ; a=ccc ; f ; echo $a')
[ "$res" = "ccc" ] || err $LINENO
res=$($com <<< 'set -a ; aaa=bbb ; env | grep ^aaa')
[ "$res" = "aaa=bbb" ] || err $LINENO
res=$($com <<< 'set -f ; echo *')
[ "$res" = '*' ] || err $LINENO
res=$($com -n <<< 'ls aaaaaaaaaaaaa')
[ "$?" -eq 0 ] || err $LINENO
res=$($com -n <<< '((')
[ "$?" -eq 2 ] || err $LINENO
res=$($com <<< 'set -- -n ; [ "$1" = "-n" ]')
[ "$?" -eq 0 ] || err $LINENO
res=$($com <<< 'test -n ""')
[ "$?" -eq 1 ] || err $LINENO
rm -f $tmp-*
echo $0 >> ./ok
exit