improving test-helper macros for better name-spaceing and more flexibility
This commit is contained in:
parent
271d1bb986
commit
9bd5f511ce
|
@ -1,29 +1,36 @@
|
|||
;;; 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)
|
||||
|
||||
(defmacro test-ob-in-code-block (marker &rest body)
|
||||
(declare (indent 1))
|
||||
`(in-org-example-file
|
||||
(goto-char (point-min))
|
||||
(re-search-forward (regexp-quote ,marker))
|
||||
,@body))
|
||||
|
||||
(ert-deftest test-org-babel-get-src-block-info-language ()
|
||||
(test-ob-in-code-block "94839181-184f-4ff4-a72f-94214df6f5ba"
|
||||
(org-test-at-marker nil "94839181-184f-4ff4-a72f-94214df6f5ba"
|
||||
(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 ()
|
||||
(test-ob-in-code-block "94839181-184f-4ff4-a72f-94214df6f5ba"
|
||||
(org-test-at-marker nil "94839181-184f-4ff4-a72f-94214df6f5ba"
|
||||
(let ((info (org-babel-get-src-block-info)))
|
||||
(should (string-match (regexp-quote "94839181-184f-4ff4-a72f-94214df6f5ba")
|
||||
(nth 1 info))))))
|
||||
|
||||
(ert-deftest test-org-babel-get-src-block-info-tangle ()
|
||||
(test-ob-in-code-block "94839181-184f-4ff4-a72f-94214df6f5ba"
|
||||
(org-test-at-marker nil "94839181-184f-4ff4-a72f-94214df6f5ba"
|
||||
(let ((info (org-babel-get-src-block-info)))
|
||||
(should (string= "no" (cdr (assoc :tangle (nth 2 info))))))))
|
||||
|
||||
|
||||
(provide 'test-ob)
|
||||
|
||||
;;; test-ob ends here
|
|
@ -71,10 +71,10 @@ 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 in-org-example-file (&rest body)
|
||||
(defmacro org-test-in-example-file (file &rest body)
|
||||
"Execute body in the Org-mode example file."
|
||||
(declare (indent 0))
|
||||
`(let ((visited-p (get-file-buffer org-test-example-file-name))
|
||||
(declare (indent 1))
|
||||
`(let ((visited-p (get-file-buffer (or ,file org-test-example-file-name)))
|
||||
to-be-removed)
|
||||
(save-window-excursion
|
||||
(save-match-data
|
||||
|
@ -88,6 +88,17 @@ currently executed.")
|
|||
(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
|
||||
|
@ -123,7 +134,7 @@ currently executed.")
|
|||
" (should t)\n"
|
||||
" (should-not nil)\n"
|
||||
" (should-error (error \"errr...\")))") full-path))
|
||||
(lambda () (car (which-function))))
|
||||
(lambda () ((lambda (res) (if (listp res) (car res) res)) (which-function))))
|
||||
|
||||
|
||||
;;; Load and Run tests
|
||||
|
@ -136,7 +147,9 @@ currently executed.")
|
|||
(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" org-test-dir))
|
||||
(rload (expand-file-name "lisp"
|
||||
(expand-file-name "contrib" org-test-dir)))))
|
||||
|
||||
(defun org-test-current-defun ()
|
||||
"Test the current function."
|
||||
|
|
Loading…
Reference in New Issue