org-test.el (org-test-with-temp-text-in-file): Wrap ,@body into (progn ...).

* org-test.el (org-test-with-temp-text-in-file): Wrap ,@body
into (progn ...) so that tests don't have to wrap it themselves.

Fix the testing suite to use this.
Also fix formatting and trailing whitespaces.
Fix test-org-src/blank-line-block so that it
checks editing of a code block with a whitespace
with point on the #+begin_src line.

Thanks to Michael Brand for spotting the (progn ...) problem.
This commit is contained in:
Bastien Guerry 2012-12-15 08:49:23 +01:00
parent c8452bfca0
commit fa0e8feea8
5 changed files with 207 additions and 234 deletions

View File

@ -28,55 +28,51 @@
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; ;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (should (re-search-forward "results:" nil t))
(should (re-search-forward "results:" nil t)) (forward-line)
(forward-line) (should
(should (string=
(string= ""
"" (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
#+begin_src emacs-lisp #+begin_src emacs-lisp
\"some text\";; \"some text\";;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (should (re-search-forward "results:" nil t))
(should (re-search-forward "results:" nil t)) (forward-line)
(forward-line) (should
(should (string=
(string= ": some text"
": some text" (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
(ert-deftest ob-emacs-lisp/commented-last-block-line-with-var () (ert-deftest ob-emacs-lisp/commented-last-block-line-with-var ()
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=1 #+begin_src emacs-lisp :var a=1
;; ;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (re-search-forward "results" nil t)
(re-search-forward "results" nil t) (forward-line)
(forward-line) (should (string=
(should (string= ""
"" (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))) (org-test-with-temp-text-in-file "
(org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=2 #+begin_src emacs-lisp :var a=2
2;; 2;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (re-search-forward "results" nil t)
(re-search-forward "results" nil t) (forward-line)
(forward-line) (should (string=
(should (string= ": 2"
": 2" (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
(provide 'test-ob-emacs-lisp) (provide 'test-ob-emacs-lisp)
;;; test-ob-emacs-lisp.el ends here ;;; test-ob-emacs-lisp.el ends here

View File

@ -148,12 +148,10 @@
#+begin_src emacs-lisp #+begin_src emacs-lisp
prop prop
#+end_src" #+end_src"
(goto-char (point-min))
(progn (org-babel-next-src-block)
(goto-char (point-min)) (let ((info (org-babel-get-src-block-info)))
(org-babel-next-src-block) (should (= 42 (org-babel-execute-src-block))))))
(let ((info (org-babel-get-src-block-info)))
(should (= 42 (org-babel-execute-src-block)))))))
(ert-deftest test-org-babel/simple-named-code-block () (ert-deftest test-org-babel/simple-named-code-block ()
"Test that simple named code blocks can be evaluated." "Test that simple named code blocks can be evaluated."
@ -163,10 +161,8 @@
#+begin_src emacs-lisp #+begin_src emacs-lisp
42 42
#+end_src" #+end_src"
(org-babel-next-src-block 1)
(progn (should (= 42 (org-babel-execute-src-block)))))
(org-babel-next-src-block 1)
(should (= 42 (org-babel-execute-src-block))))))
(ert-deftest test-org-babel/simple-variable-resolution () (ert-deftest test-org-babel/simple-variable-resolution ()
"Test that simple variable resolution is working." "Test that simple variable resolution is working."
@ -181,13 +177,12 @@
(length four) (length four)
#+end_src" #+end_src"
(progn (org-babel-next-src-block 2)
(org-babel-next-src-block 2) (should (= 4 (org-babel-execute-src-block)))
(should (= 4 (org-babel-execute-src-block))) (forward-line 5)
(forward-line 5) (should (string= ": 4" (buffer-substring
(should (string= ": 4" (buffer-substring (point-at-bol)
(point-at-bol) (point-at-eol))))))
(point-at-eol)))))))
(ert-deftest test-org-babel/multi-line-header-arguments () (ert-deftest test-org-babel/multi-line-header-arguments ()
"Test that multi-line header arguments and can be read." "Test that multi-line header arguments and can be read."
@ -202,11 +197,10 @@
(my-map 'list #'list numbers letters) (my-map 'list #'list numbers letters)
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (let ((results (org-babel-execute-src-block)))
(let ((results (org-babel-execute-src-block))) (should(equal 'a (cadr (assoc 1 results))))
(should(equal 'a (cadr (assoc 1 results)))) (should(equal 'd (cadr (assoc 4 results)))))))
(should(equal 'd (cadr (assoc 4 results))))))))
(ert-deftest test-org-babel/parse-header-args () (ert-deftest test-org-babel/parse-header-args ()
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
@ -215,17 +209,16 @@
the body the body
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (let* ((info (org-babel-get-src-block-info))
(let* ((info (org-babel-get-src-block-info)) (params (nth 2 info)))
(params (nth 2 info))) (message "%S" params)
(message "%S" params) (should (equal "example-lang" (nth 0 info)))
(should(equal "example-lang" (nth 0 info))) (should (string= "the body" (org-babel-trim (nth 1 info))))
(should(string= "the body" (org-babel-trim (nth 1 info)))) (should-not (member '(:session\ \ \ \ ) params))
(should-not (member '(:session\ \ \ \ ) params)) (should (equal '(:session) (assoc :session params)))
(should(equal '(:session) (assoc :session params))) (should (equal '(:result-type . output) (assoc :result-type params)))
(should(equal '(:result-type . output) (assoc :result-type params))) (should (equal '(num . 9) (cdr (assoc :var params)))))))
(should(equal '(num . 9) (cdr (assoc :var params))))))))
(ert-deftest test-org-babel/parse-header-args2 () (ert-deftest test-org-babel/parse-header-args2 ()
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
@ -247,20 +240,19 @@
:END: :END:
this is simple" this is simple"
(progn (should (string-match (regexp-quote "this is simple")
(should (string-match (regexp-quote "this is simple") (org-babel-ref-resolve "simple-subtree")))
(org-babel-ref-resolve "simple-subtree"))) (org-babel-next-src-block)
(org-babel-next-src-block) (should (= 14 (org-babel-execute-src-block)))))
(should (= 14 (org-babel-execute-src-block))))))
(ert-deftest test-org-babel/inline-src-blocks () (ert-deftest test-org-babel/inline-src-blocks ()
(org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18" (org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
(macrolet ((at-next (&rest body) (macrolet ((at-next (&rest body)
`(progn `(progn
(move-end-of-line 1) (move-end-of-line 1)
(re-search-forward org-babel-inline-src-block-regexp nil t) (re-search-forward org-babel-inline-src-block-regexp nil t)
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))
(save-match-data ,@body)))) (save-match-data ,@body))))
(at-next (should (equal 1 (org-babel-execute-src-block)))) (at-next (should (equal 1 (org-babel-execute-src-block))))
(at-next (should (equal 2 (org-babel-execute-src-block)))) (at-next (should (equal 2 (org-babel-execute-src-block))))
(at-next (should (equal 3 (org-babel-execute-src-block))))))) (at-next (should (equal 3 (org-babel-execute-src-block)))))))
@ -309,19 +301,19 @@ this is simple"
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))) (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
;; src_ follows space line 1... ;; src_ follows space line 1...
(let ((test-line " src_emacs-lisp{ 1 }")) (let ((test-line " src_emacs-lisp{ 1 }"))
(org-test-with-temp-text (org-test-with-temp-text
test-line test-line
(should-error (org-ctrl-c-ctrl-c)) (should-error (org-ctrl-c-ctrl-c))
(forward-char) (org-ctrl-c-ctrl-c) (forward-char) (org-ctrl-c-ctrl-c)
(should (string= (should (string=
(concat test-line " =1=") (concat test-line " =1=")
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))) (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(re-search-forward "{ 1 ") (org-ctrl-c-ctrl-c) (re-search-forward "{ 1 ") (org-ctrl-c-ctrl-c)
(should (string= (should (string=
(concat test-line " =1= =1=") (concat test-line " =1= =1=")
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))) (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(forward-char) (forward-char)
(should-error (org-ctrl-c-ctrl-c))))) (should-error (org-ctrl-c-ctrl-c))))))
(ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-2 () (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-2 ()
;; src_ at bol line 2... ;; src_ at bol line 2...
@ -346,14 +338,14 @@ this is simple"
(insert (concat "\n" test-line " end")) (insert (concat "\n" test-line " end"))
(re-search-backward "src") (org-ctrl-c-ctrl-c) (re-search-backward "src") (org-ctrl-c-ctrl-c)
(should (string= (should (string=
(concat test-line " =y= end") (concat test-line " =y= end")
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))) (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(re-search-forward "\" ") (org-ctrl-c-ctrl-c) (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
(should (string= (should (string=
(concat test-line " =y= =y= end") (concat test-line " =y= =y= end")
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))) (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(forward-char) (forward-char)
(should-error (org-ctrl-c-ctrl-c)))))) (should-error (org-ctrl-c-ctrl-c)))))
(ert-deftest test-org-babel/inline-src_blk-manual-results-replace () (ert-deftest test-org-babel/inline-src_blk-manual-results-replace ()
(let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }")) (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }"))
@ -637,15 +629,15 @@ on two lines
(ert-deftest test-ob/eval-header-argument () (ert-deftest test-ob/eval-header-argument ()
(flet ((check-eval (eval runp) (flet ((check-eval (eval runp)
(org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s (org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
(setq foo :evald) (setq foo :evald)
#+end_src" eval) #+end_src" eval)
(let ((foo :not-run)) (let ((foo :not-run))
(if runp (if runp
(progn (should (org-babel-execute-src-block)) (progn (should (org-babel-execute-src-block))
(should (eq foo :evald))) (should (eq foo :evald)))
(progn (should-not (org-babel-execute-src-block)) (progn (should-not (org-babel-execute-src-block))
(should-not (eq foo :evald)))))))) (should-not (eq foo :evald))))))))
(check-eval "never" nil) (check-eval "never" nil)
(check-eval "no" nil) (check-eval "no" nil)
(check-eval "never-export" t) (check-eval "never-export" t)
@ -700,55 +692,50 @@ on two lines
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; ;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (should (re-search-forward "\\#\\+results:" nil t))
(should (re-search-forward "\\#\\+results:" nil t)) (forward-line)
(forward-line) (should
(should (string=
(string= ""
"" (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
#+begin_src emacs-lisp #+begin_src emacs-lisp
\"some text\";; \"some text\";;
#+end_src" #+end_src"
(org-babel-next-src-block)
(progn (org-ctrl-c-ctrl-c)
(org-babel-next-src-block) (should (re-search-forward "\\#\\+results:" nil t))
(org-ctrl-c-ctrl-c) (forward-line)
(should (re-search-forward "\\#\\+results:" nil t)) (should
(forward-line) (string=
(should ": some text"
(string= (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
": some text"
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
(ert-deftest test-ob/commented-last-block-line-with-var () (ert-deftest test-ob/commented-last-block-line-with-var ()
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=1 #+begin_src emacs-lisp :var a=1
;; ;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (re-search-forward "\\#\\+results:" nil t)
(re-search-forward "\\#\\+results:" nil t) (forward-line)
(forward-line) (should (string=
(should (string= ""
"" (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=2 #+begin_src emacs-lisp :var a=2
2;; 2;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (re-search-forward "\\#\\+results:" nil t)
(re-search-forward "\\#\\+results:" nil t) (forward-line)
(forward-line) (should (string=
(should (string= ": 2"
": 2" (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
(defun test-ob-verify-result-and-removed-result (result buffer-text) (defun test-ob-verify-result-and-removed-result (result buffer-text)
"Test helper function to test `org-babel-remove-result'. "Test helper function to test `org-babel-remove-result'.
@ -759,18 +746,17 @@ The block is actually executed /twice/ to ensure result
replacement happens correctly." replacement happens correctly."
(org-test-with-temp-text (org-test-with-temp-text
buffer-text buffer-text
(progn (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c) (should (re-search-forward "\\#\\+results:" nil t))
(should (re-search-forward "\\#\\+results:" nil t)) (forward-line)
(forward-line) (should (string= result
(should (string= result (buffer-substring-no-properties
(buffer-substring-no-properties (point-at-bol)
(point-at-bol) (- (point-max) 16))))
(- (point-max) 16)))) (org-babel-previous-src-block) (org-babel-remove-result)
(org-babel-previous-src-block) (org-babel-remove-result) (should (string= buffer-text
(should (string= buffer-text (buffer-substring-no-properties
(buffer-substring-no-properties (point-min) (point-max))))))
(point-min) (point-max)))))))
(ert-deftest test-ob/org-babel-remove-result--results-default () (ert-deftest test-ob/org-babel-remove-result--results-default ()
"Test `org-babel-remove-result' with default :results." "Test `org-babel-remove-result' with default :results."
@ -778,7 +764,7 @@ replacement happens correctly."
(test-ob-verify-result-and-removed-result (test-ob-verify-result-and-removed-result
"\n" "\n"
(concat (concat
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src " language " #+begin_src " language "
#+end_src #+end_src
@ -793,7 +779,7 @@ replacement happens correctly."
- 3 - 3
- (quote (4 5))" - (quote (4 5))"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results list #+begin_src emacs-lisp :results list
'(1 2 3 '(4 5)) '(1 2 3 '(4 5))
#+end_src #+end_src
@ -805,7 +791,7 @@ replacement happens correctly."
If not inserted correctly then the second evaluation will fail If not inserted correctly then the second evaluation will fail
trying to find the :END: marker." trying to find the :END: marker."
(org-test-with-temp-text (org-test-with-temp-text
"- indented "- indented
#+begin_src sh :results file wrap #+begin_src sh :results file wrap
echo test.txt echo test.txt
#+end_src" #+end_src"
@ -834,7 +820,7 @@ trying to find the :END: marker."
(test-ob-verify-result-and-removed-result (test-ob-verify-result-and-removed-result
": \"I /am/ working!\"" ": \"I /am/ working!\""
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results pp #+begin_src emacs-lisp :results pp
\"I /am/ working!\") \"I /am/ working!\")
#+end_src #+end_src
@ -855,26 +841,24 @@ trying to find the :END: marker."
#+begin_src emacs-lisp :var a=1 #+begin_src emacs-lisp :var a=1
;; ;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (re-search-forward "\\#\\+results:" nil t)
(re-search-forward "\\#\\+results:" nil t) (forward-line)
(forward-line) (should (string=
(should (string= ""
"" (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(org-test-with-temp-text-in-file " (org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=2 #+begin_src emacs-lisp :var a=2
2;; 2;;
#+end_src" #+end_src"
(progn (org-babel-next-src-block)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c)
(org-ctrl-c-ctrl-c) (re-search-forward "\\#\\+results:" nil t)
(re-search-forward "\\#\\+results:" nil t) (forward-line)
(forward-line) (should (string=
(should (string= ": 2"
": 2" (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
(defun test-ob-verify-result-and-removed-result (result buffer-text) (defun test-ob-verify-result-and-removed-result (result buffer-text)
"Test helper function to test `org-babel-remove-result'. "Test helper function to test `org-babel-remove-result'.
@ -885,18 +869,17 @@ The block is actually executed /twice/ to ensure result
replacement happens correctly." replacement happens correctly."
(org-test-with-temp-text (org-test-with-temp-text
buffer-text buffer-text
(progn (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
(org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c) (should (re-search-forward "\\#\\+results:" nil t))
(should (re-search-forward "\\#\\+results:" nil t)) (forward-line)
(forward-line) (should (string= result
(should (string= result (buffer-substring-no-properties
(buffer-substring-no-properties (point-at-bol)
(point-at-bol) (- (point-max) 16))))
(- (point-max) 16)))) (org-babel-previous-src-block) (org-babel-remove-result)
(org-babel-previous-src-block) (org-babel-remove-result) (should (string= buffer-text
(should (string= buffer-text (buffer-substring-no-properties
(buffer-substring-no-properties (point-min) (point-max))))))
(point-min) (point-max)))))))
(ert-deftest test-ob/org-babel-remove-result--results-default () (ert-deftest test-ob/org-babel-remove-result--results-default ()
"Test `org-babel-remove-result' with default :results." "Test `org-babel-remove-result' with default :results."
@ -904,7 +887,7 @@ replacement happens correctly."
(test-ob-verify-result-and-removed-result (test-ob-verify-result-and-removed-result
"\n" "\n"
(concat (concat
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src " language " #+begin_src " language "
#+end_src #+end_src
@ -919,7 +902,7 @@ replacement happens correctly."
- 3 - 3
- (quote (4 5))" - (quote (4 5))"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results list #+begin_src emacs-lisp :results list
'(1 2 3 '(4 5)) '(1 2 3 '(4 5))
#+end_src #+end_src
@ -933,7 +916,7 @@ replacement happens correctly."
hello there hello there
:END:" :END:"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results wrap #+begin_src emacs-lisp :results wrap
\"hello there\" \"hello there\"
@ -950,7 +933,7 @@ hello there
content content
#+END_SRC" #+END_SRC"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results org #+begin_src emacs-lisp :results org
\"* heading \"* heading
** subheading ** subheading
@ -966,7 +949,7 @@ content\"
<head><body></body></head> <head><body></body></head>
#+END_HTML" #+END_HTML"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results html #+begin_src emacs-lisp :results html
\"<head><body></body></head>\" \"<head><body></body></head>\"
#+end_src #+end_src
@ -982,7 +965,7 @@ Line 2
Line 3 Line 3
#+END_LaTeX" #+END_LaTeX"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results latex #+begin_src emacs-lisp :results latex
\"Line 1 \"Line 1
Line 2 Line 2
@ -999,7 +982,7 @@ Line 3\"
\"I am working!\" \"I am working!\"
#+END_SRC" #+END_SRC"
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results code #+begin_src emacs-lisp :results code
(message \"I am working!\") (message \"I am working!\")
#+end_src #+end_src
@ -1011,7 +994,7 @@ Line 3\"
(test-ob-verify-result-and-removed-result (test-ob-verify-result-and-removed-result
": \"I /am/ working!\"" ": \"I /am/ working!\""
"* org-babel-remove-result "* org-babel-remove-result
#+begin_src emacs-lisp :results pp #+begin_src emacs-lisp :results pp
\"I /am/ working!\") \"I /am/ working!\")
#+end_src #+end_src
@ -1022,11 +1005,11 @@ Line 3\"
(org-test-with-temp-text "Block two has a space after the name. (org-test-with-temp-text "Block two has a space after the name.
#+name: foo #+name: foo
#+begin_src emacs-lisp #+begin_src emacs-lisp
1 1
#+end_src emacs-lisp #+end_src emacs-lisp
#+name: foo #+name: foo
#+begin_src emacs-lisp #+begin_src emacs-lisp
2 2
#+end_src #+end_src
@ -1060,8 +1043,8 @@ Line 3\"
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
\(+ 1 2) \(+ 1 2)
#+END_SRC\n\n\n" #+END_SRC\n\n\n"
(progn (org-babel-execute-src-block) (org-babel-execute-src-block)
(buffer-string)))))) (buffer-string)))))
(ert-deftest test-ob/results-in-narrowed-buffer () (ert-deftest test-ob/results-in-narrowed-buffer ()
"Test block execution in a narrowed buffer." "Test block execution in a narrowed buffer."
@ -1072,19 +1055,17 @@ Line 3\"
"#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3" "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS:\n: 3"
(org-test-with-temp-text (org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph" "#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
(progn (narrow-to-region (point) (save-excursion (forward-line 3) (point)))
(narrow-to-region (point) (save-excursion (forward-line 3) (point))) (org-babel-execute-src-block)
(org-babel-execute-src-block) (org-trim (buffer-string)))))
(org-trim (buffer-string))))))
(should (should
(equal (equal
"#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3" "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
(org-test-with-temp-text (org-test-with-temp-text
"#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph" "#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
(progn (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
(narrow-to-region (point) (save-excursion (forward-line 4) (point))) (org-babel-execute-src-block)
(org-babel-execute-src-block) (org-trim (buffer-string)))))
(org-trim (buffer-string))))))
;; Results in visible part of buffer, should be updated here. ;; Results in visible part of buffer, should be updated here.
(should (should
(equal (equal
@ -1105,10 +1086,9 @@ Line 3\"
: 4 : 4
Paragraph" Paragraph"
(progn (narrow-to-region (point) (save-excursion (forward-line 7) (point)))
(narrow-to-region (point) (save-excursion (forward-line 7) (point))) (org-babel-execute-src-block)
(org-babel-execute-src-block) (org-trim (buffer-string)))))
(org-trim (buffer-string))))))
;; Results in invisible part of buffer, should be updated there. ;; Results in invisible part of buffer, should be updated there.
(org-test-with-temp-text (org-test-with-temp-text
"#+NAME: test "#+NAME: test
@ -1120,12 +1100,11 @@ Paragraph"
: 4 : 4
Paragraph" Paragraph"
(progn (narrow-to-region (point) (save-excursion (forward-line 4) (point)))
(narrow-to-region (point) (save-excursion (forward-line 4) (point))) (org-babel-execute-src-block)
(org-babel-execute-src-block) (should-not (re-search-forward "^#\\+RESULTS:" nil t))
(should-not (re-search-forward "^#\\+RESULTS:" nil t)) (widen)
(widen) (should (should (re-search-forward "^: 3" nil t)))))
(should (should (re-search-forward "^: 3" nil t))))))
(provide 'test-ob) (provide 'test-ob)

View File

@ -31,21 +31,21 @@
#+begin_src line #+begin_src line
" "
(org-test-with-temp-text (org-test-with-temp-text
" "
#+begin_src emacs-lisp #+begin_src emacs-lisp
(message hello) (message hello)
#+end_src #+end_src
" "
(goto-line 2) (goto-line 2)
(org-edit-special) (org-edit-special)
(insert "blah") (insert "blah")
(org-edit-src-exit) (org-edit-src-exit)
(should (equal (buffer-string) " (should (equal (buffer-string) "
#+begin_src emacs-lisp #+begin_src emacs-lisp
blah(message hello) blah(message hello)
#+end_src #+end_src
")) "))
(should (equal (word-at-point) "blah")))) (should (equal (word-at-point) "blah"))))
(ert-deftest test-org-src/point-outside-block () (ert-deftest test-org-src/point-outside-block ()
"Editing with point before/after block signals expected error." "Editing with point before/after block signals expected error."
@ -86,16 +86,15 @@
#+end_src #+end_src
" "
(progn (goto-line 2)
(goto-line 3) (org-edit-special)
(org-edit-special) (insert "blah")
(insert "blah") (org-edit-src-exit)
(org-edit-src-exit) (should (equal (buffer-string) "
(should (equal (buffer-string) "
#+begin_src emacs-lisp #+begin_src emacs-lisp
blah blah
#+end_src #+end_src
"))))) "))))
(provide 'test-org-src) (provide 'test-org-src)
;;; test-org-src.el ends here ;;; test-org-src.el ends here

View File

@ -72,12 +72,11 @@
| | | |
#+TBLFM: $1=vsum(@1..@-1) #+TBLFM: $1=vsum(@1..@-1)
" "
(progn (re-search-forward (regexp-quote "#+tblname: simple-formula") nil t)
(re-search-forward (regexp-quote "#+tblname: simple-formula") nil t) (forward-line 1)
(forward-line 1) (should (org-at-table-p))
(should (org-at-table-p)) (should (org-table-recalculate 'all))
(should (org-table-recalculate 'all)) (should (string= "10" (first (nth 5 (org-table-to-lisp)))))))
(should (string= "10" (first (nth 5 (org-table-to-lisp))))))))
(provide 'test-org-table) (provide 'test-org-table)

View File

@ -42,7 +42,7 @@
(setq load-path (cons org-lisp-dir load-path)) (setq load-path (cons org-lisp-dir load-path))
(require 'org) (require 'org)
(require 'org-id) (require 'org-id)
(org-babel-do-load-languages (org-babel-do-load-languages
'org-babel-load-languages '((sh . t) (org . t)))) 'org-babel-load-languages '((sh . t) (org . t))))
(let* ((load-path (cons (let* ((load-path (cons
@ -214,7 +214,7 @@ otherwise place the point at the beginning of the inserted text."
(with-temp-file ,file (insert ,inside-text)) (with-temp-file ,file (insert ,inside-text))
(find-file ,file) (find-file ,file)
(org-mode) (org-mode)
(setq ,results ,@body) (setq ,results (progn ,@body))
(save-buffer) (kill-buffer (current-buffer)) (save-buffer) (kill-buffer (current-buffer))
(delete-file ,file) (delete-file ,file)
,results))) ,results)))
@ -300,7 +300,7 @@ otherwise place the point at the beginning of the inserted text."
(rld path) (rld path)
(condition-case err (condition-case err
(when (string-match "^[A-Za-z].*\\.el$" (when (string-match "^[A-Za-z].*\\.el$"
(file-name-nondirectory path)) (file-name-nondirectory path))
(load-file path)) (load-file path))
(missing-test-dependency (missing-test-dependency
(let ((name (intern (let ((name (intern