diff options
Diffstat (limited to 'tests/test-gloss-core--corrupt-file-preserves-cache.el')
| -rw-r--r-- | tests/test-gloss-core--corrupt-file-preserves-cache.el | 32 |
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 |
