summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/shuriken9
-rw-r--r--src/lib/template.source.sh9
-rwxr-xr-xtests/cli.sh82
3 files changed, 94 insertions, 6 deletions
diff --git a/bin/shuriken b/bin/shuriken
index 82c84db..b9df7c1 100755
--- a/bin/shuriken
+++ b/bin/shuriken
@@ -759,9 +759,12 @@ source_template_file() {
return "$status"
fi
- env -i PATH="$PATH" BASH_ENV="$context_file" \
- bash -euo pipefail -- "$template_path" >> "$output_path"
- status=$?
+ if env -i PATH="$PATH" BASH_ENV="$context_file" \
+ bash -euo pipefail -- "$template_path" >> "$output_path"; then
+ status=0
+ else
+ status=$?
+ fi
rm -f "$context_file"
if (( status != 0 )); then
return "$status"
diff --git a/src/lib/template.source.sh b/src/lib/template.source.sh
index 93b8187..e29458a 100644
--- a/src/lib/template.source.sh
+++ b/src/lib/template.source.sh
@@ -314,9 +314,12 @@ source_template_file() {
return "$status"
fi
- env -i PATH="$PATH" BASH_ENV="$context_file" \
- bash -euo pipefail -- "$template_path" >> "$output_path"
- status=$?
+ if env -i PATH="$PATH" BASH_ENV="$context_file" \
+ bash -euo pipefail -- "$template_path" >> "$output_path"; then
+ status=0
+ else
+ status=$?
+ fi
rm -f "$context_file"
if (( status != 0 )); then
return "$status"
diff --git a/tests/cli.sh b/tests/cli.sh
index 311cff9..25f003f 100755
--- a/tests/cli.sh
+++ b/tests/cli.sh
@@ -3380,6 +3380,7 @@ ORIGINAL_BASEPATH=''
TARBALL_INCLUDE=no
SHURIKEN_OUTPUT_MODE=quiet
+set +e
template preview out.html \
animation_class '' \
backhref '#' \
@@ -3388,6 +3389,9 @@ template preview out.html \
photo photo.jpg \
preview_num 1 \
thumbs_dir thumbs
+template_status=$?
+
+exit "$template_status"
BASH
)
status=$?
@@ -3408,6 +3412,81 @@ BASH
test::teardown
}
+test_template_failure_removes_context_file_with_errexit() {
+ local context_file
+ local fake_bin
+ local output
+ local template_dir
+ local -i status=0
+
+ test::setup
+ fake_bin="$TEST_TMPDIR/bin"
+ template_dir="$TEST_TMPDIR/templates"
+ context_file="$TEST_TMPDIR/template-context"
+ mkdir -p "$fake_bin" "$template_dir" "$TEST_TMPDIR/dist"
+ {
+ printf '#!/usr/bin/env bash\n'
+ # shellcheck disable=SC2016
+ printf 'printf %%s\\\\n \"$SHURIKEN_FAKE_CONTEXT_FILE\"\n'
+ } > "$fake_bin/mktemp"
+ chmod 0755 "$fake_bin/mktemp"
+ printf 'exit 42\n' > "$template_dir/preview.tmpl"
+
+ set +e
+ output=$(
+ bash -euo pipefail -s \
+ "$TEST_SHURIKEN" \
+ "$fake_bin" \
+ "$template_dir" \
+ "$TEST_TMPDIR/dist" \
+ "$context_file" \
+ 2>&1 \
+ <<'BASH'
+shuriken="$1"; shift
+fake_bin="$1"; shift
+template_dir="$1"; shift
+dist_dir="$1"; shift
+context_file="$1"; shift
+
+# shellcheck source=/dev/null
+source <(sed '$d' "$shuriken")
+
+PATH="$fake_bin:$PATH"
+SHURIKEN_FAKE_CONTEXT_FILE="$context_file"
+export SHURIKEN_FAKE_CONTEXT_FILE
+DIST_DIR="$dist_dir"
+TEMPLATE_DIR="$template_dir"
+TITLE='Template failure cleanup'
+HEIGHT=''
+THUMBHEIGHT=30
+MAXPREVIEWS=40
+ORIGINAL_BASEPATH=''
+TARBALL_INCLUDE=no
+SHURIKEN_OUTPUT_MODE=quiet
+
+template preview out.html \
+ animation_class '' \
+ backhref '#' \
+ html_dir . \
+ page_num 1 \
+ photo photo.jpg \
+ preview_num 1 \
+ thumbs_dir thumbs
+BASH
+ )
+ status=$?
+ set -e
+
+ if (( status == 0 )); then
+ printf 'FAIL: expected template rendering to fail\n' >&2
+ printf '%s\n' "$output" >&2
+ exit 1
+ fi
+
+ test::assert_path_absent "$context_file"
+ test::teardown
+}
+
test_generate_swap_failure_restores_dist() {
local config_file
local fake_bin
@@ -4315,6 +4394,9 @@ main() {
'template mktemp failure does not render without errexit' \
test_template_mktemp_failure_does_not_render_without_errexit
test::run_case \
+ 'template failure removes context file with errexit' \
+ test_template_failure_removes_context_file_with_errexit
+ test::run_case \
'--generate swap failure restores final dist' \
test_generate_swap_failure_restores_dist
test::run_case \