testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables. For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.
Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?
I found some suspicious code, for which I added FIXMEs.
There are also a few changes to the main files.
* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined. [ Needed to get
the tests to pass. ]
* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it). Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.
* lisp/org.el (org-log-beginning): Add FIXME.
* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.
* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.
* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded. Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.
* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler. Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.
* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.
* testing/lisp/test-org-timer.el: Require `org-timer`.
* testing/lisp/test-org-table.el: Require `ox`.
* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded. Also require `capture`, and
add missing `provide` statement.
* testing/lisp/test-org-pcomplete.el: Require `org`.
* testing/lisp/test-org-list.el: Require `org-list` and `org`.
* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.
* testing/lisp/test-org-footnote.el: Require `org-footnote`.
* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded. Also require `org` and
`org-inlinetask`.
* testing/lisp/test-org-duration.el: Require `org-duration`.
* testing/lisp/test-org-datetree.el: Require `org-datetree`.
* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.
* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.
* testing/lisp/test-org-archive.el: Require `org-archive`.
* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.
* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.
* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.
* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.
* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.
* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.
* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.
* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded. Use `with-current-buffer`.
* testing/lisp/test-ob-julia.el: Require `ob-core`.
* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.
* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.
* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.
* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-14 17:21:37 -04:00
|
|
|
;;; test-ob-exp.el -*- lexical-binding: t; -*-
|
2010-10-04 10:29:00 -04:00
|
|
|
|
2019-01-01 05:50:56 -05:00
|
|
|
;; Copyright (c) 2010-2015, 2019 Eric Schulte
|
2010-10-04 10:29:00 -04:00
|
|
|
;; Authors: Eric Schulte
|
|
|
|
|
2012-12-13 11:24:19 -05:00
|
|
|
;; This file is not part of GNU Emacs.
|
2010-10-04 10:29:00 -04:00
|
|
|
|
2012-12-13 11:24:19 -05:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2021-03-20 03:27:57 -04:00
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2012-12-13 11:24:19 -05:00
|
|
|
|
|
|
|
;;; Comments:
|
2010-10-04 10:29:00 -04:00
|
|
|
|
2016-08-23 16:13:56 -04:00
|
|
|
;; Template test file for Org tests
|
2010-10-04 10:29:00 -04:00
|
|
|
|
|
|
|
;;; Code:
|
2013-01-27 18:09:58 -05:00
|
|
|
|
testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables. For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.
Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?
I found some suspicious code, for which I added FIXMEs.
There are also a few changes to the main files.
* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined. [ Needed to get
the tests to pass. ]
* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it). Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.
* lisp/org.el (org-log-beginning): Add FIXME.
* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.
* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.
* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded. Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.
* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler. Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.
* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.
* testing/lisp/test-org-timer.el: Require `org-timer`.
* testing/lisp/test-org-table.el: Require `ox`.
* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded. Also require `capture`, and
add missing `provide` statement.
* testing/lisp/test-org-pcomplete.el: Require `org`.
* testing/lisp/test-org-list.el: Require `org-list` and `org`.
* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.
* testing/lisp/test-org-footnote.el: Require `org-footnote`.
* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded. Also require `org` and
`org-inlinetask`.
* testing/lisp/test-org-duration.el: Require `org-duration`.
* testing/lisp/test-org-datetree.el: Require `org-datetree`.
* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.
* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.
* testing/lisp/test-org-archive.el: Require `org-archive`.
* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.
* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.
* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.
* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.
* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.
* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.
* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.
* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded. Use `with-current-buffer`.
* testing/lisp/test-ob-julia.el: Require `ob-core`.
* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.
* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.
* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.
* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-14 17:21:37 -04:00
|
|
|
(require 'ob-exp)
|
|
|
|
(require 'org-src)
|
|
|
|
(require 'org-test "../testing/org-test")
|
|
|
|
|
2013-01-27 18:09:58 -05:00
|
|
|
(defmacro org-test-with-expanded-babel-code (&rest body)
|
|
|
|
"Execute BODY while in a buffer with all Babel code evaluated.
|
|
|
|
Current buffer is a copy of the original buffer."
|
2016-06-18 16:11:14 -04:00
|
|
|
`(let ((string (org-with-wide-buffer (buffer-string)))
|
|
|
|
(narrowing (list (point-min) (point-max)))
|
2016-11-12 21:54:20 -05:00
|
|
|
(org-export-use-babel t))
|
2013-01-27 18:09:58 -05:00
|
|
|
(with-temp-buffer
|
|
|
|
(org-mode)
|
|
|
|
(insert string)
|
2016-06-18 16:11:14 -04:00
|
|
|
(apply #'narrow-to-region narrowing)
|
|
|
|
(org-babel-exp-process-buffer)
|
2013-01-27 18:09:58 -05:00
|
|
|
(goto-char (point-min))
|
|
|
|
(progn ,@body))))
|
|
|
|
|
2010-10-04 10:29:00 -04:00
|
|
|
(ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
|
2013-01-27 18:09:58 -05:00
|
|
|
"Testing export without any headlines in the Org mode file."
|
2017-08-19 12:56:31 -04:00
|
|
|
(require 'ox-ascii)
|
|
|
|
(let ((text-file (concat (file-name-sans-extension org-test-no-heading-file)
|
|
|
|
".txt")))
|
|
|
|
(when (file-exists-p text-file) (delete-file text-file))
|
2010-10-04 22:07:51 -04:00
|
|
|
(org-test-in-example-file org-test-no-heading-file
|
2013-01-27 18:09:58 -05:00
|
|
|
;; Export the file to HTML.
|
2017-08-19 12:56:31 -04:00
|
|
|
(org-export-to-file 'ascii text-file))
|
|
|
|
;; should create a ".txt" file
|
|
|
|
(should (file-exists-p text-file))
|
2016-02-03 23:33:28 -05:00
|
|
|
;; should not create a file with "::" appended to its name
|
2010-10-04 22:07:51 -04:00
|
|
|
(should-not (file-exists-p (concat org-test-no-heading-file "::")))
|
2017-08-19 12:56:31 -04:00
|
|
|
(when (file-exists-p text-file) (delete-file text-file))))
|
2010-10-04 10:29:00 -04:00
|
|
|
|
2010-10-04 11:21:24 -04:00
|
|
|
(ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file ()
|
|
|
|
"Testing export from buffers which are not visiting any file."
|
2017-08-19 12:56:31 -04:00
|
|
|
(require 'ox-ascii)
|
|
|
|
(let ((name (generate-new-buffer-name "*Org ASCII Export*")))
|
2013-01-27 18:09:58 -05:00
|
|
|
(org-test-in-example-file nil
|
2017-08-19 12:56:31 -04:00
|
|
|
(org-export-to-buffer 'ascii name nil nil nil t))
|
|
|
|
;; Should create a new buffer.
|
2013-01-27 18:09:58 -05:00
|
|
|
(should (buffer-live-p (get-buffer name)))
|
|
|
|
;; Should contain the content of the buffer.
|
|
|
|
(with-current-buffer (get-buffer name)
|
|
|
|
(should (string-match (regexp-quote org-test-file-ob-anchor)
|
|
|
|
(buffer-string))))
|
|
|
|
(when (get-buffer name) (kill-buffer name))))
|
2010-10-04 11:21:24 -04:00
|
|
|
|
2011-09-06 11:07:00 -04:00
|
|
|
(ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers2 ()
|
2016-08-23 16:13:56 -04:00
|
|
|
"Testing export without any headlines in the Org file."
|
2010-10-04 22:07:51 -04:00
|
|
|
(let ((html-file (concat (file-name-sans-extension
|
|
|
|
org-test-link-in-heading-file)
|
|
|
|
".html")))
|
|
|
|
(when (file-exists-p html-file) (delete-file html-file))
|
|
|
|
(org-test-in-example-file org-test-link-in-heading-file
|
|
|
|
;; export the file to html
|
2013-01-27 18:09:58 -05:00
|
|
|
(org-export-to-file 'html html-file))
|
2010-10-04 22:07:51 -04:00
|
|
|
;; should create a .html file
|
|
|
|
(should (file-exists-p html-file))
|
2016-02-03 23:33:28 -05:00
|
|
|
;; should not create a file with "::" appended to its name
|
2010-10-04 22:07:51 -04:00
|
|
|
(should-not (file-exists-p (concat org-test-link-in-heading-file "::")))
|
|
|
|
(when (file-exists-p html-file) (delete-file html-file))))
|
|
|
|
|
2012-03-19 16:38:12 -04:00
|
|
|
(ert-deftest ob-exp/noweb-on-export ()
|
|
|
|
"Noweb header arguments export correctly.
|
|
|
|
- yes expand on both export and tangle
|
|
|
|
- no expand on neither export or tangle
|
|
|
|
- tangle expand on only tangle not export"
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
'("(message \"expanded1\")" "(message \"expanded2\")" ";; noweb-1-yes-start
|
|
|
|
(message \"expanded1\")" ";; noweb-no-start
|
|
|
|
<<noweb-example1>>" ";; noweb-2-yes-start
|
2015-01-29 15:05:31 -05:00
|
|
|
(message \"expanded2\")"
|
|
|
|
";; noweb-tangle-start
|
2013-01-27 18:09:58 -05:00
|
|
|
<<noweb-example1>>
|
|
|
|
<<noweb-example2>>")
|
|
|
|
(org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(org-element-map
|
|
|
|
(org-test-with-expanded-babel-code (org-element-parse-buffer))
|
|
|
|
'src-block
|
|
|
|
(lambda (src) (org-trim (org-element-property :value src))))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/noweb-on-export-with-exports-results ()
|
|
|
|
"Noweb header arguments export correctly using :exports results.
|
|
|
|
- yes expand on both export and tangle
|
|
|
|
- no expand on neither export or tangle
|
|
|
|
- tangle expand on only tangle not export"
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
'(";; noweb-no-start
|
|
|
|
<<noweb-example1>>" "<<noweb-example1>>
|
|
|
|
<<noweb-example2>>")
|
|
|
|
(org-test-at-id "8701beb4-13d9-468c-997a-8e63e8b66f8d"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(org-element-map
|
|
|
|
(org-test-with-expanded-babel-code (org-element-parse-buffer))
|
|
|
|
'src-block
|
|
|
|
(lambda (src) (org-trim (org-element-property :value src))))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/exports-both ()
|
2013-01-27 18:09:58 -05:00
|
|
|
"Test the \":exports both\" header argument.
|
|
|
|
The code block evaluation should create both a code block and
|
|
|
|
a table."
|
2012-03-19 16:38:12 -04:00
|
|
|
(org-test-at-id "92518f2a-a46a-4205-a3ab-bcce1008a4bb"
|
|
|
|
(org-narrow-to-subtree)
|
2013-01-27 18:09:58 -05:00
|
|
|
(let ((tree (org-test-with-expanded-babel-code (org-element-parse-buffer))))
|
|
|
|
(should (and (org-element-map tree 'src-block 'identity)
|
|
|
|
(org-element-map tree 'table 'identity))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/mixed-blocks-with-exports-both ()
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
'(property-drawer plain-list src-block fixed-width src-block plain-list)
|
|
|
|
(org-test-at-id "5daa4d03-e3ea-46b7-b093-62c1b7632df3"
|
|
|
|
(org-narrow-to-subtree)
|
testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables. For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.
Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?
I found some suspicious code, for which I added FIXMEs.
There are also a few changes to the main files.
* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined. [ Needed to get
the tests to pass. ]
* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it). Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.
* lisp/org.el (org-log-beginning): Add FIXME.
* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.
* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.
* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded. Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.
* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler. Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.
* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.
* testing/lisp/test-org-timer.el: Require `org-timer`.
* testing/lisp/test-org-table.el: Require `ox`.
* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded. Also require `capture`, and
add missing `provide` statement.
* testing/lisp/test-org-pcomplete.el: Require `org`.
* testing/lisp/test-org-list.el: Require `org-list` and `org`.
* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.
* testing/lisp/test-org-footnote.el: Require `org-footnote`.
* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded. Also require `org` and
`org-inlinetask`.
* testing/lisp/test-org-duration.el: Require `org-duration`.
* testing/lisp/test-org-datetree.el: Require `org-datetree`.
* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.
* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.
* testing/lisp/test-org-archive.el: Require `org-archive`.
* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.
* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.
* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.
* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.
* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.
* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.
* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.
* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded. Use `with-current-buffer`.
* testing/lisp/test-ob-julia.el: Require `ob-core`.
* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.
* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.
* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.
* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-14 17:21:37 -04:00
|
|
|
(mapcar #'org-element-type
|
2013-01-27 18:09:58 -05:00
|
|
|
(org-element-map
|
|
|
|
(org-test-with-expanded-babel-code
|
|
|
|
(org-element-parse-buffer 'greater-element))
|
|
|
|
'section 'org-element-contents nil t))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/export-with-name ()
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"=qux="
|
|
|
|
(let ((org-babel-exp-code-template
|
|
|
|
"=%name=\n#+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
|
|
|
|
(org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(org-test-with-expanded-babel-code
|
|
|
|
(buffer-string)))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/export-with-header-argument ()
|
|
|
|
(let ((org-babel-exp-code-template
|
|
|
|
"
|
|
|
|
| header | value |
|
|
|
|
|---------+----------|
|
|
|
|
| foo | %foo |
|
|
|
|
| results | %results |
|
|
|
|
#+BEGIN_SRC %lang%flags\nbody\n#+END_SRC"))
|
|
|
|
(org-test-at-id "b02ddd8a-eeb8-42ab-8664-8a759e6f43d9"
|
|
|
|
(org-narrow-to-subtree)
|
2013-01-27 18:09:58 -05:00
|
|
|
(org-test-with-expanded-babel-code
|
|
|
|
(should (string-match "baz" (buffer-string)))
|
|
|
|
(should (string-match "replace" (buffer-string)))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/noweb-no-export-and-exports-both ()
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"<<noweb-no-export-and-exports-both-1>>"
|
|
|
|
(org-test-at-id "8a820f6c-7980-43db-8a24-0710d33729c9"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(org-test-with-expanded-babel-code
|
|
|
|
(org-element-map (org-element-parse-buffer) 'src-block
|
|
|
|
(lambda (src-block) (org-element-property :value src-block))
|
|
|
|
nil t))))))
|
2012-01-16 22:39:12 -05:00
|
|
|
|
2012-01-23 12:33:12 -05:00
|
|
|
(ert-deftest ob-exp/evaluate-all-executables-in-order ()
|
testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables. For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.
Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?
I found some suspicious code, for which I added FIXMEs.
There are also a few changes to the main files.
* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined. [ Needed to get
the tests to pass. ]
* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it). Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.
* lisp/org.el (org-log-beginning): Add FIXME.
* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.
* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.
* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded. Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.
* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler. Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.
* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.
* testing/lisp/test-org-timer.el: Require `org-timer`.
* testing/lisp/test-org-table.el: Require `ox`.
* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded. Also require `capture`, and
add missing `provide` statement.
* testing/lisp/test-org-pcomplete.el: Require `org`.
* testing/lisp/test-org-list.el: Require `org-list` and `org`.
* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.
* testing/lisp/test-org-footnote.el: Require `org-footnote`.
* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded. Also require `org` and
`org-inlinetask`.
* testing/lisp/test-org-duration.el: Require `org-duration`.
* testing/lisp/test-org-datetree.el: Require `org-datetree`.
* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.
* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.
* testing/lisp/test-org-archive.el: Require `org-archive`.
* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.
* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.
* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.
* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.
* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.
* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.
* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.
* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded. Use `with-current-buffer`.
* testing/lisp/test-ob-julia.el: Require `ob-core`.
* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.
* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.
* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.
* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-14 17:21:37 -04:00
|
|
|
(defvar *evaluation-collector*)
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(equal '(5 4 3 2 1)
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t) *evaluation-collector*)
|
2013-01-27 18:09:58 -05:00
|
|
|
(org-test-at-id "96cc7073-97ec-4556-87cf-1f9bffafd317"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(buffer-string)
|
|
|
|
(org-test-with-expanded-babel-code *evaluation-collector*))))))
|
2012-01-23 12:33:12 -05:00
|
|
|
|
2012-09-15 11:23:37 -04:00
|
|
|
(ert-deftest ob-exp/exports-inline ()
|
2013-01-27 18:09:58 -05:00
|
|
|
(should
|
|
|
|
(string-match
|
2020-09-07 13:27:49 -04:00
|
|
|
(regexp-quote "Here is one in the middle {{{results(=1=)}}} of a line.
|
|
|
|
Here is one at the end of a line. {{{results(=2=)}}}
|
|
|
|
{{{results(=3=)}}} Here is one at the beginning of a line.")
|
2013-01-27 18:09:58 -05:00
|
|
|
(org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
|
|
|
|
(org-narrow-to-subtree)
|
2015-01-22 00:59:04 -05:00
|
|
|
(let ((org-babel-inline-result-wrap "=%s="))
|
|
|
|
(org-test-with-expanded-babel-code (buffer-string)))))))
|
2012-09-15 11:23:37 -04:00
|
|
|
|
2014-06-13 09:32:54 -04:00
|
|
|
(ert-deftest ob-exp/exports-inline-code ()
|
2018-01-30 04:11:02 -05:00
|
|
|
(should
|
|
|
|
(equal "src_emacs-lisp[]{(+ 1 1)}"
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[:exports code]{(+ 1 1)}"
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
|
|
|
(should
|
|
|
|
(equal "src_emacs-lisp[]{(+ 1 1)}"
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[ :exports code ]{(+ 1 1)}"
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
2021-04-13 03:55:29 -04:00
|
|
|
;; Do not escape characters in inline source blocks.
|
|
|
|
(should
|
|
|
|
(equal "src_c[]{*a}"
|
|
|
|
(org-test-with-temp-text "src_c[ :exports code ]{*a}"
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
2018-01-30 04:11:02 -05:00
|
|
|
(should
|
|
|
|
(equal "src_emacs-lisp[]{(+ 1 1)} {{{results(=2=)}}}"
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[:exports both]{(+ 1 1)}"
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
|
|
|
(should
|
|
|
|
(equal "{{{results(=2=)}}}"
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"src_emacs-lisp[:exports results :results scalar]{(+ 1 1)}"
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
|
|
|
(should
|
2018-02-03 18:30:00 -05:00
|
|
|
(equal "foosrc_emacs-lisp[:exports code]{(+ 1 1)}"
|
2018-01-30 04:11:02 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"foosrc_emacs-lisp[:exports code]{(+ 1 1)}"
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
|
|
|
(should
|
|
|
|
(let ((text "src_emacs lisp{(+ 1 1)}"))
|
|
|
|
(string-match (regexp-quote text)
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-temp-text
|
2018-01-30 04:11:02 -05:00
|
|
|
text
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string)))))
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"\\\\\\[]{" "\\(?:\\[]\\)?{" ;accept both src_sh[]{...} or src_sh{...}
|
|
|
|
(regexp-quote "Here is one in the middle src_sh[]{echo 1} of a line.
|
2014-06-13 09:32:54 -04:00
|
|
|
Here is one at the end of a line. src_sh[]{echo 2}
|
|
|
|
src_sh[]{echo 3} Here is one at the beginning of a line.
|
2020-09-07 13:27:49 -04:00
|
|
|
Here is one that is also evaluated: src_sh[]{echo 4} {{{results(=4=)}}}")
|
2018-01-30 04:11:02 -05:00
|
|
|
nil t)
|
|
|
|
(org-test-at-id "cd54fc88-1b6b-45b6-8511-4d8fa7fc8076"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
|
|
|
(org-export-use-babel t))
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-expanded-babel-code (buffer-string)))))))
|
2014-06-13 09:32:54 -04:00
|
|
|
|
2014-08-01 05:28:05 -04:00
|
|
|
(ert-deftest ob-exp/exports-inline-code-double-eval ()
|
|
|
|
"Based on default header arguments for inline code blocks (:exports
|
2014-06-13 09:32:54 -04:00
|
|
|
results), the resulting code block `src_emacs-lisp{2}' should also be
|
|
|
|
evaluated."
|
2015-01-22 00:59:04 -05:00
|
|
|
(let ((org-babel-inline-result-wrap "=%s=")
|
2016-11-12 21:54:20 -05:00
|
|
|
(org-export-use-babel t))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should
|
2015-01-29 15:05:31 -05:00
|
|
|
(string-match "\\`{{{results(src_emacs-lisp\\[\\]{2})}}}$"
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"src_emacs-lisp[:exports results :results code]{(+ 1 1)}"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))))
|
2014-06-13 09:32:54 -04:00
|
|
|
|
2014-08-01 05:28:05 -04:00
|
|
|
(ert-deftest ob-exp/exports-inline-code-eval-code-once ()
|
2014-06-13 09:32:54 -04:00
|
|
|
"Ibid above, except that the resulting inline code block should not
|
2014-08-01 05:28:05 -04:00
|
|
|
be evaluated."
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should
|
2015-01-29 15:05:31 -05:00
|
|
|
(string-match "{{{results(src_emacs-lisp\\(?:\\[[: a-zA-Z]+]\\)?{2})}}}$"
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
(concat "src_emacs-lisp[:exports results :results code "
|
|
|
|
":results_switches \":exports code\"]{(+ 1 1)}")
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))))
|
2014-06-13 09:32:54 -04:00
|
|
|
|
2014-08-01 05:28:05 -04:00
|
|
|
(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both ()
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should
|
|
|
|
(string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
|
2015-01-29 15:05:31 -05:00
|
|
|
"{{{results(src_emacs-lisp\\[ :exports code\\]{2})}}}$")
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
(concat "src_emacs-lisp[:exports both :results code "
|
|
|
|
":results_switches \":exports code\"]{(+ 1 1)}")
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))))
|
2014-06-13 09:32:54 -04:00
|
|
|
|
2012-03-19 16:38:12 -04:00
|
|
|
(ert-deftest ob-exp/export-call-line-information ()
|
|
|
|
(org-test-at-id "bec63a04-491e-4caa-97f5-108f3020365c"
|
|
|
|
(org-narrow-to-subtree)
|
2013-01-27 18:09:58 -05:00
|
|
|
(let ((org-babel-exp-call-line-template "\n: call: %line special-token"))
|
|
|
|
(org-test-with-expanded-babel-code
|
|
|
|
(should (string-match "double" (buffer-string)))
|
|
|
|
(should (string-match "16" (buffer-string)))
|
|
|
|
(should (string-match "special-token" (buffer-string)))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
|
|
|
(ert-deftest ob-exp/noweb-strip-export-ensure-strips ()
|
|
|
|
(org-test-at-id "8e7bd234-99b2-4b14-8cd6-53945e409775"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(org-babel-next-src-block 2)
|
|
|
|
(should (= 110 (org-babel-execute-src-block)))
|
2013-01-27 18:09:58 -05:00
|
|
|
(let ((result (org-test-with-expanded-babel-code (buffer-string))))
|
|
|
|
(should-not (string-match (regexp-quote "<<strip-export-1>>") result))
|
|
|
|
(should-not (string-match (regexp-quote "i=\"10\"") result)))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2013-06-19 05:36:36 -04:00
|
|
|
(ert-deftest ob-exp/use-case-of-reading-entry-properties ()
|
|
|
|
(org-test-at-id "cc5fbc20-bca5-437a-a7b8-2b4d7a03f820"
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(let* ((case-fold-search nil)
|
|
|
|
(result (org-test-with-expanded-babel-code (buffer-string)))
|
|
|
|
(sect "a:1, b:0, c:3, d:0, e:0")
|
|
|
|
(sub0 "a:1, b:2, c:4, d:0, e:0")
|
|
|
|
(sub1 "a:1, b:2, c:5, d:0, e:6")
|
|
|
|
(func sub0))
|
|
|
|
;; entry "section"
|
2015-01-22 00:59:04 -05:00
|
|
|
(should (string-match (concat "_shell-sect-call\n: shell " sect "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should (string-match (concat "_elisp-sect-call\n: elisp " sect "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
(should (string-match (concat "\n- sect inline shell " sect "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
(should (string-match (concat "\n- sect inline elisp " sect "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
;; entry "subsection", call without arguments
|
2015-01-22 00:59:04 -05:00
|
|
|
(should (string-match (concat "_shell-sub0-call\n: shell " sub0 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should (string-match (concat "_elisp-sub0-call\n: elisp " sub0 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
(should (string-match (concat "\n- sub0 inline shell " sub0 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
(should (string-match (concat "\n- sub0 inline elisp " sub0 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
|
|
|
;; entry "subsection", call with arguments
|
2015-01-22 00:59:04 -05:00
|
|
|
(should (string-match (concat "_shell-sub1-call\n: shell " sub1 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should (string-match (concat "_elisp-sub1-call\n: elisp " sub1 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
(should (string-match (concat "\n- sub1 inline shell " sub1 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
2015-01-29 15:05:31 -05:00
|
|
|
(should (string-match (concat "\n- sub1 inline elisp " sub1 "\n")
|
2013-06-19 05:36:36 -04:00
|
|
|
result))
|
|
|
|
;; entry "function definition"
|
|
|
|
(should (string-match (concat "_location_shell\n: shell " func "\n")
|
|
|
|
result))
|
|
|
|
(should (string-match (concat "_location_elisp\n: elisp " func "\n")
|
|
|
|
result)))))
|
|
|
|
|
2012-03-19 16:38:12 -04:00
|
|
|
(ert-deftest ob-exp/export-from-a-temp-buffer ()
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t))
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"
|
2012-03-19 16:38:12 -04:00
|
|
|
#+Title: exporting from a temporary buffer
|
|
|
|
|
|
|
|
#+name: foo
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
:foo
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
#+name: bar
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
:bar
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp :var foo=foo :noweb yes :exports results
|
|
|
|
(list foo <<bar>>)
|
|
|
|
#+END_SRC
|
|
|
|
"
|
2015-01-22 00:59:04 -05:00
|
|
|
(let* ((ascii (org-export-as 'ascii)))
|
|
|
|
(should (string-match
|
|
|
|
(regexp-quote " :foo :bar \n")
|
|
|
|
ascii))))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-01-18 09:25:01 -05:00
|
|
|
(ert-deftest ob-export/export-with-results-before-block ()
|
|
|
|
"Test export when results are inserted before source block."
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t))
|
2015-01-22 00:59:04 -05:00
|
|
|
(should
|
|
|
|
(equal
|
|
|
|
"#+RESULTS: src1
|
2014-01-18 09:25:01 -05:00
|
|
|
: 2
|
|
|
|
|
|
|
|
#+NAME: src1
|
2022-06-15 23:54:31 -04:00
|
|
|
#+begin_src emacs-lisp
|
2014-01-18 09:25:01 -05:00
|
|
|
\(+ 1 1)
|
2022-06-15 23:54:31 -04:00
|
|
|
#+end_src"
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+RESULTS: src1
|
2014-01-18 09:25:01 -05:00
|
|
|
|
|
|
|
#+NAME: src1
|
|
|
|
#+BEGIN_SRC emacs-lisp :exports both
|
|
|
|
\(+ 1 1)
|
|
|
|
#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-trim (org-no-properties (buffer-string))))))))
|
2012-10-15 16:29:30 -04:00
|
|
|
|
2014-01-29 03:01:43 -05:00
|
|
|
(ert-deftest ob-export/export-src-block-with-switches ()
|
|
|
|
"Test exporting a source block with switches."
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"\\`#\\+BEGIN_SRC emacs-lisp -n -r$"
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+BEGIN_SRC emacs-lisp -n -r\n\(+ 1 1)\n#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2014-01-29 03:01:43 -05:00
|
|
|
(buffer-string)))))
|
|
|
|
|
2014-01-20 08:07:57 -05:00
|
|
|
(ert-deftest ob-export/export-src-block-with-flags ()
|
|
|
|
"Test exporting a source block with a flag."
|
|
|
|
(should
|
2014-01-29 03:01:43 -05:00
|
|
|
(string-match
|
|
|
|
"\\`#\\+BEGIN_SRC emacs-lisp -some-flag$"
|
2014-01-20 08:07:57 -05:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+BEGIN_SRC emacs-lisp :flags -some-flag\n\(+ 1 1)\n#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2014-01-20 08:07:57 -05:00
|
|
|
(buffer-string)))))
|
|
|
|
|
2014-02-01 15:49:37 -05:00
|
|
|
(ert-deftest ob-export/export-and-indentation ()
|
|
|
|
"Test indentation of evaluated source blocks during export."
|
|
|
|
;; No indentation.
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"^t"
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n t\n#+END_SRC"
|
|
|
|
(let ((indent-tabs-mode t)
|
|
|
|
(tab-width 1)
|
|
|
|
(org-src-preserve-indentation nil))
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2014-02-01 15:49:37 -05:00
|
|
|
(buffer-string)))))
|
|
|
|
;; Preserve indentation with "-i" flag.
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"^ t"
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n t\n#+END_SRC"
|
|
|
|
(let ((indent-tabs-mode t)
|
|
|
|
(tab-width 1))
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2014-02-01 15:49:37 -05:00
|
|
|
(buffer-string)))))
|
|
|
|
;; Preserve indentation with a non-nil
|
|
|
|
;; `org-src-preserve-indentation'.
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"^ t"
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n t\n#+END_SRC"
|
|
|
|
(let ((indent-tabs-mode t)
|
|
|
|
(tab-width 1)
|
|
|
|
(org-src-preserve-indentation t))
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2014-02-01 15:49:37 -05:00
|
|
|
(buffer-string))))))
|
|
|
|
|
2014-03-15 04:34:05 -04:00
|
|
|
(ert-deftest ob-export/export-under-commented-headline ()
|
|
|
|
"Test evaluation of code blocks under COMMENT headings."
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t)
|
2015-01-22 00:59:04 -05:00
|
|
|
(org-babel-inline-result-wrap "=%s="))
|
|
|
|
;; Do not eval block in a commented headline.
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
": 2"
|
|
|
|
(org-test-with-temp-text "* Headline
|
2014-03-15 04:34:05 -04:00
|
|
|
#+BEGIN_SRC emacs-lisp :exports results
|
|
|
|
\(+ 1 1)
|
|
|
|
#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))
|
|
|
|
(should-not
|
|
|
|
(string-match
|
|
|
|
": 2"
|
|
|
|
(org-test-with-temp-text "* COMMENT Headline
|
2014-03-15 04:34:05 -04:00
|
|
|
#+BEGIN_SRC emacs-lisp :exports results
|
|
|
|
\(+ 1 1)
|
|
|
|
#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))
|
|
|
|
;; Do not eval inline blocks either.
|
|
|
|
(should
|
|
|
|
(string-match
|
|
|
|
"=2="
|
|
|
|
(org-test-with-temp-text "* Headline
|
2014-03-15 04:34:05 -04:00
|
|
|
src_emacs-lisp{(+ 1 1)}"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))
|
|
|
|
(should-not
|
|
|
|
(string-match
|
|
|
|
"=2="
|
|
|
|
(org-test-with-temp-text "* COMMENT Headline
|
2014-03-15 04:34:05 -04:00
|
|
|
src_emacs-lisp{(+ 1 1)}"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))
|
|
|
|
;; Also check parent headlines.
|
|
|
|
(should-not
|
|
|
|
(string-match
|
|
|
|
": 2"
|
|
|
|
(org-test-with-temp-text "
|
2014-03-15 04:34:05 -04:00
|
|
|
* COMMENT Headline
|
|
|
|
** Children
|
|
|
|
#+BEGIN_SRC emacs-lisp :exports results
|
|
|
|
\(+ 1 1)
|
|
|
|
#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer)
|
2015-01-22 00:59:04 -05:00
|
|
|
(buffer-string))))))
|
2014-03-15 04:34:05 -04:00
|
|
|
|
2014-03-14 10:27:32 -04:00
|
|
|
(ert-deftest ob-export/reference-in-post-header ()
|
|
|
|
"Test references in :post header during export."
|
|
|
|
(should
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
#+NAME: foo
|
|
|
|
#+BEGIN_SRC emacs-lisp :exports none :var bar=\"baz\"
|
|
|
|
(concat \"bar\" bar)
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
#+NAME: nofun
|
|
|
|
#+BEGIN_SRC emacs-lisp :exports results :post foo(\"nofun\")
|
|
|
|
#+END_SRC"
|
2016-06-18 16:11:14 -04:00
|
|
|
(org-babel-exp-process-buffer) t)))
|
2014-03-14 10:27:32 -04:00
|
|
|
|
2016-04-28 11:25:31 -04:00
|
|
|
(ert-deftest ob-export/babel-evaluate ()
|
2016-11-12 21:54:20 -05:00
|
|
|
"Test `org-export-use-babel' effect."
|
2016-04-28 11:25:31 -04:00
|
|
|
;; When nil, no Babel code is executed.
|
|
|
|
(should-not
|
|
|
|
(string-match-p
|
|
|
|
"2"
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+BEGIN_SRC emacs-lisp :exports results\n(+ 1 1)\n#+END_SRC"
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel nil)) (org-babel-exp-process-buffer))
|
2016-04-28 11:25:31 -04:00
|
|
|
(buffer-string))))
|
|
|
|
(should-not
|
|
|
|
(string-match-p
|
|
|
|
"2"
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"src_emacs-lisp{(+ 1 1)}"
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel nil)) (org-babel-exp-process-buffer))
|
2016-04-28 11:25:31 -04:00
|
|
|
(buffer-string))))
|
|
|
|
;; When non-nil, all Babel code types are executed.
|
|
|
|
(should
|
|
|
|
(string-match-p
|
|
|
|
"2"
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+BEGIN_SRC emacs-lisp :exports results\n(+ 1 1)\n#+END_SRC"
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t)) (org-babel-exp-process-buffer))
|
2016-04-28 11:25:31 -04:00
|
|
|
(buffer-string))))
|
|
|
|
(should
|
|
|
|
(string-match-p
|
|
|
|
"2"
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"src_emacs-lisp{(+ 1 1)}"
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t)) (org-babel-exp-process-buffer))
|
2016-04-28 11:25:31 -04:00
|
|
|
(buffer-string)))))
|
|
|
|
|
2016-08-28 05:45:39 -04:00
|
|
|
(ert-deftest ob-export/body-with-coderef ()
|
|
|
|
"Test exporting a code block with coderefs."
|
|
|
|
(should
|
2022-06-15 23:54:31 -04:00
|
|
|
(equal "#+begin_src emacs-lisp\n0 (ref:foo)\n#+end_src"
|
2016-08-28 05:45:39 -04:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+BEGIN_SRC emacs-lisp :exports code\n0 (ref:foo)\n#+END_SRC"
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t)
|
2016-08-28 05:45:39 -04:00
|
|
|
(org-coderef-label-format "(ref:foo)"))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string))))
|
|
|
|
(should
|
|
|
|
(equal
|
2022-06-15 23:54:31 -04:00
|
|
|
"#+begin_src emacs-lisp -l \"r:%s\"\n1 r:foo\n#+end_src"
|
2016-08-28 05:45:39 -04:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+BEGIN_SRC emacs-lisp -l \"r:%s\" -lisp :exports code\n1 r:foo\n#+END_SRC"
|
2016-11-12 21:54:20 -05:00
|
|
|
(let ((org-export-use-babel t))
|
2016-08-28 05:45:39 -04:00
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string)))))
|
|
|
|
|
2017-03-18 05:28:15 -04:00
|
|
|
(ert-deftest ob-exp/src-block-with-affiliated-keyword ()
|
|
|
|
"Test exporting a code block with affiliated keywords."
|
2018-09-20 05:23:49 -04:00
|
|
|
;; Pathological case: affiliated keyword matches inline source block
|
2017-03-18 05:28:15 -04:00
|
|
|
;; syntax.
|
|
|
|
(should
|
2022-06-15 23:54:31 -04:00
|
|
|
(equal "#+name: call_foo\n#+begin_src emacs-lisp\n42\n#+end_src"
|
2017-03-18 05:28:15 -04:00
|
|
|
(org-test-with-temp-text
|
|
|
|
"#+name: call_foo\n#+BEGIN_SRC emacs-lisp\n42\n#+END_SRC"
|
|
|
|
(let ((org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer))
|
|
|
|
(buffer-string)))))
|
|
|
|
|
2021-03-21 13:41:31 -04:00
|
|
|
(ert-deftest ob-exp/unknown-call-reference ()
|
|
|
|
"Test exporting with a call that references an unknown name."
|
|
|
|
(should-error
|
|
|
|
(org-test-with-temp-text
|
|
|
|
"call_foo()"
|
|
|
|
(let ((org-export-use-babel t))
|
|
|
|
(org-babel-exp-process-buffer)))
|
|
|
|
:type 'user-error))
|
2014-03-15 04:34:05 -04:00
|
|
|
|
2010-10-04 10:29:00 -04:00
|
|
|
(provide 'test-ob-exp)
|
|
|
|
|
|
|
|
;;; test-ob-exp.el ends here
|