add common.sh and test_common.sh

master
Артемий 3 years ago
parent 7badf08ce5
commit ce5c0c10d4

7
1

@ -0,0 +1,7 @@
#!/bin/bash
lol() {
echo "$@"
echo -----
echo "$*"
}
lol $(echo -e "1\n2\n3")

@ -8,13 +8,33 @@ INTERNAL_DIR="${DESTDIR}var/lib/linux-infosec-setupper"
AUDIT_RULES_FILE=${DESTDIR}etc/audit/rules.d/90-linux-infosec-setupper.rules
AUDIT_DAEMON_CONFIG=${DESTDIR}etc/audit/auditd.conf
_check_argument() {
case "$1" in
error() {
printf "$@" 1>&2
echo '' 1>&2
}
_check_argument_is_number() {
if [[ "$1" == [0-9]* ]]; then
return 0
else
printf $"Argument to %s must be a number" "$2"
error $"Argument to %s must be a number" "$2"
return 1
fi
}
_check_argument_value() {
if [[ "$1" < "$2" ]]; then
error $"Argument to %s must be greater than %s" "$2" "$3"
return 1
else
return 0
fi
}
_check_argument_is_string() {
if [[ "$1" == *[[:blank:]]* ]]; then
error $"Argument to %s must be a string without spaces" "$2"
return 1
else
return 0
fi
}

@ -0,0 +1,21 @@
#!/bin/bash
#set -x
TESTING=1
. ./common.sh
_check_argument_is_number 123 "this" || failed="$((++failed))"
_check_argument_is_number NotNumber "this" && failed="$((++failed))"
_check_argument_value 8 7 "this" || failed="$((++failed))"
_check_argument_value 1 7 "this" && failed="$((++failed))"
_check_argument_is_string "Hello" "this" || failed="$((++failed))"
_check_argument_is_string "Hello world" "this" && failed="$((++failed))"
failed="${failed:-0}"
echo "$failed"
exit "$failed"
Loading…
Cancel
Save