Pārlūkot izejas kodu

test-org-clocktable: fix batch testing

* testing/lisp/test-org-clock.el (test-org-clock/clocktable): New
  function, refactor the original test sequence.
  (test-org-clock/clocktable1, test-org-clock/clocktable2): New tests
  using the new function.

ert-deftest is a macro.  Let-binding a defvar before it is defined
causes the variable to be undefined later on, so the second test
fails for Emacsen that do not perform eager macro expansion.
Achim Gratz 10 gadi atpakaļ
vecāks
revīzija
9231460ac0
1 mainītis faili ar 27 papildinājumiem un 40 dzēšanām
  1. 27 40
      testing/lisp/test-org-clock.el

+ 27 - 40
testing/lisp/test-org-clock.el

@@ -84,7 +84,25 @@ contents.  The clocktable doesn't appear in the buffer."
 
 ;;; Clocktable
 
-(ert-deftest test-org-clock/clocktable ()
+(defun test-org-clock/clocktable (string)
+  (let ((org-clock-total-time-cell-format "*%s*"))
+    ;; Install Clock lines in "Foo".
+    (search-forward "** Foo")
+    (forward-line)
+    (insert (org-test-clock-create-clock "-2d 8:00" "-2d 13:00"))
+    (insert (org-test-clock-create-clock ". 8:00" "13:00"))
+    ;; Install Clock lines in "Bar".
+    (search-forward "** Bar")
+    (forward-line)
+    (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
+    (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
+    (insert (org-test-clock-create-clock "-1d 15:00" "-1d 18:00"))
+    (insert (org-test-clock-create-clock ". 15:00"))
+    ;; Previous two days.
+    (goto-char (point-min))
+    (forward-line)
+    (test-org-clock-clocktable-contents-at-point string)))
+(ert-deftest test-org-clock/clocktable1 ()
   "Test clocktable specifications."
   ;; Relative time: Previous two days.
   (should
@@ -97,25 +115,11 @@ contents.  The clocktable doesn't appear in the buffer."
 | Foo                          |         |  5:00 |
 | Bar                          |         | 11:00 |
 "
-    (org-test-with-temp-text "* Relative times in clocktable\n** Foo\n** Bar\n"
-      (let ((org-clock-total-time-cell-format "*%s*"))
-	;; Install Clock lines in "Foo".
-	(search-forward "** Foo")
-	(forward-line)
-	(insert (org-test-clock-create-clock "-2d 8:00" "-2d 13:00"))
-	(insert (org-test-clock-create-clock ". 8:00" "13:00"))
-	;; Install Clock lines in "Bar".
-	(search-forward "** Bar")
-	(forward-line)
-	(insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
-	(insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
-	(insert (org-test-clock-create-clock "-1d 15:00" "-1d 18:00"))
-	(insert (org-test-clock-create-clock ". 15:00"))
-	;; Previous two days.
-	(goto-char (point-min))
-	(forward-line)
-	(test-org-clock-clocktable-contents-at-point
-	 ":tstart \"<today-2>\" :tend \"<today>\" :indent nil")))))
+    (org-test-with-temp-text
+     "* Relative times in clocktable\n** Foo\n** Bar\n"
+     (test-org-clock/clocktable ":tstart \"<today-2>\" :tend \"<today>\" :indent nil")))))
+(ert-deftest test-org-clock/clocktable2 ()
+  "Test clocktable specifications."
   ;; Relative time: Yesterday until now.
   (should
    (equal
@@ -127,26 +131,9 @@ contents.  The clocktable doesn't appear in the buffer."
 | Foo                          |         | 5:00 |
 | Bar                          |         | 8:00 |
 "
-    (org-test-with-temp-text "* Relative times in clocktable\n** Foo\n** Bar\n"
-      (progn
-	;; Install Clock lines in "Foo".
-	(search-forward "** Foo")
-	(forward-line)
-	(insert (org-test-clock-create-clock "-2d 8:00" "-2d 13:00"))
-	(insert (org-test-clock-create-clock ". 8:00" "13:00"))
-	;; Install Clock lines in "Bar".
-	(search-forward "** Bar")
-	(forward-line)
-	(insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
-	(insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
-	(insert (org-test-clock-create-clock "-1d 15:00" "-1d 18:00"))
-	(insert (org-test-clock-create-clock ". 15:00"))
-	;; Previous two days.
-	(goto-char (point-min))
-	(forward-line)
-	(test-org-clock-clocktable-contents-at-point
-	 ":tstart \"<yesterday>\" :tend \"<tomorrow>\" :indent nil"))))))
-
+    (org-test-with-temp-text
+     "* Relative times in clocktable\n** Foo\n** Bar\n"
+     (test-org-clock/clocktable ":tstart \"<yesterday>\" :tend \"<tomorrow>\" :indent nil")))))
 
 (provide 'test-org-clock)
 ;;; test-org-clock.el end here