6
# Process substitution isn't POSIX compliant and cause trouble
8
# Command isn't included in the Ubuntu packages asdf depends on. Also not
11
# echo isn't consistent across operating systems, and sometimes output can
12
# be confused with echo flags. printf does everything echo does and more.
14
# It's best to avoid eval as it makes it easier to accidentally execute
17
# realpath not available by default on OSX.
19
# source isn't POSIX compliant. . behaves the same and is POSIX compliant
20
# Except in fish, where . is deprecated, and will be removed in the future.
22
# For consistency, [ should be used instead. There is a leading space so 'fail_test', etc. is not matched
26
banned_commands_regex=(
27
# grep -y does not work on alpine and should be "grep -i" either way
29
# grep -P is not a valid option in OSX.
31
# Ban grep long commands as they do not work on alpine
33
# readlink -f on OSX behaves differently from readlink -f on other Unix systems
34
'readlink.+-.*f.+["$]'
35
# sort --sort-version isn't supported everywhere
37
"sort.*--sort-versions"
39
# ls often gets used when we want to glob for files that match a pattern
40
# or when we want to find all files/directories that match a pattern or are
41
# found in a certain location. Using shell globs is preferred over ls, and
42
# find is better at locating files that are in a certain location or that
43
# match certain filename patterns.
44
# https://github-wiki-see.page/m/koalaman/shellcheck/wiki/SC2012
47
# Ban recursive asdf calls as they are inefficient and may introduce bugs.
48
# If you find yourself needing to invoke an `asdf` command from within
49
# asdf code, please source the appropriate file and invoke the
50
# corresponding function.
62
@test "banned commands are not found in source code" {
63
# Assert command is not used in the lib and bin dirs
64
# or expect an explicit comment at end of line, allowing it.
65
# Also ignore matches that are contained in comments or a string or
66
# followed by an underscore (indicating it's a variable and not a
68
for cmd in "${banned_commands[@]}"; do
69
run bash -c "grep -nHR --include \*.bash --include \*.sh '$cmd' asdf.* lib bin\
71
| grep -v '\".*$cmd.*\"' \
73
| grep -v '# asdf_allow: $cmd'"
75
# Only print output if we've found a banned command
76
#if [ "$status" -ne 1 ]; then
77
if [ "" != "$output" ]; then
78
echo "banned command $cmd: $output"
85
for cmd in "${banned_commands_regex[@]}"; do
86
run bash -c "grep -nHRE --include \*.bash --include \*.sh '$cmd' asdf.* lib bin\
88
| grep -v '\".*$cmd.*\"' \
90
| grep -v '# asdf_allow: $cmd'"
92
# Only print output if we've found a banned command
93
#if [ "$status" -ne 1 ]; then
94
if [ "" != "$output" ]; then
95
echo "banned command $cmd: $output"