From: Jens Lechtenboerger <lechten@wi.uni-muenster.de>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: Eli Zaretskii <eliz@gnu.org>, <emacs-orgmode@gnu.org>
Subject: Re: Proposal: Change publication timestamps
Date: Sun, 15 Sep 2024 14:02:48 +0200 [thread overview]
Message-ID: <871q1lcefr.fsf@wi.uni-muenster.de> (raw)
In-Reply-To: <87le0kleqo.fsf@wi.uni-muenster.de> (Jens Lechtenboerger's message of "Sun, 25 Aug 2024 19:00:15 +0200")
[-- Attachment #1.1: Type: text/plain, Size: 426 bytes --]
On 2024-08-25, Jens Lechtenboerger wrote:
> On 2024-08-15, Ihor Radchenko wrote:
>
>> The patch looks reasonable.
>> Applied, onto main.
>> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=38d1bc67b2
>
> Great, thanks!
>
>> Ideally, it would be nice to have tests as well.
>
> I added test cases in the attached patch.
I amended the commit message. I hope this to be ready for inclusion.
Best wishes,
Jens
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-test-ox-publish.el-Add-tests-for-publish-cache.patch --]
[-- Type: text/x-diff, Size: 7447 bytes --]
From 8914a3c6aa3821917ae10c965f4b1d9aadb4b554 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jens=20Lechtenb=C3=B6rger?= <lechten@wi.uni-muenster.de>
Date: Sun, 25 Aug 2024 18:52:59 +0200
Subject: [PATCH] test-ox-publish.el: Add tests for publish cache
* testing/lisp/test-ox-publish.el (org-test-publish): Add optional
arguments `timestamp-flag' and `pubdir' for control over existing
local variables, add optional argument `keep-pubdir-p' for conditional
deletion of publication directory.
(org-test-publish-touch): New function to change modification time of
file.
(test-org-publish/publish-cache): New function with tests.
* testing/examples/pub-cache/source.org: New source test file.
* testing/examples/pub-cache/config.org: New config file.
---
testing/examples/pub-cache/config.org | 3 +
testing/examples/pub-cache/source.org | 4 ++
testing/lisp/test-ox-publish.el | 98 +++++++++++++++++++++++++--
3 files changed, 98 insertions(+), 7 deletions(-)
create mode 100644 testing/examples/pub-cache/config.org
create mode 100644 testing/examples/pub-cache/source.org
diff --git a/testing/examples/pub-cache/config.org b/testing/examples/pub-cache/config.org
new file mode 100644
index 000000000..70628d3af
--- /dev/null
+++ b/testing/examples/pub-cache/config.org
@@ -0,0 +1,3 @@
+#+OPTIONS: author:nil
+
+This is included.
diff --git a/testing/examples/pub-cache/source.org b/testing/examples/pub-cache/source.org
new file mode 100644
index 000000000..7072f560e
--- /dev/null
+++ b/testing/examples/pub-cache/source.org
@@ -0,0 +1,4 @@
+#+TITLE: Test
+#+INCLUDE: config.org
+
+Nothing special
diff --git a/testing/lisp/test-ox-publish.el b/testing/lisp/test-ox-publish.el
index 6419b8f6c..a8127ccf2 100644
--- a/testing/lisp/test-ox-publish.el
+++ b/testing/lisp/test-ox-publish.el
@@ -24,7 +24,9 @@
\f
;;; Helper functions
-(defun org-test-publish (properties handler &optional remove-prop)
+(defun org-test-publish
+ (properties handler
+ &optional remove-prop timestamp-flag pubdir keep-pubdir-p)
"Publish a project defined by PROPERTIES.
Call HANDLER with the publishing directory as its sole argument.
Unless set otherwise in PROPERTIES, `:base-directory' is set to
@@ -33,12 +35,17 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
Because `org-publish-property' uses `plist-member' to check the
existence of a property, a property with a value nil is different
from a non-existing property. Properties in REMOVE-PROP will be
-removed from the final plist."
+removed from the final plist.
+Assign optional TIMESTAMP-FLAG to `org-publish-use-timestamps-flag'.
+Optional PUBDIR specifies the `:publishing-directory', which
+overrides the default of a randomly generated temporary directory.
+If optional KEEP-PUBDIR-P is non-nil, keep publishing directory,
+including timestamp directory; otherwise, delete it."
(declare (indent 1))
- (let* ((org-publish-use-timestamps-flag nil)
+ (let* ((org-publish-use-timestamps-flag timestamp-flag)
(org-publish-cache nil)
(base-dir (expand-file-name "examples/pub/" org-test-dir))
- (pub-dir (make-temp-file "org-test" t))
+ (pub-dir (or pubdir (make-temp-file "org-test" t)))
(org-publish-timestamp-directory
(expand-file-name ".org-timestamps/" pub-dir))
(props (org-plist-delete-all
@@ -54,8 +61,9 @@ removed from the final plist."
(progn
(org-publish-projects (list project))
(funcall handler pub-dir))
- ;; Clear published data.
- (delete-directory pub-dir t)
+ (unless keep-pubdir-p
+ ;; Clear published data.
+ (delete-directory pub-dir t))
;; Delete auto-generated site-map file, if applicable.
(let ((site-map (and (plist-get properties :auto-sitemap)
(expand-file-name
@@ -69,7 +77,7 @@ removed from the final plist."
;;; Mandatory properties
(ert-deftest test-org-publish/base-extension ()
- "Test `:base-extension' specifications"
+ "Test `:base-extension' specifications."
;; Regular tests.
(should
(equal '("a.org" "b.org")
@@ -114,6 +122,82 @@ removed from the final plist."
(equal (org-test-publish nil func '(:publishing-function))
(org-test-publish '(:publishing-function org-html-publish-to-html) func)))))
+\f
+;;; Publish cache
+
+(defun org-test-publish-touch (file)
+ "Change the modification time of FILE."
+ (let ((buf (get-file-buffer file)))
+ (when buf
+ (kill-buffer buf)))
+ (find-file file)
+ (set-buffer-modified-p t)
+ (save-buffer 0))
+
+(ert-deftest test-org-publish/publish-cache ()
+ "Test publish cache based on timestamps.
+Publish a source file, which includes a config file, to HTML.
+Test updates of source and config file."
+ (let* ((base (expand-file-name "examples/pub-cache/" org-test-dir))
+ (source (expand-file-name "source.org" base))
+ (config (expand-file-name "config.org" base))
+ (pub-dir (make-temp-file "org-test" t))
+ (html (expand-file-name "source.html" pub-dir))
+ (plist `(:publishing-function org-html-publish-to-html
+ :base-extension nil
+ :base-directory ,base
+ :exclude "."
+ :include ("source.org")))
+ (handler (lambda (dir)
+ (remove ".org-timestamps"
+ (cl-remove-if #'file-directory-p
+ (directory-files dir))))))
+ (should
+ ;; Publish HTML from source.org for the first time.
+ (equal '("source.html")
+ (org-test-publish plist handler nil t pub-dir t)))
+ (let ((hmtime (org-publish-cache-mtime-of-src html)))
+ (sleep-for 0.1)
+ ;; Publish again, without source changes.
+ ;; Should not publish, but keep the HTML file unchanged.
+ (org-test-publish plist handler nil t pub-dir t)
+ (should
+ (equal hmtime
+ (org-publish-cache-mtime-of-src html)))
+
+ ;; Pretend the source has changed.
+ ;; Publish again, with a new mtime.
+ (org-test-publish-touch source)
+ (org-test-publish plist handler nil t pub-dir t)
+ (let ((hmtime2 (org-publish-cache-mtime-of-src html)))
+ (should
+ (time-less-p hmtime hmtime2))
+
+ (sleep-for 0.1)
+ ;; Publish again, without source changes.
+ ;; Does not publish, but keeps the HTML file unchanged.
+ (org-test-publish plist handler nil t pub-dir t)
+ (should
+ (equal hmtime2
+ (org-publish-cache-mtime-of-src html)))
+
+ ;; Pretend file config.org has changed.
+ ;; Publish again, with a new mtime.
+ (org-test-publish-touch config)
+ (org-test-publish plist handler nil t pub-dir t)
+ (let ((hmtime3 (org-publish-cache-mtime-of-src html)))
+ (should
+ (time-less-p hmtime2 hmtime3))
+
+ (sleep-for 0.1)
+ ;; Publish again, without source changes.
+ ;; Should not publish, but keep the HTML file unchanged.
+ (org-test-publish plist handler nil t pub-dir t)
+ (should
+ (equal hmtime3
+ (org-publish-cache-mtime-of-src html))))))
+ (delete-directory pub-dir t)))
+
\f
;;; Site-map
--
2.25.1
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6187 bytes --]
next prev parent reply other threads:[~2024-09-15 12:03 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 9:38 Please document the caching and its user options Eli Zaretskii
2024-06-14 13:12 ` Ihor Radchenko
2024-06-14 13:41 ` Eli Zaretskii
2024-06-14 15:31 ` Ihor Radchenko
2024-06-14 15:56 ` Eli Zaretskii
2024-06-15 12:47 ` Ihor Radchenko
2024-06-15 13:01 ` Eli Zaretskii
2024-06-15 14:13 ` Ihor Radchenko
2024-06-15 14:37 ` Eli Zaretskii
2024-06-16 9:05 ` Ihor Radchenko
2024-06-16 10:41 ` Eli Zaretskii
2024-06-23 9:12 ` Björn Bidar
2024-06-15 13:47 ` Ihor Radchenko
2024-06-14 13:56 ` Jens Lechtenboerger
2024-06-14 14:31 ` Publishing cache (was: Please document the caching and its user options) Ihor Radchenko
2024-08-12 7:55 ` Proposal: Change publication timestamps (was: Publishing cache) Jens Lechtenboerger
2024-08-15 18:29 ` Ihor Radchenko
2024-08-25 17:00 ` Proposal: Change publication timestamps Jens Lechtenboerger
2024-09-15 12:02 ` Jens Lechtenboerger [this message]
2024-09-17 18:33 ` Ihor Radchenko
2024-06-16 5:40 ` Please document the caching and its user options Daniel Clemente
2024-06-16 12:36 ` Ihor Radchenko
2024-06-17 12:41 ` Daniel Clemente
2024-06-18 15:53 ` Ihor Radchenko
2024-06-18 16:15 ` Eli Zaretskii
2024-06-18 16:25 ` Ihor Radchenko
2024-06-18 16:33 ` Eli Zaretskii
2024-06-18 16:55 ` Ihor Radchenko
2024-06-19 9:27 ` Colin Baxter
2024-06-19 10:35 ` Ihor Radchenko
2024-06-19 13:04 ` Eli Zaretskii
2024-06-19 13:30 ` Ihor Radchenko
2024-06-19 16:07 ` Colin Baxter
2024-06-19 16:15 ` Ihor Radchenko
2024-06-18 22:06 ` Rudolf Adamkovič
2024-06-19 4:29 ` tomas
2024-06-23 11:45 ` Daniel Clemente
2024-06-24 10:36 ` Ihor Radchenko
2024-06-26 12:59 ` Daniel Clemente
2024-06-26 13:21 ` org-crypt leaking data when encryption password is not entered twice (was: Please document the caching and its user options) Ihor Radchenko
2024-06-27 8:55 ` Daniel Clemente
2024-06-27 10:15 ` org-encrypt-entries is slow (was: org-crypt leaking data when encryption password is not entered twice (was: Please document the caching and its user options)) Ihor Radchenko
2024-07-02 16:54 ` Daniel Clemente
2024-07-02 19:16 ` Ihor Radchenko
2024-07-04 10:36 ` Daniel Clemente
2024-07-06 13:02 ` Ihor Radchenko
2024-07-10 13:09 ` Daniel Clemente
2024-07-11 10:40 ` Ihor Radchenko
2024-07-15 17:00 ` Daniel Clemente
2024-07-20 14:14 ` Ihor Radchenko
2024-07-24 13:47 ` Daniel Clemente
2024-07-25 7:31 ` Ihor Radchenko
2024-07-25 14:08 ` Daniel Clemente
2024-07-25 14:15 ` Ihor Radchenko
2024-10-05 18:56 ` Daniel Clemente
2024-10-20 12:57 ` Ihor Radchenko
2024-06-27 10:34 ` org-crypt leaking data when encryption password is not entered twice (was: Please document the caching and its user options) Ihor Radchenko
2024-07-02 16:53 ` Daniel Clemente
2024-06-27 9:27 ` Please document the caching and its user options Eli Zaretskii
2024-06-27 10:11 ` Ihor Radchenko
2024-06-27 10:30 ` Eli Zaretskii
2024-06-28 12:54 ` Rudolf Adamkovič
2024-06-28 15:31 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871q1lcefr.fsf@wi.uni-muenster.de \
--to=lechten@wi.uni-muenster.de \
--cc=eliz@gnu.org \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).