Commit b5848ae3 authored by Leo's avatar Leo

implement tests of braced-variable

parent 32eba273
......@@ -717,4 +717,114 @@ is_travis() {
[[ $status -eq 0 ]]
}
@test 'valid variable bracing with underscore' {
cat <<-"EOF" >$apkbuild
pkgname="${pypi_name}_alpine"
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'valid variable bracing with letter' {
cat <<-"EOF" >$apkbuild
pkgname="${pypi_name}Alpine"
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'valid variable bracing with number' {
cat <<-"EOF" >$apkbuild
pkgname="${pypi_name}0alpine"
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'valid variable bracing with capital letter' {
cat <<-"EOF" >$apkbuild
pkgname="${pypi_name}Alpine"
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'invalid variable bracing due to hyphen' {
cat <<-"EOF" >$apkbuild
pkgname="${pypi_name}-Alpine"
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "\[AL32\].*:.*unnecesary usage of braces"
}
@test 'invalid variable bracing due to end of line' {
cat <<-"EOF" >$apkbuild
pkgname=${pypi_name}
foo() {
local pkgname=${pypi_name}
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "\[AL32\].*:.*unnecesary usage of braces"
assert_match "${lines[1]}" "\[AL32\].*:.*unnecesary usage of braces"
}
@test 'invalid variable bracing due to double-quotes' {
cat <<-"EOF" >$apkbuild
pkgname="${pypi_name}"
foo() {
local pkgname="${pypi_name}"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "\[AL32\].*:.*unnecesary usage of braces"
assert_match "${lines[1]}" "\[AL32\].*:.*unnecesary usage of braces"
}
@test 'valid variable bracing with local keyword and underscore' {
cat <<-"EOF" >$apkbuild
foo() {
local pkgname="${pypi_name}_Alpine"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'valid variable bracing with local keyword and letter' {
cat <<-"EOF" >$apkbuild
foo() {
local _py3ver pkgname="${pypi_name}Alpine"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'invalid variable bracing within other variables in a local statement' {
cat <<-"EOF" >$apkbuild
foo() {
local _py3ver pkgname="${pypi_name}" _test
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" "\[AL32\].*:.*unnecesary usage of braces"
}
# assert_match "${lines[0]}" "\[AL32\].*:.*unnecesary usage of braces"
# vim: noexpandtab
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment