Subject: Re: bug#76446: [PATCH v2 5/5] tests: Support older Emacs sorting conventions

From: Morgan Smith <[email-masked]>
Date: Sun, 23 Feb 2025 14:21:49 -0500

Michael Albinus <[email-masked]> writes:

> Morgan Smith <[email-masked]> writes:
>
>> --- a/test/debbugs-tests.el
>> +++ b/test/debbugs-tests.el
>> +  (eval-and-compile
>> +    (defun alist-sort (x y)
>> +      (string< (car x) (car y))))
>
> I would define this function in debbugs-test-helpers.el. And perhaps
> give it a debbugs-test- prefix; we don't want to pollute the Emacs name
> space.

Ah, my bad.  I wrongly assumed Emacs had lexical scoping.

I've attached an alternative solution.  It would help stabilize the
return value of `debbugs-get-status'.  But also users should not be
relying on `debbugs-get-status' to have a stable return so maybe this is
a bad idea.

> Best regards, Michael.

>From 82a242ad878aee8371229a2c54ff961db03cc93f Mon Sep 17 00:00:00 2001
From: Morgan Smith <[email-masked]>
Date: Fri, 21 Feb 2025 12:49:04 -0500
Subject: [PATCH v3 5/5] Sort return value of `debbugs-get-status'

* debbugs.el(debbugs-get-status): Sort return value to ensure a stable return
value.
* test/debbugs-test-helpers.el(debbugs-test--bug-status): Sort.
* test/debbugs-tests.el(debbugs-test-get-status): Remove unnecessary sorting.
---
 debbugs.el                   |  4 +++-
 test/debbugs-test-helpers.el | 19 ++++++++++---------
 test/debbugs-tests.el        |  8 ++++----
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/debbugs.el b/debbugs.el
index 71c3cba233..288a057b52 100644
--- a/debbugs.el
+++ b/debbugs.el
@@ -590,7 +590,9 @@ Example:
 	  ;; Cache the result, and return.
       (debbugs-put-cache
        (alist-get 'key x)
-       (alist-get 'value x))))
+       (sort (alist-get 'value x)
+             (lambda (x y)
+               (string< (car x) (car y)))))))
       debbugs-soap-invoke-async-object))))
 
 (defun debbugs-get-usertag (&rest query)
diff --git a/test/debbugs-test-helpers.el b/test/debbugs-test-helpers.el
index 7ea6f00dce..14bd261c9f 100644
--- a/test/debbugs-test-helpers.el
+++ b/test/debbugs-test-helpers.el
@@ -55,17 +55,18 @@
 ;; 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 <[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)
+  '(((cache_time . 5000) (affects) (archived . t) (blockedby) (blocks)
+     (bug_num . 64064) (date . 1686745022)
+     (done . "Michael Albinus <[email-masked]>") (fixed) (fixed_date)
+     (fixed_versions) (forwarded) (found) (found_date) (found_versions)
+     (id . 64064) (keywords "patch") (last_modified . 1689593050)
+     (location . "archive") (log_modified . 1689593050) (mergedwith)
      (msgid
       . "<[email-masked]>")
-     (owner) (found_versions) (fixed_date) (bug_num . 64064)))
+     (originator . "Morgan Smith <[email-masked]>") (owner)
+     (package "emacs") (pending . "done") (severity . "normal")
+     (source . "unknown") (subject . "[PATCH 0/4] debbugs improvements") (summary)
+     (tags "patch") (unarchived)))
   "Mock result from `debbugs-get-status' for bug 64064.")
 
 ;;; Helper Functions:
diff --git a/test/debbugs-tests.el b/test/debbugs-tests.el
index da1b9dffe6..16c8c6629a 100644
--- a/test/debbugs-tests.el
+++ b/test/debbugs-tests.el
@@ -64,15 +64,15 @@
 
 (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 (equal (car (debbugs-get-status 64064))
+                 (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 (car (debbugs-get-status 64064))
+                 (car debbugs-test--bug-status)))
   (should (equal debbugs-test--soap-operation-name nil))
   (should (equal debbugs-test--soap-parameters nil)))
 
-- 
2.48.1