Subject: bug#76446: [PATCH v2 1/5] tests: Move helper and wrapper functions into their own file

From: Michael Albinus <[email-masked]>
Date: Sat, 22 Feb 2025 16:56:09 +0100

Morgan Smith <[email-masked]> writes:

>> We might be better with
>>
>> --8<---------------cut here---------------start------------->8---
>> @$(EMACS) -Q --batch -L . -L ./test -l $(TESTSOURCE) -f ert-run-tests-batch-and-exit
>> --8<---------------cut here---------------end--------------->8---
>>
>
> I did the '-L ./test' part but I kept the foreach.
>
> Without the foreach the command looks like "... -l file1.el file2.el
> file3.el ..." and emacs only actually loads the first file.  The command
> needs to look like "... -l file1.el -l file2.el -l file3.el ..."

My point is, that we have only the make target 'check', which runs all
ert tests located in different files. But I would also like to run only
the tests in, say for example, debbugs-tests.el. So we need an own
target for every *-tests.el file.

>>> --- /dev/null
>>> +++ b/test/debbugs-test-helpers.el
>>> @@ -0,0 +1,146 @@
>>> +(defconst debbugs-test--bug-status-soap-return
>>> +(defconst debbugs-test--bug-status
>>
>> Perhaps we should move these data into an ert-resource file (or two).
>>
>
> I read the info manual and source code pertaining to 'ert-resource' and
> I fail to see any benefit from using it.

Both defconsts contain data. Those data belong into a ressource file,
and shall be read from there. Something like

--8<---------------cut here---------------start------------->8---
;; -*- lisp-data -*-
(((cache_time . 5000) (source . "unknown") (unarchived)
  (keywords "patch") (blocks) (pending . "done") (severity . "normal")
  (done . "Michael Albinus <[email-masked]>") (location . "archive")
  (log_modified . 1689593050) (subject . "[PATCH 0/4] debbugs improvements")
  (last_modified . 1689593050) (found) (tags "patch") (package "emacs")
  (originator . "Morgan Smith <[email-masked]>") (archived . t)
  (blockedby) (affects) (mergedwith) (summary) (date . 1686745022)
  (fixed_versions) (id . 64064) (fixed) (found_date) (forwarded)
  (msgid
   . "<[email-masked]>")
  (owner) (found_versions) (fixed_date) (bug_num . 64064)))
--8<---------------cut here---------------end--------------->8---

With this, we could reuse tests with the sam logic, but different data
files. In the future.

> --- /dev/null
> +++ b/test/debbugs-test-helpers.el
> +(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 <[email-masked]>")
> +       (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 <[email-masked]>")
> +       (source . "unknown")
> +       (msgid
> +        . "<[email-masked]>")
> +       (bug_num . 64064) (subject . "[PATCH 0/4] debbugs improvements")
> +       (fixed_date)))))
> +  "Mock result from `soap-invoke' for bug 64064.")

Read from ressource file.

> +(defconst debbugs-test--bug-status
> +  '(((cache_time . 5000) (source . "unknown") (unarchived)
> +     (keywords "patch") (blocks) (pending . "done") (severity . "normal")
> +     (done . "Michael Albinus <[email-masked]>") (location . "archive")
> +     (log_modified . 1689593050) (subject . "[PATCH 0/4] debbugs improvements")
> +     (last_modified . 1689593050) (found) (tags "patch") (package "emacs")
> +     (originator . "Morgan Smith <[email-masked]>") (archived . t)
> +     (blockedby) (affects) (mergedwith) (summary) (date . 1686745022)
> +     (fixed_versions) (id . 64064) (fixed) (found_date) (forwarded)
> +     (msgid
> +      . "<[email-masked]>")
> +     (owner) (found_versions) (fixed_date) (bug_num . 64064)))
> +  "Mock result from `debbugs-get-status' for bug 64064.")

Read from ressource file.