aboutsummaryrefslogtreecommitdiff
path: root/tests/test-gloss-core--first-call-creates-file.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-28 14:31:34 -0500
committerCraig Jennings <c@cjennings.net>2026-04-28 14:31:34 -0500
commit1e2da6b1a463492ada31ce473414289e761519ca (patch)
tree4b8c51e542890b74a8cc946c117d9ae2a2017411 /tests/test-gloss-core--first-call-creates-file.el
parent08cd3a12730d26cfc2eae8510da132747643da9e (diff)
downloadgloss-1e2da6b1a463492ada31ce473414289e761519ca.tar.gz
gloss-1e2da6b1a463492ada31ce473414289e761519ca.zip
refactor: extract missing-glossary test helper
Four tests across lookup, list, find-buffer-position, and first-call-creates-file shared the same boilerplate. Each let-bound gloss-file to a randomized nonexistent path, wrapped in unwind-protect, reset the cache, and cleaned up file and buffer afterward. Extracted as gloss-test--with-missing-glossary in testutil-gloss.el, parallel to the existing gloss-test--with-temp-glossary. The four call sites drop from 8-10 lines each to 2-3. Tested by running the full 32-test suite. All 32 pass in 0.21 seconds.
Diffstat (limited to 'tests/test-gloss-core--first-call-creates-file.el')
-rw-r--r--tests/test-gloss-core--first-call-creates-file.el27
1 files changed, 9 insertions, 18 deletions
diff --git a/tests/test-gloss-core--first-call-creates-file.el b/tests/test-gloss-core--first-call-creates-file.el
index e168435..22d313e 100644
--- a/tests/test-gloss-core--first-call-creates-file.el
+++ b/tests/test-gloss-core--first-call-creates-file.el
@@ -14,24 +14,15 @@
(ert-deftest test-gloss-core-save-creates-file-when-missing ()
"Normal: first save creates the file with a TITLE header."
- (let ((gloss-file (concat temporary-file-directory "gloss-create-"
- (number-to-string (random 100000)) ".org")))
- (unwind-protect
- (progn
- (gloss-core--cache-reset)
- (should-not (file-exists-p gloss-file))
- (gloss-core-save "anaphora" "Reference earlier." 'manual)
- (should (file-exists-p gloss-file))
- (let ((content (with-temp-buffer
- (insert-file-contents gloss-file)
- (buffer-string))))
- (should (string-match-p "#\\+TITLE:" content))
- (should (string-match-p "^\\* anaphora" content))))
- (gloss-core--cache-reset)
- (when-let ((buf (find-buffer-visiting gloss-file)))
- (with-current-buffer buf (set-buffer-modified-p nil))
- (kill-buffer buf))
- (when (file-exists-p gloss-file) (delete-file gloss-file)))))
+ (gloss-test--with-missing-glossary
+ (should-not (file-exists-p gloss-file))
+ (gloss-core-save "anaphora" "Reference earlier." 'manual)
+ (should (file-exists-p gloss-file))
+ (let ((content (with-temp-buffer
+ (insert-file-contents gloss-file)
+ (buffer-string))))
+ (should (string-match-p "#\\+TITLE:" content))
+ (should (string-match-p "^\\* anaphora" content)))))
(ert-deftest test-gloss-core-save-creates-parent-directory ()
"Boundary: first save creates missing parent directory."