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,7 +28,6 @@
#+begin_src emacs-lisp
;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(should (re-search-forward "results:" nil t))
@ -36,13 +35,12 @@
(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 "
#+begin_src emacs-lisp
\"some text\";;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(should (re-search-forward "results:" nil t))
@ -50,14 +48,13 @@
(should
(string=
": 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 ()
(org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=1
;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(re-search-forward "results" nil t)
@ -69,14 +66,13 @@
#+begin_src emacs-lisp :var a=2
2;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(re-search-forward "results" nil t)
(forward-line)
(should (string=
": 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)
;;; test-ob-emacs-lisp.el ends here

View File

@ -148,12 +148,10 @@
#+begin_src emacs-lisp
prop
#+end_src"
(progn
(goto-char (point-min))
(org-babel-next-src-block)
(let ((info (org-babel-get-src-block-info)))
(should (= 42 (org-babel-execute-src-block)))))))
(should (= 42 (org-babel-execute-src-block))))))
(ert-deftest test-org-babel/simple-named-code-block ()
"Test that simple named code blocks can be evaluated."
@ -163,10 +161,8 @@
#+begin_src emacs-lisp
42
#+end_src"
(progn
(org-babel-next-src-block 1)
(should (= 42 (org-babel-execute-src-block))))))
(should (= 42 (org-babel-execute-src-block)))))
(ert-deftest test-org-babel/simple-variable-resolution ()
"Test that simple variable resolution is working."
@ -181,13 +177,12 @@
(length four)
#+end_src"
(progn
(org-babel-next-src-block 2)
(should (= 4 (org-babel-execute-src-block)))
(forward-line 5)
(should (string= ": 4" (buffer-substring
(point-at-bol)
(point-at-eol)))))))
(point-at-eol))))))
(ert-deftest test-org-babel/multi-line-header-arguments ()
"Test that multi-line header arguments and can be read."
@ -202,11 +197,10 @@
(my-map 'list #'list numbers letters)
#+end_src"
(progn
(org-babel-next-src-block)
(let ((results (org-babel-execute-src-block)))
(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 ()
(org-test-with-temp-text-in-file "
@ -215,7 +209,6 @@
the body
#+end_src"
(progn
(org-babel-next-src-block)
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info)))
@ -225,7 +218,7 @@
(should-not (member '(:session\ \ \ \ ) params))
(should (equal '(:session) (assoc :session 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 ()
(org-test-with-temp-text-in-file "
@ -247,11 +240,10 @@
:END:
this is simple"
(progn
(should (string-match (regexp-quote "this is simple")
(org-babel-ref-resolve "simple-subtree")))
(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 ()
(org-test-at-id "54cb8dc3-298c-4883-a933-029b3c9d4b18"
@ -321,7 +313,7 @@ this is simple"
(concat test-line " =1= =1=")
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(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 ()
;; src_ at bol line 2...
@ -353,7 +345,7 @@ this is simple"
(concat test-line " =y= =y= end")
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(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 ()
(let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }"))
@ -700,7 +692,6 @@ on two lines
#+begin_src emacs-lisp
;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(should (re-search-forward "\\#\\+results:" nil t))
@ -708,13 +699,11 @@ on two lines
(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 "
#+begin_src emacs-lisp
\"some text\";;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(should (re-search-forward "\\#\\+results:" nil t))
@ -722,33 +711,31 @@ on two lines
(should
(string=
": some text"
(buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
(ert-deftest test-ob/commented-last-block-line-with-var ()
(org-test-with-temp-text-in-file "
#+begin_src emacs-lisp :var a=1
;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(re-search-forward "\\#\\+results:" nil t)
(forward-line)
(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 "
#+begin_src emacs-lisp :var a=2
2;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(re-search-forward "\\#\\+results:" nil t)
(forward-line)
(should (string=
": 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)
"Test helper function to test `org-babel-remove-result'.
@ -759,7 +746,6 @@ The block is actually executed /twice/ to ensure result
replacement happens correctly."
(org-test-with-temp-text
buffer-text
(progn
(org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
(should (re-search-forward "\\#\\+results:" nil t))
(forward-line)
@ -770,7 +756,7 @@ replacement happens correctly."
(org-babel-previous-src-block) (org-babel-remove-result)
(should (string= buffer-text
(buffer-substring-no-properties
(point-min) (point-max)))))))
(point-min) (point-max))))))
(ert-deftest test-ob/org-babel-remove-result--results-default ()
"Test `org-babel-remove-result' with default :results."
@ -855,26 +841,24 @@ trying to find the :END: marker."
#+begin_src emacs-lisp :var a=1
;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(re-search-forward "\\#\\+results:" nil t)
(forward-line)
(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 "
#+begin_src emacs-lisp :var a=2
2;;
#+end_src"
(progn
(org-babel-next-src-block)
(org-ctrl-c-ctrl-c)
(re-search-forward "\\#\\+results:" nil t)
(forward-line)
(should (string=
": 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)
"Test helper function to test `org-babel-remove-result'.
@ -885,7 +869,6 @@ The block is actually executed /twice/ to ensure result
replacement happens correctly."
(org-test-with-temp-text
buffer-text
(progn
(org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c)
(should (re-search-forward "\\#\\+results:" nil t))
(forward-line)
@ -896,7 +879,7 @@ replacement happens correctly."
(org-babel-previous-src-block) (org-babel-remove-result)
(should (string= buffer-text
(buffer-substring-no-properties
(point-min) (point-max)))))))
(point-min) (point-max))))))
(ert-deftest test-ob/org-babel-remove-result--results-default ()
"Test `org-babel-remove-result' with default :results."
@ -1060,8 +1043,8 @@ Line 3\"
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp
\(+ 1 2)
#+END_SRC\n\n\n"
(progn (org-babel-execute-src-block)
(buffer-string))))))
(org-babel-execute-src-block)
(buffer-string)))))
(ert-deftest test-ob/results-in-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"
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\nParagraph"
(progn
(narrow-to-region (point) (save-excursion (forward-line 3) (point)))
(org-babel-execute-src-block)
(org-trim (buffer-string))))))
(org-trim (buffer-string)))))
(should
(equal
"#+NAME: test\n#+BEGIN_SRC emacs-lisp\n(+ 1 2)\n#+END_SRC\n\n#+RESULTS: test\n: 3"
(org-test-with-temp-text
"#+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)))
(org-babel-execute-src-block)
(org-trim (buffer-string))))))
(org-trim (buffer-string)))))
;; Results in visible part of buffer, should be updated here.
(should
(equal
@ -1105,10 +1086,9 @@ Line 3\"
: 4
Paragraph"
(progn
(narrow-to-region (point) (save-excursion (forward-line 7) (point)))
(org-babel-execute-src-block)
(org-trim (buffer-string))))))
(org-trim (buffer-string)))))
;; Results in invisible part of buffer, should be updated there.
(org-test-with-temp-text
"#+NAME: test
@ -1120,12 +1100,11 @@ Paragraph"
: 4
Paragraph"
(progn
(narrow-to-region (point) (save-excursion (forward-line 4) (point)))
(org-babel-execute-src-block)
(should-not (re-search-forward "^#\\+RESULTS:" nil t))
(widen)
(should (should (re-search-forward "^: 3" nil t))))))
(should (should (re-search-forward "^: 3" nil t)))))
(provide 'test-ob)

View File

@ -86,8 +86,7 @@
#+end_src
"
(progn
(goto-line 3)
(goto-line 2)
(org-edit-special)
(insert "blah")
(org-edit-src-exit)
@ -95,7 +94,7 @@
#+begin_src emacs-lisp
blah
#+end_src
")))))
"))))
(provide 'test-org-src)
;;; test-org-src.el ends here

View File

@ -72,12 +72,11 @@
| |
#+TBLFM: $1=vsum(@1..@-1)
"
(progn
(re-search-forward (regexp-quote "#+tblname: simple-formula") nil t)
(forward-line 1)
(should (org-at-table-p))
(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)

View File

@ -214,7 +214,7 @@ otherwise place the point at the beginning of the inserted text."
(with-temp-file ,file (insert ,inside-text))
(find-file ,file)
(org-mode)
(setq ,results ,@body)
(setq ,results (progn ,@body))
(save-buffer) (kill-buffer (current-buffer))
(delete-file ,file)
,results)))