branch: externals/matlab-mode
commit 31c58c719a37dace3f569ef1c5fb85f7ba1d0c8a
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    sweep-test-matlab-ts-mode-indent: create diff file, add *.sh to run it
---
 tests/README-TEST-MATLAB-TREE-SITTER.org  | 32 ++++++++++++-
 tests/sweep-test-matlab-ts-mode-indent.el |  7 +--
 tests/sweep-test-matlab-ts-mode-indent.sh | 23 ++++++++++
 tests/t-utils.el                          | 75 +++++++++++++++----------------
 4 files changed, 95 insertions(+), 42 deletions(-)

diff --git a/tests/README-TEST-MATLAB-TREE-SITTER.org 
b/tests/README-TEST-MATLAB-TREE-SITTER.org
index 698d27f5b0..1473339351 100644
--- a/tests/README-TEST-MATLAB-TREE-SITTER.org
+++ b/tests/README-TEST-MATLAB-TREE-SITTER.org
@@ -237,4 +237,34 @@ You can view the annotated parse tree of a =*.m= file 
using:
    You can click with mouse or type RET on the =[START,END]= ranges to 
highlight the text in
    =NAME.m=.
 
-#  LocalWords:  showall backports libtree SLIB dylib ABI abi MFILES utils VC 
vcvars
+* Test: sweep-test-matlab-ts-mode-indent.sh
+
+Check matlab tree-sitter indent by /sweeping/ over the =*.m= files in a 
directory tree and indenting
+them. The indent sweep test can find issues in matlab-ts-mode *OR* in the tree 
sitter grammar.
+
+To use sweep-test-matlab-ts-mode-indent.sh
+
+1. Run sweep test
+
+   #+begin_src bash
+     cd /PATH/TO/DIRECTORY/CONTAINING/MFILES
+     
/YOUR/WORK/DIRECTORY/Emacs-MATLAB-Mode/tests/sweep-test-matlab-ts-mode-indent.sh
+   #+end_src
+
+   or if mlint (which mlint) isn't on the path
+
+   #+begin_src matlab
+     env PATH=/matlab-install/bin:$PATH \
+         
/YOUR/WORK/DIRECTORY/Emacs-MATLAB-Mode/tests/sweep-test-matlab-ts-mode-indent.sh
+   #+end_src
+
+2. Results
+
+   - *sweep-test-matlab-ts-mode-indent.log*
+
+     This lists the files parsed and whether or not they have syntax errors.
+
+   - *sweep-test-matlab-ts-mode-indent.result.txt*
+
+# LocalWords:  showall backports libtree SLIB dylib ABI abi MFILES utils VC 
vcvars logdone env
+# LocalWords:  inlineimages latexpreview usepackage parskip svg
diff --git a/tests/sweep-test-matlab-ts-mode-indent.el 
b/tests/sweep-test-matlab-ts-mode-indent.el
index 27f5696c94..ee51105990 100644
--- a/tests/sweep-test-matlab-ts-mode-indent.el
+++ b/tests/sweep-test-matlab-ts-mode-indent.el
@@ -33,7 +33,7 @@
 
 (defvar sweep-test-matlab-ts-mode-indent--mlint
   (or (matlab--get-mlint-exe)
-      (error "MLint not found, is matlab on your PATH?")))
+      (error "MLint not found, is /path/to/matlab/bin on your PATH?")))
 
 (defun sweep-test-matlab-ts-mode-indent--syntax-checker (file)
   "MLint FILE, return pair (VALID . CHECK-RESULT).
@@ -87,14 +87,15 @@ the results are displayed on stdout."
   (let ((test-name "sweep-test-matlab-ts-mode-indent")
         (matlab-ts-mode--indent-assert t))
 
+    (add-to-list 'major-mode-remap-alist '(matlab-mode . matlab-ts-mode))
+
     (t-utils-sweep-test-indent
      test-name
      (or directory default-directory)
      (rx ".m" eos)
      #'matlab-ts-mode
      :syntax-checker-fun #'sweep-test-matlab-ts-mode-indent--syntax-checker
-     :check-valid-parse check-valid-parse
-     :save-indent-to-tilde-file t)))
+     :check-valid-parse check-valid-parse)))
 
 (provide 'sweep-test-matlab-ts-mode-indent)
 ;;; sweep-test-matlab-ts-mode-indent.el ends here
diff --git a/tests/sweep-test-matlab-ts-mode-indent.sh 
b/tests/sweep-test-matlab-ts-mode-indent.sh
new file mode 100755
index 0000000000..809b7cfb72
--- /dev/null
+++ b/tests/sweep-test-matlab-ts-mode-indent.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/bash
+# File: Emacs-MATLAB-Mode/tests/sweep-test-matlab-ts-mode-indent.sh
+# Abstract:
+#
+#   See ./README-TEST-MATLAB-TREE-SITTER.org for usage.
+#
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
+
+. "$SCRIPT_DIR/test-tree-sitter-utils.sh"
+
+set -x
+
+emacs --batch -q "${tsExtraLoadPath[@]}" \
+        -L "$EmacsMATLABModeDir" \
+        -l "$EmacsMATLABModeDir/matlab-autoload.el" \
+        -L "$EmacsMATLABModeDir/tests" \
+        -l "$EmacsMATLABModeDir/tests/t-utils.el" \
+        -l "$EmacsMATLABModeDir/tests/sweep-test-matlab-ts-mode-indent.el" \
+        -f sweep-test-matlab-ts-mode-indent
+
+# LocalWords:  usr MFILES dylib slib uname elif esac libtree realpath fn setq 
treesit dev utils
diff --git a/tests/t-utils.el b/tests/t-utils.el
index cc585f1153..b8d55fcf59 100644
--- a/tests/t-utils.el
+++ b/tests/t-utils.el
@@ -510,34 +510,25 @@ baseline check fails."
                test-name lang-file (t-utils--took start-time)))
     error-msg))
 
-(defun t-utils--display-result (test-name directory result &optional 
result-file)
+(defun t-utils--display-result (test-name directory result &optional 
result-file info-message)
   "Display a test RESULT.
-Save result to RESULT-FILE, defaulting to TEST-NAME.result.txt.  If
-noninteractive display message \"See: RESULT-FILE\".  If interactive
-show *TEST-NAME* result buffer with `default-directory' set to DIRECTORY
-containing RESULT."
-
-  (setq result (concat
-                "# -*- mode: fundamental; eval: (compilation-minor-mode 1) 
-*-\n\n"
-                result))
-  (if noninteractive
-      (let ((coding-system-for-write 'no-conversion))
-        (setq result-file (file-truename (or result-file (concat test-name 
".result.txt"))))
-        (write-region result nil result-file)
-        (message "See: %s" result-file))
-    (let ((result-buf (get-buffer-create (concat "*" test-name "*"))))
+Save result to RESULT-FILE, defaulting to DIRECTORY/TEST-NAME.result.txt.
+Optional INFO-MESSAGE is placed at top of the RESULT-FILE.
+When interactive show the RESULT-FILE."
+  (let ((coding-system-for-write 'no-conversion))
+    (setq result-file (file-truename (or result-file
+                                         (concat
+                                          (file-name-as-directory 
(expand-file-name directory))
+                                          test-name ".result.txt"))))
+    (write-region (concat "# -*- mode: fundamental; eval: 
(compilation-minor-mode 1) -*-\n\n"
+                          (when info-message (concat info-message "\n\n"))
+                          result)
+                  nil result-file)
+    (message "See: %s" result-file))
+  (when (not noninteractive)
+    (let ((result-buf (find-file result-file)))
       (with-current-buffer result-buf
-        (read-only-mode -1)
-        (buffer-disable-undo)
-        (setq-local default-directory (file-truename directory))
-        (erase-buffer)
-        (insert result)
-        (goto-char (point-min))
-        (fundamental-mode)
-        (compilation-minor-mode 1) ;; this lets us navigate to errors (would 
be nice to disable "g")
-        (set-buffer-modified-p nil)
-        (read-only-mode 1))
-      (display-buffer result-buf))))
+        (buffer-disable-undo)))))
 
 (defun t-utils--insert-file-for-test (file
                                       &optional file-major-mode setup-callback 
skip-corrupt-check)
@@ -1804,8 +1795,7 @@ else return nil and write a skipping message to LOG-FILE."
                                      check-valid-parse
                                      error-nodes-regexp
                                      log-file
-                                     result-file
-                                     save-indent-to-tilde-file)
+                                     result-file)
   "Sweep test indent on files under DIRECTORY recursively.
 File base names matching LANG-FILE-REGEXP are tested.
 TEST-NAME is used in messages.
@@ -1834,10 +1824,10 @@ it is reported because the tree-sitter parser says it 
has errors and
 the SYNTAX-CHECKER-FUN says it does not.
 
 Next, the buffer is indented using `indent-region' and if this fails it
-is reported.  In addition, the slowest indents are reported.  If
-SAVE-INDENT-TO-TILDE-FILE is non-nil, the indent result is saved to the
-file name with a tilde suffix, e.g. indent of foo.ext is saved to
-foo.ext~.
+is reported.  In addition, the slowest indents are reported.  The result
+of indent is saved to the file name with a tilde suffix, e.g. indent of
+foo.ext is saved to foo.ext~.  Differences are saved to a *.diff file
+which the LOG-FILE with the extension replaced with .diff.
 
 Callers of this function should activate any assertions prior to calling
 this function.  For example, the last rule of the tree-sitter mode may
@@ -1914,9 +1904,12 @@ LANGUAGE tree-sitter that need addressing or some other 
issue."
         (invalid-successful-parse "")
         (indent-errors "")
         (took-ht (make-hash-table :test 'equal))
+        diff-file
         n-lines)
 
     (setq log-file (t-utils--log-create test-name log-file))
+    (setq diff-file (concat (file-name-sans-extension log-file) ".diff"))
+    (message "Diff: %s" diff-file)
 
     (t-utils--log log-file (format "Found %d files to indent %s\n"
                                    (length all-lang-files) (t-utils--took 
start-time)))
@@ -1940,11 +1933,15 @@ LANGUAGE tree-sitter that need addressing or some other 
issue."
                 (indent-region (point-min) (point-max))
                 (puthash lang-file (float-time (time-subtract (current-time) 
indent-start))
                          took-ht)
-                (when save-indent-to-tilde-file
-                  (let ((lang-file-tilde (concat lang-file "~")))
-                    (t-utils--log log-file (format "IndentSavedTo: %s\n" 
lang-file-tilde))
-                    (write-region (point-min) (point-max) lang-file-tilde)))
-                )
+
+                (let ((lang-file-tilde (concat lang-file "~")))
+                  (write-region (point-min) (point-max) lang-file-tilde)
+                  (t-utils--log log-file (format "IndentSavedTo: %s\n" 
lang-file-tilde))
+                  (with-current-buffer (diff-no-select lang-file 
lang-file-tilde "-u" t)
+                    ;; Remove diff summary (\nDiff Finished ...)
+                    (goto-char (point-max))
+                    (forward-line -2)
+                    (write-region (buffer-substring (point-min) (point)) nil 
diff-file t))))
             (error (progn
                      (t-utils--log log-file (format "Failed-indent-region: 
%s\n" lang-file))
                      (setq indent-errors
@@ -1987,7 +1984,9 @@ LANGUAGE tree-sitter that need addressing or some other 
issue."
                            "Slowest-indents:\n"
                            slow-files)))
 
-      (t-utils--display-result test-name directory result result-file))
+      (t-utils--display-result test-name directory result result-file
+                               (concat "No files modified.\n"
+                                       "Indent results for FILE are saved to 
FILE~")))
 
     (message "FINISHED: %s %s" test-name (t-utils--took start-time))))
 

Reply via email to