Browse Source

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
Eric Schulte 14 years ago
parent
commit
e1b90eea45

+ 5 - 1
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
 	    ;; attempt to go to the same heading in the original file
 	    (set-buffer (get-file-buffer org-current-export-file))
 	    (set-buffer (get-file-buffer org-current-export-file))
 	  (save-restriction
 	  (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)
 	    (setf (nth 2 info)
 		  (org-babel-merge-params
 		  (org-babel-merge-params
 		   org-babel-default-header-args
 		   org-babel-default-header-args

+ 0 - 0
testing/examples/example-file-no-header.org → testing/examples/no-heading.org


+ 26 - 8
testing/lisp/test-ob-exp.el

@@ -13,20 +13,23 @@
 
 
 ;;; Code:
 ;;; Code:
 (require 'org-test)
 (require 'org-test)
+(require 'org-test-ob-consts)
 
 
 
 
 ;;; Tests
 ;;; Tests
 (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
 (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
   "Testing export without any headlines in the org-mode file."
   "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 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 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 ()
 (ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file ()
   "Testing export from buffers which are not visiting any file."
   "Testing export from buffers which are not visiting any file."
@@ -39,10 +42,25 @@
   ;; should contain the content of the buffer
   ;; should contain the content of the buffer
   (save-excursion
   (save-excursion
     (set-buffer (get-buffer "*Org HTML Export*"))
     (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))))
 			  (buffer-string))))
   (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*")))
   (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)
 (provide 'test-ob-exp)
 
 
 ;;; test-ob-exp.el ends here
 ;;; test-ob-exp.el ends here

+ 5 - 4
testing/lisp/test-ob.el

@@ -13,20 +13,21 @@
 
 
 ;;; Code:
 ;;; Code:
 (require 'org-test)
 (require 'org-test)
+(require 'org-test-ob-consts)
 
 
 (ert-deftest test-org-babel-get-src-block-info-language ()
 (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)))
     (let ((info (org-babel-get-src-block-info)))
       (should (string= "emacs-lisp" (nth 0 info))))))
       (should (string= "emacs-lisp" (nth 0 info))))))
 
 
 (ert-deftest test-org-babel-get-src-block-info-body ()
 (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)))
     (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))))))
 			    (nth 1 info))))))
 
 
 (ert-deftest test-org-babel-get-src-block-info-tangle ()
 (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)))
     (let ((info (org-babel-get-src-block-info)))
       (should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
       (should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
 
 

+ 23 - 0
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

+ 2 - 5
testing/org-test.el

@@ -62,15 +62,12 @@ org-test searches this directory up the directory tree.")
 (defconst org-test-file
 (defconst org-test-file
   (expand-file-name "normal.org" org-test-example-dir))
   (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
 (defconst org-test-link-in-heading-file
   (expand-file-name "link-in-heading.org" org-test-dir))
   (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
 ;;; Functions for writing tests