From e1b90eea45aa8ea366d82feb4dbd8e4219207557 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 4 Oct 2010 20:07:51 -0600 Subject: [PATCH] ob-exp: fixed export when headings have links, with tests also some organization of the test directory * lisp/ob-exp.el (org-babel-exp-src-blocks): fixed export when headings have links, with tests --- lisp/ob-exp.el | 6 +++- ...mple-file-no-header.org => no-heading.org} | 0 testing/lisp/test-ob-exp.el | 34 ++++++++++++++----- testing/lisp/test-ob.el | 9 ++--- testing/org-test-ob-consts.el | 23 +++++++++++++ testing/org-test.el | 7 ++-- 6 files changed, 61 insertions(+), 18 deletions(-) rename testing/examples/{example-file-no-header.org => no-heading.org} (100%) create mode 100644 testing/org-test-ob-consts.el diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 3b5410d47..3004c4a95 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -119,7 +119,11 @@ none ----- do not display either code or results upon export" ;; attempt to go to the same heading in the original file (set-buffer (get-file-buffer org-current-export-file)) (save-restriction - (org-open-link-from-string link) + (condition-case nil + (org-open-link-from-string link) + (error (when heading + (goto-char (point-min)) + (re-search-forward (regexp-quote heading) nil t)))) (setf (nth 2 info) (org-babel-merge-params org-babel-default-header-args diff --git a/testing/examples/example-file-no-header.org b/testing/examples/no-heading.org similarity index 100% rename from testing/examples/example-file-no-header.org rename to testing/examples/no-heading.org diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el index b0b562bf4..cc874776a 100644 --- a/testing/lisp/test-ob-exp.el +++ b/testing/lisp/test-ob-exp.el @@ -13,20 +13,23 @@ ;;; Code: (require 'org-test) +(require 'org-test-ob-consts) ;;; Tests (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers () "Testing export without any headlines in the org-mode file." - (org-test-in-example-file org-test-no-header-file - ;; export the file to html - (org-export-as-html nil) + (let ((html-file (concat (file-name-sans-extension org-test-no-heading-file) + ".html"))) + (when (file-exists-p html-file) (delete-file html-file)) + (org-test-in-example-file org-test-no-heading-file + ;; export the file to html + (org-export-as-html nil)) ;; should create a .html file - (should (file-exists-p (concat - (file-name-sans-extension org-test-no-header-file) - ".html"))) + (should (file-exists-p html-file)) ;; should not create a file with "::" appended to it's name - (should-not (file-exists-p (concat org-test-no-header-file "::"))))) + (should-not (file-exists-p (concat org-test-no-heading-file "::"))) + (when (file-exists-p html-file) (delete-file html-file)))) (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file () "Testing export from buffers which are not visiting any file." @@ -39,10 +42,25 @@ ;; should contain the content of the buffer (save-excursion (set-buffer (get-buffer "*Org HTML Export*")) - (should (string-match (regexp-quote test-org-code-block-anchor) + (should (string-match (regexp-quote org-test-file-ob-anchor) (buffer-string)))) (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*"))) +(ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers () + "Testing export without any headlines in the org-mode file." + (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 + (org-export-as-html nil)) + ;; should create a .html file + (should (file-exists-p html-file)) + ;; should not create a file with "::" appended to it's name + (should-not (file-exists-p (concat org-test-link-in-heading-file "::"))) + (when (file-exists-p html-file) (delete-file html-file)))) + (provide 'test-ob-exp) ;;; test-ob-exp.el ends here diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index d4336926b..b28753e8c 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -13,20 +13,21 @@ ;;; Code: (require 'org-test) +(require 'org-test-ob-consts) (ert-deftest test-org-babel-get-src-block-info-language () - (org-test-at-marker nil test-org-code-block-anchor + (org-test-at-marker nil org-test-file-ob-anchor (let ((info (org-babel-get-src-block-info))) (should (string= "emacs-lisp" (nth 0 info)))))) (ert-deftest test-org-babel-get-src-block-info-body () - (org-test-at-marker nil test-org-code-block-anchor + (org-test-at-marker nil org-test-file-ob-anchor (let ((info (org-babel-get-src-block-info))) - (should (string-match (regexp-quote test-org-code-block-anchor) + (should (string-match (regexp-quote org-test-file-ob-anchor) (nth 1 info)))))) (ert-deftest test-org-babel-get-src-block-info-tangle () - (org-test-at-marker nil test-org-code-block-anchor + (org-test-at-marker nil org-test-file-ob-anchor (let ((info (org-babel-get-src-block-info))) (should (string= "no" (cdr (assoc :tangle (nth 2 info)))))))) diff --git a/testing/org-test-ob-consts.el b/testing/org-test-ob-consts.el new file mode 100644 index 000000000..75b4e3b06 --- /dev/null +++ b/testing/org-test-ob-consts.el @@ -0,0 +1,23 @@ +;;; org-test-ob-consts.el --- constants for use in code block tests + +;; 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: +(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") + +(provide 'org-test-ob-consts) + +;;; org-test-ob-consts.el ends here \ No newline at end of file diff --git a/testing/org-test.el b/testing/org-test.el index 82d954261..524895219 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -62,15 +62,12 @@ org-test searches this directory up the directory tree.") (defconst org-test-file (expand-file-name "normal.org" org-test-example-dir)) -(defconst org-test-no-header-file - (expand-file-name "no-header.org" org-test-dir)) +(defconst org-test-no-heading-file + (expand-file-name "no-heading.org" org-test-example-dir)) (defconst org-test-link-in-heading-file (expand-file-name "link-in-heading.org" org-test-dir)) -(defconst test-org-code-block-anchor - "94839181-184f-4ff4-a72f-94214df6f5ba") - ;;; Functions for writing tests