branch: externals/debbugs
commit e09643671277c316aad1cc55599a3a2e8a8df01f
Author: Morgan Smith <morgan.j.sm...@outlook.com>
Commit: Michael Albinus <michael.albi...@gmx.de>

    tests: Move helper and wrapper functions into their own file
    
    * Makefile (check): Load all files in the test directory.
    
    * test/debbugs-test-helpers.el: New file.
    
    * test/debbugs-tests.el: Move test helper and wrapper functions into the new
    file and require it.
---
 Makefile                                           |   8 +-
 test/{debbugs-tests.el => debbugs-test-helpers.el} |  58 +----------
 test/debbugs-tests.el                              | 113 +--------------------
 3 files changed, 11 insertions(+), 168 deletions(-)

diff --git a/Makefile b/Makefile
index a7b6b0c7f3..81d7b5d2f2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
 EMACS ?= emacs
 MAKEINFO ?= makeinfo
 
+# regex of tests to run
+TESTS=.*
+
 SOURCE=$(wildcard *.el)
 TESTSOURCE=$(wildcard test/*.el)
 TARGET=$(filter-out debbugs-pkg.elc,$(patsubst %.el,%.elc,$(SOURCE)))
@@ -14,6 +17,9 @@ INFOMANUALS=debbugs.info debbugs-ug.info
 %.elc: %.el
        @$(EMACS) -Q -batch -L . -f batch-byte-compile $<
 
+test/%.elc: test/%.el
+       @$(EMACS) -Q -batch -L . -L ./test -f batch-byte-compile $<
+
 %.info: %.texi
        $(MAKEINFO) --error-limit=0 --no-split $< -o $@
 
@@ -24,7 +30,7 @@ doc: $(INFOMANUALS)
 build: $(TARGET)
 
 check: build $(TESTTARGET)
-       @$(EMACS) -Q --batch -L . -l $(TESTSOURCE) -f 
ert-run-tests-batch-and-exit
+       @$(EMACS) -Q --batch -L . -L ./test $(foreach file,$(TESTSOURCE), -l 
$(file)) --eval '(ert-run-tests-batch-and-exit "$(TESTS)")'
 
 clean:
        -rm -f $(TARGET) $(TESTTARGET) $(INFOMANUALS)
diff --git a/test/debbugs-tests.el b/test/debbugs-test-helpers.el
similarity index 69%
copy from test/debbugs-tests.el
copy to test/debbugs-test-helpers.el
index f3abea2837..f98bab40ed 100644
--- a/test/debbugs-tests.el
+++ b/test/debbugs-test-helpers.el
@@ -1,4 +1,4 @@
-;;; debbugs-tests.el --- tests for debbugs.el -*- lexical-binding: t; -*-
+;;; debbugs-test-helpers.el --- Helpers for testing debbugs -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2024-2025 Free Software Foundation, Inc.
 
@@ -140,59 +140,7 @@ These mock functions are needed to make the tests 
reproducible."
                 ,@body
                 (debbugs-test--teardown)))
 
-;;; Tests:
-
-(ert-deftest--debbugs debbugs-test-get-bugs ()
-  "Test \"get_bugs\"."
-  (debbugs-get-bugs
-   :tag "patch"
-   :severity "critical"
-   :status "open"
-   :status "forwarded")
-  (should (string-equal debbugs-test--soap-operation-name "get_bugs"))
-  (should (equal debbugs-test--soap-parameters
-                 '(["tag" "patch" "severity" "critical"
-                    "status" "open" "status" "forwarded"]))))
-
-(ert-deftest--debbugs debbugs-test-newest-bugs ()
-  "Test \"newest_bugs\"."
-  (debbugs-newest-bugs 4)
-  (should (string-equal debbugs-test--soap-operation-name "newest_bugs"))
-  (should (equal debbugs-test--soap-parameters '(4))))
-
-(ert-deftest--debbugs debbugs-test-newest-bug-cached ()
-  "Test getting the newest bug from the cache."
-  ;; First time we get it from the server.
-  (should (equal (debbugs-newest-bugs 1) '(0)))
-  (should (equal debbugs-test--soap-operation-name "newest_bugs"))
-  (should (equal debbugs-test--soap-parameters '(1)))
-  (setq debbugs-test--soap-operation-name nil)
-  (setq debbugs-test--soap-parameters nil)
-  ;; Now it's cached
-  (should (equal (debbugs-newest-bugs 1) '(0)))
-  (should (equal debbugs-test--soap-operation-name nil))
-  (should (equal debbugs-test--soap-parameters nil)))
-
-(ert-deftest--debbugs debbugs-test-get-status ()
-  "Test \"get_status\"."
-  (should (equal (sort (car (debbugs-get-status 64064)))
-                 (sort (car debbugs-test--bug-status))))
-  (should (string-equal debbugs-test--soap-operation-name "get_status"))
-  (should (equal debbugs-test--soap-parameters '([64064])))
-  (setq debbugs-test--soap-operation-name nil)
-  (setq debbugs-test--soap-parameters nil)
-  ;; cached
-  (should (equal (sort (car (debbugs-get-status 64064)))
-                 (sort (car debbugs-test--bug-status))))
-  (should (equal debbugs-test--soap-operation-name nil))
-  (should (equal debbugs-test--soap-parameters nil)))
-
-(ert-deftest--debbugs debbugs-test-get-usertag ()
-  "Test \"get_usertag\"."
-  (should (equal (debbugs-get-usertag :user "emacs") '("hi")))
-  (should (string-equal debbugs-test--soap-operation-name "get_usertag"))
-  (should (equal debbugs-test--soap-parameters '("emacs"))))
 
-(provide 'debbugs-tests)
+(provide 'debbugs-test-helpers)
 
-;;; debbugs-tests.el ends here
+;;; debbugs-test-helpers.el ends here
diff --git a/test/debbugs-tests.el b/test/debbugs-tests.el
index f3abea2837..da1b9dffe6 100644
--- a/test/debbugs-tests.el
+++ b/test/debbugs-tests.el
@@ -27,118 +27,7 @@
 ;;; Code:
 
 (require 'debbugs)
-
-;;; Helper Data:
-
-;; Generated using this:
-;; (soap-invoke debbugs-wsdl debbugs-port "get_status" [64064])
-(defconst debbugs-test--bug-status-soap-return
-  '(((item
-      (key . 64064)
-      (value
-       (package . "emacs") (found_date) (last_modified . 1689593050)
-       (affects) (date . 1686745022) (fixed_versions)
-       (originator . "Morgan Smith <morgan.j.sm...@outlook.com>")
-       (blocks) (archived . 1) (found) (unarchived) (tags . "patch")
-       (severity . "normal") (location . "archive") (owner) (fixed)
-       (blockedby) (pending . "done") (keywords . "patch") (id . 64064)
-       (found_versions) (mergedwith) (summary) (forwarded)
-       (log_modified . 1689593050)
-       (done . "Michael Albinus <michael.albi...@gmx.de>")
-       (source . "unknown")
-       (msgid
-        . 
"<dm5pr03mb31632e3a4fe170c62e7d4b0cc5...@dm5pr03mb3163.namprd03.prod.outlook.com>")
-       (bug_num . 64064) (subject . "[PATCH 0/4] debbugs improvements")
-       (fixed_date)))))
-  "Mock result from `soap-invoke' for bug 64064.")
-
-;; Generated using this:
-;; (debbugs-get-status 64064)
-(defconst debbugs-test--bug-status
-  '(((cache_time . 5000) (source . "unknown") (unarchived)
-     (keywords "patch") (blocks) (pending . "done") (severity . "normal")
-     (done . "Michael Albinus <michael.albi...@gmx.de>") (location . "archive")
-     (log_modified . 1689593050) (subject . "[PATCH 0/4] debbugs improvements")
-     (last_modified . 1689593050) (found) (tags "patch") (package "emacs")
-     (originator . "Morgan Smith <morgan.j.sm...@outlook.com>") (archived . t)
-     (blockedby) (affects) (mergedwith) (summary) (date . 1686745022)
-     (fixed_versions) (id . 64064) (fixed) (found_date) (forwarded)
-     (msgid
-      . 
"<dm5pr03mb31632e3a4fe170c62e7d4b0cc5...@dm5pr03mb3163.namprd03.prod.outlook.com>")
-     (owner) (found_versions) (fixed_date) (bug_num . 64064)))
-  "Mock result from `debbugs-get-status' for bug 64064.")
-
-;;; Helper Functions:
-
-(defvar debbugs-test--soap-operation-name nil)
-(defvar debbugs-test--soap-parameters nil)
-(defun debbugs-test--soap-invoke-internal
-    (callback _cbargs _wsdl _service operation-name &rest parameters)
-  "Over-ride for testing."
-  (setq debbugs-test--soap-operation-name operation-name)
-  (setq debbugs-test--soap-parameters parameters)
-  (let ((return
-         (cond ((string-equal operation-name "get_status")
-                debbugs-test--bug-status-soap-return)
-               ((string-equal operation-name "get_usertag")
-                '(((hi))))
-               (t '((0))))))
-    (if callback
-        (progn
-          (funcall callback return)
-          nil)
-      return)))
-
-(defun debbugs-test--override-float-time (func &rest rest)
-  "Override `float-time' for FUNC with args REST."
-  (cl-letf (((symbol-function #'float-time)
-             (lambda (&optional _specified-time) 5000)))
-    (apply func rest)))
-
-(defun debbugs-test--setup ()
-  "Mock network and time functions.
-These mock functions are needed to make the tests reproducible."
-  (setq debbugs-test--soap-operation-name nil)
-  (setq debbugs-test--soap-parameters nil)
-
-  (add-function
-   :override (symbol-function #'soap-invoke-internal)
-   #'debbugs-test--soap-invoke-internal)
-
-  (add-function
-   :around (symbol-function #'debbugs-get-cache)
-   #'debbugs-test--override-float-time)
-
-  (add-function
-   :around (symbol-function #'debbugs-put-cache)
-   #'debbugs-test--override-float-time))
-
-(defun debbugs-test--teardown ()
-  "Restore functions to as they where before."
-  (setq debbugs-test--soap-operation-name nil)
-  (setq debbugs-test--soap-parameters nil)
-
-  (remove-function
-   (symbol-function #'soap-invoke-internal)
-   #'debbugs-test--soap-invoke-internal)
-
-  (remove-function
-   (symbol-function #'debbugs-get-cache)
-   #'debbugs-test--override-float-time)
-
-  (remove-function
-   (symbol-function #'debbugs-put-cache)
-   #'debbugs-test--override-float-time))
-
-(defmacro ert-deftest--debbugs (name args docstring &rest body)
-  "The same as `ert-deftest' but runs setup and teardown functions."
-  (declare
-   (doc-string 3)
-   (indent 2))
-  `(ert-deftest ,name ,args ,docstring
-                (debbugs-test--setup)
-                ,@body
-                (debbugs-test--teardown)))
+(require 'debbugs-test-helpers)
 
 ;;; Tests:
 

Reply via email to