From 25c9d743527a8b3155309e49b63f24f99459821e Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 08:57:28 -0600 Subject: [PATCH 1/7] ensure that the testing/contrib/lisp directory is created thanks to Nick Dokos for noticing this --- testing/contrib/lisp/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 testing/contrib/lisp/.gitignore diff --git a/testing/contrib/lisp/.gitignore b/testing/contrib/lisp/.gitignore new file mode 100644 index 000000000..6e7ef91f9 --- /dev/null +++ b/testing/contrib/lisp/.gitignore @@ -0,0 +1 @@ +# this file ensures that the testing/contrib/lisp directory is created by git \ No newline at end of file From be42b2fb51c443e10f5710fbf176afc200bde402 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 09:02:25 -0600 Subject: [PATCH 2/7] ensuring that test files include org-test in their load path again thanks to Nick Dokos for pointing this out --- testing/lisp/test-ob-exp.el | 8 ++++++-- testing/lisp/test-ob.el | 8 ++++++-- testing/org-test.el | 7 ++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el index cc874776a..503c830fa 100644 --- a/testing/lisp/test-ob-exp.el +++ b/testing/lisp/test-ob-exp.el @@ -12,8 +12,12 @@ ;;; Code: -(require 'org-test) -(require 'org-test-ob-consts) +(let ((load-path (cons (expand-file-name + ".." (file-name-directory + (or load-file-name buffer-file-name))) + load-path))) + (require 'org-test) + (require 'org-test-ob-consts)) ;;; Tests diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index b28753e8c..38696a056 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -12,8 +12,12 @@ ;;; Code: -(require 'org-test) -(require 'org-test-ob-consts) +(let ((load-path (cons (expand-file-name + ".." (file-name-directory + (or load-file-name buffer-file-name))) + load-path))) + (require 'org-test) + (require 'org-test-ob-consts)) (ert-deftest test-org-babel-get-src-block-info-language () (org-test-at-marker nil org-test-file-ob-anchor diff --git a/testing/org-test.el b/testing/org-test.el index faafa2e6e..1c16187cd 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -139,7 +139,12 @@ files." ";; Template test file for Org-mode tests\n\n" " \n" ";;; Code:\n" - "(require 'org-test)\n\n" + "(let ((load-path (cons (expand-file-name\n" + " \"..\" (file-name-directory\n" + " (or load-file-name buffer-file-name)))\n" + " load-path)))\n" + " (require 'org-test)\n" + " (require 'org-test-ob-consts))\n\n" " \n" ";;; Tests\n" "(ert-deftest " name "/example-test ()\n" From 462fc24cd333eb88aba52ebf476ea5e982c44f60 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 09:04:06 -0600 Subject: [PATCH 3/7] typo in testing/README.org, once again, thanks Nick Dokos * testing/README.org: type --- testing/README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/README.org b/testing/README.org index 8a3b3909d..f374a48de 100644 --- a/testing/README.org +++ b/testing/README.org @@ -21,7 +21,7 @@ Org-mode test framework. 3) The =org-test-jump= command is now bound to =M-C-j= in all emacs-lisp files. Call this command from any file in the =lisp/= - directory of the org-mode repository to just to the related test + directory of the org-mode repository to jump to the related test file in the =testing/= directory. Call this functions with a prefix argument, and the corresponding test file will be stubbed out if it doesn't already exist. From 19efdcca43742b1c0d9a071476659b0f7c7fc57d Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 10:23:50 -0600 Subject: [PATCH 4/7] added tangle tests exercising new desired tangling behavior --- testing/examples/babel.org | 29 ++++++++++++++++++++ testing/lisp/test-ob-exp.el | 19 ++++++++++++++ testing/lisp/test-ob-tangle.el | 48 ++++++++++++++++++++++++++++++++++ testing/org-test.el | 26 +++++++++++++++--- 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 testing/examples/babel.org create mode 100644 testing/lisp/test-ob-tangle.el diff --git a/testing/examples/babel.org b/testing/examples/babel.org new file mode 100644 index 000000000..491b6c5ab --- /dev/null +++ b/testing/examples/babel.org @@ -0,0 +1,29 @@ +#+Title: a collection of examples for Babel tests + +* =:noweb= header argument expansion + :PROPERTIES: + :ID: eb1f6498-5bd9-45e0-9c56-50717053e7b7 + :END: + +#+source: noweb-example +#+begin_src emacs-lisp + (message "expanded") +#+end_src + +#+begin_src emacs-lisp :noweb yes + ;; noweb-yes-start + <> + ;; noweb-yes-end +#+end_src + +#+begin_src emacs-lisp :noweb no + ;; noweb-no-start + <> + ;; noweb-no-end +#+end_src + +#+begin_src emacs-lisp :noweb tangle + ;; noweb-tangle-start + <> + ;; noweb-tangle-end +#+end_src diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el index 503c830fa..471453f4a 100644 --- a/testing/lisp/test-ob-exp.el +++ b/testing/lisp/test-ob-exp.el @@ -65,6 +65,25 @@ (should-not (file-exists-p (concat org-test-link-in-heading-file "::"))) (when (file-exists-p html-file) (delete-file html-file)))) +(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" + (let (html) + (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7" + (org-narrow-to-subtree) + (setq html (org-export-as-html nil nil nil 'string))) + (flet ((exp-p (arg) + (and + (string-match + (format "noweb-%s-start\\([^\000]*\\)noweb-%s-end" arg arg) + html) + (string-match "expanded" (match-string 1 html))))) + (should (exp-p "yes")) + (should-not (exp-p "no")) + (should-not (exp-p "tangle"))))) + (provide 'test-ob-exp) ;;; test-ob-exp.el ends here diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el new file mode 100644 index 000000000..b99995ef4 --- /dev/null +++ b/testing/lisp/test-ob-tangle.el @@ -0,0 +1,48 @@ +;;; test-ob-tangle.el + +;; Copyright (c) 2010 Eric Schulte +;; Authors: Eric Schulte + +;; Released under the GNU General Public License version 3 +;; see: http://www.gnu.org/licenses/gpl-3.0.html + +;;;; Comments: + +;; Template test file for Org-mode tests + + +;;; Code: +(let ((load-path (cons (expand-file-name + ".." (file-name-directory + (or load-file-name buffer-file-name))) + load-path))) + (require 'org-test) + (require 'org-test-ob-consts)) + + +;;; Tests +(ert-deftest ob-tangle/noweb-on-tangle () + "Noweb header arguments tangle correctly. +- yes expand on both export and tangle +- no expand on neither export or tangle +- tangle expand on only tangle not export" + (let ((target-file (make-temp-file "ob-tangle-test-"))) + (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7" + (org-narrow-to-subtree) + (org-babel-tangle target-file)) + (let ((tang (with-temp-buffer + (insert-file-contents target-file) + (buffer-string)))) + (flet ((exp-p (arg) + (and + (string-match + (format "noweb-%s-start\\([^\000]*\\)noweb-%s-end" arg arg) + tang) + (string-match "expanded" (match-string 1 tang))))) + (should (exp-p "yes")) + (should-not (exp-p "no")) + (should (exp-p "tangle")))))) + +(provide 'test-ob-tangle) + +;;; test-ob-tangle.el ends here diff --git a/testing/org-test.el b/testing/org-test.el index 1c16187cd..970ab9865 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -79,6 +79,26 @@ If file is non-nil insert it's contents in there.") If file is not given, search for a file named after the test currently executed.") +(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) + (save-window-excursion + (save-match-data + (org-id-goto ,id) + (setq to-be-removed (current-buffer)) + (condition-case nil + (progn + (org-show-subtree) + (org-show-block-all)) + (error nil)) + (save-restriction ,@body))) + (unless visited-p + (kill-buffer to-be-removed)))) + (defmacro org-test-in-example-file (file &rest body) "Execute body in the Org-mode example file." (declare (indent 1)) @@ -96,7 +116,7 @@ currently executed.") (org-show-subtree) (org-show-block-all)) (error nil)) - ,@body)) + (save-restriction ,@body))) (unless visited-p (kill-buffer to-be-removed)))) @@ -179,11 +199,11 @@ files." (ert (car (which-function)))) (defun org-test-run-all-tests () - "Run all defined tests matching \"^org\". + "Run all defined tests matching \"\\(org\\|ob\\)\". Load all test files first." (interactive) (org-test-load) - (ert "org")) + (ert "\\(org\\|ob\\)")) (provide 'org-test) From f687f51dd0c21feb4c6bbcbc283b2b4b9842775f Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 10:37:46 -0600 Subject: [PATCH 5/7] ob-exp: ":noweb tangle" now expands noweb references during tangling * lisp/ob-tangle.el (org-babel-tangle-collect-blocks): accepting "tangle" as a positive argument for the :noweb header argument during tangling --- lisp/ob-tangle.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index a9429c4c9..3a0426acd 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -294,7 +294,10 @@ code blocks by language." 'org-babel-expand-body:generic) body params))) (if (and (cdr (assoc :noweb params)) - (string= "yes" (cdr (assoc :noweb params)))) + (let ((nowebs (split-string + (cdr (assoc :noweb params))))) + (or (member "yes" nowebs) + (member "tangle" nowebs)))) (org-babel-expand-noweb-references info) (nth 1 info)))) (comment (when (or (string= "both" (cdr (assoc :comments params))) From 3701c0aeb39274f77b3fa79234000192ec02e1e0 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 10:42:43 -0600 Subject: [PATCH 6/7] doc: updating :noweb documentation to reflect the new "tangle" argument * doc/org.texi (noweb): updating :noweb documentation to reflect the new "tangle" argument --- doc/org.texi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 64ca8be0f..4020c8d12 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -11966,16 +11966,20 @@ interpreted language. The @code{:noweb} header argument controls expansion of ``noweb'' style (see @ref{Noweb reference syntax}) references in a code block. This header -argument can have one of two values: @code{yes} or @code{no}. +argument can have one of three values: @code{yes} @code{no} or @code{tangle}. @itemize @bullet +@item @code{yes} +All ``noweb'' syntax references in the body of the code block will be +expanded before the block is evaluated, tangled or exported. @item @code{no} The default. No ``noweb'' syntax specific action is taken on evaluating code blocks, However, noweb references will still be expanded during tangling. @item @code{yes} All ``noweb'' syntax references in the body of the code block will be -expanded before the block is evaluated. +expanded before the block is tangled, however ``noweb'' references will not +be expanded when the block is evaluated or exported. @end itemize @subsubheading Noweb prefix lines From 09015851055266778152f74a970727c1093ae046 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 6 Oct 2010 10:50:39 -0600 Subject: [PATCH 7/7] ob: minor fix to a documentation string * lisp/ob.el (org-babel-number-p): fixed documentation string --- lisp/ob.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ob.el b/lisp/ob.el index 572847bed..b05100ce5 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1671,7 +1671,7 @@ This is taken almost directly from `org-read-prop'." cell)) (defun org-babel-number-p (string) - "Return t if STRING represents a number." + "If STRING represents a number return it's value." (if (and (string-match "^-?[0-9]*\\.?[0-9]*$" string) (= (length (substring string (match-beginning 0) (match-end 0)))