浏览代码

Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

Carsten Dominik 14 年之前
父节点
当前提交
af4bd933d0

+ 6 - 0
.gitmodules

@@ -0,0 +1,6 @@
+[submodule "testing/jump"]
+	path = testing/jump
+	url = git://github.com/eschulte/jump.el.git
+[submodule "testing/ert"]
+	path = testing/ert
+	url = http://github.com/ohler/ert.git

+ 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
 	    (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

+ 99 - 0
testing/README.org

@@ -0,0 +1,99 @@
+#+OPTIONS:  ^:nil
+
+
+* Testing elisp files with ERT
+
+  The aim is to provide a few simple yet helpfull commands for testing
+  while hacking on elisp files.  The entire thing is based on
+  conventions.  You don't need to care for those conventions, but it
+  makes live easier.
+
+  Currently three commands are provided:
+
+  * =org-test-edit-buffer-file-tests= :: Open the file with tests for
+      the current buffer.  If the file and it's parent directories do
+      not yet exist, create them.  If the file did not yet exist,
+      insert a little template test to get started.
+
+  * =org-test-edit-current-defuns-tests= :: Open the file with tests for
+      the current defun.  Note: this opens a file with the name of the
+      current defun.  If you do not expect many tests for a file to be
+      written, you could as call `org-test-edit-buffer-file-tests'.
+
+  * =org-test-test-current-defun= :: Look up test files for defun at
+       point and execute the tests.  This is done by searching an
+       elisp file with the name of the current defun plus ".el".  In
+       case your point is in defun DEFUN in the file
+       =proj/lisp/FILE.el=, this command will search the directory tree
+       up until it finds a directory named =testing/=.  If there is a
+       directory =proj/testing/= it assumes your tests are in
+       =proj/testing/lisp/FILE.el/DEFUN.el=.  If that file is found, it
+       will be loaded and all ERT tests for the selector "^DEFUN" will
+       be executed.  If that file does not exist, fall back on loading
+       =proj/testing/lisp/FILE.el/tests.el=.
+
+  * =org-test-test-buffer-file= :: Look up a test file for
+       `buffer-file-name' and execute the tests.  This is done by
+       searching for a directory =testing/= from `buffer-file-name's
+       directory upwards and then apply the relative path to your
+       source file there.  In case you're editing =proj/lisp/FILE.el=,
+       and a directory =proj/testing/= exists, this command will try to
+       load =proj/testing/lisp/FILE.el/tests.el= and other elisp files
+       in that directory.  The resulting list of files will be loaded
+       and all ERT tests for selector "^FILE" will be executed.  With
+       a prefix argument, load only =tests.el=.
+
+  * =org-test-run-all-tests= :: Run all tests for all lisp files and all
+       defuns in your project.
+
+
+  The first two commands call `ert-delete-all-tests' to make sure that
+  only the desired tests are executed.  All functions load the test
+  files for each call, hence always a current version of tests are
+  used.  (This might change in the future...)
+
+
+* Getting started
+
+  You should obtain ERT by cloning Christian Ohler's public git
+  repository:
+
+  : sh$ git clone http://github.com/ohler/ert.git
+
+  Ensure that the =ert/= directory is in your loadpath:
+
+  : (add-to-list 'load-path "~/path/to/ert/")
+
+
+*** Where to put the tests
+
+    The tests live in a directory (e.g. =proj/testing/=) that closely
+    resembles the directory structure below =proj/=.
+
+    For example let's assume a file =proj/lisp/FILE.el= exists.  To write tests
+    for this file, create a directory structure in =proj/testing/= with the relative
+    path to your file plus the name of that file as directory:
+    =proj/testing/lisp/FILE.el/=
+
+    Org-test searches that directory for a file named =tests.el= and
+    executes all ERT tests that match the selector "=^FILE=".
+
+    To run a test, you might want to use one of the two commands
+    provided by =org-test.el= (see above).
+
+
+* TODOs
+
+*** TODO Setup a buffers for testing
+
+***** TODO Compare the contents of such a buffer
+      ...with a control file.
+
+*** TODO Provide directory and file functions
+    Provide little services to help test writers with temporary
+    buffers, files and directories.
+
+    Or just use temp-files for that?
+
+*** TODO let-bind different setups for tests
+    Maybe just provide an example on how to do that.

+ 1 - 0
testing/ert

@@ -0,0 +1 @@
+Subproject commit 87b475f856ab6eab479b439b911c5e0c23918a36

+ 10 - 0
testing/examples/link-in-heading.org

@@ -0,0 +1,10 @@
+this file has a link in it's heading, which can cause problems
+
+* [[http://www.example.com][example]]
+
+what a weird heading...
+
+#+begin_src emacs-lisp
+  ;; a8b1d111-eca8-49f0-8930-56d4f0875155
+  (message "my heading has a link")
+#+end_src

+ 9 - 0
testing/examples/no-heading.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

+ 18 - 0
testing/examples/normal.org

@@ -0,0 +1,18 @@
+#+TITLE: Example file
+#+OPTIONS: num:nil ^:nil
+#+STARTUP: hideblocks
+
+This is an example file for use by the Org-mode tests.
+
+* top
+** code block
+   :PROPERTIES:
+   :tangle:   yes
+   :CUSTOM_ID: code-block-section
+   :END:
+Here are a couple of code blocks.
+
+#+begin_src emacs-lisp :tangle no
+  ;; 94839181-184f-4ff4-a72f-94214df6f5ba
+  (message "I am code")
+#+end_src

+ 1 - 0
testing/jump

@@ -0,0 +1 @@
+Subproject commit 0def5442723f8a2928eda7bcf428aa29f8aa97c1

+ 66 - 0
testing/lisp/test-ob-exp.el

@@ -0,0 +1,66 @@
+;;; 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)
+(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."
+  (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 html-file))
+    ;; should not create a file with "::" appended to it's name
+    (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."
+  (when (get-buffer "*Org HTML Export*") (kill-buffer "*Org HTML Export*"))
+  (should-not (get-buffer "*Org HTML Export*"))
+  ;; export the file to HTML in a temporary buffer
+  (org-test-in-example-file nil (org-export-as-html-to-buffer nil))
+  ;; should create a .html buffer
+  (should (buffer-live-p (get-buffer "*Org HTML Export*")))
+  ;; should contain the content of the buffer
+  (save-excursion
+    (set-buffer (get-buffer "*Org HTML Export*"))
+    (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

+ 37 - 0
testing/lisp/test-ob.el

@@ -0,0 +1,37 @@
+;;; test-ob.el --- tests for ob.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)
+(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
+    (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 org-test-file-ob-anchor
+    (let ((info (org-babel-get-src-block-info)))
+      (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 org-test-file-ob-anchor
+    (let ((info (org-babel-get-src-block-info)))
+      (should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
+
+
+(provide 'test-ob)
+
+;;; test-ob ends here

+ 0 - 0
testing/org-html/tests.el → testing/old/org-html.el


+ 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

+ 184 - 0
testing/org-test.el

@@ -0,0 +1,184 @@
+;;;; org-test.el --- Tests for Org-mode
+
+;; Copyright (c) 2010 Sebastian Rose, Eric Schulte
+;; Authors:
+;;     Sebastian Rose, Hannover, Germany, sebastian_rose gmx de
+;;     Eric Schulte, Santa Fe, New Mexico, USA, schulte.eric gmail com
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+;;;; Comments:
+
+;; Interactive testing for Org mode.
+
+;; The heart of all this is the commands `org-test-current-defun'.  If
+;; called while in a `defun' all ert tests with names matching the
+;; name of the function are run.
+
+;;; Prerequisites:
+
+;; ERT and jump.el are both included as git submodules, install with
+;;   $ git submodule init
+;;   $ git submodule update
+
+
+;;;; Code:
+(let* ((org-test-dir (expand-file-name
+		      (file-name-directory
+		       (or load-file-name buffer-file-name))))
+       (load-path (cons
+		   (expand-file-name "ert" org-test-dir)
+		   (cons
+		    (expand-file-name "jump" org-test-dir)
+		    load-path))))
+  (require 'ert-batch)
+  (require 'ert)
+  (require 'ert-exp)
+  (require 'ert-exp-t)
+  (require 'ert-run)
+  (require 'ert-ui)
+  (require 'jump)
+  (require 'which-func)
+  (require 'org))
+
+(defconst org-test-default-test-file-name "tests.el"
+  "For each defun a separate file with tests may be defined.
+tests.el is the fallback or default if you like.")
+
+(defconst org-test-default-directory-name "testing"
+  "Basename or the directory where the tests live.
+org-test searches this directory up the directory tree.")
+
+(defconst org-test-dir
+  (expand-file-name (file-name-directory (or load-file-name buffer-file-name))))
+
+(defconst org-base-dir
+  (expand-file-name ".." org-test-dir))
+
+(defconst org-test-example-dir
+  (expand-file-name "examples" org-test-dir))
+
+(defconst org-test-file
+  (expand-file-name "normal.org" org-test-example-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))
+
+
+;;; Functions for writing tests
+
+(defun org-test-buffer (&optional file)
+  "TODO:  Setup and return a buffer to work with.
+If file is non-nil insert it's contents in there.")
+
+(defun org-test-compare-with-file (&optional file)
+  "TODO:  Compare the contents of the test buffer with FILE.
+If file is not given, search for a file named after the test
+currently executed.")
+
+(defmacro org-test-in-example-file (file &rest body)
+  "Execute body in the Org-mode example file."
+  (declare (indent 1))
+  `(let* ((my-file (or ,file org-test-file))
+	  (visited-p (get-file-buffer my-file))
+	  to-be-removed)
+     (save-window-excursion
+       (save-match-data
+	 (find-file my-file)
+	 (setq to-be-removed (current-buffer))
+	 (goto-char (point-min))
+	 (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))))
+
+(defmacro org-test-at-marker (file marker &rest body)
+  "Run body after placing the point at MARKER in FILE.
+Note the uuidgen command-line command can be useful for
+generating unique markers for insertion as anchors into org
+files."
+  (declare (indent 2))
+  `(org-test-in-example-file ,file
+     (goto-char (point-min))
+     (re-search-forward (regexp-quote ,marker))
+     ,@body))
+
+
+;;; Navigation Functions
+(defjump 'org-test-jump
+  '(("lisp/\\1.el" . "testing/lisp/test-\\1.el")
+    ("lisp/\\1.el" . "testing/lisp/\\1.el/test.*.el")
+    ("contrib/lisp/\\1.el" . "testing/contrib/lisp/test-\\1.el")
+    ("contrib/lisp/\\1.el" . "testing/contrib/lisp/\\1.el/test.*.el")
+    ("testing/lisp/test-\\1.el" . "lisp/\\1.el")
+    ("testing/lisp/\\1.el" . "lisp/\\1.el/test.*.el")
+    ("testing/contrib/lisp/test-\\1.el" . "contrib/lisp/\\1.el")
+    ("testing/contrib/lisp/test-\\1.el" . "contrib/lisp/\\1.el/test.*.el"))
+  (concat org-base-dir "/")
+  "Jump between org-mode files and their tests."
+  (lambda (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
+       ";;; " 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"
+       ";; see: http://www.gnu.org/licenses/gpl-3.0.html\n\n"
+       ";;;; Comments:\n\n"
+       ";; Template test file for Org-mode tests\n\n"
+       "\n"
+       ";;; Code:\n"
+       "(require 'org-test)\n\n"
+       "\n"
+       ";;; Tests\n"
+       "(ert-deftest " name "/example-test ()\n"
+       "  \"Just an example to get you started.\"\n"
+       "  (should t)\n"
+       "  (should-not nil)\n"
+       "  (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))))
+
+
+;;; Load and Run tests
+(defun org-test-load ()
+  "Load up the org-mode test suite."
+  (interactive)
+  (flet ((rload (base)
+		(mapc
+		 (lambda (path)
+		   (if (file-directory-p path) (rload path) (load-file path)))
+		 (directory-files base 'full
+				  "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.el"))))
+    (rload (expand-file-name "lisp" org-test-dir))
+    (rload (expand-file-name "lisp"
+			     (expand-file-name "contrib" org-test-dir)))))
+
+(defun org-test-current-defun ()
+  "Test the current function."
+  (interactive)
+  (ert (car (which-function))))
+
+(defun org-test-run-all-tests ()
+  "Run all defined tests matching \"^org\".
+Load all test files first."
+  (interactive)
+  (org-test-load)
+  (ert "org"))
+
+(provide 'org-test)
+
+;;; org-test.el ends here