diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-28 18:08:09 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-28 18:08:09 -0500 |
| commit | 3a846506399dc12ab219bfa8047947c122dd1d04 (patch) | |
| tree | ca547a7abc756e32398dc493c97cc8874367dfe9 /tests/testutil-gloss.el | |
| parent | 166d3bde50718eacd51c75cb82246988d9ec0151 (diff) | |
| download | gloss-3a846506399dc12ab219bfa8047947c122dd1d04.tar.gz gloss-3a846506399dc12ab219bfa8047947c122dd1d04.zip | |
test: add Wiktionary fixture loader helper
Append `gloss-test--load-wiktionary-fixture' to tests/testutil-gloss.el. It takes a fixture name (e.g. "anaphora") and returns the raw JSON body from tests/fixtures/wiktionary-NAME.json, or signals `error' with the full path when the file isn't there. The helper resolves the fixtures directory from a `defconst' captured at load time. That way it works the same whether a test file requires testutil-gloss directly or pulls it in transitively through `make test'.
Three ERT cases under tests/test-testutil-gloss--load-wiktionary-fixture.el cover Normal (anaphora loads as a non-empty JSON string), Boundary (the smallest fixture, 404, loads), and Error (a missing fixture raises with the path embedded in the message).
Verified with `make test': 35 passed, 0 unexpected.
Diffstat (limited to 'tests/testutil-gloss.el')
| -rw-r--r-- | tests/testutil-gloss.el | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/testutil-gloss.el b/tests/testutil-gloss.el index 7510765..36ba7ef 100644 --- a/tests/testutil-gloss.el +++ b/tests/testutil-gloss.el @@ -76,5 +76,22 @@ any visiting buffer if BODY created them." (when (file-exists-p gloss-file) (delete-file gloss-file))))) +(defconst gloss-test--testutil-dir + (file-name-directory (or load-file-name buffer-file-name default-directory)) + "Directory of this testutil file; used to locate fixtures.") + +(defun gloss-test--load-wiktionary-fixture (name) + "Return the raw JSON body of fixture `wiktionary-NAME.json' as a string. +NAME is the fixture name without the `wiktionary-' prefix or `.json' +suffix (e.g. \"anaphora\"). Fixtures live in tests/fixtures/ alongside +this file. Signal `error' with the full path if the file is missing." + (let ((path (expand-file-name (format "fixtures/wiktionary-%s.json" name) + gloss-test--testutil-dir))) + (unless (file-exists-p path) + (error "Wiktionary fixture not found: %s" path)) + (with-temp-buffer + (insert-file-contents path) + (buffer-string)))) + (provide 'testutil-gloss) ;;; testutil-gloss.el ends here |
