Skip to content

Commit

Permalink
make failing test case succeed on test all (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
matsl authored Jan 21, 2025
1 parent cd8f06a commit 398adca
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 14 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2025-01-20 Mats Lidell <[email protected]>

* test/test-helpers-tests.el (test-helpers-test--make-random-wikiword):
Add test.

* test/MANIFEST: Test file for the test helpers.

* test/hy-test-helpers.el (hy-make-random-wikiword): Helper for making
random WikiWords.

2025-01-20 Bob Weiner <[email protected]>

* hsys-ert.el (require 'hbut): For 'defib'.
Expand Down
1 change: 1 addition & 0 deletions test/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ kotl-mode-tests.el - kotl-mode-el tests
kotl-orgtbl-tests.el - kotl orgtbl tests
set-tests.el - mathematical set library tests
smart-org-tests.el - smart-org-el tests
test-helpers-tests.el - unit test of the test helpers
4 changes: 2 additions & 2 deletions test/hui-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 30-Jan-21 at 12:00:00
;; Last-Mod: 20-Jan-25 at 01:39:41 by Bob Weiner
;; Last-Mod: 21-Jan-25 at 17:05:46 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Copyright (C) 2021-2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
Expand Down
21 changes: 19 additions & 2 deletions test/hy-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 30-Jan-21 at 12:00:00
;; Last-Mod: 15-Dec-24 at 14:24:42 by Bob Weiner
;; Last-Mod: 21-Jan-25 at 17:02:36 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Copyright (C) 2021-2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
Expand Down Expand Up @@ -100,5 +100,22 @@ Checks ACTYPE, ARGS, LOC, LBL-KEY and NAME."
(kill-buffer buf))
(delete-directory dir)))

(defun hy-make-random-wikiword (&optional length word-length)
"Create a random WikiWord (string).
The WikiWord will have a total of LENGTH characters. Each word part of
the WikiWord will have WORD-LENGTH characters. The default LENGTH is 12
and the default WORD-LENGTH is 4."
(unless length
(setq length 12))
(unless word-length
(setq word-length 4))
(let ((chars (vconcat (number-sequence ?a ?z)))
(result ""))
(dotimes (i length)
(when (zerop (mod i word-length))
(setq result (concat result " ")))
(setq result (concat result (char-to-string (elt chars (random (length chars)))))))
(replace-regexp-in-string "[[:space:]]" "" (capitalize result))))

(provide 'hy-test-helpers)
;;; hy-test-helpers.el ends here
4 changes: 2 additions & 2 deletions test/hycontrol-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 8-Jan-25 at 22:52:00
;; Last-Mod: 8-Jan-25 at 23:13:27 by Mats Lidell
;; Last-Mod: 21-Jan-25 at 17:03:54 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2021-2022 Free Software Foundation, Inc.
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
Expand Down
4 changes: 2 additions & 2 deletions test/hyrolo-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 19-Jun-21 at 22:42:00
;; Last-Mod: 18-Jan-25 at 22:46:39 by Bob Weiner
;; Last-Mod: 21-Jan-25 at 17:04:35 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Copyright (C) 2021-2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
Expand Down
32 changes: 26 additions & 6 deletions test/hywiki-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2024 Free Software Foundation, Inc.
;; Copyright (C) 2024-2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
Expand Down Expand Up @@ -893,16 +893,36 @@ Note special meaning of `hywiki-allow-plurals-flag'."

(ert-deftest hywiki-tests--add-org-roam-node ()
"Verify `hywiki-add-org-roam-node'."
(let ((hywiki-directory (make-temp-file "hywiki" t))
(wikiword "WikiWord"))
(let* ((hywiki-directory (make-temp-file "hywiki" t))
(wiki-page (cdr (hywiki-add-page "FirstWord")))
(wikiword (hy-make-random-wikiword)))
(unwind-protect
(mocklet (((hypb:require-package 'org-roam) => t)
((org-roam-node-read) => t)
((org-roam-node-title t) => "org-roam-node"))
((org-roam-node-read) => "node")
((org-roam-node-title "node") => "node-title"))
(hywiki-add-org-roam-node wikiword)
(should (equal '(org-roam-node . "org-roam-node")
(should (equal '(org-roam-node . "node-title")
(hywiki-get-referent wikiword))))
(hy-delete-file-and-buffer wiki-page)
(hy-delete-dir-and-buffer hywiki-directory))))

;;; FIXME
;; Without creating an initial page the test case above oddly fails on
;; first run when executed interactively in a fresh Emacs. Such as
;; running "make all-tests" in a shell. Why?
;;
;; (ert-deftest hywiki-tests--add-org-roam-node ()
;; "Verify `hywiki-add-org-roam-node'."
;; (let* ((hywiki-directory (make-temp-file "hywiki" t))
;; (wikiword (hy-make-random-wikiword)))
;; (unwind-protect
;; (mocklet (((hypb:require-package 'org-roam) => t)
;; ((org-roam-node-read) => "node")
;; ((org-roam-node-title "node") => "node-title"))
;; (hywiki-add-org-roam-node wikiword)
;; (should (equal '(org-roam-node . "node-title")
;; (hywiki-get-referent wikiword))))
;; (hy-delete-dir-and-buffer hywiki-directory))))

(provide 'hywiki-tests)
;;; hywiki-tests.el ends here
44 changes: 44 additions & 0 deletions test/test-helpers-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;;; test-helpers-tests.el --- tests of the test helpers -*- lexical-binding: t; -*-
;;
;; Author: Mats Lidell
;;
;; Orig-Date: 20-Jan-25 at 20:22:05
;; Last-Mod: 21-Jan-25 at 17:02:12 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.

;;; Commentary:
;;
;; These are tests for the test helpers used in other tests.

;;; Code:

(require 'ert)
(require 'hy-test-helpers)

(unless (fboundp #'char-uppercase-p)
(defun char-uppercase-p (char)
"Return non-nil if CHAR is an upper-case character.
If the Unicode tables are not yet available, e.g. during bootstrap,
then gives correct answers only for ASCII characters."
(cond ((unicode-property-table-internal 'lowercase)
(characterp (get-char-code-property char 'lowercase)))
((<= ?A char ?Z)))))

(ert-deftest test-helpers-test--make-random-wikiword ()
"Verify hy-make-random-wikiword."
(should (= 12 (length (hy-make-random-wikiword))))
(dolist (wwl '(3 9 21))
(dolist (wl '(2 3 9))
(let ((ww (hy-make-random-wikiword wwl wl)))
(should (= wwl (length ww)))
(should (char-uppercase-p (string-to-char (substring ww 0 1))))
(should-not (char-uppercase-p (string-to-char (substring ww 1 2))))))))

(provide 'test-helpers-tests)
;;; test-helpers-tests.el ends here

0 comments on commit 398adca

Please sign in to comment.