From 5bafe303aafc54d0d09ba548750165e429c64806 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 4 Oct 2010 08:29:00 -0600 Subject: [PATCH] beginning tests for ob-exp, and related improvements to org-test - fixed issue in creation of new files - fixed issue in org-test-in-file - new example file w/o any headlines --- testing/example-file-no-header.org | 9 +++++++++ testing/lisp/test-ob-exp.el | 36 ++++++++++++++++++++++++++++++++++++ testing/org-test.el | 30 ++++++++++++++++++++---------- 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 testing/example-file-no-header.org create mode 100644 testing/lisp/test-ob-exp.el diff --git a/testing/example-file-no-header.org b/testing/example-file-no-header.org new file mode 100644 index 000000000..24d7c0868 --- /dev/null +++ b/testing/example-file-no-header.org @@ -0,0 +1,9 @@ +This is an example file for use by the Org-mode tests. + +This file is special because it has no headings, which can be +erroneously assumed by some code. + +#+begin_src emacs-lisp :tangle no + ;; 94839181-184f-4ff4-a72f-94214df6f5ba + (message "I am code") +#+end_src diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el new file mode 100644 index 000000000..87c2b7a20 --- /dev/null +++ b/testing/lisp/test-ob-exp.el @@ -0,0 +1,36 @@ +;;; test-ob-exp.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: +(require 'org-test) + + +;;; 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-example-file-name + ;; 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-example-file-name) + ".html"))) + ;; should not create a file with "::" appended to it's name + (should-not (file-exists-p + (concat org-test-no-header-example-file-name "::"))))) + +(provide 'test-ob-exp) + +;;; test-ob-exp.el ends here diff --git a/testing/org-test.el b/testing/org-test.el index e14dcaf1f..6e78bad34 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -59,6 +59,9 @@ org-test searches this directory up the directory tree.") (defconst org-test-example-file-name (expand-file-name "example-file.org" org-test-dir)) +(defconst org-test-no-header-example-file-name + (expand-file-name "example-file-no-header.org" org-test-dir)) + ;;; Functions for writing tests @@ -74,16 +77,20 @@ currently executed.") (defmacro org-test-in-example-file (file &rest body) "Execute body in the Org-mode example file." (declare (indent 1)) - `(let ((visited-p (get-file-buffer (or ,file org-test-example-file-name))) - to-be-removed) + `(let* ((my-file (or ,file org-test-example-file-name)) + (visited-p (get-file-buffer my-file)) + to-be-removed) (save-window-excursion (save-match-data - (find-file org-test-example-file-name) + (find-file my-file) (setq to-be-removed (current-buffer)) (goto-char (point-min)) - (outline-next-visible-heading 1) - (org-show-subtree) - (org-show-block-all) + (condition-case nil + (progn + (outline-next-visible-heading 1) + (org-show-subtree) + (org-show-block-all)) + (error nil)) ,@body)) (unless visited-p (kill-buffer to-be-removed)))) @@ -113,11 +120,12 @@ files." (concat org-base-dir "/") "Jump between org-mode files and their tests." (lambda (path) - (let ((full-path (expand-file-name path org-base-dir)) - (name (file-name-nondirectory 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 - ";;; " name "\n\n" + ";;; " file-name "\n\n" ";; Copyright (c) 2010 " user-full-name "\n" ";; Authors: " user-full-name "\n\n" ";; Released under the GNU General Public License version 3\n" @@ -133,7 +141,9 @@ files." " \"Just an example to get you started.\"\n" " (should t)\n" " (should-not nil)\n" - " (should-error (error \"errr...\")))") full-path)) + " (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)))) -- 2.11.4.GIT