emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/d-mode e52434e 218/346: d-mode-test.el: Save actual result


From: ELPA Syncer
Subject: [nongnu] elpa/d-mode e52434e 218/346: d-mode-test.el: Save actual result to file in case of mismatch
Date: Sun, 29 Aug 2021 11:00:34 -0400 (EDT)

branch: elpa/d-mode
commit e52434ed465b14cc5b54c8bee7b62a9f39c4e95d
Author: Vladimir Panteleev <git@thecybershadow.net>
Commit: Vladimir Panteleev <git@thecybershadow.net>

    d-mode-test.el: Save actual result to file in case of mismatch
---
 .gitignore     |  1 +
 Makefile       |  1 +
 d-mode-test.el | 18 ++++++++++++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1304fa2..9e02930 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 *.elc
 /.cask/
+/tests/*.res.*
diff --git a/Makefile b/Makefile
index a51239f..6455f89 100644
--- a/Makefile
+++ b/Makefile
@@ -9,5 +9,6 @@ compile:
 
 clean:
        rm -f d-mode.elc
+       find tests -name '*.res.*' -delete
 
 .PHONY:        all test
diff --git a/d-mode-test.el b/d-mode-test.el
index 0616251..a5b98a7 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -253,6 +253,17 @@ Called from the #run snippet of individual test files."
      imenu--index-alist))
    '<))
 
+(defun d-test-save-result (filename)
+  "In case of an unexpected result, save it to a file.
+
+FILENAME is the original (versioned) file name."
+  (write-region
+   nil nil
+   (concat
+    (file-name-sans-extension filename)
+    ".res"
+    (file-name-extension filename t))))
+
 (defun d-test-indent ()
   "Re-indent the current file.
 
@@ -262,7 +273,8 @@ If the resulting indentation ends up being different, raise 
an error."
     (error
      (let ((orig (buffer-string)))
        (let (buffer-read-only)
-        (c-indent-region (point-min) (point-max)))
+        (c-indent-region (point-min) (point-max))
+         (d-test-save-result (buffer-file-name)))
        (error (concat "Test case has been indented differently.\n"
                      
"Expected:\n--------------------\n%s\n--------------------\n"
                      "Got:     
\n--------------------\n%s\n--------------------\n")
@@ -282,11 +294,13 @@ the reference file, raise an error."
          (default-value 'font-lock-fontify-region-function)))
 
   (let* ((hfy-optimisations '(body-text-only merge-adjacent-tags))
+         (html-filename (concat filename ".html"))
         (actual (with-current-buffer (htmlfontify-buffer nil "test.d") 
(buffer-string)))
         (expected (with-temp-buffer
-                    (insert-file-contents (concat filename ".html"))
+                    (insert-file-contents html-filename)
                     (buffer-string))))
     (unless (equal actual expected)
+      (with-temp-buffer (insert actual) (d-test-save-result html-filename))
       (error (concat "Test case has been fontified differently.\n"
                     
"Expected:\n--------------------\n%s\n--------------------\n"
                     "Got:     
\n--------------------\n%s\n--------------------\n")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]