Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2026-03-21 Bob Weiner <rsw@gnu.org>

* test/hywiki-tests.el (hywiki-tests--referent-test): Remove these
lines for testing the cache every time this is called. Test
that in a single test instead.
(hywiki-tests--referent-cache-test): Add to
test saving and reloading a bookmark referent from cache.
(hywiki-tests--save-referent-org-id): Fix to
call 'hywiki-add-referent' around 'hywiki-add-org-id' since
interactive runs of this test without that wrapper return nil
for comparison to the expected (cons 'org-id "generated-org-id".

2026-03-18 Mats Lidell <matsl@gnu.org>

* hactypes.el (link-to-org-id): Fix quote in docstring.
Expand Down
87 changes: 53 additions & 34 deletions test/hywiki-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 18-May-24 at 23:59:48
;; Last-Mod: 16-Mar-26 at 21:52:06 by Bob Weiner
;; Last-Mod: 21-Mar-26 at 13:55:18 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand All @@ -27,6 +27,27 @@
(require 'ox-publish)
(require 'seq) ;; for `seq-take-while' and `seq-uniq'

(defmacro hywiki-tests--referent-test (expected-referent &rest prepare)
"Template macro for generating a non-page HyWikiWord referent.
EXPECTED-REFERENT is the result expected from `hywiki-get-referent'.
The template runs the PREPARE body, and that must add the HyWikiWord
named WikiReferent with a non-page referent type."
(declare (indent 0) (debug t))
`(let* ((hsys-consult-flag nil)
(vertico-mode 0)
(hywiki-directory (make-temp-file "hywiki" t))
(wiki-word-non-page "WikiReferent")
(mode-require-final-newline nil))
(unwind-protect
(save-excursion
(should (equal '() (hywiki-get-wikiword-list)))

,@prepare

(should (equal ,expected-referent (hywiki-get-referent wiki-word-non-page))))
(hy-delete-files-and-buffers (list (hywiki-cache-default-file)))
(hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))

(defconst hywiki-tests--edit-string-pairs
[
;; !! TODO: This test fails
Expand Down Expand Up @@ -1229,37 +1250,35 @@ Note special meaning of `hywiki-allow-plurals-flag'."
(should (equal '(org-roam-node . "node-title")
(hywiki-get-referent wikiword)))))))

(defmacro hywiki-tests--referent-test (expected-referent &rest prepare)
"Template macro for generating a non-page HyWikiWord referent.
EXPECTED-REFERENT is the result expected from `hywiki-get-referent'.
The template runs the PREPARE body, and that must add the HyWikiWord
named WikiReferent with a non-page referent type."
(declare (indent 0) (debug t))
`(let* ((hsys-consult-flag nil)
(vertico-mode 0)
(hywiki-directory (make-temp-file "hywiki" t))
(wiki-word-non-page "WikiReferent")
(mode-require-final-newline nil))
(unwind-protect
(save-excursion
(should (equal '() (hywiki-get-wikiword-list)))

,@prepare

;; Stop checking existence of cache file since there may be
;; a race condition that makes it not exist yet.
;; (should (file-exists-p (hywiki-cache-default-file)))

(should (equal ,expected-referent (hywiki-get-referent wiki-word-non-page)))

;; Simulate reload from cache
(hywiki-cache-save)
(setq hywiki--referent-hasht nil)
(hywiki-make-referent-hasht)

(should (equal ,expected-referent (hywiki-get-referent wiki-word-non-page))))
(hy-delete-files-and-buffers (list (hywiki-cache-default-file)))
(hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--referent-cache-test ()
"Test to check that a HyWiki referent read back from cache is as expected."
(let* ((hsys-consult-flag nil)
(vertico-mode 0)
(hywiki-directory (make-temp-file "hywiki" t))
(file (make-temp-file "hypb"))
(wiki-word-non-page "WikiReferent")
(mode-require-final-newline nil))
(unwind-protect
(progn
(find-file file)
(hy-test-helpers:ert-simulate-keys (concat wiki-word-non-page "\r")
(hywiki-add-bookmark wiki-word-non-page))
(should (equal (cons 'bookmark wiki-word-non-page)
(hywiki-get-referent wiki-word-non-page)))

;; Stop checking existence of cache file since there may be
;; a race condition that makes it not exist yet.
;; (should (file-exists-p (hywiki-cache-default-file)))

;; Simulate reload from cache
(hywiki-cache-save)
(setq hywiki--referent-hasht nil)
(hywiki-make-referent-hasht)

(should (equal (cons 'bookmark wiki-word-non-page)
(hywiki-get-referent wiki-word-non-page))))
(hy-delete-files-and-buffers (list file (hywiki-cache-default-file)))
(hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--save-referent-keyseries ()
"Verify saving and loading a referent keyseries works ."
Expand Down Expand Up @@ -1455,8 +1474,8 @@ named WikiReferent with a non-page referent type."
(hywiki-tests--insert "* header\n")
(mocklet (((org-id-get) => "generated-org-id"))
(goto-char (point-max))
(hywiki-add-org-id wiki-word-non-page)
(hywiki-get-referent wiki-word-non-page)))
(hywiki-add-referent wiki-word-non-page
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. Adding the referent using hywiki-add-referent is basically what the test is about so doing that explicitly will not test the right thing. The tests purpose is to verify that hywiki-add-org-id will call hywiki-add-referent here.

With this version:

; TEST: Old test for checking verification
(ert-deftest hywiki-tests--save-referent-org-id-alt ()
  "Verify saving and loading a referent org id works."
  (hywiki-tests--referent-test-with-cache
    (cons 'org-id "generated-org-id")
    (save-excursion
      (let ((filea (make-temp-file "hypb" nil ".org")))
        (unwind-protect
            (with-current-buffer (find-file filea)
              (hywiki-tests--insert "* header\n")
              (mocklet (((org-id-get) => "generated-org-id"))
                (goto-char (point-max))
                ;; 1 - (hywiki-get-referent-hasht)
                ;; 2 - (should-not (hywiki-get-referent wiki-word-non-page))
	        (hywiki-add-org-id wiki-word-non-page)))
	  (hy-delete-file-and-buffer filea))))))

When I run it in my development Emacs it fails as you have seen at your end but when I run it in a clean docker environment also interactively it works.

Even more confusing is that if I uncomment either or line beinning with ";; 1" or ";; 2" the test does also work in my development Emacs. (And continues to work in docker.)

And if that was not enough - In the commited version the call to hywiki-add.-org-id will actually call hywiki-add-referent before hywiki-add-referent is called from the test code. (Since the return value of hywiki-add-org-id comes from the call to hywiki-add-referent. Bah.)

Anyway - I think having the call to hywiki-add-referent in the test is misleading. We need to figure out why this is happening.

(hywiki-add-org-id wiki-word-non-page))))
(hy-delete-file-and-buffer filea))))))

;; !! FIXME: Add Org-id links tests.
Expand Down
Loading