summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-05-11 18:44:02 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-05-11 18:44:02 +0200
commitee5d40b001951d2d056f709f10c7dca19456bef5 (patch)
treeec63aa3d300fd1ca3bbba4a0ca2477569d27b110
parentd1786a0908ee46f2a0749a845d44e0854410f130 (diff)
downloadorg-mode-ee5d40b001951d2d056f709f10c7dca19456bef5.tar.gz
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.
-rw-r--r--lisp/org-clock.el4
-rw-r--r--testing/lisp/test-org-clock.el183
2 files changed, 186 insertions, 1 deletions
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index e4b5189..52e8795 100644
--- a/lisp/org-clock.el
+++ b/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))))
diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 335b7a6..29e7de8 100644
--- a/testing/lisp/test-org-clock.el
+++ b/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