diff --git a/Makefile b/Makefile index adbab42..999982f 100755 --- a/Makefile +++ b/Makefile @@ -50,10 +50,10 @@ build: ./dist/hosts $(ALT_FORMATS_OUT) stats: ./dist/most_abused_tlds.txt ./dist/most_abused_suffixes.txt ./dist/most_abused_tlds.txt: ./dist/hosts_domains.txt - ./resources/stats/suffix.sh ./dist/hosts_domains.txt none > '$@' + ./resources/stats/stats.sh ./dist/hosts_domains.txt no-psl > '$@' ./dist/most_abused_suffixes.txt: ./dist/hosts_domains.txt - ./resources/stats/suffix.sh ./dist/hosts_domains.txt > '$@' + ./resources/stats/stats.sh ./dist/hosts_domains.txt > '$@' ################################################## ## "index" target @@ -63,7 +63,7 @@ stats: ./dist/most_abused_tlds.txt ./dist/most_abused_suffixes.txt index: ./dist/index.html ./dist/index.html: ./dist/hosts $(ALT_FORMATS_OUT) ./dist/most_abused_tlds.txt ./dist/most_abused_suffixes.txt - ./resources/templates/index.sh ./dist/ > '$@' + ./resources/index/index.sh ./dist/ > '$@' ################################################## ## "man" target @@ -93,7 +93,7 @@ lint: test: find ./resources/tests/ -type f -name 'test-*.sh' | sort -n | xargs -n1 env -i \ - PATH='/usr/sbin:/usr/bin:/sbin:/bin' TEST_SHELL='$(TEST_SHELL)' HBLOCK_SCRIPT='./hblock' + PATH='/usr/sbin:/usr/bin:/sbin:/bin' TEST_SHELL='$(TEST_SHELL)' ################################################## ## "install" target diff --git a/resources/templates/index.sh b/resources/index/index.sh similarity index 100% rename from resources/templates/index.sh rename to resources/index/index.sh diff --git a/resources/stats/stats.sh b/resources/stats/stats.sh index 9e8849c..18566da 100755 --- a/resources/stats/stats.sh +++ b/resources/stats/stats.sh @@ -73,7 +73,7 @@ main() { | sort | uniq -c > "${blocklistFile:?}.aux" \ && mv -f -- "${blocklistFile:?}.aux" "${blocklistFile:?}" - if [ "${publicSuffixList:?}" != 'none' ]; then + if [ "${publicSuffixList:?}" != 'no-psl' ]; then # Download public suffix list. fetchUrl "${publicSuffixList:?}" > "${blocklistFile:?}.suffixes" diff --git a/resources/tests/domains.txt b/resources/tests/domains.txt new file mode 100644 index 0000000..68f6b25 --- /dev/null +++ b/resources/tests/domains.txt @@ -0,0 +1,42 @@ +example-000.arpa +example-001.xn--od0alg.xn--j6w193g +example-002.net +example-003.jp +example-004.net +example-005.home.arpa +example-006.xn--j6w193g +example-007.arpa +example-008.xn--j6w193g +example-009.xn--od0alg.xn--j6w193g +example-010.xn--j6w193g +example-011.xn--j6w193g +example-012.jp +example-013.jp +example-014.com +example-015.unknown +example-016.home.arpa +example-017.org +example-018.xn--od0alg.xn--j6w193g +example-019.arpa +example-020.xn--1lqs71d.jp +example-021.org +example-022.xn--od0alg.xn--j6w193g +example-023.xn--j6w193g +example-024.com +example-025.com +example-026.arpa +example-027.xn--od0alg.xn--j6w193g +example-028.xn--1lqs71d.jp +example-029.home.arpa +example-030.xn--1lqs71d.jp +example-031.xn--od0alg.xn--j6w193g +example-032.jp +example-033.com +example-034.home.arpa +example-035.home.arpa +example-036.net +example-037.net +example-038.xn--1lqs71d.jp +example-039.org +example-040.xn--od0alg.xn--j6w193g +example-041.jp diff --git a/resources/tests/env.sh b/resources/tests/env.sh index ed2c5a0..47e4cba 100644 --- a/resources/tests/env.sh +++ b/resources/tests/env.sh @@ -9,6 +9,7 @@ export LC_ALL='C' SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" +# Set base environment. export HOSTNAME='hblock' export HBLOCK_OUTPUT_FILE='/dev/null' export HBLOCK_HEADER_FILE='builtin' @@ -18,8 +19,8 @@ export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt" export HBLOCK_ALLOWLIST_FILE='builtin' export HBLOCK_DENYLIST_FILE='builtin' -hBlockInTestShell() { - ${TEST_SHELL:-/bin/sh} -- "${HBLOCK_SCRIPT:-hblock}" "${@-}" 2>&1 ||: +runInTestShell() { + ${TEST_SHELL:-/bin/sh} -- "${@-}" 2>&1 ||: } assertEquals() { diff --git a/resources/tests/psl.txt b/resources/tests/psl.txt new file mode 100644 index 0000000..1dff9d1 --- /dev/null +++ b/resources/tests/psl.txt @@ -0,0 +1,15 @@ +// Public suffix list sample file + +com +info +org +net + +arpa +home.arpa + +jp +東京.jp + +香港 +網絡.香港 diff --git a/resources/tests/test-comment-opt.out b/resources/tests/test-main-comment-opt.out similarity index 100% rename from resources/tests/test-comment-opt.out rename to resources/tests/test-main-comment-opt.out diff --git a/resources/tests/test-comment-opt.sh b/resources/tests/test-main-comment-opt.sh similarity index 61% rename from resources/tests/test-comment-opt.sh rename to resources/tests/test-main-comment-opt.sh index efb495b..ff8e292 100755 --- a/resources/tests/test-comment-opt.sh +++ b/resources/tests/test-main-comment-opt.sh @@ -15,16 +15,16 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" main() { export HBLOCK_COMMENT='#' - printf 'Test: "-C" short option\n' - actual="$(hBlockInTestShell -qO- -C '# %')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-comment-opt.out)" + printf -- 'Test - Main: "-C" short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -C '# %')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi - printf 'Test: "--comment" long option\n' - actual="$(hBlockInTestShell -qO- --comment='# %')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-comment-opt.out)" + printf -- 'Test - Main: "--comment" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --comment='# %')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-default-opts.out b/resources/tests/test-main-default-opts.out similarity index 100% rename from resources/tests/test-default-opts.out rename to resources/tests/test-main-default-opts.out diff --git a/resources/tests/test-default-opts.sh b/resources/tests/test-main-default-opts.sh similarity index 74% rename from resources/tests/test-default-opts.sh rename to resources/tests/test-main-default-opts.sh index 8b7dcea..3359c44 100755 --- a/resources/tests/test-default-opts.sh +++ b/resources/tests/test-main-default-opts.sh @@ -13,9 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" . "${SCRIPT_DIR:?}"/env.sh main() { - printf 'Test: default options\n' - actual="$(hBlockInTestShell -qO-)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-default-opts.out)" + printf -- 'Test - Main: Default options\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-double-dash-arg.out b/resources/tests/test-main-double-dash-arg.out similarity index 100% rename from resources/tests/test-double-dash-arg.out rename to resources/tests/test-main-double-dash-arg.out diff --git a/resources/tests/test-invalid-short-opt.sh b/resources/tests/test-main-double-dash-arg.sh similarity index 72% rename from resources/tests/test-invalid-short-opt.sh rename to resources/tests/test-main-double-dash-arg.sh index 14cbf5d..db9a70a 100755 --- a/resources/tests/test-invalid-short-opt.sh +++ b/resources/tests/test-main-double-dash-arg.sh @@ -13,9 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" . "${SCRIPT_DIR:?}"/env.sh main() { - printf 'Test: invalid short option\n' - actual="$(hBlockInTestShell -qO- -i 'VALUE')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-invalid-short-opt.out)" + printf -- 'Test - Main: Double dash argument\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -- -v)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-invalid-long-opt.out b/resources/tests/test-main-invalid-long-opt.out similarity index 100% rename from resources/tests/test-invalid-long-opt.out rename to resources/tests/test-main-invalid-long-opt.out diff --git a/resources/tests/test-invalid-long-opt.sh b/resources/tests/test-main-invalid-long-opt.sh similarity index 71% rename from resources/tests/test-invalid-long-opt.sh rename to resources/tests/test-main-invalid-long-opt.sh index 2d1b145..a0413fe 100755 --- a/resources/tests/test-invalid-long-opt.sh +++ b/resources/tests/test-main-invalid-long-opt.sh @@ -13,9 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" . "${SCRIPT_DIR:?}"/env.sh main() { - printf 'Test: invalid long option\n' - actual="$(hBlockInTestShell -qO- --invalid='VALUE')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-invalid-long-opt.out)" + printf -- 'Test - Main: Invalid long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --invalid='VALUE')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-invalid-short-opt.out b/resources/tests/test-main-invalid-short-opt.out similarity index 100% rename from resources/tests/test-invalid-short-opt.out rename to resources/tests/test-main-invalid-short-opt.out diff --git a/resources/tests/test-double-dash-arg.sh b/resources/tests/test-main-invalid-short-opt.sh similarity index 72% rename from resources/tests/test-double-dash-arg.sh rename to resources/tests/test-main-invalid-short-opt.sh index d782f60..8196fec 100755 --- a/resources/tests/test-double-dash-arg.sh +++ b/resources/tests/test-main-invalid-short-opt.sh @@ -13,9 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" . "${SCRIPT_DIR:?}"/env.sh main() { - printf 'Test: double dash argument\n' - actual="$(hBlockInTestShell -qO- -- -v)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-double-dash-arg.out)" + printf -- 'Test - Main: Invalid short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -i 'VALUE')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-lenient-opt.out b/resources/tests/test-main-lenient-opt.out similarity index 100% rename from resources/tests/test-lenient-opt.out rename to resources/tests/test-main-lenient-opt.out diff --git a/resources/tests/test-lenient-opt.sh b/resources/tests/test-main-lenient-opt.sh similarity index 62% rename from resources/tests/test-lenient-opt.sh rename to resources/tests/test-main-lenient-opt.sh index 29446fa..3bebaf0 100755 --- a/resources/tests/test-lenient-opt.sh +++ b/resources/tests/test-main-lenient-opt.sh @@ -15,16 +15,16 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" main() { export HBLOCK_LENIENT='false' - printf 'Test: "-l" short option\n' - actual="$(hBlockInTestShell -qO- -l)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-lenient-opt.out)" + printf -- 'Test - Main: "-l" short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -l)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi - printf 'Test: "--lenient" long option\n' - actual="$(hBlockInTestShell -qO- --lenient)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-lenient-opt.out)" + printf -- 'Test - Main: "--lenient" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --lenient)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-no-lenient-opt.out b/resources/tests/test-main-no-lenient-opt.out similarity index 100% rename from resources/tests/test-no-lenient-opt.out rename to resources/tests/test-main-no-lenient-opt.out diff --git a/resources/tests/test-no-lenient-opt.sh b/resources/tests/test-main-no-lenient-opt.sh similarity index 72% rename from resources/tests/test-no-lenient-opt.sh rename to resources/tests/test-main-no-lenient-opt.sh index 3b18179..f63e24c 100755 --- a/resources/tests/test-no-lenient-opt.sh +++ b/resources/tests/test-main-no-lenient-opt.sh @@ -15,9 +15,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" main() { export HBLOCK_LENIENT='true' - printf 'Test: "--no-lenient" long option\n' - actual="$(hBlockInTestShell -qO- --no-lenient)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-no-lenient-opt.out)" + printf -- 'Test - Main: "--no-lenient" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --no-lenient)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-no-regex-opt.out b/resources/tests/test-main-no-regex-opt.out similarity index 100% rename from resources/tests/test-no-regex-opt.out rename to resources/tests/test-main-no-regex-opt.out diff --git a/resources/tests/test-no-regex-opt.sh b/resources/tests/test-main-no-regex-opt.sh similarity index 78% rename from resources/tests/test-no-regex-opt.sh rename to resources/tests/test-main-no-regex-opt.sh index 3bd127d..6edb76c 100755 --- a/resources/tests/test-no-regex-opt.sh +++ b/resources/tests/test-main-no-regex-opt.sh @@ -22,9 +22,9 @@ main() { EOF )" - printf 'Test: "--no-regex" long option\n' - actual="$(hBlockInTestShell -qO- --no-regex)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-no-regex-opt.out)" + printf -- 'Test - Main: "--no-regex" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --no-regex)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-redirection-opt.out b/resources/tests/test-main-redirection-opt.out similarity index 100% rename from resources/tests/test-redirection-opt.out rename to resources/tests/test-main-redirection-opt.out diff --git a/resources/tests/test-redirection-opt.sh b/resources/tests/test-main-redirection-opt.sh similarity index 61% rename from resources/tests/test-redirection-opt.sh rename to resources/tests/test-main-redirection-opt.sh index cc7ac4c..7246ddc 100755 --- a/resources/tests/test-redirection-opt.sh +++ b/resources/tests/test-main-redirection-opt.sh @@ -15,16 +15,16 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" main() { export HBLOCK_REDIRECTION='0.0.0.0' - printf 'Test: "-R" short option\n' - actual="$(hBlockInTestShell -qO- -R '::1')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-redirection-opt.out)" + printf -- 'Test - Main: "-R" short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -R '::1')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi - printf 'Test: "--redirection" long option\n' - actual="$(hBlockInTestShell -qO- --redirection='::1')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-redirection-opt.out)" + printf -- 'Test - Main: "--redirection" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --redirection='::1')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-regex-opt.out b/resources/tests/test-main-regex-opt.out similarity index 100% rename from resources/tests/test-regex-opt.out rename to resources/tests/test-main-regex-opt.out diff --git a/resources/tests/test-regex-opt.sh b/resources/tests/test-main-regex-opt.sh similarity index 67% rename from resources/tests/test-regex-opt.sh rename to resources/tests/test-main-regex-opt.sh index 2d832d8..f14869b 100755 --- a/resources/tests/test-regex-opt.sh +++ b/resources/tests/test-main-regex-opt.sh @@ -21,16 +21,16 @@ main() { EOF )" - printf 'Test: "-r" short option\n' - actual="$(hBlockInTestShell -qO- -r)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-regex-opt.out)" + printf -- 'Test - Main: "-r" short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -r)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi - printf 'Test: "--regex" long option\n' - actual="$(hBlockInTestShell -qO- --regex)" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-regex-opt.out)" + printf -- 'Test - Main: "--regex" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --regex)" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-template-opt.out b/resources/tests/test-main-template-opt.out similarity index 100% rename from resources/tests/test-template-opt.out rename to resources/tests/test-main-template-opt.out diff --git a/resources/tests/test-template-opt.sh b/resources/tests/test-main-template-opt.sh similarity index 59% rename from resources/tests/test-template-opt.sh rename to resources/tests/test-main-template-opt.sh index 5873fee..557aafb 100755 --- a/resources/tests/test-template-opt.sh +++ b/resources/tests/test-main-template-opt.sh @@ -15,16 +15,16 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" main() { export HBLOCK_TEMPLATE='%R %D' - printf 'Test: "-T" short option\n' - actual="$(hBlockInTestShell -qO- -T '%D\n\t└─ %R')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-template-opt.out)" + printf -- 'Test - Main: "-T" short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -T '%D\n\t└─ %R')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi - printf 'Test: "--template" long option\n' - actual="$(hBlockInTestShell -qO- --template='%D\n\t└─ %R')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-template-opt.out)" + printf -- 'Test - Main: "--template" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --template='%D\n\t└─ %R')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-wrap-opt.out b/resources/tests/test-main-wrap-opt.out similarity index 100% rename from resources/tests/test-wrap-opt.out rename to resources/tests/test-main-wrap-opt.out diff --git a/resources/tests/test-wrap-opt.sh b/resources/tests/test-main-wrap-opt.sh similarity index 61% rename from resources/tests/test-wrap-opt.sh rename to resources/tests/test-main-wrap-opt.sh index 611b38d..6b5b433 100755 --- a/resources/tests/test-wrap-opt.sh +++ b/resources/tests/test-main-wrap-opt.sh @@ -15,16 +15,16 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" main() { export HBLOCK_WRAP='1' - printf 'Test: "-W" short option\n' - actual="$(hBlockInTestShell -qO- -W '5')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-wrap-opt.out)" + printf -- 'Test - Main: "-W" short option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -W '5')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi - printf 'Test: "--wrap" long option\n' - actual="$(hBlockInTestShell -qO- --wrap='5')" - expected="$(cat -- "${SCRIPT_DIR:?}"/test-wrap-opt.out)" + printf -- 'Test - Main: "--wrap" long option\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --wrap='5')" + expected="$(cat -- "${0%.sh}".out)" if ! assertEquals "${actual?}" "${expected?}"; then exit 1 fi diff --git a/resources/tests/test-stats-suffixes.out b/resources/tests/test-stats-suffixes.out new file mode 100644 index 0000000..5ba45c2 --- /dev/null +++ b/resources/tests/test-stats-suffixes.out @@ -0,0 +1,11 @@ +Top Hosts Suffix +1 7 .xn--od0alg.xn--j6w193g +2 5 .home.arpa +3 5 .jp +4 5 .xn--j6w193g +5 4 .arpa +6 4 .com +7 4 .net +8 4 .xn--1lqs71d.jp +9 3 .org +10 1 .unknown diff --git a/resources/tests/test-stats-suffixes.sh b/resources/tests/test-stats-suffixes.sh new file mode 100755 index 0000000..16b5874 --- /dev/null +++ b/resources/tests/test-stats-suffixes.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Author: Héctor Molinero Fernández +# License: MIT, https://opensource.org/licenses/MIT +# Repository: https://github.com/hectorm/hblock + +set -eu +export LC_ALL='C' + +SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" + +# shellcheck disable=SC1090 +. "${SCRIPT_DIR:?}"/env.sh + +main() { + printf -- 'Test - Stats: Suffixes\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../stats/stats.sh" "${SCRIPT_DIR:?}/domains.txt" "file://${SCRIPT_DIR:?}/psl.txt")" + expected="$(cat -- "${0%.sh}".out)" + if ! assertEquals "${actual?}" "${expected?}"; then + exit 1 + fi +} + +main "${@-}" diff --git a/resources/tests/test-stats-tlds.out b/resources/tests/test-stats-tlds.out new file mode 100644 index 0000000..3207060 --- /dev/null +++ b/resources/tests/test-stats-tlds.out @@ -0,0 +1,8 @@ +Top Hosts Suffix +1 12 .xn--j6w193g +2 9 .arpa +3 9 .jp +4 4 .com +5 4 .net +6 3 .org +7 1 .unknown diff --git a/resources/tests/test-stats-tlds.sh b/resources/tests/test-stats-tlds.sh new file mode 100755 index 0000000..c0a7063 --- /dev/null +++ b/resources/tests/test-stats-tlds.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Author: Héctor Molinero Fernández +# License: MIT, https://opensource.org/licenses/MIT +# Repository: https://github.com/hectorm/hblock + +set -eu +export LC_ALL='C' + +SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)" + +# shellcheck disable=SC1090 +. "${SCRIPT_DIR:?}"/env.sh + +main() { + printf -- 'Test - Stats: TLDs\n' + actual="$(runInTestShell "${SCRIPT_DIR:?}/../stats/stats.sh" "${SCRIPT_DIR:?}/domains.txt" no-psl)" + expected="$(cat -- "${0%.sh}".out)" + if ! assertEquals "${actual?}" "${expected?}"; then + exit 1 + fi +} + +main "${@-}"