ソースを参照

org-clock: Fix `org-clock-drawer-name'

* lisp/org-clock.el (org-clock-drawer-name): When
  `org-clock-into-drawer' is a number and `org-log-into-drawer' is t,
  default to "LOGBOOK".

* testing/lisp/test-org-clock.el (test-org-clock/into-drawer):
(test-org-clock/drawer-name): New tests.
Nicolas Goaziou 8 年 前
コミット
ee5d40b001
2 ファイル変更186 行追加1 行削除
  1. 3 1
      lisp/org-clock.el
  2. 183 0
      testing/lisp/test-org-clock.el

+ 3 - 1
lisp/org-clock.el

@@ -560,7 +560,9 @@ of a different task.")
 (defun org-clock-drawer-name ()
   "Return clock drawer's name for current entry, or nil."
   (let ((drawer (org-clock-into-drawer)))
-    (cond ((integerp drawer) (or (org-log-into-drawer) "LOGBOOK"))
+    (cond ((integerp drawer)
+	   (let ((log-drawer (org-log-into-drawer)))
+	     (if (stringp log-drawer) log-drawer "LOGBOOK")))
 	  ((stringp drawer) drawer)
 	  (t nil))))
 

+ 183 - 0
testing/lisp/test-org-clock.el

@@ -80,6 +80,189 @@ contents.  The clocktable doesn't appear in the buffer."
     ;; Remove clocktable.
     (delete-region (point) (search-forward "#+END:\n"))))
 
+
+;;; Clock drawer
+
+(ert-deftest test-org-clock/into-drawer ()
+  "Test `org-clock-into-drawer' specifications."
+  ;; When `org-clock-into-drawer' is nil, do not use a clock drawer.
+  (should-not
+   (org-test-with-temp-text "* H"
+     (let ((org-clock-into-drawer nil)
+	   (org-log-into-drawer nil))
+       (org-clock-into-drawer))))
+  (should-not
+   (org-test-with-temp-text "* H"
+     (let ((org-clock-into-drawer nil)
+	   (org-log-into-drawer t))
+       (org-clock-into-drawer))))
+  (should-not
+   (org-test-with-temp-text "* H"
+     (let ((org-clock-into-drawer nil)
+	   (org-log-into-drawer "BAR"))
+       (org-clock-into-drawer))))
+  ;; When `org-clock-into-drawer' is a string, use it
+  ;; unconditionally.
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer "FOO")
+		  (org-log-into-drawer nil))
+	      (org-clock-into-drawer)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer "FOO")
+		  (org-log-into-drawer t))
+	      (org-clock-into-drawer)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer "FOO")
+		  (org-log-into-drawer "BAR"))
+	      (org-clock-into-drawer)))))
+  ;; When `org-clock-into-drawer' is an integer, return it.
+  (should
+   (= 1
+      (org-test-with-temp-text "* H"
+	(let ((org-clock-into-drawer 1)
+	      (org-log-into-drawer nil))
+	  (org-clock-into-drawer)))))
+  (should
+   (= 1
+      (org-test-with-temp-text "* H"
+	(let ((org-clock-into-drawer 1)
+	      (org-log-into-drawer t))
+	  (org-clock-into-drawer)))))
+  (should
+   (= 1
+      (org-test-with-temp-text "* H"
+	(let ((org-clock-into-drawer 1)
+	      (org-log-into-drawer "BAR"))
+	  (org-clock-into-drawer)))))
+  ;; Otherwise, any non-nil value defaults to `org-log-into-drawer' or
+  ;; "LOGBOOK" if it is nil.
+  (should
+   (equal "LOGBOOK"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer t)
+		  (org-log-into-drawer nil))
+	      (org-clock-into-drawer)))))
+  (should
+   (equal "LOGBOOK"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer t)
+		  (org-log-into-drawer t))
+	      (org-clock-into-drawer)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer t)
+		  (org-log-into-drawer "FOO"))
+	      (org-clock-into-drawer)))))
+  ;; A non-nil "CLOCK_INTO_DRAWER" property overrides
+  ;; `org-clock-into-drawer' value.
+  (should
+   (equal "LOGBOOK"
+	  (org-test-with-temp-text
+	      "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:"
+	    (let ((org-clock-into-drawer nil)
+		  (org-log-into-drawer nil))
+	      (org-clock-into-drawer)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text
+	      "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:"
+	    (let ((org-clock-into-drawer nil)
+		  (org-log-into-drawer nil))
+	      (org-clock-into-drawer)))))
+  (should-not
+   (org-test-with-temp-text
+       "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:"
+     (let ((org-clock-into-drawer t)
+	   (org-log-into-drawer nil))
+       (org-clock-into-drawer))))
+  ;; "CLOCK_INTO_DRAWER" can be inherited.
+  (should
+   (equal "LOGBOOK"
+	  (org-test-with-temp-text
+	      "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:\n** H2<point>"
+	    (let ((org-clock-into-drawer nil)
+		  (org-log-into-drawer nil))
+	      (org-clock-into-drawer)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text
+	      "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:\n** H2<point>"
+	    (let ((org-clock-into-drawer nil)
+		  (org-log-into-drawer nil))
+	      (org-clock-into-drawer)))))
+  (should-not
+   (org-test-with-temp-text
+       "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:\n** H2<point>"
+     (let ((org-clock-into-drawer t)
+	   (org-log-into-drawer nil))
+       (org-clock-into-drawer)))))
+
+(ert-deftest test-org-clock/drawer-name ()
+  "Test `org-clock-drawer-name' specifications."
+  ;; A nil value for `org-clock-into-drawer' means no drawer is
+  ;; expected whatsoever.
+  (should-not
+   (org-test-with-temp-text "* H"
+     (let ((org-clock-into-drawer nil)
+	   (org-log-into-drawer nil))
+       (org-clock-drawer-name))))
+  (should-not
+   (org-test-with-temp-text "* H"
+     (let ((org-clock-into-drawer nil)
+	   (org-log-into-drawer t))
+       (org-clock-drawer-name))))
+  (should-not
+   (org-test-with-temp-text "* H"
+     (let ((org-clock-into-drawer nil)
+	   (org-log-into-drawer "FOO"))
+       (org-clock-drawer-name))))
+  ;; A string value for `org-clock-into-drawer' means to use it
+  ;; unconditionally.
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer "FOO")
+		  (org-log-into-drawer nil))
+	      (org-clock-drawer-name)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer "FOO")
+		  (org-log-into-drawer t))
+	      (org-clock-drawer-name)))))
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer "FOO")
+		  (org-log-into-drawer "BAR"))
+	      (org-clock-drawer-name)))))
+  ;; When the value in `org-clock-into-drawer' is a number, re-use
+  ;; `org-log-into-drawer' or use default "LOGBOOK" value.
+  (should
+   (equal "FOO"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer 1)
+		  (org-log-into-drawer "FOO"))
+	      (org-clock-drawer-name)))))
+  (should
+   (equal "LOGBOOK"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer 1)
+		  (org-log-into-drawer t))
+	      (org-clock-drawer-name)))))
+  (should
+   (equal "LOGBOOK"
+	  (org-test-with-temp-text "* H"
+	    (let ((org-clock-into-drawer 1)
+		  (org-log-into-drawer nil))
+	      (org-clock-drawer-name))))))
 
 
 ;;; Clocktable