2016-08-23 16:13:56 -04:00
|
|
|
|
;;;; org-test.el --- Tests for Org
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2015-02-15 19:40:07 -05:00
|
|
|
|
;; Copyright (c) 2010-2015 Sebastian Rose, Eric Schulte
|
2010-10-02 17:23:27 -04:00
|
|
|
|
;; Authors:
|
|
|
|
|
;; Sebastian Rose, Hannover, Germany, sebastian_rose gmx de
|
2010-10-03 12:45:07 -04:00
|
|
|
|
;; Eric Schulte, Santa Fe, New Mexico, USA, schulte.eric gmail com
|
2011-09-18 04:35:50 -04:00
|
|
|
|
;; David Maus, Brunswick, Germany, dmaus ictsoc de
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
|
|
|
|
;; Released under the GNU General Public License version 3
|
|
|
|
|
;; see: http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
|
|
2011-09-18 04:35:50 -04:00
|
|
|
|
;; Definition of `special-mode' copied from Emacs23's simple.el to be
|
|
|
|
|
;; provide a testing environment for Emacs22.
|
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
;;;; Comments:
|
|
|
|
|
|
|
|
|
|
;; Interactive testing for Org mode.
|
|
|
|
|
|
2010-10-03 12:45:07 -04:00
|
|
|
|
;; The heart of all this is the commands `org-test-current-defun'. If
|
|
|
|
|
;; called while in a `defun' all ert tests with names matching the
|
|
|
|
|
;; name of the function are run.
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2011-09-12 11:50:28 -04:00
|
|
|
|
;;; Test Development
|
|
|
|
|
;; For test development purposes a number of navigation and test
|
|
|
|
|
;; function construction routines are available as a git submodule
|
|
|
|
|
;; (jump.el)
|
|
|
|
|
;; Install with...
|
|
|
|
|
;; $ git submodule init
|
|
|
|
|
;; $ git submodule update
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Code:
|
2013-03-13 06:23:56 -04:00
|
|
|
|
|
|
|
|
|
;;; Ob constants
|
|
|
|
|
|
|
|
|
|
(defconst org-test-file-ob-anchor
|
|
|
|
|
"94839181-184f-4ff4-a72f-94214df6f5ba")
|
|
|
|
|
|
|
|
|
|
(defconst org-test-link-in-heading-file-ob-anchor
|
|
|
|
|
"a8b1d111-eca8-49f0-8930-56d4f0875155")
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(unless (and (boundp 'org-batch-test) org-batch-test)
|
|
|
|
|
(let* ((org-test-dir (expand-file-name
|
|
|
|
|
(file-name-directory
|
|
|
|
|
(or load-file-name buffer-file-name))))
|
|
|
|
|
(org-lisp-dir (expand-file-name
|
|
|
|
|
(concat org-test-dir "../lisp"))))
|
|
|
|
|
|
|
|
|
|
(unless (featurep 'org)
|
|
|
|
|
(setq load-path (cons org-lisp-dir load-path))
|
|
|
|
|
(require 'org)
|
|
|
|
|
(require 'org-id)
|
|
|
|
|
(require 'ox)
|
|
|
|
|
(org-babel-do-load-languages
|
2014-01-31 11:02:03 -05:00
|
|
|
|
'org-babel-load-languages '((shell . t) (org . t))))
|
2013-05-19 03:20:17 -04:00
|
|
|
|
|
2016-07-25 10:11:51 -04:00
|
|
|
|
(let ((load-path (cons org-test-dir
|
|
|
|
|
(cons (expand-file-name "jump" org-test-dir)
|
|
|
|
|
load-path))))
|
|
|
|
|
(require 'cl-lib)
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(require 'ert)
|
|
|
|
|
(require 'ert-x)
|
2016-07-25 10:11:51 -04:00
|
|
|
|
(when (file-exists-p (expand-file-name "jump/jump.el" org-test-dir))
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(require 'jump)
|
|
|
|
|
(require 'which-func)))))
|
2011-09-09 16:21:06 -04:00
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
(defconst org-test-default-test-file-name "tests.el"
|
|
|
|
|
"For each defun a separate file with tests may be defined.
|
|
|
|
|
tests.el is the fallback or default if you like.")
|
|
|
|
|
|
|
|
|
|
(defconst org-test-default-directory-name "testing"
|
|
|
|
|
"Basename or the directory where the tests live.
|
|
|
|
|
org-test searches this directory up the directory tree.")
|
|
|
|
|
|
2010-10-03 12:45:07 -04:00
|
|
|
|
(defconst org-test-dir
|
|
|
|
|
(expand-file-name (file-name-directory (or load-file-name buffer-file-name))))
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-10-03 20:44:10 -04:00
|
|
|
|
(defconst org-base-dir
|
|
|
|
|
(expand-file-name ".." org-test-dir))
|
|
|
|
|
|
2010-10-04 21:36:39 -04:00
|
|
|
|
(defconst org-test-example-dir
|
|
|
|
|
(expand-file-name "examples" org-test-dir))
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-10-04 21:36:39 -04:00
|
|
|
|
(defconst org-test-file
|
|
|
|
|
(expand-file-name "normal.org" org-test-example-dir))
|
|
|
|
|
|
2010-10-04 22:07:51 -04:00
|
|
|
|
(defconst org-test-no-heading-file
|
|
|
|
|
(expand-file-name "no-heading.org" org-test-example-dir))
|
2010-10-04 21:36:39 -04:00
|
|
|
|
|
org-attach*, org, org-manual, org-news, ox-html, testing/*
* lisp/org-attach.el
Changed the way attachments deal with property-inheritance. It now
adheres to the =org-use-property-inheritance= setting by default but
it can be customized if needed (I recommend to enable it!).
The property ATTACH_DIR is deprecated in favour of the shorter and simpler
property DIR.
Added an explicit option to =org-attach= for unsetting
attachment-directories (i.e. remove DIR property and deal with the
attachments by interaction).
Added attachment link type with the prefix "attachment:".
Added customizations:
- org-attach-dir-relative
- org-attach-preferred-new-method
- org-attach-use-inheritance
- org-attach-id-to-path-function
Hooks added:
- org-attach-after-change-hook
- org-attach-open-hook
A new linktype "attachment" is added in order to reduce
link-duplication when wanting to link to files in attached folders of
nodes. This works for both ID and DIR properties. The goal is to
make the functionality for attachment links mirror the functionality
for file links.
* lisp/org-attach-git.el
New file, existing functionality. Code here has been factored out
from org-attach.el and if GIT-functionality is to be used this module
needs to be required sepatately. It extends org-attach by use of its
hooks.
Activating git functionality in org-attach is done by loading
org-attach-git from now on, instead of customizing a variable.
Naming of both functions and tests has been modified to match the move
of functionality into its own module.
* lisp/org.el
Inline images are shown also using attachment-links, exactly the same
as it works for file-links today.
Make org-open-at-point respect ARG when opening attachment-dir.
* lisp/org-compat.el
org-attach-directory has been deprecated in favour for
org-attach-id-dir. The new name matches its purpose better.
* lisp/ox-html.el
Export attachment links to images as inline images, in the same way as
file links work today.
* etc/ORG-NEWS
Mention the changes in this patch.
* doc/org-manual.org
The chapter "Refile, Copy, Archive" has been split into two separate
chapters.
- "Refile, Copy and Archiving" for information related to moving
existing data around.
- "Capture, Attachments, RSS Feeds and Protocols" for information
related to working with external data.
The attachment-part has been rewritten and extended to match the
changes in this patch.
The new attachment link type is mentioned both inside the attachments
chapter and in the chapter dealing with links.
Documentation related to external links has been improved.
* testing/lisp/test-org-attach-annex.el
Require org-attach-git instead of org-attach, since this file tests
the GIT-functionality.
* testing/lisp/test-org-attach.el
Add tests for org-attach.
* testing/org-test.el
Define a symbol for a file to test attachments with.
* testing/examples/*
A bunch of new example files and folders are created and are used in
testing of org-attach to verify its functionality.
2018-11-25 15:38:44 -05:00
|
|
|
|
(defconst org-test-attachments-file
|
|
|
|
|
(expand-file-name "attachments.org" org-test-example-dir))
|
|
|
|
|
|
2010-10-04 21:36:39 -04:00
|
|
|
|
(defconst org-test-link-in-heading-file
|
|
|
|
|
(expand-file-name "link-in-heading.org" org-test-dir))
|
2010-10-04 10:29:00 -04:00
|
|
|
|
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(defconst org-id-locations-file
|
|
|
|
|
(expand-file-name ".test-org-id-locations" org-test-dir))
|
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-10-03 12:45:07 -04:00
|
|
|
|
;;; Functions for writing tests
|
2011-11-13 14:30:25 -05:00
|
|
|
|
(put 'missing-test-dependency
|
|
|
|
|
'error-conditions
|
|
|
|
|
'(error missing-test-dependency))
|
|
|
|
|
|
2011-09-21 18:34:43 -04:00
|
|
|
|
(defun org-test-for-executable (exe)
|
|
|
|
|
"Throw an error if EXE is not available.
|
|
|
|
|
This can be used at the top of code-block-language specific test
|
|
|
|
|
files to avoid loading the file on systems without the
|
|
|
|
|
executable."
|
2017-07-14 15:55:17 -04:00
|
|
|
|
(unless (cl-reduce
|
2011-09-26 08:16:55 -04:00
|
|
|
|
(lambda (acc dir)
|
|
|
|
|
(or acc (file-exists-p (expand-file-name exe dir))))
|
|
|
|
|
exec-path :initial-value nil)
|
2011-11-13 14:30:25 -05:00
|
|
|
|
(signal 'missing-test-dependency (list exe))))
|
2011-09-21 18:34:43 -04:00
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
(defun org-test-buffer (&optional file)
|
|
|
|
|
"TODO: Setup and return a buffer to work with.
|
2016-02-03 23:33:28 -05:00
|
|
|
|
If file is non-nil insert its contents in there.")
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
|
|
|
|
(defun org-test-compare-with-file (&optional file)
|
|
|
|
|
"TODO: Compare the contents of the test buffer with FILE.
|
|
|
|
|
If file is not given, search for a file named after the test
|
|
|
|
|
currently executed.")
|
|
|
|
|
|
2010-10-06 12:23:50 -04:00
|
|
|
|
(defmacro org-test-at-id (id &rest body)
|
|
|
|
|
"Run body after placing the point in the headline identified by ID."
|
|
|
|
|
(declare (indent 1))
|
|
|
|
|
`(let* ((id-location (org-id-find ,id))
|
|
|
|
|
(id-file (car id-location))
|
|
|
|
|
(visited-p (get-file-buffer id-file))
|
|
|
|
|
to-be-removed)
|
2013-01-27 18:09:58 -05:00
|
|
|
|
(unwind-protect
|
|
|
|
|
(save-window-excursion
|
|
|
|
|
(save-match-data
|
|
|
|
|
(org-id-goto ,id)
|
|
|
|
|
(setq to-be-removed (current-buffer))
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(progn
|
|
|
|
|
(org-show-subtree)
|
2017-12-06 10:03:23 -05:00
|
|
|
|
(org-show-all '(blocks)))
|
2013-01-27 18:09:58 -05:00
|
|
|
|
(error nil))
|
|
|
|
|
(save-restriction ,@body)))
|
|
|
|
|
(unless (or visited-p (not to-be-removed))
|
|
|
|
|
(kill-buffer to-be-removed)))))
|
2012-01-11 12:11:15 -05:00
|
|
|
|
(def-edebug-spec org-test-at-id (form body))
|
2010-10-06 12:23:50 -04:00
|
|
|
|
|
2010-10-04 10:06:16 -04:00
|
|
|
|
(defmacro org-test-in-example-file (file &rest body)
|
2016-08-23 16:13:56 -04:00
|
|
|
|
"Execute body in the Org example file."
|
2010-10-04 10:06:16 -04:00
|
|
|
|
(declare (indent 1))
|
2010-10-04 21:36:39 -04:00
|
|
|
|
`(let* ((my-file (or ,file org-test-file))
|
2010-10-04 10:29:00 -04:00
|
|
|
|
(visited-p (get-file-buffer my-file))
|
2019-05-25 21:34:34 -04:00
|
|
|
|
to-be-removed
|
|
|
|
|
results)
|
2010-10-03 12:45:07 -04:00
|
|
|
|
(save-window-excursion
|
|
|
|
|
(save-match-data
|
2010-10-04 10:29:00 -04:00
|
|
|
|
(find-file my-file)
|
2011-10-11 03:07:27 -04:00
|
|
|
|
(unless (eq major-mode 'org-mode)
|
2011-09-25 03:26:50 -04:00
|
|
|
|
(org-mode))
|
2010-10-03 12:45:07 -04:00
|
|
|
|
(setq to-be-removed (current-buffer))
|
|
|
|
|
(goto-char (point-min))
|
2010-10-04 10:29:00 -04:00
|
|
|
|
(condition-case nil
|
|
|
|
|
(progn
|
|
|
|
|
(outline-next-visible-heading 1)
|
|
|
|
|
(org-show-subtree)
|
2017-12-06 10:03:23 -05:00
|
|
|
|
(org-show-all '(blocks)))
|
2010-10-04 10:29:00 -04:00
|
|
|
|
(error nil))
|
2019-05-25 21:34:34 -04:00
|
|
|
|
(setq results (save-restriction ,@body))))
|
2010-10-03 12:45:07 -04:00
|
|
|
|
(unless visited-p
|
2019-05-25 21:34:34 -04:00
|
|
|
|
(kill-buffer to-be-removed))
|
|
|
|
|
results))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
(def-edebug-spec org-test-in-example-file (form body))
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-10-04 10:06:16 -04:00
|
|
|
|
(defmacro org-test-at-marker (file marker &rest body)
|
|
|
|
|
"Run body after placing the point at MARKER in FILE.
|
|
|
|
|
Note the uuidgen command-line command can be useful for
|
|
|
|
|
generating unique markers for insertion as anchors into org
|
|
|
|
|
files."
|
|
|
|
|
(declare (indent 2))
|
|
|
|
|
`(org-test-in-example-file ,file
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(re-search-forward (regexp-quote ,marker))
|
|
|
|
|
,@body))
|
2011-11-18 13:29:47 -05:00
|
|
|
|
(def-edebug-spec org-test-at-marker (form form body))
|
2010-10-04 10:06:16 -04:00
|
|
|
|
|
2011-09-19 12:01:32 -04:00
|
|
|
|
(defmacro org-test-with-temp-text (text &rest body)
|
2016-08-23 16:13:56 -04:00
|
|
|
|
"Run body in a temporary buffer with Org mode as the active
|
2011-09-19 12:01:32 -04:00
|
|
|
|
mode holding TEXT. If the string \"<point>\" appears in TEXT
|
2011-09-23 17:49:31 -04:00
|
|
|
|
then remove it and place the point there before running BODY,
|
|
|
|
|
otherwise place the point at the beginning of the inserted text."
|
2011-09-19 12:01:32 -04:00
|
|
|
|
(declare (indent 1))
|
2015-01-22 00:59:04 -05:00
|
|
|
|
`(let ((inside-text (if (stringp ,text) ,text (eval ,text)))
|
|
|
|
|
(org-mode-hook nil))
|
2013-11-17 15:31:03 -05:00
|
|
|
|
(with-temp-buffer
|
2011-09-20 11:01:11 -04:00
|
|
|
|
(org-mode)
|
2014-04-10 05:53:27 -04:00
|
|
|
|
(let ((point (string-match "<point>" inside-text)))
|
2014-04-09 13:39:16 -04:00
|
|
|
|
(if point
|
|
|
|
|
(progn
|
|
|
|
|
(insert (replace-match "" nil nil inside-text))
|
|
|
|
|
(goto-char (1+ (match-beginning 0))))
|
2014-04-10 05:53:27 -04:00
|
|
|
|
(insert inside-text)
|
|
|
|
|
(goto-char (point-min))))
|
2020-02-12 03:37:04 -05:00
|
|
|
|
(font-lock-ensure (point-min) (point-max))
|
2012-12-15 02:00:30 -05:00
|
|
|
|
,@body)))
|
2011-11-18 13:29:47 -05:00
|
|
|
|
(def-edebug-spec org-test-with-temp-text (form body))
|
|
|
|
|
|
|
|
|
|
(defmacro org-test-with-temp-text-in-file (text &rest body)
|
2019-05-25 21:34:34 -04:00
|
|
|
|
"Run body in a temporary file buffer with Org mode as the active mode.
|
|
|
|
|
If the string \"<point>\" appears in TEXT then remove it and
|
|
|
|
|
place the point there before running BODY, otherwise place the
|
|
|
|
|
point at the beginning of the buffer."
|
2011-11-18 13:29:47 -05:00
|
|
|
|
(declare (indent 1))
|
2019-05-25 21:34:34 -04:00
|
|
|
|
`(let ((file (make-temp-file "org-test"))
|
|
|
|
|
(inside-text (if (stringp ,text) ,text (eval ,text)))
|
|
|
|
|
buffer)
|
|
|
|
|
(with-temp-file file (insert inside-text))
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(progn
|
|
|
|
|
(setq buffer (find-file file))
|
|
|
|
|
(when (re-search-forward "<point>" nil t)
|
|
|
|
|
(replace-match ""))
|
|
|
|
|
(org-mode)
|
|
|
|
|
(progn ,@body))
|
|
|
|
|
(let ((kill-buffer-query-functions nil))
|
|
|
|
|
(when buffer
|
|
|
|
|
(set-buffer buffer)
|
|
|
|
|
;; Ignore changes, we're deleting the file in the next step
|
|
|
|
|
;; anyways.
|
|
|
|
|
(set-buffer-modified-p nil)
|
|
|
|
|
(kill-buffer))
|
|
|
|
|
(delete-file file)))))
|
2011-11-18 13:29:47 -05:00
|
|
|
|
(def-edebug-spec org-test-with-temp-text-in-file (form body))
|
2011-09-19 12:01:32 -04:00
|
|
|
|
|
2012-12-28 08:59:17 -05:00
|
|
|
|
(defun org-test-table-target-expect (target &optional expect laps
|
|
|
|
|
&rest tblfm)
|
|
|
|
|
"For all TBLFM: Apply the formula to TARGET, compare EXPECT with result.
|
|
|
|
|
Either LAPS and TBLFM are nil and the table will only be aligned
|
|
|
|
|
or LAPS is the count of recalculations that should be made on
|
|
|
|
|
each TBLFM. To save ERT run time keep LAPS as low as possible to
|
|
|
|
|
get the table stable. Anyhow, if LAPS is 'iterate then iterate,
|
|
|
|
|
but this will run one recalculation longer. When EXPECT is nil
|
|
|
|
|
it will be set to TARGET.
|
|
|
|
|
|
2013-04-26 11:07:55 -04:00
|
|
|
|
When running a test interactively in ERT is not enough and you
|
|
|
|
|
need to examine the target table with e. g. the Org formula
|
|
|
|
|
debugger or an Emacs Lisp debugger (e. g. with point in a data
|
|
|
|
|
field and calling the instrumented `org-table-eval-formula') then
|
|
|
|
|
copy and paste the table with formula from the ERT results buffer
|
|
|
|
|
or temporarily substitute the `org-test-with-temp-text' of this
|
|
|
|
|
function with `org-test-with-temp-text-in-file'. Also consider
|
|
|
|
|
setting `pp-escape-newlines' to nil manually."
|
2012-12-28 08:59:17 -05:00
|
|
|
|
(require 'pp)
|
2015-01-22 00:59:04 -05:00
|
|
|
|
(require 'ert)
|
2012-12-28 08:59:17 -05:00
|
|
|
|
(let ((back pp-escape-newlines) (current-tblfm))
|
|
|
|
|
(unless tblfm
|
|
|
|
|
(should-not laps)
|
|
|
|
|
(push "" tblfm)) ; Dummy formula.
|
|
|
|
|
(unless expect (setq expect target))
|
|
|
|
|
(while (setq current-tblfm (pop tblfm))
|
|
|
|
|
(org-test-with-temp-text (concat target current-tblfm)
|
2013-04-26 11:07:55 -04:00
|
|
|
|
;; Search the last of possibly several tables, let the ERT
|
|
|
|
|
;; test fail if not found.
|
|
|
|
|
(goto-char (point-max))
|
2012-12-28 08:59:17 -05:00
|
|
|
|
(while (not (org-at-table-p))
|
2013-04-26 11:07:55 -04:00
|
|
|
|
(should (eq 0 (forward-line -1))))
|
2012-12-28 08:59:17 -05:00
|
|
|
|
(when laps
|
|
|
|
|
(if (and (symbolp laps) (eq laps 'iterate))
|
|
|
|
|
(should (org-table-recalculate 'iterate t))
|
|
|
|
|
(should (integerp laps))
|
|
|
|
|
(should (< 0 laps))
|
|
|
|
|
(let ((cnt laps))
|
|
|
|
|
(while (< 0 cnt)
|
|
|
|
|
(should (org-table-recalculate 'all t))
|
|
|
|
|
(setq cnt (1- cnt))))))
|
|
|
|
|
(org-table-align)
|
|
|
|
|
(setq pp-escape-newlines nil)
|
|
|
|
|
;; Declutter the ERT results buffer by giving only variables
|
|
|
|
|
;; and not directly the forms to `should'.
|
|
|
|
|
(let ((expect (concat expect current-tblfm))
|
|
|
|
|
(result (buffer-substring-no-properties
|
|
|
|
|
(point-min) (point-max))))
|
|
|
|
|
(should (equal expect result)))
|
|
|
|
|
;; If `should' passed then set back `pp-escape-newlines' here,
|
|
|
|
|
;; else leave it nil as a side effect to see the failed table
|
|
|
|
|
;; on multiple lines in the ERT results buffer.
|
|
|
|
|
(setq pp-escape-newlines back)))))
|
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-10-03 20:44:10 -04:00
|
|
|
|
;;; Navigation Functions
|
2011-09-12 11:50:28 -04:00
|
|
|
|
(when (featurep 'jump)
|
2011-09-20 03:44:24 -04:00
|
|
|
|
(defjump org-test-jump
|
|
|
|
|
(("lisp/\\1.el" . "testing/lisp/test-\\1.el")
|
|
|
|
|
("lisp/\\1.el" . "testing/lisp/\\1.el/test.*.el")
|
|
|
|
|
("testing/lisp/test-\\1.el" . "lisp/\\1.el")
|
2012-03-19 16:38:12 -04:00
|
|
|
|
("testing/lisp/\\1.el" . "lisp/\\1.el/test.*.el"))
|
2011-09-20 03:44:24 -04:00
|
|
|
|
(concat org-base-dir "/")
|
2016-08-23 16:13:56 -04:00
|
|
|
|
"Jump between Org files and their tests."
|
2011-09-20 03:44:24 -04:00
|
|
|
|
(lambda (path)
|
|
|
|
|
(let* ((full-path (expand-file-name path org-base-dir))
|
|
|
|
|
(file-name (file-name-nondirectory path))
|
|
|
|
|
(name (file-name-sans-extension file-name)))
|
|
|
|
|
(find-file full-path)
|
|
|
|
|
(insert
|
|
|
|
|
";;; " file-name "\n\n"
|
|
|
|
|
";; Copyright (c) " (nth 5 (decode-time (current-time)))
|
|
|
|
|
" " user-full-name "\n"
|
|
|
|
|
";; Authors: " user-full-name "\n\n"
|
|
|
|
|
";; Released under the GNU General Public License version 3\n"
|
|
|
|
|
";; see: http://www.gnu.org/licenses/gpl-3.0.html\n\n"
|
|
|
|
|
";;;; Comments:\n\n"
|
2016-08-23 16:13:56 -04:00
|
|
|
|
";; Template test file for Org tests\n\n"
|
2011-09-20 03:44:24 -04:00
|
|
|
|
"\n"
|
|
|
|
|
";;; Code:\n"
|
|
|
|
|
"(let ((load-path (cons (expand-file-name\n"
|
|
|
|
|
" \"..\" (file-name-directory\n"
|
|
|
|
|
" (or load-file-name buffer-file-name)))\n"
|
|
|
|
|
" load-path)))\n"
|
2013-03-13 06:23:56 -04:00
|
|
|
|
" (require 'org-test)\n\n"
|
2011-09-20 03:44:24 -04:00
|
|
|
|
"\n"
|
|
|
|
|
";;; Tests\n"
|
|
|
|
|
"(ert-deftest " name "/example-test ()\n"
|
|
|
|
|
" \"Just an example to get you started.\"\n"
|
|
|
|
|
" (should t)\n"
|
|
|
|
|
" (should-not nil)\n"
|
|
|
|
|
" (should-error (error \"errr...\")))\n\n\n"
|
|
|
|
|
"(provide '" name ")\n\n"
|
|
|
|
|
";;; " file-name " ends here\n") full-path))
|
|
|
|
|
(lambda () ((lambda (res) (if (listp res) (car res) res)) (which-function)))))
|
2010-10-02 18:50:57 -04:00
|
|
|
|
|
2010-10-05 22:51:04 -04:00
|
|
|
|
(define-key emacs-lisp-mode-map "\M-\C-j" 'org-test-jump)
|
|
|
|
|
|
2011-02-01 00:28:34 -05:00
|
|
|
|
|
|
|
|
|
;;; Miscellaneous helper functions
|
|
|
|
|
(defun org-test-strip-text-props (s)
|
|
|
|
|
"Return S without any text properties."
|
|
|
|
|
(let ((noprop (copy-sequence s)))
|
|
|
|
|
(set-text-properties 0 (length noprop) nil noprop)
|
|
|
|
|
noprop))
|
2010-10-03 20:44:10 -04:00
|
|
|
|
|
2011-03-02 13:07:15 -05:00
|
|
|
|
|
|
|
|
|
(defun org-test-string-exact-match (regex string &optional start)
|
2016-07-25 10:11:51 -04:00
|
|
|
|
"Case sensitive string-match"
|
2011-03-02 13:07:15 -05:00
|
|
|
|
(let ((case-fold-search nil)
|
|
|
|
|
(case-replace nil))
|
|
|
|
|
(if(and (equal regex "")
|
|
|
|
|
(not(equal string "")))
|
|
|
|
|
nil
|
|
|
|
|
(if (equal 0 (string-match regex string start))
|
|
|
|
|
t
|
|
|
|
|
nil))))
|
|
|
|
|
|
2010-10-03 20:44:10 -04:00
|
|
|
|
;;; Load and Run tests
|
2010-10-03 21:03:41 -04:00
|
|
|
|
(defun org-test-load ()
|
2016-08-23 16:13:56 -04:00
|
|
|
|
"Load up the Org test suite."
|
2010-10-02 17:23:27 -04:00
|
|
|
|
(interactive)
|
2016-06-14 15:26:11 -04:00
|
|
|
|
(cl-flet ((rld (base)
|
2011-09-21 18:34:43 -04:00
|
|
|
|
;; Recursively load all files, if files throw errors
|
|
|
|
|
;; then silently ignore the error and continue to the
|
|
|
|
|
;; next file. This allows files to error out if
|
|
|
|
|
;; required executables aren't available.
|
|
|
|
|
(mapc
|
|
|
|
|
(lambda (path)
|
|
|
|
|
(if (file-directory-p path)
|
2011-11-13 09:43:34 -05:00
|
|
|
|
(rld path)
|
2011-11-13 14:30:25 -05:00
|
|
|
|
(condition-case err
|
|
|
|
|
(when (string-match "^[A-Za-z].*\\.el$"
|
2012-12-15 02:49:23 -05:00
|
|
|
|
(file-name-nondirectory path))
|
2011-11-13 14:30:25 -05:00
|
|
|
|
(load-file path))
|
|
|
|
|
(missing-test-dependency
|
|
|
|
|
(let ((name (intern
|
|
|
|
|
(concat "org-missing-dependency/"
|
|
|
|
|
(file-name-nondirectory
|
|
|
|
|
(file-name-sans-extension path))))))
|
|
|
|
|
(eval `(ert-deftest ,name ()
|
|
|
|
|
:expected-result :failed (should nil))))))))
|
2011-09-21 18:34:43 -04:00
|
|
|
|
(directory-files base 'full
|
|
|
|
|
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.el$"))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
(rld (expand-file-name "lisp" org-test-dir))))
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-10-03 12:45:07 -04:00
|
|
|
|
(defun org-test-current-defun ()
|
|
|
|
|
"Test the current function."
|
2010-10-02 17:23:27 -04:00
|
|
|
|
(interactive)
|
2010-11-02 16:11:16 -04:00
|
|
|
|
(ert (which-function)))
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2010-11-22 13:29:05 -05:00
|
|
|
|
(defun org-test-current-file ()
|
|
|
|
|
"Run all tests for current file."
|
|
|
|
|
(interactive)
|
|
|
|
|
(ert (concat "test-"
|
|
|
|
|
(file-name-sans-extension
|
|
|
|
|
(file-name-nondirectory (buffer-file-name)))
|
|
|
|
|
"/")))
|
|
|
|
|
|
2012-03-19 16:38:12 -04:00
|
|
|
|
(defvar org-test-buffers nil
|
2016-08-23 16:13:56 -04:00
|
|
|
|
"Hold buffers open for running Org tests.")
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
2011-08-23 10:36:45 -04:00
|
|
|
|
(defun org-test-touch-all-examples ()
|
|
|
|
|
(dolist (file (directory-files
|
|
|
|
|
org-test-example-dir 'full
|
|
|
|
|
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.org$"))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
(unless (get-file-buffer file)
|
|
|
|
|
(add-to-list 'org-test-buffers (find-file file)))))
|
|
|
|
|
|
|
|
|
|
(defun org-test-kill-all-examples ()
|
|
|
|
|
(while org-test-buffers
|
|
|
|
|
(let ((b (pop org-test-buffers)))
|
|
|
|
|
(when (buffer-live-p b) (kill-buffer b)))))
|
2011-08-23 10:36:45 -04:00
|
|
|
|
|
2011-11-14 16:14:50 -05:00
|
|
|
|
(defun org-test-update-id-locations ()
|
|
|
|
|
(org-id-update-id-locations
|
|
|
|
|
(directory-files
|
|
|
|
|
org-test-example-dir 'full
|
|
|
|
|
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.org$")))
|
|
|
|
|
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(defun org-test-run-batch-tests (&optional org-test-selector)
|
|
|
|
|
"Run all tests matching an optional regex which defaults to \"\\(org\\|ob\\)\".
|
2011-09-08 11:11:26 -04:00
|
|
|
|
Load all test files first."
|
|
|
|
|
(interactive)
|
2011-11-14 16:14:50 -05:00
|
|
|
|
(let ((org-id-track-globally t)
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(org-test-selector
|
|
|
|
|
(if org-test-selector org-test-selector "\\(org\\|ob\\)"))
|
2013-11-30 11:02:46 -05:00
|
|
|
|
org-confirm-babel-evaluate org-startup-folded vc-handled-backends)
|
2011-11-14 16:14:50 -05:00
|
|
|
|
(org-test-touch-all-examples)
|
|
|
|
|
(org-test-update-id-locations)
|
|
|
|
|
(org-test-load)
|
2013-11-23 11:46:35 -05:00
|
|
|
|
(message "selected tests: %s" org-test-selector)
|
2013-05-19 03:20:17 -04:00
|
|
|
|
(ert-run-tests-batch-and-exit org-test-selector)))
|
2011-09-08 11:11:26 -04:00
|
|
|
|
|
2010-10-03 12:45:07 -04:00
|
|
|
|
(defun org-test-run-all-tests ()
|
2010-10-06 12:23:50 -04:00
|
|
|
|
"Run all defined tests matching \"\\(org\\|ob\\)\".
|
2010-10-03 12:45:07 -04:00
|
|
|
|
Load all test files first."
|
2010-10-02 18:50:57 -04:00
|
|
|
|
(interactive)
|
2011-11-14 16:52:22 -05:00
|
|
|
|
(org-test-touch-all-examples)
|
2013-11-23 11:46:35 -05:00
|
|
|
|
(org-test-update-id-locations)
|
2011-11-14 16:52:22 -05:00
|
|
|
|
(org-test-load)
|
2012-03-19 16:38:12 -04:00
|
|
|
|
(ert "\\(org\\|ob\\)")
|
|
|
|
|
(org-test-kill-all-examples))
|
2010-10-02 17:23:27 -04:00
|
|
|
|
|
2019-02-12 17:44:23 -05:00
|
|
|
|
(defmacro org-test-at-time (time &rest body)
|
|
|
|
|
"Run body while pretending that the current time is TIME.
|
|
|
|
|
TIME can be a non-nil Lisp time value, or a string specifying a date and time."
|
|
|
|
|
(declare (indent 1))
|
|
|
|
|
(let ((tm (cl-gensym))
|
|
|
|
|
(at (cl-gensym)))
|
|
|
|
|
`(let* ((,tm ,time)
|
|
|
|
|
(,at (if (stringp ,tm)
|
|
|
|
|
(apply #'encode-time (org-parse-time-string ,tm))
|
|
|
|
|
,tm)))
|
|
|
|
|
(cl-letf
|
|
|
|
|
;; Wrap builtins whose behavior can depend on the current time.
|
|
|
|
|
(((symbol-function 'current-time)
|
|
|
|
|
(lambda () ,at))
|
|
|
|
|
((symbol-function 'current-time-string)
|
|
|
|
|
(lambda (&optional time &rest args)
|
|
|
|
|
(apply ,(symbol-function 'current-time-string)
|
|
|
|
|
(or time ,at) args)))
|
|
|
|
|
((symbol-function 'current-time-zone)
|
|
|
|
|
(lambda (&optional time &rest args)
|
|
|
|
|
(apply ,(symbol-function 'current-time-zone)
|
|
|
|
|
(or time ,at) args)))
|
|
|
|
|
((symbol-function 'decode-time)
|
|
|
|
|
(lambda (&optional time) (funcall ,(symbol-function 'decode-time)
|
|
|
|
|
(or time ,at))))
|
|
|
|
|
((symbol-function 'encode-time)
|
|
|
|
|
(lambda (time &rest args)
|
|
|
|
|
(apply ,(symbol-function 'encode-time) (or time ,at) args)))
|
|
|
|
|
((symbol-function 'float-time)
|
|
|
|
|
(lambda (&optional time)
|
|
|
|
|
(funcall ,(symbol-function 'float-time) (or time ,at))))
|
|
|
|
|
((symbol-function 'format-time-string)
|
|
|
|
|
(lambda (format &optional time &rest args)
|
|
|
|
|
(apply ,(symbol-function 'format-time-string)
|
|
|
|
|
format (or time ,at) args)))
|
|
|
|
|
((symbol-function 'set-file-times)
|
|
|
|
|
(lambda (file &optional time)
|
|
|
|
|
(funcall ,(symbol-function 'set-file-times) file (or time ,at))))
|
|
|
|
|
((symbol-function 'time-add)
|
|
|
|
|
(lambda (a b) (funcall ,(symbol-function 'time-add)
|
|
|
|
|
(or a ,at) (or b ,at))))
|
|
|
|
|
((symbol-function 'time-equal-p)
|
|
|
|
|
(lambda (a b) (funcall ,(symbol-function 'time-equal-p)
|
|
|
|
|
(or a ,at) (or b ,at))))
|
|
|
|
|
((symbol-function 'time-less-p)
|
|
|
|
|
(lambda (a b) (funcall ,(symbol-function 'time-less-p)
|
|
|
|
|
(or a ,at) (or b ,at))))
|
|
|
|
|
((symbol-function 'time-subtract)
|
|
|
|
|
(lambda (a b) (funcall ,(symbol-function 'time-subtract)
|
|
|
|
|
(or a ,at) (or b ,at)))))
|
|
|
|
|
,@body))))
|
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
(provide 'org-test)
|
2010-10-03 12:45:07 -04:00
|
|
|
|
|
2010-10-02 17:23:27 -04:00
|
|
|
|
;;; org-test.el ends here
|