mirror of
https://github.com/hectorm/hblock.git
synced 2026-04-21 22:46:32 +05:30
Updated tests
This commit is contained in:
parent
6389330808
commit
1d58f9b3ff
50 changed files with 865 additions and 167 deletions
2
resources/tests/allowlist.txt
Normal file
2
resources/tests/allowlist.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
single-entry-000.com
|
||||
entry-with-comment-000.com
|
||||
2
resources/tests/denylist.txt
Normal file
2
resources/tests/denylist.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
denied-entry-000.com
|
||||
denied-entry-001.com
|
||||
|
|
@ -12,7 +12,7 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
# Set base environment.
|
||||
export HOSTNAME='hblock'
|
||||
export ETCDIR="${SCRIPT_DIR:?}/etc"
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export XDG_CONFIG_HOME="${ETCDIR:?}"
|
||||
|
||||
runInTestShell() {
|
||||
${TEST_SHELL:-/bin/sh} -- "${@-}" 2>&1 ||:
|
||||
|
|
|
|||
2
resources/tests/footer.txt
Normal file
2
resources/tests/footer.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Footer line 1
|
||||
Footer line 2
|
||||
2
resources/tests/header.txt
Normal file
2
resources/tests/header.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Header line 1
|
||||
Header line 2
|
||||
|
|
@ -13,7 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
printf -- 'Test - Main: Double dash argument\n'
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
|
||||
printf -- 'Test - Main - Argument: Double dash argument\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -- -v)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
|
|
@ -13,7 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
printf -- 'Test - Main: Invalid long option\n'
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
|
||||
printf -- 'Test - Main - Argument: Invalid long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --invalid='VALUE')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
|
|
@ -13,7 +13,9 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
printf -- 'Test - Main: Invalid short option\n'
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
|
||||
printf -- 'Test - Main - Argument: Invalid short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -i 'VALUE')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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 - Main: Default options\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
1
resources/tests/test-main-feature-allowlist-invalid.out
Normal file
1
resources/tests/test-main-feature-allowlist-invalid.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ERROR] No such file: /hblock/invalid.txt
|
||||
32
resources/tests/test-main-feature-allowlist.out
Normal file
32
resources/tests/test-main-feature-allowlist.out
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 15
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
83
resources/tests/test-main-feature-allowlist.sh
Executable file
83
resources/tests/test-main-feature-allowlist.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_ALLOWLIST_FILE=''
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "-A" short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -A "${SCRIPT_DIR:?}/allowlist.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "--allowlist" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --allowlist="${SCRIPT_DIR:?}/allowlist.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "--allowlist" long option with "builtin" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --allowlist='builtin')"
|
||||
expected="$(cat -- "${0%.sh}"-builtin.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "--allowlist" long option with "none" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --allowlist='none')"
|
||||
expected="$(cat -- "${0%.sh}"-none.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "--allowlist" long option with "-" value\n'
|
||||
actual="$(cat -- "${SCRIPT_DIR:?}/allowlist.txt" | runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --allowlist='-')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "--allowlist" long option with a non-existent file\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --allowlist='/hblock/invalid.txt')"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "HBLOCK_ALLOWLIST_FILE" environment variable\n'
|
||||
actual="$(HBLOCK_ALLOWLIST_FILE="${SCRIPT_DIR:?}/allowlist.txt" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "HBLOCK_ALLOWLIST_FILE" environment variable with a non-existent file\n'
|
||||
actual="$(HBLOCK_ALLOWLIST_FILE='/hblock/invalid.txt' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Allowlist: "HBLOCK_ALLOWLIST" environment variable\n'
|
||||
actual="$(HBLOCK_ALLOWLIST="$(cat -- "${SCRIPT_DIR:?}/allowlist.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -13,21 +13,29 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_COMMENT='#'
|
||||
|
||||
printf -- 'Test - Main: "-C" short option\n'
|
||||
printf -- 'Test - Main - Comment: "-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 - Main: "--comment" long option\n'
|
||||
printf -- 'Test - Main - Comment: "--comment" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --comment='# %')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Comment: "HBLOCK_COMMENT" environment variable\n'
|
||||
actual="$(HBLOCK_COMMENT='# %' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
34
resources/tests/test-main-feature-denylist-builtin.out
Normal file
34
resources/tests/test-main-feature-denylist-builtin.out
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
1
resources/tests/test-main-feature-denylist-invalid.out
Normal file
1
resources/tests/test-main-feature-denylist-invalid.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ERROR] No such file: /hblock/invalid.txt
|
||||
33
resources/tests/test-main-feature-denylist-none.out
Normal file
33
resources/tests/test-main-feature-denylist-none.out
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 16
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
35
resources/tests/test-main-feature-denylist.out
Normal file
35
resources/tests/test-main-feature-denylist.out
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 18
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 denied-entry-000.com
|
||||
0.0.0.0 denied-entry-001.com
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
83
resources/tests/test-main-feature-denylist.sh
Executable file
83
resources/tests/test-main-feature-denylist.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_DENYLIST_FILE=''
|
||||
|
||||
printf -- 'Test - Main - Denylist: "-D" short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -D "${SCRIPT_DIR:?}/denylist.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "--denylist" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --denylist="${SCRIPT_DIR:?}/denylist.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "--denylist" long option with "builtin" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --denylist='builtin')"
|
||||
expected="$(cat -- "${0%.sh}"-builtin.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "--denylist" long option with "none" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --denylist='none')"
|
||||
expected="$(cat -- "${0%.sh}"-none.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "--denylist" long option with "-" value\n'
|
||||
actual="$(cat -- "${SCRIPT_DIR:?}/denylist.txt" | runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --denylist='-')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "--denylist" long option with a non-existent file\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --denylist='/hblock/invalid.txt')"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "HBLOCK_DENYLIST_FILE" environment variable\n'
|
||||
actual="$(HBLOCK_DENYLIST_FILE="${SCRIPT_DIR:?}/denylist.txt" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "HBLOCK_DENYLIST_FILE" environment variable with a non-existent file\n'
|
||||
actual="$(HBLOCK_DENYLIST_FILE='/hblock/invalid.txt' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Denylist: "HBLOCK_DENYLIST" environment variable\n'
|
||||
actual="$(HBLOCK_DENYLIST="$(cat -- "${SCRIPT_DIR:?}/denylist.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
34
resources/tests/test-main-feature-footer-builtin.out
Normal file
34
resources/tests/test-main-feature-footer-builtin.out
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
1
resources/tests/test-main-feature-footer-invalid.out
Normal file
1
resources/tests/test-main-feature-footer-invalid.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ERROR] No such file: /hblock/invalid.txt
|
||||
34
resources/tests/test-main-feature-footer-none.out
Normal file
34
resources/tests/test-main-feature-footer-none.out
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
39
resources/tests/test-main-feature-footer.out
Normal file
39
resources/tests/test-main-feature-footer.out
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
|
||||
# BEGIN FOOTER
|
||||
Footer line 1
|
||||
Footer line 2
|
||||
# END FOOTER
|
||||
83
resources/tests/test-main-feature-footer.sh
Executable file
83
resources/tests/test-main-feature-footer.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_FOOTER_FILE=''
|
||||
|
||||
printf -- 'Test - Main - Footer: "-F" short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -F "${SCRIPT_DIR:?}/footer.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "--footer" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --footer="${SCRIPT_DIR:?}/footer.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "--footer" long option with "builtin" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --footer='builtin')"
|
||||
expected="$(cat -- "${0%.sh}"-builtin.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "--footer" long option with "none" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --footer='none')"
|
||||
expected="$(cat -- "${0%.sh}"-none.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "--footer" long option with "-" value\n'
|
||||
actual="$(cat -- "${SCRIPT_DIR:?}/footer.txt" | runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --footer='-')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "--footer" long option with a non-existent file\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --footer='/hblock/invalid.txt')"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "HBLOCK_FOOTER_FILE" environment variable\n'
|
||||
actual="$(HBLOCK_FOOTER_FILE="${SCRIPT_DIR:?}/footer.txt" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "HBLOCK_FOOTER_FILE" environment variable with a non-existent file\n'
|
||||
actual="$(HBLOCK_FOOTER_FILE='/hblock/invalid.txt' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Footer: "HBLOCK_FOOTER" environment variable\n'
|
||||
actual="$(HBLOCK_FOOTER="$(cat -- "${SCRIPT_DIR:?}/footer.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
34
resources/tests/test-main-feature-header-builtin.out
Normal file
34
resources/tests/test-main-feature-header-builtin.out
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
1
resources/tests/test-main-feature-header-invalid.out
Normal file
1
resources/tests/test-main-feature-header-invalid.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ERROR] No such file: /hblock/invalid.txt
|
||||
22
resources/tests/test-main-feature-header-none.out
Normal file
22
resources/tests/test-main-feature-header-none.out
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
27
resources/tests/test-main-feature-header.out
Normal file
27
resources/tests/test-main-feature-header.out
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
Header line 1
|
||||
Header line 2
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
83
resources/tests/test-main-feature-header.sh
Executable file
83
resources/tests/test-main-feature-header.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_HEADER_FILE=''
|
||||
|
||||
printf -- 'Test - Main - Header: "-H" short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -H "${SCRIPT_DIR:?}/header.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "--header" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --header="${SCRIPT_DIR:?}/header.txt")"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "--header" long option with "builtin" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --header='builtin')"
|
||||
expected="$(cat -- "${0%.sh}"-builtin.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "--header" long option with "none" value\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --header='none')"
|
||||
expected="$(cat -- "${0%.sh}"-none.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "--header" long option with "-" value\n'
|
||||
actual="$(cat -- "${SCRIPT_DIR:?}/header.txt" | runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --header='-')"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "--header" long option with a non-existent file\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --header='/hblock/invalid.txt')"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "HBLOCK_HEADER_FILE" environment variable\n'
|
||||
actual="$(HBLOCK_HEADER_FILE="${SCRIPT_DIR:?}/header.txt" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "HBLOCK_HEADER_FILE" environment variable with a non-existent file\n'
|
||||
actual="$(HBLOCK_HEADER_FILE='/hblock/invalid.txt' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}"-invalid.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Header: "HBLOCK_HEADER" environment variable\n'
|
||||
actual="$(HBLOCK_HEADER="$(cat -- "${SCRIPT_DIR:?}/header.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
34
resources/tests/test-main-feature-lenient-false.out
Normal file
34
resources/tests/test-main-feature-lenient-false.out
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Generated with: https://github.com/hectorm/hblock
|
||||
# Blocked domains: 17
|
||||
|
||||
# BEGIN HEADER
|
||||
127.0.0.1 localhost hblock
|
||||
255.255.255.255 broadcasthost
|
||||
::1 localhost hblock
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
# END HEADER
|
||||
|
||||
# BEGIN BLOCKLIST
|
||||
0.0.0.0 entry-with-comment-000.com
|
||||
0.0.0.0 entry-with-comment-001.com
|
||||
0.0.0.0 entry-with-comment-002.com
|
||||
0.0.0.0 entry-with-comment-003.com
|
||||
0.0.0.0 entry-with-comment-004.com
|
||||
0.0.0.0 entry-with-prefix-000.com
|
||||
0.0.0.0 entry-with-prefix-001.com
|
||||
0.0.0.0 entry-with-prefix-002.com
|
||||
0.0.0.0 entry-with-prefix-003.com
|
||||
0.0.0.0 entry-with-prefix-004.com
|
||||
0.0.0.0 entry-with-prefix-005.com
|
||||
0.0.0.0 entry-with-prefix-006.com
|
||||
0.0.0.0 hblock-check.molinero.dev
|
||||
0.0.0.0 single-entry-000.com
|
||||
0.0.0.0 single-entry-001.com
|
||||
0.0.0.0 single-entry-002.com
|
||||
0.0.0.0 single-entry-003.com
|
||||
# END BLOCKLIST
|
||||
50
resources/tests/test-main-feature-lenient.sh
Executable file
50
resources/tests/test-main-feature-lenient.sh
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_LENIENT='false'
|
||||
|
||||
printf -- 'Test - Main - Lenient: "-l" short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -l)"
|
||||
expected="$(cat -- "${0%.sh}"-true.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Lenient: "--lenient" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --lenient)"
|
||||
expected="$(cat -- "${0%.sh}"-true.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Lenient: "HBLOCK_LENIENT" environment variable\n'
|
||||
actual="$(HBLOCK_LENIENT='true' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}"-true.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export HBLOCK_LENIENT='true'
|
||||
|
||||
printf -- 'Test - Main - Lenient: "--no-lenient" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --no-lenient)"
|
||||
expected="$(cat -- "${0%.sh}"-false.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -13,21 +13,29 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_REDIRECTION='0.0.0.0'
|
||||
|
||||
printf -- 'Test - Main: "-R" short option\n'
|
||||
printf -- 'Test - Main - Redirection: "-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 - Main: "--redirection" long option\n'
|
||||
printf -- 'Test - Main - Redirection: "--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
|
||||
|
||||
printf -- 'Test - Main - Redirection: "HBLOCK_REDIRECTION" environment variable\n'
|
||||
actual="$(HBLOCK_REDIRECTION='::1' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
63
resources/tests/test-main-feature-regex.sh
Executable file
63
resources/tests/test-main-feature-regex.sh
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_REGEX='false'
|
||||
# shellcheck disable=SC2155
|
||||
export HBLOCK_ALLOWLIST="$(cat <<-'EOF'
|
||||
.*-00[0-3]\.com$
|
||||
^entry-with-comment-
|
||||
EOF
|
||||
)"
|
||||
|
||||
printf -- 'Test - Main - Regex: "-r" short option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -r)"
|
||||
expected="$(cat -- "${0%.sh}"-true.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Regex: "--regex" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --regex)"
|
||||
expected="$(cat -- "${0%.sh}"-true.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf -- 'Test - Main - Regex: "HBLOCK_REGEX" environment variable\n'
|
||||
actual="$(HBLOCK_REGEX='true' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}"-true.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export HBLOCK_REGEX='true'
|
||||
# shellcheck disable=SC2155
|
||||
export HBLOCK_ALLOWLIST="$(cat <<-'EOF'
|
||||
.*-00[0-3]\.com$
|
||||
^entry-with-comment-
|
||||
single-entry-000.com
|
||||
EOF
|
||||
)"
|
||||
|
||||
printf -- 'Test - Main - Regex: "--no-regex" long option\n'
|
||||
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --no-regex)"
|
||||
expected="$(cat -- "${0%.sh}"-false.out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -13,21 +13,29 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_TEMPLATE='%R %D'
|
||||
|
||||
printf -- 'Test - Main: "-T" short option\n'
|
||||
printf -- 'Test - Main - Template: "-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 - Main: "--template" long option\n'
|
||||
printf -- 'Test - Main - Template: "--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
|
||||
|
||||
printf -- 'Test - Main - Template: "HBLOCK_TEMPLATE" environment variable\n'
|
||||
actual="$(HBLOCK_TEMPLATE='%D\n\t└─ %R' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -13,21 +13,29 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
. "${SCRIPT_DIR:?}"/env.sh
|
||||
|
||||
main() {
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_WRAP='1'
|
||||
|
||||
printf -- 'Test - Main: "-W" short option\n'
|
||||
printf -- 'Test - Main - Wrap: "-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 - Main: "--wrap" long option\n'
|
||||
printf -- 'Test - Main - Wrap: "--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
|
||||
|
||||
printf -- 'Test - Main - Wrap: "HBLOCK_WRAP" environment variable\n'
|
||||
actual="$(HBLOCK_WRAP='5' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
|
||||
expected="$(cat -- "${0%.sh}".out)"
|
||||
if ! assertEquals "${actual?}" "${expected?}"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_LENIENT='false'
|
||||
|
||||
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 - 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
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_LENIENT='true'
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_REGEX='true'
|
||||
# shellcheck disable=SC2155
|
||||
export HBLOCK_ALLOWLIST="$(cat <<-'EOF'
|
||||
.*-00[0-3]\.com$
|
||||
^entry-with-comment-
|
||||
single-entry-000.com
|
||||
EOF
|
||||
)"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Author: Héctor Molinero Fernández <hector@molinero.dev>
|
||||
# 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() {
|
||||
export HBLOCK_REGEX='false'
|
||||
# shellcheck disable=SC2155
|
||||
export HBLOCK_ALLOWLIST="$(cat <<-'EOF'
|
||||
.*-00[0-3]\.com$
|
||||
^entry-with-comment-
|
||||
EOF
|
||||
)"
|
||||
|
||||
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 - 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
|
||||
}
|
||||
|
||||
main "${@-}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue