-
-
Notifications
You must be signed in to change notification settings - Fork 147
/
blog1.test.sh
95 lines (80 loc) · 1.53 KB
/
blog1.test.sh
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
#
# Tests for the blog.
#
# Fun game: try to come up with an expression that behaves differently on ALL
# FOUR shells.
#### ${##}
set -- $(seq 25)
echo ${##}
## stdout: 2
#### ${###}
set -- $(seq 25)
echo ${###}
## stdout: 25
## N-I osh stdout-json: ""
## N-I osh status: 2
#### ${####}
set -- $(seq 25)
echo ${####}
## stdout: 25
## N-I osh stdout-json: ""
## N-I osh status: 2
#### ${##2}
set -- $(seq 25)
echo ${##2}
## stdout: 5
## N-I osh stdout-json: ""
## N-I osh status: 2
#### ${###2}
set -- $(seq 25)
echo ${###2}
## stdout: 5
## BUG mksh stdout: 25
## N-I osh stdout-json: ""
## N-I osh status: 2
#### ${1####}
set -- '####'
echo ${1####}
## stdout: ##
#### ${1#'###'}
set -- '####'
echo ${1#'###'}
## stdout: #
#### ${#1#'###'}
set -- '####'
echo ${#1#'###'}
# dash and zsh accept; mksh/bash/osh don't.
## status: 2
## stdout-json: ""
## OK dash/zsh status: 0
## OK dash stdout: 4
## OK zsh stdout: 1
## N-I bash/mksh status: 1
#### Julia example from spec/oil-user-feedback
case $SH in (dash|mksh|zsh) exit ;; esac
git-branch-merged() {
cat <<EOF
foo
* bar
baz
master
EOF
}
shopt -s lastpipe # required for bash, not OSH
branches=() # dangerous when set -e is on
git-branch-merged | while read -r line; do
line=${line# *} # strip leading spaces
if [[ $line != 'master' && ! ${line:0:1} == '*' ]]; then
branches+=("$line")
fi
done
if [[ ${#branches[@]} -eq 0 ]]; then
echo "No merged branches"
else
echo git branch -D "${branches[@]}"
fi
## STDOUT:
git branch -D foo baz
## END
## N-I dash/mksh/zsh STDOUT:
## END