Update banned_commands.bats

Update banned_commands.bats so commands in comments are ignored and output
is only printed when a banned command is found.
This commit is contained in:
Trevor Brown 2021-05-21 12:40:20 -04:00
parent f125741fb5
commit e121a93716

View File

@ -38,8 +38,18 @@ teardown() {
for cmd in "${banned_commands[@]}"; do
# Assert command is not used in the lib and bin dirs
# or expect an explicit comment at end of line, allowing it.
run bash -c "grep -nHR '$cmd' lib bin | grep -v '# asdf_allow: $cmd'"
echo "banned command $cmd: $output"
# Also ignore matches that are contained in comments or followed by an
# underscore (indicating it's a variable and not a command).
run bash -c "grep -nHR '$cmd' lib bin\
| grep -v '#.*$cmd'\
| grep -v '${cmd}_'\
| grep -v '# asdf_allow: $cmd'"
# Only print output if we've found a banned command
if [ "$status" -ne 1 ]; then
echo "banned command $cmd: $output"
fi
[ "$status" -eq 1 ]
[ "" == "$output" ]
done