Ihor Radchenko <yanta...@gmail.com> writes:

> I do not see how it is related.  Do you see the error with your config
> or with clean Emacs?

Good point.  Just with my config.  Ignoring for now!

> Oops. Another side-effect of `buffer-file-name'. Fixed now.

Thank you!

>> (2) no corruption happens to the original file after export.
>
> Done.

Superb!

>> (1) re-opening the file after export always re-opens it, and
>
> I am not sure how to test this part.

How about the attached patch?

It mirrors the manual steps (find-file, export, kill-buffer, find-file),
except it calls just the 'org-export-copy-buffer' procedure instead of
exporting to HTML.  The test fails without your fix and passes with it.

Rudy

>From 8bc0f1e807df653634e77e5e5fc543a2e82191c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salu...@me.com>
Date: Fri, 7 Oct 2022 16:04:28 +0200
Subject: [PATCH] Add a regression test for 'org-export-copy-buffer'

* testing/lisp/test-ox.el (test-org-export/org-export-copy-buffer):
Make sure that 'find-file' after 'org-export-copy-buffer' re-opens the
original file instead of the copy buffer.
---
 testing/lisp/test-ox.el | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 90a9eb3aa..60bf04316 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -63,20 +63,31 @@ variable, and communication channel under `info'."
 
 (ert-deftest test-org-export/org-export-copy-buffer ()
   "Test `org-export-copy-buffer' specifications."
-  ;; The buffer copy must not cause overwriting the original file
-  ;; buffer under any circumstances.
+  ;; The copy must not overwrite the original file.
   (org-test-with-temp-text-in-file
       "* Heading"
     (let ((file (buffer-file-name)))
       (with-current-buffer (org-export-copy-buffer)
-        (insert "This must not go into actual file.")
+        (insert "This must not go into the original file.")
         (save-buffer)
         (should
          (equal
           "* Heading"
           (with-temp-buffer
             (insert-file-contents file)
-            (buffer-string))))))))
+            (buffer-string)))))))
+  ;; The copy must not show when re-opening the original file.
+  (org-test-with-temp-text-in-file
+      "* Heading"
+    (let ((file (buffer-file-name)))
+      (with-current-buffer (org-export-copy-buffer)
+        (insert "This must not show as the original file.")
+        (save-buffer))
+      (should
+       (equal "* Heading"
+              (with-temp-buffer
+                (find-file file)
+                (buffer-string)))))))
 
 (ert-deftest test-org-export/bind-keyword ()
   "Test reading #+BIND: keywords."
-- 
2.37.3

-- 
"Chop your own wood and it will warm you twice."
-- Henry Ford; Francis Kinloch, 1819; Henry David Thoreau, 1854

Rudolf Adamkovič <salu...@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

Reply via email to