Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jarelllama authored Apr 1, 2024
1 parent c551e1b commit d18100c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
1 change: 0 additions & 1 deletion functions/build_lists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ EOF

# The 'build_<format>'' functions are to specify the syntax of the various
# list formats to be used by the 'build' function.
# Input:
# $syntax: name of list syntax
# $directory: directory to create list in
# $comment: character used for comments (defaults is '#')
Expand Down
39 changes: 30 additions & 9 deletions functions/test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,12 @@ SHELLCHECK() {

printf "\n[info] Scripts checked (%s):\n%s\n" "$(wc -l <<< "$scripts")" "$scripts"

# Exit with error if test failed
if [[ "$error" == true ]]; then
printf "\n"
exit 1
fi
check_and_exit --no-log
}

# Function 'TEST_RETRIEVE_VALIDATE' can test both the retrieval process and the
# validation process depending on which argument is passed to the function.
# $1: script to test, can either be 'retrieve' or 'validate'
# $1: script to test, can either be 'retrieve' or 'validate'
TEST_RETRIEVE_VALIDATE() {
script_to_test="$1"

Expand Down Expand Up @@ -196,7 +192,7 @@ TEST_DEAD_CHECK() {
check_and_exit
}

function TEST_PARKED_CHECK {
TEST_PARKED_CHECK() {
# Placeholders used as sample data
# (split does not work well without enough records)
not_parked_placeholder=$(head -n 50 "$TOPLIST")
Expand All @@ -215,7 +211,7 @@ function TEST_PARKED_CHECK {
# (Unparked domains are not added back to light)
grep -vxF 'google.com' out_raw.txt > out_raw_light.txt

run_script "check_parked.sh"
run_script check_parked.sh

# Remove placeholder lines
comm -23 "$RAW" placeholders.txt > raw.tmp
Expand All @@ -237,6 +233,31 @@ function TEST_PARKED_CHECK {
check_and_exit
}

test_build() {
domain='build-test.com'
printf "%s\n" "$domain" >> "$RAW"
cp "$RAW" "$RAW_LIGHT"
run_script build_list.sh
check_list "||${domain}^" adblock
check_list "local=/${domain}/" dnsmasq
check_list "local-zone: \"${domain}.\" always_nxdomain" unbound
check_list "*.${domain}" wildcard_asterisk
check_list "${domain}" wildcard

check_and_exit --no-log
}

# Function 'check_list' verifies the syntax of the list format.
# $1: syntax to check for
# $2 name of format
check_list() {
if grep -qxF "$1" "lists/${2}/scams.txt"; then
printf "\e[1m[warn] %s format is not as expected:\e[0m\n" "$2"
grep -F 'build-test.com' "lists/$2"
error=true
fi
}

# The 'test_<function>' scripts are to test individual functions
# within scripts. The input.txt file is to be processed by the called script.
# The out_<name>.txt file is the expected raw file after processing
Expand Down Expand Up @@ -569,7 +590,7 @@ check_and_exit() {
# No need for additional new line since log is not printed again
error=true
else
printf "Log:\n%s\n" "$(<$DOMAIN_LOG)"
[[ "$1" != '--no-log' ]] && printf "Log:\n%s\n" "$(<$DOMAIN_LOG)"
fi

# Exit with error if test failed
Expand Down

0 comments on commit d18100c

Please sign in to comment.