aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-20 23:44:35 -0500
committerCraig Jennings <c@cjennings.net>2026-07-20 23:44:35 -0500
commit179fbd55795c27ed388860e3c6b3d8c0651422ac (patch)
tree6c6d8d83257660cb83abe26bebdc71a5affb5797
parent26eb578ab94610670196e632090b841f23611ce6 (diff)
downloadarchsetup-179fbd55795c27ed388860e3c6b3d8c0651422ac.tar.gz
archsetup-179fbd55795c27ed388860e3c6b3d8c0651422ac.zip
test: fix the weak assertions from the S6/S7 audit
The Hyprland socket check passed a shell glob to `test -S`, which breaks at both edges: zero matches leaves the literal pattern and several instances pass multiple args, failing for reasons unrelated to the socket. It now resolves one socket with find -type s. The gen_tokens degenerate-marker test asserted properties loose enough to pass on garbled output. It now pins the exact reconstruction as a characterization, with the impossible-input caveat stated, so any change to the branch surfaces. The gallery tick count leaned on split-string omit-nulls arithmetic that happened to equal the match count. It now counts occurrences directly. gallery-widget-write-svg, the last uncovered public entry point, gets a Normal-case test.
-rw-r--r--scripts/testing/tests/test_desktop.py8
-rw-r--r--tests/gallery-tokens/test_gen_tokens.py10
-rw-r--r--tests/gallery-widgets/test-gallery-widget.el23
3 files changed, 33 insertions, 8 deletions
diff --git a/scripts/testing/tests/test_desktop.py b/scripts/testing/tests/test_desktop.py
index 468bc75..1538d6a 100644
--- a/scripts/testing/tests/test_desktop.py
+++ b/scripts/testing/tests/test_desktop.py
@@ -93,7 +93,13 @@ def test_hyprland_socket(host, hyprland_installed, compositor_running):
pytest.skip("Hyprland not installed")
if not compositor_running:
pytest.skip("Hyprland not running (headless) — socket check not applicable")
- assert host.run("test -S /tmp/hypr/*/.socket.sock").rc == 0
+ # `test -S` on a shell glob breaks at both edges: zero matches leaves the
+ # literal pattern (rc 1) and several instances pass multiple args (rc 2).
+ # find -type s proves exactly one live socket path exists.
+ sock = host.run(
+ "find /tmp/hypr -maxdepth 2 -name .socket.sock -type s | head -1"
+ ).stdout.strip()
+ assert sock, "no Hyprland socket found under /tmp/hypr"
@pytest.mark.attribution("archsetup")
diff --git a/tests/gallery-tokens/test_gen_tokens.py b/tests/gallery-tokens/test_gen_tokens.py
index b9fbb50..2968119 100644
--- a/tests/gallery-tokens/test_gen_tokens.py
+++ b/tests/gallery-tokens/test_gen_tokens.py
@@ -181,11 +181,15 @@ class ReplaceBetweenMarkers(unittest.TestCase):
def test_start_marker_on_final_line_without_newline(self):
# Defensive branch: no newline after the start marker. The guard must
# not let text[:si-of-newline+1] collapse to "" and wipe the prefix.
+ # This input cannot occur in the real HTML (markers always sit on
+ # their own newline-terminated lines), so the exact-string assert is a
+ # characterization: the prefix survives, and the reconstruction's
+ # duplicated start marker is pinned deliberately so any change to the
+ # branch surfaces here instead of passing unnoticed.
src = f"keep\n{self.START} {self.END}"
out = gt.replace_between_markers(src, self.START, self.END, "X")
- self.assertTrue(out.startswith("keep\n"))
- self.assertIn(self.END, out)
- self.assertIn("X", out)
+ self.assertEqual(
+ out, f"keep\n{self.START} X\n{self.START} {self.END}")
class RealTokensJson(unittest.TestCase):
diff --git a/tests/gallery-widgets/test-gallery-widget.el b/tests/gallery-widgets/test-gallery-widget.el
index de0c165..c0d38b4 100644
--- a/tests/gallery-widgets/test-gallery-widget.el
+++ b/tests/gallery-widgets/test-gallery-widget.el
@@ -73,10 +73,12 @@
(let ((xml (test-gallery-widget--svg-string 42)))
;; arc path stroked in the wash token
(should (string-match-p (format "path[^>]*stroke=\"%s\"" (gallery-widget-token 'wash)) xml))
- ;; exactly three ticks
- (should (= 3 (cl-count-if (lambda (_) t)
- (split-string xml "class=\"tick\"" t)
- :start 1)))
+ ;; exactly three ticks, counted as direct occurrences (the earlier
+ ;; split-string arithmetic depended on omit-nulls edge behavior)
+ (should (= 3 (let ((n 0) (pos 0))
+ (while (string-match "class=\"tick\"" xml pos)
+ (setq n (1+ n) pos (match-end 0)))
+ n)))
;; needle + hub in the amber tokens
(should (string-match-p (format "class=\"needle\"[^>]*stroke=\"%s\""
(gallery-widget-token 'gold-hi))
@@ -133,6 +135,19 @@ outside a load and outside a file buffer."
(default-directory "/tmp/elsewhere/"))
(should (equal (gallery-widget--source-dir) "/tmp/elsewhere/")))))
+(ert-deftest gallery-widget-write-svg-writes-file-and-returns-path ()
+ "The output helper writes the SVG document and returns the path."
+ (let ((file (make-temp-file "gallery-widget-test-" nil ".svg")))
+ (unwind-protect
+ (let ((ret (gallery-widget-write-svg
+ (gallery-widget-needle-gauge 42) file)))
+ (should (equal ret file))
+ (should (file-exists-p file))
+ (with-temp-buffer
+ (insert-file-contents file)
+ (should (string-match-p "\\`<svg" (buffer-string)))))
+ (delete-file file))))
+
(ert-deftest gallery-widget-requires-cl-lib-at-load-time ()
"Loading the module alone brings in cl-lib, not just an autoload cookie.
A cold byte-compile or a changed autoload would otherwise break