From 1b8b95813538e1f77f3a4c58901d4a4fa8d13d37 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 09:17:48 -0500 Subject: test(config-utilities): cover cj/--benchmark-method Four tests against a temporarily fbound test target: runs the symbol once and propagates its return value, raises user-error on a nil symbol, raises user-error naming the symbol when it isn't fboundp, and verifies the with-timer announce/done messages fire. --- tests/test-config-utilities--benchmark-method.el | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/test-config-utilities--benchmark-method.el (limited to 'tests') diff --git a/tests/test-config-utilities--benchmark-method.el b/tests/test-config-utilities--benchmark-method.el new file mode 100644 index 00000000..aefc38ba --- /dev/null +++ b/tests/test-config-utilities--benchmark-method.el @@ -0,0 +1,57 @@ +;;; test-config-utilities--benchmark-method.el --- Tests for cj/--benchmark-method -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for `cj/--benchmark-method'. The internal takes a title +;; string and a method symbol, validates fboundp, and runs the +;; symbol's funcall through `with-timer'. Returns whatever the +;; funcall returns; signals `user-error' on invalid input. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'config-utilities) + +(ert-deftest test-config-utilities-benchmark-method-runs-valid-symbol () + "Normal: a valid fboundp symbol is called once and its return value +is propagated through the timer wrapper." + (let ((called 0) + (inhibit-message t)) + (defalias 'test-cu-benchmark-target (lambda () (cl-incf called) 42)) + (unwind-protect + (should (= 42 (cj/--benchmark-method "x" 'test-cu-benchmark-target))) + (fmakunbound 'test-cu-benchmark-target)) + (should (= 1 called)))) + +(ert-deftest test-config-utilities-benchmark-method-nil-symbol-raises () + "Error: a nil method symbol raises `user-error'." + (let ((inhibit-message t)) + (should-error (cj/--benchmark-method "x" nil) :type 'user-error))) + +(ert-deftest test-config-utilities-benchmark-method-unbound-symbol-raises () + "Error: a symbol that is not fboundp raises `user-error' naming the symbol." + (let* ((sym (make-symbol "test-cu-not-bound")) + (err (let ((inhibit-message t)) + (should-error (cj/--benchmark-method "x" sym) + :type 'user-error)))) + (should (string-match-p (symbol-name sym) + (error-message-string err))))) + +(ert-deftest test-config-utilities-benchmark-method-emits-timer-messages () + "Boundary: the announce and done messages from with-timer fire." + (let (messages) + (defalias 'test-cu-benchmark-noisy (lambda () nil)) + (unwind-protect + (cl-letf (((symbol-function 'message) + (lambda (fmt &rest args) + (push (apply #'format fmt args) messages)))) + (cj/--benchmark-method "ZZZ" 'test-cu-benchmark-noisy)) + (fmakunbound 'test-cu-benchmark-noisy)) + (let ((all (string-join (nreverse messages) "\n"))) + (should (string-match-p "^ZZZ\\.\\.\\.$" all)) + (should (string-match-p "^ZZZ\\.\\.\\. done (" all))))) + +(provide 'test-config-utilities--benchmark-method) +;;; test-config-utilities--benchmark-method.el ends here -- cgit v1.2.3