diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:32:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:32:59 +0000 |
commit | 4d57e0a8dab2139a631a21aab862487481548702 (patch) | |
tree | f7cea0b9939e2ecb7a301de6c83bada29452046d /test/bashisms | |
parent | Initial commit. (diff) | |
download | devscripts-upstream.tar.xz devscripts-upstream.zip |
Adding upstream version 2.23.7.upstream/2.23.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
77 files changed, 1405 insertions, 0 deletions
diff --git a/test/bashisms/531327.sh b/test/bashisms/531327.sh new file mode 100644 index 0000000..8dcc058 --- /dev/null +++ b/test/bashisms/531327.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +foo() {} + +foo \ +source something diff --git a/test/bashisms/535368.mk b/test/bashisms/535368.mk new file mode 100644 index 0000000..adba007 --- /dev/null +++ b/test/bashisms/535368.mk @@ -0,0 +1,6 @@ +#!/usr/bin/make -f + +foo: + if [ "$$(< $(DEBIAN)/foo md5sum)" != "$$(cat $(DEBIAN)/foo.md5)" ] ; then \ + echo moo; \ + fi diff --git a/test/bashisms/808271.sh b/test/bashisms/808271.sh new file mode 100644 index 0000000..0789d7e --- /dev/null +++ b/test/bashisms/808271.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if type which; then + echo "use which" +fi + +if ! type which; then + echo "well, idk" +fi diff --git a/test/bashisms/808271.sh.out b/test/bashisms/808271.sh.out new file mode 100644 index 0000000..6cb8156 --- /dev/null +++ b/test/bashisms/808271.sh.out @@ -0,0 +1,4 @@ +possible bashism in bashisms/808271.sh line 3 (type): +if type which; then +possible bashism in bashisms/808271.sh line 7 (type): +if ! type which; then diff --git a/test/bashisms/arith.sh b/test/bashisms/arith.sh new file mode 100644 index 0000000..2cbe860 --- /dev/null +++ b/test/bashisms/arith.sh @@ -0,0 +1,21 @@ +#!/bin/sh +metric=0 +echo $((metric=metric+1)) + +m=0 +n=2 +echo $((n-m++)) # BASHISM +echo $((++m)) # BASHISM +echo $(( m-- )) # BASHISM +echo $((--m)) # BASHISM + +foo_bar=0 +echo $((foo_bar++)) # BASHISM +echo $((foo_bar=foo_bar*2)) +echo $((foo_bar*3/6)) + +echo $((2*n++)) # BASHISM + +echo $(($n*n++)) # BASHISM + +echo $((3**2)) # BASHISM diff --git a/test/bashisms/arith.sh.out b/test/bashisms/arith.sh.out new file mode 100644 index 0000000..dae4b40 --- /dev/null +++ b/test/bashisms/arith.sh.out @@ -0,0 +1,16 @@ +possible bashism in bashisms/arith.sh line 7 ('$((n++))' should be '$n; $((n=n+1))'): +echo $((n-m++)) # BASHISM +possible bashism in bashisms/arith.sh line 8 ('$((++n))' should be '$((n=n+1))'): +echo $((++m)) # BASHISM +possible bashism in bashisms/arith.sh line 9 ('$((n--))' should be '$n; $((n=n-1))'): +echo $(( m-- )) # BASHISM +possible bashism in bashisms/arith.sh line 10 ('$((--n))' should be '$((n=n-1))'): +echo $((--m)) # BASHISM +possible bashism in bashisms/arith.sh line 13 ('$((n++))' should be '$n; $((n=n+1))'): +echo $((foo_bar++)) # BASHISM +possible bashism in bashisms/arith.sh line 17 ('$((n++))' should be '$n; $((n=n+1))'): +echo $((2*n++)) # BASHISM +possible bashism in bashisms/arith.sh line 19 ('$((n++))' should be '$n; $((n=n+1))'): +echo $(($n*n++)) # BASHISM +possible bashism in bashisms/arith.sh line 21 (exponentiation is not POSIX): +echo $((3**2)) # BASHISM diff --git a/test/bashisms/array-expansion.sh b/test/bashisms/array-expansion.sh new file mode 100644 index 0000000..ca2b57a --- /dev/null +++ b/test/bashisms/array-expansion.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# This is a TO DO, but irrelevant to this test case: +foo=(foo bar moo BASH ISM) + +n=1 + +echo BASHISM ${foo[1]%r} +echo BASHISM ${foo[$n]%r} +echo BASHISM ${foo[*]%o} +echo BASHISM ${foo[@]%o} + +echo BASHISM ${foo[1]%%r} +echo BASHISM ${foo[$n]%%r} +echo BASHISM ${foo[*]%%o} +echo BASHISM ${foo[@]%%o} + +echo BASHISM ${foo[1]#*a} +echo BASHISM ${foo[$n]#*a} +echo BASHISM ${foo[*]#*o} +echo BASHISM ${foo[@]#*o} + +echo BASHISM ${foo[1]##*a} +echo BASHISM ${foo[$n]##*a} +echo BASHISM ${foo[*]##*o} +echo BASHISM ${foo[@]##*o} + +echo BASHISM ${#foo[1]} +echo BASHISM ${#foo[$n]} +echo BASHISM ${#foo[*]} +echo BASHISM ${#foo[@]} + +# Technically, there are two bashisms here, but I'm happy if it at +# least matches one. The regexes become more complex without real gain +# otherwise. (hence the "BASH ISMS", with the extra space) + +echo BASHISM BASH ISMS ${foo[1]^*a} +echo BASHISM BASH ISMS ${foo[$n]^*a} +echo BASHISM BASH ISMS ${foo[*]^*o} +echo BASHISM BASH ISMS ${foo[@]^*o} + +echo BASHISM BASH ISMS ${foo[1]^^*a} +echo BASHISM BASH ISMS ${foo[$n]^^*a} +echo BASHISM BASH ISMS ${foo[*]^^*o} +echo BASHISM BASH ISMS ${foo[@]^^*o} + +echo BASHISM BASH ISMS ${foo[1],*a} +echo BASHISM BASH ISMS ${foo[$n],*a} +echo BASHISM BASH ISMS ${foo[*],*a} +echo BASHISM BASH ISMS ${foo[@],*a} + +echo BASHISM BASH ISMS ${foo[1],,*a} +echo BASHISM BASH ISMS ${foo[$n],,*a} +echo BASHISM BASH ISMS ${foo[*],,*a} +echo BASHISM BASH ISMS ${foo[@],,*a} + +echo BASHISM BASH ISMS ${foo[1]/a/R} +echo BASHISM BASH ISMS ${foo[$n]/a/R} +echo BASHISM BASH ISMS ${foo[*]/a/R} +echo BASHISM BASH ISMS ${foo[@]/a/R} diff --git a/test/bashisms/array-expansion.sh.out b/test/bashisms/array-expansion.sh.out new file mode 100644 index 0000000..d14bea0 --- /dev/null +++ b/test/bashisms/array-expansion.sh.out @@ -0,0 +1,80 @@ +possible bashism in bashisms/array-expansion.sh line 8 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[1]%r} +possible bashism in bashisms/array-expansion.sh line 9 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[$n]%r} +possible bashism in bashisms/array-expansion.sh line 10 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[*]%o} +possible bashism in bashisms/array-expansion.sh line 11 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[@]%o} +possible bashism in bashisms/array-expansion.sh line 13 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[1]%%r} +possible bashism in bashisms/array-expansion.sh line 14 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[$n]%%r} +possible bashism in bashisms/array-expansion.sh line 15 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[*]%%o} +possible bashism in bashisms/array-expansion.sh line 16 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[@]%%o} +possible bashism in bashisms/array-expansion.sh line 18 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[1]#*a} +possible bashism in bashisms/array-expansion.sh line 19 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[$n]#*a} +possible bashism in bashisms/array-expansion.sh line 20 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[*]#*o} +possible bashism in bashisms/array-expansion.sh line 21 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[@]#*o} +possible bashism in bashisms/array-expansion.sh line 23 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[1]##*a} +possible bashism in bashisms/array-expansion.sh line 24 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[$n]##*a} +possible bashism in bashisms/array-expansion.sh line 25 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[*]##*o} +possible bashism in bashisms/array-expansion.sh line 26 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${foo[@]##*o} +possible bashism in bashisms/array-expansion.sh line 28 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${#foo[1]} +possible bashism in bashisms/array-expansion.sh line 29 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${#foo[$n]} +possible bashism in bashisms/array-expansion.sh line 30 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${#foo[*]} +possible bashism in bashisms/array-expansion.sh line 31 (bash arrays, ${name[0|*|@]}): +echo BASHISM ${#foo[@]} +possible bashism in bashisms/array-expansion.sh line 37 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[1]^*a} +possible bashism in bashisms/array-expansion.sh line 38 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[$n]^*a} +possible bashism in bashisms/array-expansion.sh line 39 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[*]^*o} +possible bashism in bashisms/array-expansion.sh line 40 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[@]^*o} +possible bashism in bashisms/array-expansion.sh line 42 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[1]^^*a} +possible bashism in bashisms/array-expansion.sh line 43 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[$n]^^*a} +possible bashism in bashisms/array-expansion.sh line 44 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[*]^^*o} +possible bashism in bashisms/array-expansion.sh line 45 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[@]^^*o} +possible bashism in bashisms/array-expansion.sh line 47 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[1],*a} +possible bashism in bashisms/array-expansion.sh line 48 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[$n],*a} +possible bashism in bashisms/array-expansion.sh line 49 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[*],*a} +possible bashism in bashisms/array-expansion.sh line 50 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[@],*a} +possible bashism in bashisms/array-expansion.sh line 52 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[1],,*a} +possible bashism in bashisms/array-expansion.sh line 53 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[$n],,*a} +possible bashism in bashisms/array-expansion.sh line 54 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[*],,*a} +possible bashism in bashisms/array-expansion.sh line 55 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[@],,*a} +possible bashism in bashisms/array-expansion.sh line 57 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[1]/a/R} +possible bashism in bashisms/array-expansion.sh line 58 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[$n]/a/R} +possible bashism in bashisms/array-expansion.sh line 59 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[*]/a/R} +possible bashism in bashisms/array-expansion.sh line 60 (bash arrays, ${name[0|*|@]}): +echo BASHISM BASH ISMS ${foo[@]/a/R} diff --git a/test/bashisms/ash-setvar.sh b/test/bashisms/ash-setvar.sh new file mode 100644 index 0000000..c0ae403 --- /dev/null +++ b/test/bashisms/ash-setvar.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +setvar foo bar # BASHISM +[ bar = "$foo" ] diff --git a/test/bashisms/ash-setvar.sh.out b/test/bashisms/ash-setvar.sh.out new file mode 100644 index 0000000..121a65c --- /dev/null +++ b/test/bashisms/ash-setvar.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/ash-setvar.sh line 3 (setvar 'foo' 'bar' should be eval 'foo="'"$bar"'"'): +setvar foo bar # BASHISM diff --git a/test/bashisms/basic-bash-override.mk b/test/bashisms/basic-bash-override.mk new file mode 100644 index 0000000..7904a5e --- /dev/null +++ b/test/bashisms/basic-bash-override.mk @@ -0,0 +1,6 @@ +#!/usr/bin/make -f + + override SHELL := bash + +test: + @echo -e foo diff --git a/test/bashisms/basic-bash.mk b/test/bashisms/basic-bash.mk new file mode 100644 index 0000000..7a16131 --- /dev/null +++ b/test/bashisms/basic-bash.mk @@ -0,0 +1,6 @@ +#!/usr/bin/make -f + +SHELL := bash + +test: + echo -e foo diff --git a/test/bashisms/basic.mk b/test/bashisms/basic.mk new file mode 100644 index 0000000..31d59a2 --- /dev/null +++ b/test/bashisms/basic.mk @@ -0,0 +1,21 @@ +#!/usr/bin/make -f + +# bug: +overrideSHELL := bash + +test: + -echo -e "foo BASHISM" + @echo -e "bar BASHISM" + @-echo -e "bar BASHISM" && false + -@echo -e "bar BASHISM" && false + true + +dirs: +source diff: +source diff.gz:: +source file-stamp: +caller %.so: + : + +foo: $(shell echo dir/BASHISM/{foo,bar}) + : diff --git a/test/bashisms/basic.mk.out b/test/bashisms/basic.mk.out new file mode 100644 index 0000000..1fae795 --- /dev/null +++ b/test/bashisms/basic.mk.out @@ -0,0 +1,10 @@ +possible bashism in bashisms/basic.mk line 7 (echo -e): + -echo -e "foo BASHISM" +possible bashism in bashisms/basic.mk line 8 (echo -e): + @echo -e "bar BASHISM" +possible bashism in bashisms/basic.mk line 9 (echo -e): + @-echo -e "bar BASHISM" && false +possible bashism in bashisms/basic.mk line 10 (echo -e): + -@echo -e "bar BASHISM" && false +possible bashism in bashisms/basic.mk line 20 (brace expansion): +foo: $(shell echo dir/BASHISM/{foo,bar}) diff --git a/test/bashisms/brace-expansion.sh b/test/bashisms/brace-expansion.sh new file mode 100644 index 0000000..c34ea21 --- /dev/null +++ b/test/bashisms/brace-expansion.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo BASHISM{1..10} +echo BASHISM{1..10..2} +echo BASHISM{a..z} +echo BASHISM{Z..a} +echo BASHISM{a..z..2} +echo {a.._} +echo {a..9} diff --git a/test/bashisms/brace-expansion.sh.out b/test/bashisms/brace-expansion.sh.out new file mode 100644 index 0000000..843dc32 --- /dev/null +++ b/test/bashisms/brace-expansion.sh.out @@ -0,0 +1,10 @@ +possible bashism in bashisms/brace-expansion.sh line 3 (brace expansion, {a..b[..c]}should be $(seq a [c] b)): +echo BASHISM{1..10} +possible bashism in bashisms/brace-expansion.sh line 4 (brace expansion, {a..b[..c]}should be $(seq a [c] b)): +echo BASHISM{1..10..2} +possible bashism in bashisms/brace-expansion.sh line 5 (brace expansion): +echo BASHISM{a..z} +possible bashism in bashisms/brace-expansion.sh line 6 (brace expansion): +echo BASHISM{Z..a} +possible bashism in bashisms/brace-expansion.sh line 7 (brace expansion): +echo BASHISM{a..z..2} diff --git a/test/bashisms/case-modification.sh b/test/bashisms/case-modification.sh new file mode 100644 index 0000000..d163e6a --- /dev/null +++ b/test/bashisms/case-modification.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +foo=foo +bar=BAR + +echo BASHISM: ${foo^f} +echo BASHISM: ${foo^^o} +echo BASHISM: ${bar,B} +echo BASHISM: ${bar,,R} + +echo BASHISM: ${foo^} +echo BASHISM: ${foo^^} +echo BASHISM: ${bar,} +echo BASHISM: ${bar,,} + +echo BASHISM: ${@^} +echo BASHISM: ${*^^} +echo BASHISM: ${@,} +echo BASHISM: ${*,,} diff --git a/test/bashisms/case-modification.sh.out b/test/bashisms/case-modification.sh.out new file mode 100644 index 0000000..d60157f --- /dev/null +++ b/test/bashisms/case-modification.sh.out @@ -0,0 +1,24 @@ +possible bashism in bashisms/case-modification.sh line 6 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${foo^f} +possible bashism in bashisms/case-modification.sh line 7 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${foo^^o} +possible bashism in bashisms/case-modification.sh line 8 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${bar,B} +possible bashism in bashisms/case-modification.sh line 9 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${bar,,R} +possible bashism in bashisms/case-modification.sh line 11 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${foo^} +possible bashism in bashisms/case-modification.sh line 12 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${foo^^} +possible bashism in bashisms/case-modification.sh line 13 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${bar,} +possible bashism in bashisms/case-modification.sh line 14 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${bar,,} +possible bashism in bashisms/case-modification.sh line 16 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${@^} +possible bashism in bashisms/case-modification.sh line 17 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${*^^} +possible bashism in bashisms/case-modification.sh line 18 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${@,} +possible bashism in bashisms/case-modification.sh line 19 (${parm,[,][pat]} or ${parm^[^][pat]}): +echo BASHISM: ${*,,} diff --git a/test/bashisms/command.sh b/test/bashisms/command.sh new file mode 100644 index 0000000..bdfb8c6 --- /dev/null +++ b/test/bashisms/command.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +command test +command -p test +command -v test +command -V test +command -p test +command -p -v test +command -pv test +command -p -v -a test # BASHISM +command -p -a -v test # BASHISM +command -pa test # BASHISM +command -ap test # BASHISM +command -p -a test # BASHISM +command -pV -a test # BASHISM +command -p test diff --git a/test/bashisms/command.sh.out b/test/bashisms/command.sh.out new file mode 100644 index 0000000..1e1e111 --- /dev/null +++ b/test/bashisms/command.sh.out @@ -0,0 +1,12 @@ +possible bashism in bashisms/command.sh line 10 ('command' with option other than -p, -v or -V): +command -p -v -a test # BASHISM +possible bashism in bashisms/command.sh line 11 ('command' with option other than -p, -v or -V): +command -p -a -v test # BASHISM +possible bashism in bashisms/command.sh line 12 ('command' with option other than -p, -v or -V): +command -pa test # BASHISM +possible bashism in bashisms/command.sh line 13 ('command' with option other than -p, -v or -V): +command -ap test # BASHISM +possible bashism in bashisms/command.sh line 14 ('command' with option other than -p, -v or -V): +command -p -a test # BASHISM +possible bashism in bashisms/command.sh line 15 ('command' with option other than -p, -v or -V): +command -pV -a test # BASHISM diff --git a/test/bashisms/comments-in-quoted-strings1.sh b/test/bashisms/comments-in-quoted-strings1.sh new file mode 100644 index 0000000..36d4bd8 --- /dev/null +++ b/test/bashisms/comments-in-quoted-strings1.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +echo 's#/##g +s# #/#' + +echo ' +' # foo() {} " diff --git a/test/bashisms/comments-in-quoted-strings2.sh b/test/bashisms/comments-in-quoted-strings2.sh new file mode 100644 index 0000000..6c9ef0e --- /dev/null +++ b/test/bashisms/comments-in-quoted-strings2.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo " +\" # " # foo() {} ' diff --git a/test/bashisms/comments-parsing-fns.sh b/test/bashisms/comments-parsing-fns.sh new file mode 100644 index 0000000..933caee --- /dev/null +++ b/test/bashisms/comments-parsing-fns.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo $# ; echo -e BASHISM diff --git a/test/bashisms/comments-parsing-fns.sh.out b/test/bashisms/comments-parsing-fns.sh.out new file mode 100644 index 0000000..e0a8f6b --- /dev/null +++ b/test/bashisms/comments-parsing-fns.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/comments-parsing-fns.sh line 3 (echo -e): +echo $# ; echo -e BASHISM diff --git a/test/bashisms/coproc.sh b/test/bashisms/coproc.sh new file mode 100644 index 0000000..6d6edcc --- /dev/null +++ b/test/bashisms/coproc.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +coproc true # BASHISM diff --git a/test/bashisms/coproc.sh.out b/test/bashisms/coproc.sh.out new file mode 100644 index 0000000..63b4caa --- /dev/null +++ b/test/bashisms/coproc.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/coproc.sh line 3 (coproc): +coproc true # BASHISM diff --git a/test/bashisms/dynamic-length.sh b/test/bashisms/dynamic-length.sh new file mode 100644 index 0000000..fa76729 --- /dev/null +++ b/test/bashisms/dynamic-length.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +len=1 +f=foo + +echo "${f:1}" # BASHISM +echo "${f:$len}" # BASHISM +echo "${f:$len$len}" # BASHISM +echo "${f:${len}}" # BASHISM diff --git a/test/bashisms/dynamic-length.sh.out b/test/bashisms/dynamic-length.sh.out new file mode 100644 index 0000000..ffd0b13 --- /dev/null +++ b/test/bashisms/dynamic-length.sh.out @@ -0,0 +1,8 @@ +possible bashism in bashisms/dynamic-length.sh line 6 (${foo:3[:1]}): +echo "${f:1}" # BASHISM +possible bashism in bashisms/dynamic-length.sh line 7 (${foo:3[:1]}): +echo "${f:$len}" # BASHISM +possible bashism in bashisms/dynamic-length.sh line 8 (${foo:3[:1]}): +echo "${f:$len$len}" # BASHISM +possible bashism in bashisms/dynamic-length.sh line 9 (${foo:3[:1]}): +echo "${f:${len}}" # BASHISM diff --git a/test/bashisms/exit-code.sh b/test/bashisms/exit-code.sh new file mode 100644 index 0000000..48b9fcd --- /dev/null +++ b/test/bashisms/exit-code.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# http://bugs.debian.org/687450 +exit -- 2 # BASHISM +exit 255 +exit 256 # BASHISM +exit -1 # BASHISM diff --git a/test/bashisms/exit-code.sh.out b/test/bashisms/exit-code.sh.out new file mode 100644 index 0000000..a1b0870 --- /dev/null +++ b/test/bashisms/exit-code.sh.out @@ -0,0 +1,6 @@ +possible bashism in bashisms/exit-code.sh line 4 ('exit --' should be 'exit' (idem for return)): +exit -- 2 # BASHISM +possible bashism in bashisms/exit-code.sh line 6 (exit|return status code greater than 255): +exit 256 # BASHISM +possible bashism in bashisms/exit-code.sh line 7 (exit|return with negative status code): +exit -1 # BASHISM diff --git a/test/bashisms/fail2ban.sh b/test/bashisms/fail2ban.sh new file mode 100644 index 0000000..1ab61f8 --- /dev/null +++ b/test/bashisms/fail2ban.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +eval $_INITSCRIPT force-reload ${HIDEOUTPUT:+\>/dev/null 2\>&1} diff --git a/test/bashisms/fps.sh b/test/bashisms/fps.sh new file mode 100644 index 0000000..b1a619e --- /dev/null +++ b/test/bashisms/fps.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo -e "BASHISM" \ + "something else \n" + +#exec ${loclibdir}/tkcon.tcl \ +# -eval "source ${loclibdir}/console.tcl" \ +# -slave "package require Tk; set argc $#; set argv [list $*]; \ +# source ${loclibdir}/xcircuit.tcl" diff --git a/test/bashisms/fps.sh.out b/test/bashisms/fps.sh.out new file mode 100644 index 0000000..8f4b457 --- /dev/null +++ b/test/bashisms/fps.sh.out @@ -0,0 +1,3 @@ +possible bashism in bashisms/fps.sh line 4 (echo -e): +echo -e "BASHISM" \ + "something else \n" diff --git a/test/bashisms/functions.sh b/test/bashisms/functions.sh new file mode 100644 index 0000000..18adf3d --- /dev/null +++ b/test/bashisms/functions.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +foo() { + : +} + +_all_good () { + : +} + +_all_good101_ ( ) { + : +} + +function BASHISM() { + : +} + +function BASHISM { + : +} + +function BASHISM { + echo foo +} &>/dev/null # BASHISM + +,() { # BASHISM + : +} + +function foo:bar:BASHISM { # BASHISMS + : +} + +function foo-bar-BASHISM() { # BASHISMS + : +} + +foo-bar-BASHISM ( ) { + : +} + +_ () { + : +} + +function _ { #BASHISM + : +} + +=() { #BASHISM + : +} + +function BASHISM=() { #BASHISMS + : +} + +function BASHISM= { #BASHISMS + : +} + +# This doesn't work: +#foo=() { +# : +#} diff --git a/test/bashisms/functions.sh.out b/test/bashisms/functions.sh.out new file mode 100644 index 0000000..61a4c4d --- /dev/null +++ b/test/bashisms/functions.sh.out @@ -0,0 +1,32 @@ +possible bashism in bashisms/functions.sh line 15 ('function' is useless): +function BASHISM() { +possible bashism in bashisms/functions.sh line 19 ('function' is useless): +function BASHISM { +possible bashism in bashisms/functions.sh line 23 ('function' is useless): +function BASHISM { +possible bashism in bashisms/functions.sh line 25 (should be >word 2>&1): +} &>/dev/null # BASHISM +possible bashism in bashisms/functions.sh line 27 (function names should only contain [a-z0-9_]): +,() { # BASHISM +possible bashism in bashisms/functions.sh line 31 (function names should only contain [a-z0-9_]): +function foo:bar:BASHISM { # BASHISMS +possible bashism in bashisms/functions.sh line 31 ('function' is useless): +function foo:bar:BASHISM { # BASHISMS +possible bashism in bashisms/functions.sh line 35 (function names should only contain [a-z0-9_]): +function foo-bar-BASHISM() { # BASHISMS +possible bashism in bashisms/functions.sh line 35 ('function' is useless): +function foo-bar-BASHISM() { # BASHISMS +possible bashism in bashisms/functions.sh line 39 (function names should only contain [a-z0-9_]): +foo-bar-BASHISM ( ) { +possible bashism in bashisms/functions.sh line 47 ('function' is useless): +function _ { #BASHISM +possible bashism in bashisms/functions.sh line 51 (function names should only contain [a-z0-9_]): +=() { #BASHISM +possible bashism in bashisms/functions.sh line 55 (function names should only contain [a-z0-9_]): +function BASHISM=() { #BASHISMS +possible bashism in bashisms/functions.sh line 55 ('function' is useless): +function BASHISM=() { #BASHISMS +possible bashism in bashisms/functions.sh line 59 (function names should only contain [a-z0-9_]): +function BASHISM= { #BASHISMS +possible bashism in bashisms/functions.sh line 59 ('function' is useless): +function BASHISM= { #BASHISMS diff --git a/test/bashisms/gettext.sh b/test/bashisms/gettext.sh new file mode 100644 index 0000000..ebaec32 --- /dev/null +++ b/test/bashisms/gettext.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo $"hello world -- BASHISM" + +echo "foo ' bar moo'$" diff --git a/test/bashisms/gettext.sh.out b/test/bashisms/gettext.sh.out new file mode 100644 index 0000000..a76578e --- /dev/null +++ b/test/bashisms/gettext.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/gettext.sh line 3 ($"foo" should be eval_gettext "foo"): +echo $"hello world -- BASHISM" diff --git a/test/bashisms/glob-ignore.sh b/test/bashisms/glob-ignore.sh new file mode 100644 index 0000000..0c9cd9a --- /dev/null +++ b/test/bashisms/glob-ignore.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +GLOBIGNORE="run-tests.sh:BASHISM" +echo *.sh | grep -q run-tests.sh || echo meh diff --git a/test/bashisms/glob-ignore.sh.out b/test/bashisms/glob-ignore.sh.out new file mode 100644 index 0000000..4688c7c --- /dev/null +++ b/test/bashisms/glob-ignore.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/glob-ignore.sh line 3 (GLOBIGNORE=): +GLOBIGNORE="run-tests.sh:BASHISM" diff --git a/test/bashisms/hash.sh b/test/bashisms/hash.sh new file mode 100644 index 0000000..74fc7f4 --- /dev/null +++ b/test/bashisms/hash.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +: BASHISM; hash +hash which # BASHISM +hash -r # BASHISM diff --git a/test/bashisms/hash.sh.out b/test/bashisms/hash.sh.out new file mode 100644 index 0000000..c9136bb --- /dev/null +++ b/test/bashisms/hash.sh.out @@ -0,0 +1,6 @@ +possible bashism in bashisms/hash.sh line 3 (hash): +: BASHISM; hash +possible bashism in bashisms/hash.sh line 4 (hash): +hash which # BASHISM +possible bashism in bashisms/hash.sh line 5 (hash): +hash -r # BASHISM diff --git a/test/bashisms/heredoc-with-dash.sh b/test/bashisms/heredoc-with-dash.sh new file mode 100644 index 0000000..9200886 --- /dev/null +++ b/test/bashisms/heredoc-with-dash.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +cat << -EOF1- 1>&2 +CLEAN +-EOF1- + +cat << -EOF2 1>&2 +CLEAN +-EOF2 + +cat <<-EOF3 1>&2 +CLEAN + EOF3 + +cat <<- EOF4 1>&2 +CLEAN + EOF4 + +foo=bar + +cat << '-EOF1-' 1>&2 +CLEAN $foo +-EOF1- + +cat << '-EOF2' 1>&2 +CLEAN $foo +-EOF2 + +cat <<-'EOF3' 1>&2 +CLEAN $foo + EOF3 + +cat <<- 'EOF4' 1>&2 +CLEAN $foo + EOF4 diff --git a/test/bashisms/heredoc-with-others.sh b/test/bashisms/heredoc-with-others.sh new file mode 100644 index 0000000..9f0c04f --- /dev/null +++ b/test/bashisms/heredoc-with-others.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +cat << =EOF1 +function CLEAN() {} +=EOF1 + +cat << :EOF2 +function CLEAN() {} +:EOF2 + +cat << ,EOF3 +function CLEAN() {} +,EOF3 + +cat << ?EOF4 +function CLEAN() {} +?EOF4 + +cat << E$OF5 +function CLEAN() {} +E$OF5 + +cat << $EOF6 +function CLEAN() {} +$EOF6 + +cat << EOF_7 +function CLEAN() {} +EOF_7 + +cat << EOF;: +function CLEAN() {} +EOF + +cat << EOF{}9 +function CLEAN() {} +EOF{}9 + +cat << EOF\ 10 +function CLEAN() {} +EOF 10 + +cat << EOF\;11 +function CLEAN() {} +EOF;11 + +cat << EOF\12 +function CLEAN() {} +EOF12 + +cat << EOF\\13 +function CLEAN() {} +EOF\13 + +cat << EOF\\1\\4 +function CLEAN() {} +EOF\1\4 + +cat << \<EOF15\> +function CLEAN() {} +<EOF15> + +cat << "E\OF16" +function CLEAN() {} +E\OF16 + +cat << 'E\OF17' +function CLEAN() {} +E\OF17 + +cat << EOF18|: +function CLEAN() {} +EOF18 + +cat << EOF19>/dev/null +echo -e CLEAN() {} +EOF19 diff --git a/test/bashisms/heredocs.sh b/test/bashisms/heredocs.sh new file mode 100644 index 0000000..39dd076 --- /dev/null +++ b/test/bashisms/heredocs.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +cat <<- FOO + foo + bar + moo +FOO + +echo -e moo # BASHISM + +foo() { + cat <<- FOO + foo + bar + moo + FOO + echo -e BASHISM +} + +bar() { + cat <<- FOO + foo + bar + moo + FOO + echo -e nothing wrong here +FOO + echo -e BASHISM +} + + +moo() { + cat << FOO + foo + bar + moo + FOO + echo -e nothing wrong here + FOO + echo -e still nothing wrong here +FOO + echo -e BASHISM +} + +baz() { + cat << EOF1 +EOF1 + echo -e still inside the here doc +EOF1 ; echo -e still inside... +EOF1 + echo -e BASHISM +} diff --git a/test/bashisms/heredocs.sh.out b/test/bashisms/heredocs.sh.out new file mode 100644 index 0000000..15e3910 --- /dev/null +++ b/test/bashisms/heredocs.sh.out @@ -0,0 +1,10 @@ +possible bashism in bashisms/heredocs.sh line 9 (echo -e): +echo -e moo # BASHISM +possible bashism in bashisms/heredocs.sh line 17 (echo -e): + echo -e BASHISM +possible bashism in bashisms/heredocs.sh line 28 (echo -e): + echo -e BASHISM +possible bashism in bashisms/heredocs.sh line 42 (echo -e): + echo -e BASHISM +possible bashism in bashisms/heredocs.sh line 51 (echo -e): + echo -e BASHISM diff --git a/test/bashisms/jobs.sh b/test/bashisms/jobs.sh new file mode 100644 index 0000000..9e2df54 --- /dev/null +++ b/test/bashisms/jobs.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# POSIX+UP: +jobs # BASHISM +jobs -l # BASHISM +jobs -p # BASHISM + +# Non-POSIX at all: + +sleep 10 & +j=$(jobs -p) # possible BASHISM (context changes because of subshell) +jobs -r # BASHISM +jobs -s # BASHISM +jobs -n # BASHISM +jobs -x # BASHISM
\ No newline at end of file diff --git a/test/bashisms/jobs.sh.out b/test/bashisms/jobs.sh.out new file mode 100644 index 0000000..de8f8b3 --- /dev/null +++ b/test/bashisms/jobs.sh.out @@ -0,0 +1,16 @@ +possible bashism in bashisms/jobs.sh line 4 (jobs): +jobs # BASHISM +possible bashism in bashisms/jobs.sh line 5 (jobs): +jobs -l # BASHISM +possible bashism in bashisms/jobs.sh line 6 (jobs): +jobs -p # BASHISM +possible bashism in bashisms/jobs.sh line 11 (jobs): +j=$(jobs -p) # possible BASHISM (context changes because of subshell) +possible bashism in bashisms/jobs.sh line 12 (jobs): +jobs -r # BASHISM +possible bashism in bashisms/jobs.sh line 13 (jobs): +jobs -s # BASHISM +possible bashism in bashisms/jobs.sh line 14 (jobs): +jobs -n # BASHISM +possible bashism in bashisms/jobs.sh line 15 (jobs): +jobs -x # BASHISM diff --git a/test/bashisms/line-continuation.sh b/test/bashisms/line-continuation.sh new file mode 100644 index 0000000..e83b6d4 --- /dev/null +++ b/test/bashisms/line-continuation.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +echo foo; \ +shopt something # BASHISM + +echo foo; echo \ +shopt something + +cat <<EOF \ +&>/dev/null #BASHISM +bar +moo +EOF + +cat <<EOF +foo\ +bar\ +moo +EOF diff --git a/test/bashisms/line-continuation.sh.out b/test/bashisms/line-continuation.sh.out new file mode 100644 index 0000000..a243228 --- /dev/null +++ b/test/bashisms/line-continuation.sh.out @@ -0,0 +1,6 @@ +possible bashism in bashisms/line-continuation.sh line 4 (shopt): +echo foo; \ +shopt something # BASHISM +possible bashism in bashisms/line-continuation.sh line 10 (should be >word 2>&1): +cat <<EOF \ +&>/dev/null #BASHISM diff --git a/test/bashisms/negations.sh b/test/bashisms/negations.sh new file mode 100644 index 0000000..8901357 --- /dev/null +++ b/test/bashisms/negations.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +case "moo" in + [^f]oo) # BASHISM + echo hey + ;; + [!f]oo) + echo hey + ;; +esac + diff --git a/test/bashisms/negations.sh.out b/test/bashisms/negations.sh.out new file mode 100644 index 0000000..2a481c1 --- /dev/null +++ b/test/bashisms/negations.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/negations.sh line 4 ([^] should be [!]): + [^f]oo) # BASHISM diff --git a/test/bashisms/other-vars.sh b/test/bashisms/other-vars.sh new file mode 100644 index 0000000..46dbedc --- /dev/null +++ b/test/bashisms/other-vars.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +test() { + echo $FUNCNAME BASHISM +} + +test + +echo $DIRSTACK BASHISM +echo $SECONDS BASHISM +echo $TMOUT BASHISM +echo $TIMEFORMAT BASHISM +TMOUT=2 # BASHISM +read REPLY +TIMEFORMAT='' # BASHISM diff --git a/test/bashisms/other-vars.sh.out b/test/bashisms/other-vars.sh.out new file mode 100644 index 0000000..1f0e2b2 --- /dev/null +++ b/test/bashisms/other-vars.sh.out @@ -0,0 +1,14 @@ +possible bashism in bashisms/other-vars.sh line 4 ($FUNCNAME): + echo $FUNCNAME BASHISM +possible bashism in bashisms/other-vars.sh line 9 ($DIRSTACK): +echo $DIRSTACK BASHISM +possible bashism in bashisms/other-vars.sh line 10 ($SECONDS): +echo $SECONDS BASHISM +possible bashism in bashisms/other-vars.sh line 11 ($TMOUT): +echo $TMOUT BASHISM +possible bashism in bashisms/other-vars.sh line 12 ($TIMEFORMAT): +echo $TIMEFORMAT BASHISM +possible bashism in bashisms/other-vars.sh line 13 (TMOUT=): +TMOUT=2 # BASHISM +possible bashism in bashisms/other-vars.sh line 15 (TIMEFORMAT=): +TIMEFORMAT='' # BASHISM diff --git a/test/bashisms/printf.sh b/test/bashisms/printf.sh new file mode 100644 index 0000000..1ba20b8 --- /dev/null +++ b/test/bashisms/printf.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +printf -v some_var "this is a BASHISM" + +printf "the use of %q is bad\n" "BASHISMS" >/dev/null + +printf "%q leading the string is bad\n" "BASHISMS" >/dev/null diff --git a/test/bashisms/printf.sh.out b/test/bashisms/printf.sh.out new file mode 100644 index 0000000..05472da --- /dev/null +++ b/test/bashisms/printf.sh.out @@ -0,0 +1,6 @@ +possible bashism in bashisms/printf.sh line 3 ('printf -v var ...' should be var='$(printf ...)'): +printf -v some_var "this is a BASHISM" +possible bashism in bashisms/printf.sh line 5 (printf %q): +printf "the use of %q is bad\n" "BASHISMS" >/dev/null +possible bashism in bashisms/printf.sh line 7 (printf %q): +printf "%q leading the string is bad\n" "BASHISMS" >/dev/null diff --git a/test/bashisms/quoted-strings.sh b/test/bashisms/quoted-strings.sh new file mode 100644 index 0000000..bf88104 --- /dev/null +++ b/test/bashisms/quoted-strings.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +foo=" +echo -e nothing wrong here +#crap" + +echo -e BASHISM + +foo="\ +#crap" + +echo -e BASHISM + +case foo in + *\'*) + echo -e BASHISM + ;; +esac +#' +echo -e BASHISM + +case foo in + *\\"*") + echo -e BASHISM + ;; + *\\\"*) + echo -e BASHISM + ;; + *\"*) + echo -e BASHISM + ;; +esac +#" +echo -e BASHISM + +foo='\' +echo -e BASHISM diff --git a/test/bashisms/quoted-strings.sh.out b/test/bashisms/quoted-strings.sh.out new file mode 100644 index 0000000..a1fd9d7 --- /dev/null +++ b/test/bashisms/quoted-strings.sh.out @@ -0,0 +1,18 @@ +possible bashism in bashisms/quoted-strings.sh line 7 (echo -e): +echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 12 (echo -e): +echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 16 (echo -e): + echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 20 (echo -e): +echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 24 (echo -e): + echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 27 (echo -e): + echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 30 (echo -e): + echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 34 (echo -e): +echo -e BASHISM +possible bashism in bashisms/quoted-strings.sh line 37 (echo -e): +echo -e BASHISM diff --git a/test/bashisms/return.sh b/test/bashisms/return.sh new file mode 100644 index 0000000..c6735e0 --- /dev/null +++ b/test/bashisms/return.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +foo() { + return -- 1 # BASHISM +} + +bar () { + return 256 # BASHISM +} + +moo () { + return -1 # BASHISM +} diff --git a/test/bashisms/return.sh.out b/test/bashisms/return.sh.out new file mode 100644 index 0000000..ad1aae0 --- /dev/null +++ b/test/bashisms/return.sh.out @@ -0,0 +1,6 @@ +possible bashism in bashisms/return.sh line 4 ('exit --' should be 'exit' (idem for return)): + return -- 1 # BASHISM +possible bashism in bashisms/return.sh line 8 (exit|return status code greater than 255): + return 256 # BASHISM +possible bashism in bashisms/return.sh line 12 (exit|return with negative status code): + return -1 # BASHISM diff --git a/test/bashisms/shell-vars.mk b/test/bashisms/shell-vars.mk new file mode 100644 index 0000000..54b71cb --- /dev/null +++ b/test/bashisms/shell-vars.mk @@ -0,0 +1,5 @@ +#!/usr/bin/make -f + +foo: + read foo bar | echo $$foo and $$bar + echo my pid: $$$$ diff --git a/test/bashisms/source b/test/bashisms/source new file mode 100644 index 0000000..412f8bd --- /dev/null +++ b/test/bashisms/source @@ -0,0 +1,2 @@ +#!/bin/sh +source foo.sh # BASHISM diff --git a/test/bashisms/source.out b/test/bashisms/source.out new file mode 100644 index 0000000..d17fa5f --- /dev/null +++ b/test/bashisms/source.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/source line 2 (should be '.', not 'source'): +source foo.sh # BASHISM diff --git a/test/bashisms/special-case.sh b/test/bashisms/special-case.sh new file mode 100644 index 0000000..5dd43e0 --- /dev/null +++ b/test/bashisms/special-case.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +case "foo" in + foo) + echo once + ;& # BASHISM + moo) + echo twice + ;;& # BASHISM + foo) + echo foo again + ;; +esac diff --git a/test/bashisms/special-case.sh.out b/test/bashisms/special-case.sh.out new file mode 100644 index 0000000..2b0a5e3 --- /dev/null +++ b/test/bashisms/special-case.sh.out @@ -0,0 +1,4 @@ +possible bashism in bashisms/special-case.sh line 6 (;;& and ;& special case operators): + ;& # BASHISM +possible bashism in bashisms/special-case.sh line 9 (;;& and ;& special case operators): + ;;& # BASHISM diff --git a/test/bashisms/special-expansions.sh b/test/bashisms/special-expansions.sh new file mode 100644 index 0000000..93a4f7f --- /dev/null +++ b/test/bashisms/special-expansions.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -- foo bar moo + +echo BASHISM: ${#@} +echo BASHISM: ${#*} + +echo BASHISM: ${@%f*} +echo BASHISM: ${*%f*} +echo BASHISM: ${@%%f*} +echo BASHISM: ${*%%f*} + +echo BASHISM: ${@#*o} +echo BASHISM: ${*#*o} +echo BASHISM: ${@##*o} +echo BASHISM: ${*##*o} + +echo BASHISM: ${@/?/u} +echo BASHISM: ${*/?/u} +echo BASHISM: ${@/?/} +echo BASHISM: ${*/?/} + +echo BASHISM: ${@:2} +echo BASHISM: ${*:2} +echo BASHISM: ${@:1:1} +echo BASHISM: ${*:1:1} diff --git a/test/bashisms/special-expansions.sh.out b/test/bashisms/special-expansions.sh.out new file mode 100644 index 0000000..66e60fd --- /dev/null +++ b/test/bashisms/special-expansions.sh.out @@ -0,0 +1,36 @@ +possible bashism in bashisms/special-expansions.sh line 5 (${#@} or ${#*}): +echo BASHISM: ${#@} +possible bashism in bashisms/special-expansions.sh line 6 (${#@} or ${#*}): +echo BASHISM: ${#*} +possible bashism in bashisms/special-expansions.sh line 8 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${@%f*} +possible bashism in bashisms/special-expansions.sh line 9 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${*%f*} +possible bashism in bashisms/special-expansions.sh line 10 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${@%%f*} +possible bashism in bashisms/special-expansions.sh line 11 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${*%%f*} +possible bashism in bashisms/special-expansions.sh line 13 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${@#*o} +possible bashism in bashisms/special-expansions.sh line 14 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${*#*o} +possible bashism in bashisms/special-expansions.sh line 15 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${@##*o} +possible bashism in bashisms/special-expansions.sh line 16 (${[@|*]#[#]pat} or ${[@|*]%[%]pat}): +echo BASHISM: ${*##*o} +possible bashism in bashisms/special-expansions.sh line 18 (${parm/?/pat[/str]}): +echo BASHISM: ${@/?/u} +possible bashism in bashisms/special-expansions.sh line 19 (${parm/?/pat[/str]}): +echo BASHISM: ${*/?/u} +possible bashism in bashisms/special-expansions.sh line 20 (${parm/?/pat[/str]}): +echo BASHISM: ${@/?/} +possible bashism in bashisms/special-expansions.sh line 21 (${parm/?/pat[/str]}): +echo BASHISM: ${*/?/} +possible bashism in bashisms/special-expansions.sh line 23 (${foo:3[:1]}): +echo BASHISM: ${@:2} +possible bashism in bashisms/special-expansions.sh line 24 (${foo:3[:1]}): +echo BASHISM: ${*:2} +possible bashism in bashisms/special-expansions.sh line 25 (${foo:3[:1]}): +echo BASHISM: ${@:1:1} +possible bashism in bashisms/special-expansions.sh line 26 (${foo:3[:1]}): +echo BASHISM: ${*:1:1} diff --git a/test/bashisms/subshell-no-arith.sh b/test/bashisms/subshell-no-arith.sh new file mode 100644 index 0000000..f3a5a29 --- /dev/null +++ b/test/bashisms/subshell-no-arith.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo $((echo foo); echo bar) diff --git a/test/bashisms/tilde-expansion.sh b/test/bashisms/tilde-expansion.sh new file mode 100644 index 0000000..e58069a --- /dev/null +++ b/test/bashisms/tilde-expansion.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +echo tilde alone: ~/ +echo tilde with name: ~root/ + +cd ; cd - >/dev/null + +echo BASHISM: tilde plus: ~+ +echo BASHISM: tilde minus: ~- + +pushd ~ >/dev/null 2>&1 # BASHISM +for i in $(seq 1 9); do + pushd / >/dev/null 2>&1 # BASHISM +done + +echo BASHISM: tilde plus n: ~+1 +echo BASHISM: tilde implicit plus n: ~1 +echo BASHISM: tilde minus n: ~-1 + +echo BASHISM: tilde plus 10: ~+10 +echo BASHISM: tilde implicit plus 10: ~10 +echo BASHISM: tilde minus 10: ~-10 + +echo BASHISM=~-/bin +echo BASHISM=/:~+/bin/ +BASHISM=~-/bin ; echo $BASHISM +BASHISM=/:~+/bin/ ; echo $BASHISM + +echo nothing wrong here: ~+foo/ +echo nothing wrong here: ~-moo/ +echo nothing wrong here: ~+1foo/ +echo nothing wrong here: ~1foo/ +echo nothing wrong here: ~-1moo/ + +# Again, but without the slash +echo nothing wrong here: ~+foo +echo nothing wrong here: ~-moo +echo nothing wrong here: ~+1foo +echo nothing wrong here: ~1foo +echo nothing wrong here: ~-1moo + diff --git a/test/bashisms/tilde-expansion.sh.out b/test/bashisms/tilde-expansion.sh.out new file mode 100644 index 0000000..6ae792e --- /dev/null +++ b/test/bashisms/tilde-expansion.sh.out @@ -0,0 +1,28 @@ +possible bashism in bashisms/tilde-expansion.sh line 8 (non-standard tilde expansion): +echo BASHISM: tilde plus: ~+ +possible bashism in bashisms/tilde-expansion.sh line 9 (non-standard tilde expansion): +echo BASHISM: tilde minus: ~- +possible bashism in bashisms/tilde-expansion.sh line 11 ((push|pop)d): +pushd ~ >/dev/null 2>&1 # BASHISM +possible bashism in bashisms/tilde-expansion.sh line 13 ((push|pop)d): + pushd / >/dev/null 2>&1 # BASHISM +possible bashism in bashisms/tilde-expansion.sh line 16 (non-standard tilde expansion): +echo BASHISM: tilde plus n: ~+1 +possible bashism in bashisms/tilde-expansion.sh line 17 (non-standard tilde expansion): +echo BASHISM: tilde implicit plus n: ~1 +possible bashism in bashisms/tilde-expansion.sh line 18 (non-standard tilde expansion): +echo BASHISM: tilde minus n: ~-1 +possible bashism in bashisms/tilde-expansion.sh line 20 (non-standard tilde expansion): +echo BASHISM: tilde plus 10: ~+10 +possible bashism in bashisms/tilde-expansion.sh line 21 (non-standard tilde expansion): +echo BASHISM: tilde implicit plus 10: ~10 +possible bashism in bashisms/tilde-expansion.sh line 22 (non-standard tilde expansion): +echo BASHISM: tilde minus 10: ~-10 +possible bashism in bashisms/tilde-expansion.sh line 24 (non-standard tilde expansion): +echo BASHISM=~-/bin +possible bashism in bashisms/tilde-expansion.sh line 25 (non-standard tilde expansion): +echo BASHISM=/:~+/bin/ +possible bashism in bashisms/tilde-expansion.sh line 26 (non-standard tilde expansion): +BASHISM=~-/bin ; echo $BASHISM +possible bashism in bashisms/tilde-expansion.sh line 27 (non-standard tilde expansion): +BASHISM=/:~+/bin/ ; echo $BASHISM diff --git a/test/bashisms/traps.sh b/test/bashisms/traps.sh new file mode 100644 index 0000000..b357ce7 --- /dev/null +++ b/test/bashisms/traps.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +trap foo ERR # BASHISM +trap foo RETURN # BASHISM +trap foo DEBUG # BASHISM + +trap "echo BASHISM" ERR +trap "echo BASHISM" RETURN +trap "echo BASHISM" DEBUG + +foo() { + echo ": dummy function" +} + +trap $(foo BASHISM) ERR +trap "$(foo BASHISM)" RETURN +trap "echo $foo BASHISM" DEBUG diff --git a/test/bashisms/traps.sh.out b/test/bashisms/traps.sh.out new file mode 100644 index 0000000..300ad70 --- /dev/null +++ b/test/bashisms/traps.sh.out @@ -0,0 +1,18 @@ +possible bashism in bashisms/traps.sh line 3 (trap with ERR|DEBUG|RETURN): +trap foo ERR # BASHISM +possible bashism in bashisms/traps.sh line 4 (trap with ERR|DEBUG|RETURN): +trap foo RETURN # BASHISM +possible bashism in bashisms/traps.sh line 5 (trap with ERR|DEBUG|RETURN): +trap foo DEBUG # BASHISM +possible bashism in bashisms/traps.sh line 7 (trap with ERR|DEBUG|RETURN): +trap "echo BASHISM" ERR +possible bashism in bashisms/traps.sh line 8 (trap with ERR|DEBUG|RETURN): +trap "echo BASHISM" RETURN +possible bashism in bashisms/traps.sh line 9 (trap with ERR|DEBUG|RETURN): +trap "echo BASHISM" DEBUG +possible bashism in bashisms/traps.sh line 15 (trap with ERR|DEBUG|RETURN): +trap $(foo BASHISM) ERR +possible bashism in bashisms/traps.sh line 16 (trap with ERR|DEBUG|RETURN): +trap "$(foo BASHISM)" RETURN +possible bashism in bashisms/traps.sh line 17 (trap with ERR|DEBUG|RETURN): +trap "echo $foo BASHISM" DEBUG diff --git a/test/bashisms/underscore-var.sh b/test/bashisms/underscore-var.sh new file mode 100644 index 0000000..a4f2ea4 --- /dev/null +++ b/test/bashisms/underscore-var.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo BASHISM $_ diff --git a/test/bashisms/underscore-var.sh.out b/test/bashisms/underscore-var.sh.out new file mode 100644 index 0000000..dbfe699 --- /dev/null +++ b/test/bashisms/underscore-var.sh.out @@ -0,0 +1,2 @@ +possible bashism in bashisms/underscore-var.sh line 3 ($_): +echo BASHISM $_ diff --git a/test/bashisms/unknown-fns.sh b/test/bashisms/unknown-fns.sh new file mode 100644 index 0000000..64d1b46 --- /dev/null +++ b/test/bashisms/unknown-fns.sh @@ -0,0 +1,297 @@ +#!/bin/sh + +################################################################################ +# # +# Copyright (c) 2009 FUJITSU LIMITED # +# # +# This program is free software; you can redistribute it and#or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # +# for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Author: Miao Xie <miaox@cn.fujitsu.com> # +# # +################################################################################ + +cd $LTPROOT/testcases/bin + +. ./cpuset_funcs.sh + +export TCID="cpuset01" +export TST_TOTAL=97 +export TST_COUNT=1 + +nr_cpus=$NR_CPUS +nr_mems=$N_NODES + +cpus_all="$(seq -s, 0 $((nr_cpus-1)))" +mems_all="$(seq -s, 0 $((nr_mems-1)))" + +exit_status=0 + +cfile_name= + +# base_op_write_and_test <write_file_name> <write_string> <expect_string> +base_op_write_and_test() +{ + local write_file="$1" + local write_string="$2" + local expect_string="$3" + local write_result= + local ret=0 + + mkdir -p "$(dirname $write_file)" || { + tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)" + return 1 + } + [ "$write_string" = NULL ] && write_string=" " + + /bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr + ret=$? + write_result="$(cat "$write_file")" + + case "$expect_string" in + EMPTY) + test -z "$write_result" -a $ret = 0 + ret=$? + ;; + WRITE_ERROR) + ret=$((!$ret)) + ;; + *) + test "$expect_string" = "$write_result" -a $ret = 0 + ret=$? + ;; + esac + + if [ $ret -eq 0 ]; then + tst_resm TPASS "$cfile_name: Get the expected string" + else + tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\"" + fi + return $ret +} + +base_op_test() +{ + setup + if [ $? -ne 0 ]; then + exit_status=1 + else + base_op_write_and_test "$@" + if [ $? -ne 0 ]; then + exit_status=1 + fi + + cleanup + if [ $? -ne 0 ]; then + exit_status=1 + fi + fi + : $((TST_COUNT++)) #BASHISM +} + +test_cpus() +{ + cfile_name="cpus" + while read cpus result + do + base_op_test "$CPUSET/1/cpus" "$cpus" "$result" + done <<- EOF + NULL EMPTY + 0 0 + $nr_cpus WRITE_ERROR + $cpus_all 0-$((nr_cpus-1)) + ${cpus_all}$nr_cpus WRITE_ERROR + 0,0 0 + 0-0 0 + 0-$((nr_cpus-1)) 0-$((nr_cpus-1)) + -1 WRITE_ERROR + 0-$nr_cpus WRITE_ERROR + 0- WRITE_ERROR + 0--$((nr_cpus-1)) WRITE_ERROR + 0,1-$((nr_cpus-2)),$((nr_cpus-1)) 0-$((nr_cpus-1)) + 0,1-$((nr_cpus-2)), 0-$((nr_cpus-2)) + 0AAA WRITE_ERROR + AAA WRITE_ERROR + EOF + # while read cpus result +} + +test_mems() +{ + cfile_name="mems" + while read mems result + do + base_op_test "$CPUSET/1/mems" "$mems" "$result" + done <<- EOF + NULL EMPTY + 0 0 + $nr_mems WRITE_ERROR + $mems_all 0-$((nr_mems-1)) + ${mems_all}$nr_mems WRITE_ERROR + 0,0 0 + 0-0 0 + 0-$((nr_mems-1)) 0-$((nr_mems-1)) + -1 WRITE_ERROR + 0-$nr_mems WRITE_ERROR + 0- WRITE_ERROR + 0--$((nr_mems-1)) WRITE_ERROR + 0,1-$((nr_mems-2)),$((nr_mems-1)) 0-$((nr_mems-1)) + 0,1-$((nr_mems-2)), 0-$((nr_mems-2)) + 0AAA WRITE_ERROR + AAA WRITE_ERROR + EOF + # while read mems result +} + +test_flags() +{ + for filename in cpu_exclusive mem_exclusive mem_hardwall \ + memory_migrate memory_spread_page memory_spread_slab \ + sched_load_balance memory_pressure_enabled + do + cfile_name="$filename" + while read flags result + do + base_op_test "$CPUSET/$filename" "$flags" "$result" + done <<- EOF + NULL 0 + 0 0 + 1 1 + -1 WRITE_ERROR + A WRITE_ERROR + 2 1 + EOF + # while read flags, result + done # for filename in flagfiles +} + +test_domain() +{ + cfile_name="sched_relax_domain_level" + while read domain_level result + do + base_op_test "$CPUSET/sched_relax_domain_level" "$domain_level" "$result" + done <<- EOF + NULL 0 + 0 0 + 1 1 + 2 2 + 3 3 + 4 4 + 5 5 + 6 WRITE_ERROR + -1 -1 + -2 WRITE_ERROR + A WRITE_ERROR + EOF + # while read domain_level result +} + +# attach_task_test <cpus> <mems> <expect> +attach_task_test() +{ + local cpus=$1 + local mems=$2 + local expect=$3 + + local pid= + local ret= + + setup + if [ $? -ne 0 ]; then + exit_status=1 + cleanup + ((TST_COUNT++)) #BASHISM + return + fi + + # create sub cpuset + mkdir "$CPUSET/sub_cpuset" > /dev/null + if [ $? -ne 0 ]; then + exit_status=1 + cleanup + ((TST_COUNT++)) # BASHISM + return + fi + + if [ "$cpus" != "NULL" ]; then + echo $cpus > "$CPUSET/sub_cpuset/cpus" + fi + if [ "$mems" != "NULL" ]; then + echo $mems > "$CPUSET/sub_cpuset/mems" + fi + + cat /dev/zero > /dev/null & + pid=$! + + # attach task into the cpuset group + echo $pid > "$CPUSET/sub_cpuset/tasks" 2> /dev/null + if [ $? -eq $expect ]; then + tst_resm TPASS "Attaching Task Test successed!!" + else + tst_resm TFAIL "Attaching Task Test failed!! cpus - \"$cpus\", mems - \"$mems\", Expect - \"$expect\", Fact - \"$ret\". (0 - Attach Success, 1 - Attach Fail)" + exit_status=1 + fi + + /bin/kill $pid &> /dev/null # BASHISM + cleanup + if [ $? -ne 0 ]; then + exit_status=1 + fi + ((TST_COUNT++)) # BASHISM +} + + +test_attach_task() +{ + cfile_name="tasks" + while read cpus mems expect + do + attach_task_test "$cpus" "$mems" "$expect" + done <<- EOF + 0 NULL 1 + 0 0 0 + NULL 0 1 + EOF + # while read cpus mems expect +} + +test_readonly_cfiles() +{ + for filename in cpus mems memory_pressure + do + cfile_name="$filename(READONLY)" + base_op_test "$CPUSET/$filename" "0" "WRITE_ERROR" + done # for filename in readonly cfiles +} + +# Case 1-3 +test_readonly_cfiles + +# Case 4-19 +test_cpus + +# Case 20-35 +test_mems + +# Case 36-83 +test_flags + +# Case 84-94 +test_domain + +# Case 95-97 +test_attach_task + +exit $exit_status diff --git a/test/bashisms/unknown-fns.sh.out b/test/bashisms/unknown-fns.sh.out new file mode 100644 index 0000000..82f0896 --- /dev/null +++ b/test/bashisms/unknown-fns.sh.out @@ -0,0 +1,10 @@ +possible bashism in bashisms/unknown-fns.sh line 100 ('$((n++))' should be '$n; $((n=n+1))'): + : $((TST_COUNT++)) #BASHISM +possible bashism in bashisms/unknown-fns.sh line 215 ('((' should be '$(('): + ((TST_COUNT++)) #BASHISM +possible bashism in bashisms/unknown-fns.sh line 224 ('((' should be '$(('): + ((TST_COUNT++)) # BASHISM +possible bashism in bashisms/unknown-fns.sh line 247 (should be >word 2>&1): + /bin/kill $pid &> /dev/null # BASHISM +possible bashism in bashisms/unknown-fns.sh line 252 ('((' should be '$(('): + ((TST_COUNT++)) # BASHISM diff --git a/test/bashisms/unterminated-string.sh b/test/bashisms/unterminated-string.sh new file mode 100644 index 0000000..bde111e --- /dev/null +++ b/test/bashisms/unterminated-string.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CLEAN="'("'"c"'")'" +echo "foo +bar" diff --git a/test/bashisms/unterminated-string2.sh b/test/bashisms/unterminated-string2.sh new file mode 100644 index 0000000..35d41d2 --- /dev/null +++ b/test/bashisms/unterminated-string2.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CLEAN="("'"c"'")" +echo "foo +bar" |