test.sh: add test for including sfeed_update as a library - sfeed_tests - sfeed tests and RSS and Atom files
(HTM) git clone git://git.codemadness.org/sfeed_tests
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 2307a973ed993fe3483c010398c650c31228b573
(DIR) parent fa3a25d42003e780f028a56098f79e67f39f2d43
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 26 Jan 2024 19:57:13 +0100
test.sh: add test for including sfeed_update as a library
... also add a regression test. Prompted by a user who send a patch which
would've caused this regression.
Diffstat:
M input/sfeed_update/test.sh | 147 ++++++++++++++++++++++++++++++-
1 file changed, 146 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/input/sfeed_update/test.sh b/input/sfeed_update/test.sh
@@ -1,6 +1,7 @@
#!/bin/sh
-SFEED_UPDATE="sfeed_update"
+SFEED_UPDATE="$(command -v sfeed_update)"
+[ "$SFEED_UPDATE" != "" ] || exit 1
# expect(expect, got, [extra])
expect() {
@@ -1174,6 +1175,146 @@ feeds() {
echo "test_fail_order: test OK" >&2
}
+# basic test for SFEED_UPDATE_INCLUDE=1
+test_include() {
+ init_test
+
+ script="$(mktemp)"
+
+ createrc > "$rc" <<!
+sfeedpath="$feedpath"
+maxjobs=1 # must be run sequential
+
+feeds() {
+ # feed <name> <feedurl> [basesiteurl] [encoding]
+ feed "1" "file:///dev/null"
+ feed "2" "file:///dev/null_fail"
+ feed "3" "file:///dev/null"
+}
+!
+
+ # include sfeed_update and call it in the normal way.
+ cat > "$script" <<!
+#!/bin/sh
+SFEED_UPDATE_INCLUDE=1 . "$SFEED_UPDATE"
+main "\$@"
+!
+
+ chmod +x "$script"
+ "$script" "$rc" >"$log_stdout" 2> "$log_stderr"
+ expect "1" "$?" "exit statuscode"
+
+ linecount=$(wc -l < "$log_stdout")
+ linecount=$((linecount+0))
+ expect "2" "$linecount" "2 lines should be written to stdout"
+
+ linecount=$(wc -l < "$log_stderr")
+ linecount=$((linecount+0))
+ expect "1" "$linecount" "1 line should be written to stderr"
+
+ test -d "$feedpath"
+ expect "0" "$?" "directory should exist: $feedpath"
+
+ for i in 1 2 3; do
+ f="$feedpath/$i"
+ test -f "$f"
+ expect "0" "$?" "file should exist: $f"
+ done
+
+ rm -f "$script"
+ cleanup
+
+ echo "test_include: test OK" >&2
+}
+
+# basic test for SFEED_UPDATE_INCLUDE=1 and config variables.
+test_include_config_vars() {
+ init_test
+
+ script="$(mktemp)"
+
+ createrc > "$rc" <<!
+sfeedpath="$feedpath"
+maxjobs=1
+
+# do not set defaults
+_feed() {
+ printf '%s\t%s\n' "\$sfeedpath" "\$maxjobs"
+}
+
+feeds() {
+ # feed <name> <feedurl> [basesiteurl] [encoding]
+ feed "1" "file:///dev/null"
+}
+!
+
+ # include sfeed_update and call it in the normal way.
+ cat > "$script" <<!
+#!/bin/sh
+SFEED_UPDATE_INCLUDE=1 . "$SFEED_UPDATE"
+main "\$@"
+!
+
+ chmod +x "$script"
+ "$script" "$rc" >"$log_stdout" 2> "$log_stderr"
+ expect "0" "$?" "exit statuscode"
+
+ linecount=$(wc -l < "$log_stderr")
+ linecount=$((linecount+0))
+ expect "0" "$linecount" "0 lines should be written to stderr"
+
+ content="$(cat "$log_stdout")"
+ expect "$content" "$feedpath 1" "config values are invalid"
+
+ rm -f "$script"
+ cleanup
+
+ echo "test_include_config_vars: test OK" >&2
+}
+
+# basic test for SFEED_UPDATE_INCLUDE=1 and default config values for
+# variables.
+test_include_config_vars_default() {
+ init_test
+
+ script="$(mktemp)"
+
+ createrc > "$rc" <<!
+# do not set defaults
+_feed() {
+ printf '%s\t%s\n' "\$sfeedpath" "\$maxjobs"
+}
+
+feeds() {
+ # feed <name> <feedurl> [basesiteurl] [encoding]
+ feed "1" "file:///dev/null"
+}
+!
+
+ # include sfeed_update and call it in the normal way.
+ cat > "$script" <<!
+#!/bin/sh
+SFEED_UPDATE_INCLUDE=1 . "$SFEED_UPDATE"
+main "\$@"
+!
+
+ chmod +x "$script"
+ "$script" "$rc" >"$log_stdout" 2> "$log_stderr"
+ expect "0" "$?" "exit statuscode"
+
+ linecount=$(wc -l < "$log_stderr")
+ linecount=$((linecount+0))
+ expect "0" "$linecount" "0 lines should be written to stderr"
+
+ content="$(cat "$log_stdout")"
+ expect "$content" "$HOME/.sfeed/feeds 16" "default config values are invalid"
+
+ rm -f "$script"
+ cleanup
+
+ echo "test_include_config_vars_default: test OK" >&2
+}
+
test_normal
test_one_fail
test_tmpdir
@@ -1198,6 +1339,10 @@ test_override_filter
test_override_merge
test_override_order
+test_include
+test_include_config_vars
+test_include_config_vars_default
+
echo "Testing SIGTERM (has some delay)..."
# NOTE: SIGINT can't reliably be tested.