Removed double dash from "printf".

It's not necessary and the Toybox implementation interprets it literally.
This commit is contained in:
Héctor Molinero Fernández 2021-02-28 16:27:42 +01:00
commit e34217ee24
26 changed files with 108 additions and 108 deletions

48
hblock
View file

@ -136,13 +136,13 @@ optArgBool() {
else optArg='false'; fi
}
optDie() {
printf -- '%s\n' "${@-}" "Try 'hblock --help' for more information" >&2
printf '%s\n' "${@-}" "Try 'hblock --help' for more information" >&2
exit 2
}
# Show help and quit.
showHelp() {
printf -- '%s\n' "$(sed -e 's/%NL/\n/g' <<-EOF
printf '%s\n' "$(sed -e 's/%NL/\n/g' <<-EOF
Usage: hblock [OPTION]...
hBlock is a POSIX-compliant shell script that gets a list of domains that serve
@ -248,7 +248,7 @@ showHelp() {
# Show version number and quit.
showVersion() {
getMetadata() { sed -ne 's|^# '"${1:?}"':[[:blank:]]*\(.\{1,\}\)$|\1|p' -- "${0:?}"; }
printf -- '%s\n' "$(cat <<-EOF
printf '%s\n' "$(cat <<-EOF
hBlock $(getMetadata 'Version')
Author: $(getMetadata 'Author')
License: $(getMetadata 'License')
@ -269,22 +269,22 @@ exists() {
# Pretty print methods.
printInfo() {
if [ "${quiet-}" != 'true' ]; then
if [ "${color-}" != 'true' ]; then printf -- '[INFO] %s\n' "${@-}"
else printf -- '\033[0m[\033[1;32mINFO\033[0m] %s\n' "${@-}"; fi
if [ "${color-}" != 'true' ]; then printf '[INFO] %s\n' "${@-}"
else printf '\033[0m[\033[1;32mINFO\033[0m] %s\n' "${@-}"; fi
fi
}
printWarn() {
if [ "${color-}" != 'true' ]; then printf -- '[WARN] %s\n' "${@-}" >&2
else printf -- '\033[0m[\033[1;33mWARN\033[0m] %s\n' "${@-}" >&2; fi
if [ "${color-}" != 'true' ]; then printf '[WARN] %s\n' "${@-}" >&2
else printf '\033[0m[\033[1;33mWARN\033[0m] %s\n' "${@-}" >&2; fi
}
printError() {
if [ "${color-}" != 'true' ]; then printf -- '[ERROR] %s\n' "${@-}" >&2
else printf -- '\033[0m[\033[1;31mERROR\033[0m] %s\n' "${@-}" >&2; fi
if [ "${color-}" != 'true' ]; then printf '[ERROR] %s\n' "${@-}" >&2
else printf '\033[0m[\033[1;31mERROR\033[0m] %s\n' "${@-}" >&2; fi
}
printList() {
if [ "${quiet-}" != 'true' ]; then
if [ "${color-}" != 'true' ]; then printf -- ' * %s\n' "${@-}"
else printf -- '\033[0m \033[1;36m*\033[0m %s\n' "${@-}"; fi
if [ "${color-}" != 'true' ]; then printf ' * %s\n' "${@-}"
else printf '\033[0m \033[1;36m*\033[0m %s\n' "${@-}"; fi
fi
}
@ -297,7 +297,7 @@ rand() {
mktempFile() {
# POSIX does not specify the mktemp utility, so here comes a hacky solution.
while file="${TMPDIR:-${TMP:-/tmp}}/hblock.${$}.$(rand)" && [ -e "${file:?}" ]; do sleep 1; done
(umask 077 && touch -- "${file:?}"); printf -- '%s' "${file:?}"
(umask 077 && touch -- "${file:?}"); printf '%s' "${file:?}"
}
# Write stdin to a file.
@ -461,7 +461,7 @@ main() {
# Parse command line options.
# shellcheck disable=SC2086
{ optParse "${@-}"; set -- ${posArgs-}; }
{ optParse "${@-}"; set -- ${posArgs-} >/dev/null; }
if [ "${color:?}" = 'auto' ]; then
# Check color support, but honor ${NO_COLOR} variable (https://no-color.org).
@ -479,7 +479,7 @@ main() {
# If the file value equals "none", use an empty file.
'none') headerFile="$(mktempFile)"; true > "${headerFile:?}" ;;
# If the file value equals "builtin", use the built-in value.
'builtin') headerFile="$(mktempFile)"; printf -- '%s' "${HBLOCK_HEADER_BUILTIN?}" > "${headerFile:?}" ;;
'builtin') headerFile="$(mktempFile)"; printf '%s' "${HBLOCK_HEADER_BUILTIN?}" > "${headerFile:?}" ;;
# If the file does not exist, throw an error.
*) [ -e "${headerFile:?}" ] || { printError "No such file: ${headerFile:?}"; exit 1; } ;;
esac
@ -491,7 +491,7 @@ main() {
# If the file value equals "none", use an empty file.
'none') footerFile="$(mktempFile)"; true > "${footerFile:?}" ;;
# If the file value equals "builtin", use the built-in value.
'builtin') footerFile="$(mktempFile)"; printf -- '%s' "${HBLOCK_FOOTER_BUILTIN?}" > "${footerFile:?}" ;;
'builtin') footerFile="$(mktempFile)"; printf '%s' "${HBLOCK_FOOTER_BUILTIN?}" > "${footerFile:?}" ;;
# If the file does not exist, throw an error.
*) [ -e "${footerFile:?}" ] || { printError "No such file: ${footerFile:?}"; exit 1; } ;;
esac
@ -503,7 +503,7 @@ main() {
# If the file value equals "none", use an empty file.
'none') sourcesFile="$(mktempFile)"; true > "${sourcesFile:?}" ;;
# If the file value equals "builtin", use the built-in value.
'builtin') sourcesFile="$(mktempFile)"; printf -- '%s' "${HBLOCK_SOURCES_BUILTIN?}" > "${sourcesFile:?}" ;;
'builtin') sourcesFile="$(mktempFile)"; printf '%s' "${HBLOCK_SOURCES_BUILTIN?}" > "${sourcesFile:?}" ;;
# If the file does not exist, throw an error.
*) [ -e "${sourcesFile:?}" ] || { printError "No such file: ${sourcesFile:?}"; exit 1; } ;;
esac
@ -515,7 +515,7 @@ main() {
# If the file value equals "none", use an empty file.
'none') allowlistFile="$(mktempFile)"; true > "${allowlistFile:?}" ;;
# If the file value equals "builtin", use the built-in value.
'builtin') allowlistFile="$(mktempFile)"; printf -- '%s' "${HBLOCK_ALLOWLIST_BUILTIN?}" > "${allowlistFile:?}" ;;
'builtin') allowlistFile="$(mktempFile)"; printf '%s' "${HBLOCK_ALLOWLIST_BUILTIN?}" > "${allowlistFile:?}" ;;
# If the file does not exist, throw an error.
*) [ -e "${allowlistFile:?}" ] || { printError "No such file: ${allowlistFile:?}"; exit 1; } ;;
esac
@ -527,7 +527,7 @@ main() {
# If the file value equals "none", use an empty file.
'none') denylistFile="$(mktempFile)"; true > "${denylistFile:?}" ;;
# If the file value equals "builtin", use the built-in value.
'builtin') denylistFile="$(mktempFile)"; printf -- '%s' "${HBLOCK_DENYLIST_BUILTIN?}" > "${denylistFile:?}" ;;
'builtin') denylistFile="$(mktempFile)"; printf '%s' "${HBLOCK_DENYLIST_BUILTIN?}" > "${denylistFile:?}" ;;
# If the file does not exist, throw an error.
*) [ -e "${denylistFile:?}" ] || { printError "No such file: ${denylistFile:?}"; exit 1; } ;;
esac
@ -658,23 +658,23 @@ main() {
# If the header file is not empty, it is appended to the output file.
if [ -s "${headerFile:?}" ]; then
[ -z "${C?}" ] || printf -- '\n%s\n' "${C?} BEGIN HEADER"
[ -z "${C?}" ] || printf '\n%s\n' "${C?} BEGIN HEADER"
awk 1 < "${headerFile:?}"
[ -z "${C?}" ] || printf -- '%s\n' "${C?} END HEADER"
[ -z "${C?}" ] || printf '%s\n' "${C?} END HEADER"
fi
# If the blocklist file is not empty, it is appended to the output file.
if [ -s "${blocklistFile:?}" ]; then
[ -z "${C?}" ] || printf -- '\n%s\n' "${C?} BEGIN BLOCKLIST"
[ -z "${C?}" ] || printf '\n%s\n' "${C?} BEGIN BLOCKLIST"
awk 1 < "${blocklistFile:?}"
[ -z "${C?}" ] || printf -- '%s\n' "${C?} END BLOCKLIST"
[ -z "${C?}" ] || printf '%s\n' "${C?} END BLOCKLIST"
fi
# If the footer file is not empty, it is appended to the output file.
if [ -s "${footerFile:?}" ]; then
[ -z "${C?}" ] || printf -- '\n%s\n' "${C?} BEGIN FOOTER"
[ -z "${C?}" ] || printf '\n%s\n' "${C?} BEGIN FOOTER"
awk 1 < "${footerFile:?}"
[ -z "${C?}" ] || printf -- '%s\n' "${C?} END FOOTER"
[ -z "${C?}" ] || printf '%s\n' "${C?} END FOOTER"
fi
}

View file

@ -43,7 +43,7 @@ sha256Checksum() {
# Escape string for use in HTML.
escapeHTML() {
printf -- '%s' "${1?}" | awk -v RS='' "$(cat <<-'EOF'
printf '%s' "${1?}" | awk -v RS='' "$(cat <<-'EOF'
{
gsub(/&/, "\\&#38;")
gsub(/</, "\\&#60;")
@ -60,7 +60,7 @@ escapeHTML() {
# RFC 3986 compliant URL encoding method.
encodeURI() {
_LC_COLLATE="${LC_COLLATE-}"; LC_COLLATE='C'
hex="$(printf -- '%s' "${1?}" | base16Encode | sed 's|\(.\{2\}\)|\1 |g')"
hex="$(printf '%s' "${1?}" | base16Encode | sed 's|\(.\{2\}\)|\1 |g')"
for h in ${hex?}; do
case "${h:?}" in
3[0-9]|\
@ -76,7 +76,7 @@ encodeURI() {
# Calculate digest for Content-Security-Policy.
cspDigest() {
hex="$(printf -- '%s' "${1?}" | sha256Checksum | sed 's|\(.\{2\}\)|\1 |g')"
hex="$(printf '%s' "${1?}" | sha256Checksum | sed 's|\(.\{2\}\)|\1 |g')"
b64="$(for h in ${hex?}; do printf '%b' '\0'"$(printf '%o' "0x${h:?}")"; done | base64Encode)"
printf 'sha256-%s' "${b64?}"
}
@ -114,7 +114,7 @@ main() {
directory="${1:-./}"
if [ ! -d "${directory:?}" ] || [ ! -r "${directory:?}" ]; then
printf -- '%s\n' "Cannot read directory: '${directory:?}'" >&2
printf '%s\n' "Cannot read directory: '${directory:?}'" >&2
exit 1
fi
@ -136,7 +136,7 @@ main() {
fileDate="$(getFileModificationTime "${file:?}")"
escapedFileDate="$(escapeHTML "${fileDate:?}")"
printf -- '%s\n' "$(cat <<-EOF
printf '%s\n' "$(cat <<-EOF
<a class="row" href="./${escapedFileNameURI:?}" title="${escapedFileName:?}">
<div class="cell">${escapedFileName:?}</div>
<div class="cell">${escapedFileSize:?}</div>
@ -345,7 +345,7 @@ main() {
)"
# HTML.
printf -- '%s\n' "$(tr -d '\n' <<-EOF
printf '%s\n' "$(tr -d '\n' <<-EOF
<!DOCTYPE html>
<html lang="en">

View file

@ -1,6 +1,6 @@
# Maintainer: Héctor Molinero Fernández <hector@molinero.dev>
pkgname='hblock'
pkgver='m4_esyscmd(printf -- '%s' "${PKG_VERSION?}")'
pkgver='m4_esyscmd(printf '%s' "${PKG_VERSION?}")'
pkgrel='0'
pkgdesc='Adblocker that creates a hosts file from multiple sources'
url='https://github.com/hectorm/hblock'

View file

@ -1,6 +1,6 @@
m4_changequote([[, ]])m4_dnl
hblock (m4_esyscmd(printf -- '%s' "${PKG_VERSION?}")) unstable; urgency=medium
hblock (m4_esyscmd(printf '%s' "${PKG_VERSION?}")) unstable; urgency=medium
* m4_esyscmd(printf -- '%s' "${PKG_VERSION?}") release.
* m4_esyscmd(printf '%s' "${PKG_VERSION?}") release.
-- Héctor Molinero Fernández <hector@molinero.dev> m4_esyscmd(date -Ru)

View file

@ -1,7 +1,7 @@
m4_changequote([[, ]])m4_dnl
{
"name": "hblock",
"version": "m4_esyscmd(printf -- '%s' "${PKG_VERSION?}")",
"version": "m4_esyscmd(printf '%s' "${PKG_VERSION?}")",
"description": "Adblocker that creates a hosts file from multiple sources",
"keywords": [
"ad-block",

View file

@ -1,6 +1,6 @@
# Maintainer: Héctor Molinero Fernández <hector@molinero.dev>
pkgname='hblock'
pkgver='m4_esyscmd(printf -- '%s' "${PKG_VERSION?}")'
pkgver='m4_esyscmd(printf '%s' "${PKG_VERSION?}")'
pkgrel='1'
pkgdesc='Adblocker that creates a hosts file from multiple sources'
arch=('any')

View file

@ -1,6 +1,6 @@
m4_changequote([[, ]])m4_dnl
%define name hblock
%define version m4_esyscmd(printf -- '%s' "${PKG_VERSION?}")
%define version m4_esyscmd(printf '%s' "${PKG_VERSION?}")
Name: %{name}
Version: %{version}

View file

@ -31,7 +31,7 @@ rand() {
mktempFile() {
# POSIX does not specify the mktemp utility, so here comes a hacky solution.
while file="${TMPDIR:-${TMP:-/tmp}}/hblock.${$}.$(rand)" && [ -e "${file:?}" ]; do sleep 1; done
(umask 077 && touch -- "${file:?}"); printf -- '%s' "${file:?}"
(umask 077 && touch -- "${file:?}"); printf '%s' "${file:?}"
}
# Write stdin to a file.
@ -69,7 +69,7 @@ main() {
pslUrl="${2:-https://publicsuffix.org/list/public_suffix_list.dat}"
if [ ! -e "${domainsFile:?}" ]; then
printf -- '%s\n' "No such file: '${domainsFile:?}'" >&2
printf '%s\n' "No such file: '${domainsFile:?}'" >&2
exit 1
fi
@ -102,7 +102,7 @@ main() {
while IFS= read -r suffix || [ -n "${suffix?}" ]; do
if grep -- "${suffix:?}" "${workFile:?}" > "${matchFile:?}"; then
count="$(awk '{N+=$1}END{print(N)}' < "${matchFile:?}")"
printf -- '%s\t%s\n' "${count:?}" "${suffix:?}" >> "${statsFile:?}"
printf '%s\t%s\n' "${count:?}" "${suffix:?}" >> "${statsFile:?}"
{ grep -v -- "${suffix:?}" "${workFile:?}" ||:; } | sponge "${workFile:?}"
fi
done < "${pslFile:?}"

View file

@ -21,9 +21,9 @@ runInTestShell() {
assertEquals() {
actual="${1?}"; expected="${2?}"
if [ "${actual?}" != "${expected?}" ]; then
printf -- '\nError, values are not equal\n\n' >&2
printf -- '[Actual]:\n\n%s\n\n' "${actual?}" >&2
printf -- '[Expected]:\n\n%s\n\n' "${expected?}" >&2
printf '\nError, values are not equal\n\n' >&2
printf '[Actual]:\n\n%s\n\n' "${actual?}" >&2
printf '[Expected]:\n\n%s\n\n' "${expected?}" >&2
return 1
fi
return 0

View file

@ -15,7 +15,7 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
printf -- 'Test - Main - Argument: Double dash argument\n'
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

View file

@ -15,7 +15,7 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
printf -- 'Test - Main - Argument: Invalid long option\n'
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

View file

@ -15,7 +15,7 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
printf -- 'Test - Main - Argument: Invalid short option\n'
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

View file

@ -16,63 +16,63 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_ALLOWLIST_FILE=''
printf -- 'Test - Main - Allowlist: "-A" short option\n'
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'
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'
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'
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'
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'
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'
printf 'Test - Main - Allowlist: "HBLOCK_ALLOWLIST_FILE" environment variable\n'
actual="$(set -a; 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'
printf 'Test - Main - Allowlist: "HBLOCK_ALLOWLIST_FILE" environment variable with a non-existent file\n'
actual="$(set -a; 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'
printf 'Test - Main - Allowlist: "HBLOCK_ALLOWLIST" environment variable\n'
actual="$(set -a; HBLOCK_ALLOWLIST="$(cat -- "${SCRIPT_DIR:?}/allowlist.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,21 +16,21 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_COMMENT='#'
printf -- 'Test - Main - Comment: "-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: "--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'
printf 'Test - Main - Comment: "HBLOCK_COMMENT" environment variable\n'
actual="$(set -a; HBLOCK_COMMENT='# %' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,63 +16,63 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_DENYLIST_FILE=''
printf -- 'Test - Main - Denylist: "-D" short option\n'
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'
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'
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'
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'
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'
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'
printf 'Test - Main - Denylist: "HBLOCK_DENYLIST_FILE" environment variable\n'
actual="$(set -a; 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'
printf 'Test - Main - Denylist: "HBLOCK_DENYLIST_FILE" environment variable with a non-existent file\n'
actual="$(set -a; 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'
printf 'Test - Main - Denylist: "HBLOCK_DENYLIST" environment variable\n'
actual="$(set -a; HBLOCK_DENYLIST="$(cat -- "${SCRIPT_DIR:?}/denylist.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,21 +16,21 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_FILTER_SUBDOMAINS='false'
printf -- 'Test - Main - Filter subdomains: "-f" short option\n'
printf 'Test - Main - Filter subdomains: "-f" short option\n'
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- -f)"
expected="$(cat -- "${0%.sh}"-true.out)"
if ! assertEquals "${actual?}" "${expected?}"; then
exit 1
fi
printf -- 'Test - Main - Filter subdomains: "--filter-subdomains" long option\n'
printf 'Test - Main - Filter subdomains: "--filter-subdomains" long option\n'
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --filter-subdomains)"
expected="$(cat -- "${0%.sh}"-true.out)"
if ! assertEquals "${actual?}" "${expected?}"; then
exit 1
fi
printf -- 'Test - Main - Filter subdomains: "HBLOCK_FILTER_SUBDOMAINS" environment variable\n'
printf 'Test - Main - Filter subdomains: "HBLOCK_FILTER_SUBDOMAINS" environment variable\n'
actual="$(set -a; HBLOCK_FILTER_SUBDOMAINS='true' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}"-true.out)"
if ! assertEquals "${actual?}" "${expected?}"; then
@ -39,7 +39,7 @@ main() {
export HBLOCK_FILTER_SUBDOMAINS='true'
printf -- 'Test - Main - Filter subdomains: "--no-filter-subdomains" long option\n'
printf 'Test - Main - Filter subdomains: "--no-filter-subdomains" long option\n'
actual="$(runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO- --no-filter-subdomains)"
expected="$(cat -- "${0%.sh}"-false.out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,63 +16,63 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_FOOTER_FILE=''
printf -- 'Test - Main - Footer: "-F" short option\n'
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'
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'
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'
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'
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'
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'
printf 'Test - Main - Footer: "HBLOCK_FOOTER_FILE" environment variable\n'
actual="$(set -a; 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'
printf 'Test - Main - Footer: "HBLOCK_FOOTER_FILE" environment variable with a non-existent file\n'
actual="$(set -a; 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'
printf 'Test - Main - Footer: "HBLOCK_FOOTER" environment variable\n'
actual="$(set -a; HBLOCK_FOOTER="$(cat -- "${SCRIPT_DIR:?}/footer.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,63 +16,63 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_HEADER_FILE=''
printf -- 'Test - Main - Header: "-H" short option\n'
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'
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'
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'
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'
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'
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'
printf 'Test - Main - Header: "HBLOCK_HEADER_FILE" environment variable\n'
actual="$(set -a; 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'
printf 'Test - Main - Header: "HBLOCK_HEADER_FILE" environment variable with a non-existent file\n'
actual="$(set -a; 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'
printf 'Test - Main - Header: "HBLOCK_HEADER" environment variable\n'
actual="$(set -a; HBLOCK_HEADER="$(cat -- "${SCRIPT_DIR:?}/header.txt")" runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,21 +16,21 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_LENIENT='false'
printf -- 'Test - Main - Lenient: "-l" short option\n'
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'
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'
printf 'Test - Main - Lenient: "HBLOCK_LENIENT" environment variable\n'
actual="$(set -a; HBLOCK_LENIENT='true' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}"-true.out)"
if ! assertEquals "${actual?}" "${expected?}"; then
@ -39,7 +39,7 @@ main() {
export HBLOCK_LENIENT='true'
printf -- 'Test - Main - Lenient: "--no-lenient" long option\n'
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

View file

@ -16,21 +16,21 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_REDIRECTION='0.0.0.0'
printf -- 'Test - Main - Redirection: "-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: "--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'
printf 'Test - Main - Redirection: "HBLOCK_REDIRECTION" environment variable\n'
actual="$(set -a; HBLOCK_REDIRECTION='::1' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -22,21 +22,21 @@ main() {
EOF
)"
printf -- 'Test - Main - Regex: "-r" short option\n'
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'
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'
printf 'Test - Main - Regex: "HBLOCK_REGEX" environment variable\n'
actual="$(set -a; HBLOCK_REGEX='true' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}"-true.out)"
if ! assertEquals "${actual?}" "${expected?}"; then
@ -52,7 +52,7 @@ main() {
EOF
)"
printf -- 'Test - Main - Regex: "--no-regex" long option\n'
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

View file

@ -16,21 +16,21 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_TEMPLATE='%R %D'
printf -- 'Test - Main - Template: "-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: "--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'
printf 'Test - Main - Template: "HBLOCK_TEMPLATE" environment variable\n'
actual="$(set -a; HBLOCK_TEMPLATE='%D\n\t└─ %R' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -16,21 +16,21 @@ main() {
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/test-domains-source.txt"
export HBLOCK_WRAP='1'
printf -- 'Test - Main - Wrap: "-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: "--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'
printf 'Test - Main - Wrap: "HBLOCK_WRAP" environment variable\n'
actual="$(set -a; HBLOCK_WRAP='5' runInTestShell "${SCRIPT_DIR:?}/../../hblock" -qO-)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -13,7 +13,7 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
. "${SCRIPT_DIR:?}"/env.sh
main() {
printf -- 'Test - Stats: Suffixes\n'
printf 'Test - Stats: Suffixes\n'
actual="$(runInTestShell "${SCRIPT_DIR:?}/../stats/stats.sh" "${SCRIPT_DIR:?}/test-domains-stats.txt" "file://${SCRIPT_DIR:?}/psl.txt")"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -13,7 +13,7 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
. "${SCRIPT_DIR:?}"/env.sh
main() {
printf -- 'Test - Stats: TLDs\n'
printf 'Test - Stats: TLDs\n'
actual="$(runInTestShell "${SCRIPT_DIR:?}/../stats/stats.sh" "${SCRIPT_DIR:?}/test-domains-stats.txt" none)"
expected="$(cat -- "${0%.sh}".out)"
if ! assertEquals "${actual?}" "${expected?}"; then

View file

@ -72,7 +72,7 @@ setVersion() {
make -C "${PROJECT_DIR:?}" man
# Regenerate checksum file.
printf -- '%s %s\n' "${hblockScriptChecksum:?}" 'hblock' > "${PROJECT_DIR:?}"/hblock.sha256
printf '%s %s\n' "${hblockScriptChecksum:?}" 'hblock' > "${PROJECT_DIR:?}"/hblock.sha256
}
if [ "${1:?}" = 'get' ]; then