aboutsummaryrefslogtreecommitdiff
path: root/tests/test-gloss-core--corrupt-file-preserves-cache.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-28 14:21:18 -0500
committerCraig Jennings <c@cjennings.net>2026-04-28 14:21:18 -0500
commit4cd1e8e63d885d8de2728dc76d4f35f0eb597037 (patch)
treeb427f0516c3fa3d5d9767ad80f36108bcd3a3d9a /tests/test-gloss-core--corrupt-file-preserves-cache.el
parent71ccfdd0e6216356ec6cac90bc627fe02dbfdeb1 (diff)
downloadgloss-4cd1e8e63d885d8de2728dc76d4f35f0eb597037.tar.gz
gloss-4cd1e8e63d885d8de2728dc76d4f35f0eb597037.zip
test: add gloss-core test suite (red phase)
The commit lands eight per-function test files and a shared testutil. 32 tests across Normal/Boundary/Error categories cover the public API (lookup, save, list, find-buffer-position) and the internals that need observable behavior tests (mtime invalidation, corrupt-file resilience, alphabetical insert, first-call file creation). All 32 fail with void-function on the gloss-core symbols. That is the intended red-phase signal. The next commit lands the implementation that turns them green. testutil-gloss provides a with-temp-glossary macro. It binds gloss-file to a temp file, resets the cache before and after, and cleans up the visiting buffer.
Diffstat (limited to 'tests/test-gloss-core--corrupt-file-preserves-cache.el')
-rw-r--r--tests/test-gloss-core--corrupt-file-preserves-cache.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test-gloss-core--corrupt-file-preserves-cache.el b/tests/test-gloss-core--corrupt-file-preserves-cache.el
new file mode 100644
index 0000000..6cc6cfc
--- /dev/null
+++ b/tests/test-gloss-core--corrupt-file-preserves-cache.el
@@ -0,0 +1,32 @@
+;;; test-gloss-core--corrupt-file-preserves-cache.el --- Tests for corrupt-file resilience -*- lexical-binding: t -*-
+
+;; SPDX-License-Identifier: GPL-3.0-or-later
+
+;;; Commentary:
+;; Tests that a parser failure during cache reload does not destroy the
+;; existing cache; previously-cached lookups still succeed and the user
+;; sees an informative message.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'ert)
+(require 'gloss-core)
+(require 'testutil-gloss)
+
+(ert-deftest test-gloss-core-corrupt-file-preserves-existing-cache ()
+ "Error: parser failure during reload preserves the existing cache."
+ (gloss-test--with-temp-glossary gloss-test--sample-content
+ ;; Prime cache.
+ (should (gloss-core-lookup "anaphora"))
+ ;; Force mtime change to trigger a reload attempt.
+ (set-file-times gloss-file (time-add (current-time) 5))
+ ;; Mock the parse helper to fail.
+ (cl-letf (((symbol-function 'gloss-core--parse-file-into-cache)
+ (lambda () (error "simulated parse failure"))))
+ (let ((inhibit-message t))
+ ;; Lookup must not propagate the error; cached entry remains findable.
+ (should (gloss-core-lookup "anaphora"))))))
+
+(provide 'test-gloss-core--corrupt-file-preserves-cache)
+;;; test-gloss-core--corrupt-file-preserves-cache.el ends here