Ihor Radchenko <yanta...@posteo.net> writes:

> Note that your
> `test-org-tests/test-duplicates-detector-testing-find-duplicates' does
> not look right. I had to adjust the `equal' condition in order to make
> it pass. May you please check if the return value of
> `test-duplicates-detector--find-duplicates' is what you intended?

Yeah, now it works as it should. Thanks. I've made some minor changes
I've described in the attached patch.

>From 8bcd02bac32d3a4442814c2a42b097d642964372 Mon Sep 17 00:00:00 2001
From: Ilya Chernyshov <ichernysho...@gmail.com>
Date: Fri, 9 Feb 2024 17:32:58 +0600
Subject: [PATCH] test-duplicates-detector.el: Simplify the docs, refactor,
 optimize the search

*
test-duplicates-detector.el (test-duplicates-detector-duplicate-forms):
Simplify the docstring.  Add that the list also may have information
about duplicate ert test definitions.

*
test-duplicates-detector.el (test-duplicates-detector--find-duplicates):
Don't go through a duplicate ert test definition.

*
test-duplicates-detector.el (test-duplicates-detector--search-forms-recursively):
Replace (car-safe sub-form) with (car sub-form) because we already
checked that sub-form is a cons.
---
 testing/lisp/test-duplicates-detector.el | 51 ++++++++++--------------
 1 file changed, 22 insertions(+), 29 deletions(-)

diff --git a/testing/lisp/test-duplicates-detector.el b/testing/lisp/test-duplicates-detector.el
index 25293f185..58da27c07 100644
--- a/testing/lisp/test-duplicates-detector.el
+++ b/testing/lisp/test-duplicates-detector.el
@@ -61,24 +61,19 @@ Immediate children inside these are not checked for duplicates.")
     (expand-file-name "lisp" org-test-dir) t "\\.el$")))
 
 (defvar test-duplicates-detector-duplicate-forms nil
-  "A nested list of the form:
+  "A list where each element is either:
 
-  (((file test-name [(form-1 . numerical-order)
-                     (form-2 . numerical-order) ...])
-    (dup-form-1 . (numerical-order [numerical-order ...]))
-  [ (dup-form-2 . (numerical-order [numerical-order ...]))
-    (dup-form-3 . (numerical-order [numerical-order ...]))
-     ...])
-   
-   ((file test-name [(form-1 . numerical-order)
-                     (form-2 . numerical-order) ...])
+  ((file test-name [(form-1 . numerical-order)
+                    (form-2 . numerical-order) ...])
     (dup-form-1 . (numerical-order [numerical-order ...]))
   [ (dup-form-2 . (numerical-order [numerical-order ...]))
     (dup-form-3 . (numerical-order [numerical-order ...]))
      ...])
 
-   ...
-  )
+or
+
+  (test-1-symbol . duplicate-of-test-1-symbol)
+
 
 Where
 
@@ -88,31 +83,29 @@ Where
 is a path to duplicates.  For example, the path for the
 duplicates in the following test:
 
-                                             test-ob-haskell-ghci.el
+                                             test-file.el
 
-  (ertdeftest ob-haskell/session-named-none-means-one-shot-sessions ()
-    \"When no session, use a new session.
-  \"none\" is a special name that means `no session'.\"
+  (ertdeftest test-name ()
+    \"Docstring.\"
     (let ((var-1 \"value\"))
      (when var-1
        (should-not
-        (equal 2 (test-ob-haskell-ghci \":session \"none\"\" \"x\" nil)))
-       (test-ob-haskell-ghci \":session none\" \"x=2\")
+        (equal 2 (some-func \"string\" \"x\" nil)))
+       (some-func \"string\" \"x=2\")
        (should-not
-        (equal 2 (test-ob-haskell-ghci \":session \"none\"\" \"x\" nil)))
-       (test-ob-haskell-ghci \":session none\" \"x=2\"))))
+        (equal 2 (some-func \"string\" \"x\" nil)))
+       (some-func \"string\" \"x=2\"))))
 
 would look like this:
 
-  (\"test-ob-haskell-ghci.el\"
-    ob-haskell/session-named-none-means-one-shot-sessions
+  (\"/absolute/path/to/test-file.el\"
+    test-name
     (let . 4) (when . 2))
 
 And the records about the duplicates would look like this:
 
-  ((test-ob-haskell-ghci \":session none\" \"x=2\") 5 3)
   ((should-not
-    (equal 2 (test-ob-haskell-ghci \":session \"none\"\" \"x\" nil))) 4 2)")
+    (equal 2 (some-func \"string\" \"x\" nil))) 4 2)")
 
 (defvar test-duplicates-detector-forms nil
   "Nested alist of found forms and paths to them (not filtered).")
@@ -168,9 +161,9 @@ Duplicate forms will be written to
 				  (cdddr x))))
 			     found-deftests)))
                     (push (cons test-name (cadr f)) duplicate-tests)
-		  (push deftest found-deftests))
-		(test-duplicates-detector--search-forms-recursively
-		 deftest (list file (cadr deftest)))))))))
+		  (push deftest found-deftests)
+                  (test-duplicates-detector--search-forms-recursively
+		   deftest (list file test-name)))))))))
     (setq test-duplicates-detector-duplicate-forms
           (seq-filter
 	   #'cdr
@@ -239,11 +232,11 @@ Write each form to `test-duplicates-detector-forms'"
                      (alist-get form-path test-duplicates-detector-forms
                                 nil nil #'equal)
                      nil nil #'equal-including-properties)))
-        (unless (memq (car-safe sub-form)
+        (unless (memq (car sub-form)
 		      '(should-not should should-error))
 	  (test-duplicates-detector--search-forms-recursively
            sub-form
-           (append form-path (list (cons (car-safe sub-form) idx))))))
+           (append form-path (list (cons (car sub-form) idx))))))
       (cl-incf idx))))
 
 ;;;; Testing the detector itself
-- 
2.41.0

Reply via email to