1 ;;; test-org-clock.el --- Tests for org-clock.el
3 ;; Copyright (C) 2012, 2014, 2015 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; Released under the GNU General Public License version 3
8 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
16 (defun org-test-clock-create-timestamp (input &optional inactive with-time
)
17 "Create a timestamp out of a date/time prompt string.
19 INPUT is a string as expected in a date/time prompt, i.e \"+2d\"
22 When optional argument INACTIVE is non-nil, return an inactive
23 timestamp. When optional argument WITH-TIME is non-nil, also
24 insert hours and minutes.
26 Return the timestamp as a string."
27 (org-element-interpret-data
28 (let ((time (decode-time
30 (mapcar (lambda (el) (or el
0))
31 (org-read-date-analyze
32 input nil
(decode-time (current-time))))))))
34 (list :type
(if inactive
'inactive
'active
)
35 :minute-start
(and with-time
(nth 1 time
))
36 :hour-start
(and with-time
(nth 2 time
))
37 :day-start
(nth 3 time
)
38 :month-start
(nth 4 time
)
39 :year-start
(nth 5 time
))))))
41 (defun org-test-clock-create-clock (input1 &optional input2
)
42 "Create a clock line out of two date/time prompts.
44 INPUT1 and INPUT2 are strings as expected in a date/time prompt,
45 i.e \"+2d\" or \"2/5\". They respectively refer to start and end
46 range. INPUT2 can be omitted if clock hasn't finished yet.
48 Return the clock line as a string."
49 (let* ((beg (org-test-clock-create-timestamp input1 t t
))
50 (end (and input2
(org-test-clock-create-timestamp input2 t t
)))
52 (floor (- (org-time-string-to-seconds end
)
53 (org-time-string-to-seconds beg
))))))
54 (concat org-clock-string
" " beg
56 (concat "--" end
" => "
59 (/ (mod sec-diff
3600) 60))))
62 (defun test-org-clock-clocktable-contents (options &optional initial
)
63 "Return contents of a Clock table for current buffer
65 OPTIONS is a string of Clock table options. Optional argument
66 INITIAL is a string specifying initial contents within the Clock
69 Caption is ignored in contents. The clocktable doesn't appear in
72 (goto-char (point-min))
74 (insert "#+BEGIN: clocktable " options
"\n")
75 (when initial
(insert initial
))
76 (unless (string-suffix-p "\n" initial
) (insert "\n"))
80 (let ((org-duration-format 'h
:mm
)) (org-update-dblock))
83 (when (looking-at "#\\+CAPTION:") (forward-line))
84 (buffer-substring-no-properties
85 (point) (progn (search-forward "#+END:") (line-end-position 0))))
87 (delete-region (point) (search-forward "#+END:\n"))))
92 (ert-deftest test-org-clock
/into-drawer
()
93 "Test `org-clock-into-drawer' specifications."
94 ;; When `org-clock-into-drawer' is nil, do not use a clock drawer.
96 (org-test-with-temp-text "* H"
97 (let ((org-clock-into-drawer nil
)
98 (org-log-into-drawer nil
))
99 (org-clock-into-drawer))))
101 (org-test-with-temp-text "* H"
102 (let ((org-clock-into-drawer nil
)
103 (org-log-into-drawer t
))
104 (org-clock-into-drawer))))
106 (org-test-with-temp-text "* H"
107 (let ((org-clock-into-drawer nil
)
108 (org-log-into-drawer "BAR"))
109 (org-clock-into-drawer))))
110 ;; When `org-clock-into-drawer' is a string, use it
114 (org-test-with-temp-text "* H"
115 (let ((org-clock-into-drawer "FOO")
116 (org-log-into-drawer nil
))
117 (org-clock-into-drawer)))))
120 (org-test-with-temp-text "* H"
121 (let ((org-clock-into-drawer "FOO")
122 (org-log-into-drawer t
))
123 (org-clock-into-drawer)))))
126 (org-test-with-temp-text "* H"
127 (let ((org-clock-into-drawer "FOO")
128 (org-log-into-drawer "BAR"))
129 (org-clock-into-drawer)))))
130 ;; When `org-clock-into-drawer' is an integer, return it.
133 (org-test-with-temp-text "* H"
134 (let ((org-clock-into-drawer 1)
135 (org-log-into-drawer nil
))
136 (org-clock-into-drawer)))))
139 (org-test-with-temp-text "* H"
140 (let ((org-clock-into-drawer 1)
141 (org-log-into-drawer t
))
142 (org-clock-into-drawer)))))
145 (org-test-with-temp-text "* H"
146 (let ((org-clock-into-drawer 1)
147 (org-log-into-drawer "BAR"))
148 (org-clock-into-drawer)))))
149 ;; Otherwise, any non-nil value defaults to `org-log-into-drawer' or
150 ;; "LOGBOOK" if it is nil.
153 (org-test-with-temp-text "* H"
154 (let ((org-clock-into-drawer t
)
155 (org-log-into-drawer nil
))
156 (org-clock-into-drawer)))))
159 (org-test-with-temp-text "* H"
160 (let ((org-clock-into-drawer t
)
161 (org-log-into-drawer t
))
162 (org-clock-into-drawer)))))
165 (org-test-with-temp-text "* H"
166 (let ((org-clock-into-drawer t
)
167 (org-log-into-drawer "FOO"))
168 (org-clock-into-drawer)))))
169 ;; A non-nil "CLOCK_INTO_DRAWER" property overrides
170 ;; `org-clock-into-drawer' value.
173 (org-test-with-temp-text
174 "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:"
175 (let ((org-clock-into-drawer nil
)
176 (org-log-into-drawer nil
))
177 (org-clock-into-drawer)))))
180 (org-test-with-temp-text
181 "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:"
182 (let ((org-clock-into-drawer nil
)
183 (org-log-into-drawer nil
))
184 (org-clock-into-drawer)))))
186 (org-test-with-temp-text
187 "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:"
188 (let ((org-clock-into-drawer t
)
189 (org-log-into-drawer nil
))
190 (org-clock-into-drawer))))
191 ;; "CLOCK_INTO_DRAWER" can be inherited.
194 (org-test-with-temp-text
195 "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:\n** H2<point>"
196 (let ((org-clock-into-drawer nil
)
197 (org-log-into-drawer nil
))
198 (org-clock-into-drawer)))))
201 (org-test-with-temp-text
202 "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:\n** H2<point>"
203 (let ((org-clock-into-drawer nil
)
204 (org-log-into-drawer nil
))
205 (org-clock-into-drawer)))))
207 (org-test-with-temp-text
208 "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:\n** H2<point>"
209 (let ((org-clock-into-drawer t
)
210 (org-log-into-drawer nil
))
211 (org-clock-into-drawer)))))
213 (ert-deftest test-org-clock
/drawer-name
()
214 "Test `org-clock-drawer-name' specifications."
215 ;; A nil value for `org-clock-into-drawer' means no drawer is
216 ;; expected whatsoever.
218 (org-test-with-temp-text "* H"
219 (let ((org-clock-into-drawer nil
)
220 (org-log-into-drawer nil
))
221 (org-clock-drawer-name))))
223 (org-test-with-temp-text "* H"
224 (let ((org-clock-into-drawer nil
)
225 (org-log-into-drawer t
))
226 (org-clock-drawer-name))))
228 (org-test-with-temp-text "* H"
229 (let ((org-clock-into-drawer nil
)
230 (org-log-into-drawer "FOO"))
231 (org-clock-drawer-name))))
232 ;; A string value for `org-clock-into-drawer' means to use it
236 (org-test-with-temp-text "* H"
237 (let ((org-clock-into-drawer "FOO")
238 (org-log-into-drawer nil
))
239 (org-clock-drawer-name)))))
242 (org-test-with-temp-text "* H"
243 (let ((org-clock-into-drawer "FOO")
244 (org-log-into-drawer t
))
245 (org-clock-drawer-name)))))
248 (org-test-with-temp-text "* H"
249 (let ((org-clock-into-drawer "FOO")
250 (org-log-into-drawer "BAR"))
251 (org-clock-drawer-name)))))
252 ;; When the value in `org-clock-into-drawer' is a number, re-use
253 ;; `org-log-into-drawer' or use default "LOGBOOK" value.
256 (org-test-with-temp-text "* H"
257 (let ((org-clock-into-drawer 1)
258 (org-log-into-drawer "FOO"))
259 (org-clock-drawer-name)))))
262 (org-test-with-temp-text "* H"
263 (let ((org-clock-into-drawer 1)
264 (org-log-into-drawer t
))
265 (org-clock-drawer-name)))))
268 (org-test-with-temp-text "* H"
269 (let ((org-clock-into-drawer 1)
270 (org-log-into-drawer nil
))
271 (org-clock-drawer-name))))))
276 (ert-deftest test-org-clock
/clocktable
/ranges
()
277 "Test ranges in Clock table."
278 ;; Relative time: Previous two days.
281 "| Headline | Time | |
282 |------------------------------+--------+------|
283 | *Total time* | *8:00* | |
284 |------------------------------+--------+------|
285 | Relative times in clocktable | 8:00 | |
287 (org-test-with-temp-text
288 "* Relative times in clocktable\n** Foo\n<point>"
289 (insert (org-test-clock-create-clock "-3d 8:00" "-3d 12:00"))
290 (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
291 (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
292 (test-org-clock-clocktable-contents
293 ":tstart \"<-2d>\" :tend \"<today>\" :indent nil"))))
294 ;; Relative time: Yesterday until now.
297 "| Headline | Time | |
298 |------------------------------+--------+------|
299 | *Total time* | *6:00* | |
300 |------------------------------+--------+------|
301 | Relative times in clocktable | 6:00 | |
303 (org-test-with-temp-text
304 "* Relative times in clocktable\n** Foo\n<point>"
305 (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
306 (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
307 (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
308 (test-org-clock-clocktable-contents
309 ":tstart \"<yesterday>\" :tend \"<tomorrow>\" :indent nil"))))
310 ;; Test `untilnow' block.
313 "| Headline | Time | |
314 |------------------------------+--------+------|
315 | *Total time* | *6:00* | |
316 |------------------------------+--------+------|
317 | Relative times in clocktable | 6:00 | |
319 (org-test-with-temp-text
320 "* Relative times in clocktable\n** Foo\n<point>"
321 (insert (org-test-clock-create-clock "-10y 15:00" "-10y 18:00"))
322 (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
323 (test-org-clock-clocktable-contents ":block untilnow :indent nil")))))
325 (ert-deftest test-org-clock
/clocktable
/tags
()
326 "Test \":tags\" parameter in Clock table."
327 ;; Test tag filtering.
330 "| Headline | Time | |
331 |--------------+--------+------|
332 | *Total time* | *2:00* | |
333 |--------------+--------+------|
335 (org-test-with-temp-text "** H1\n\n*** H2 :tag:\n\n*** H3\n<point>"
336 (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
338 (insert (org-test-clock-create-clock ". 2:00" ". 4:00"))
339 (test-org-clock-clocktable-contents ":tags \"tag\" :indent nil")))))
341 (ert-deftest test-org-clock
/clocktable
/scope
()
342 "Test \":scope\" parameter in Clock table."
343 ;; Test `file-with-archives' scope. In particular, preserve "TBLFM"
344 ;; line, and ignore "file" column.
347 "| Headline | Time | |
348 |--------------+--------+-----|
349 | *Total time* | *8:40* | foo |
350 |--------------+--------+-----|
351 | Test | 8:40 | foo |
352 #+TBLFM: $3=string(\"foo\")"
353 (org-test-with-temp-text-in-file
355 CLOCK: [2012-03-29 Thu 8:00]--[2012-03-29 Thu 16:40] => 8:40"
356 (test-org-clock-clocktable-contents ":scope file-with-archives"
357 "#+TBLFM: $3=string(\"foo\")"))))
358 ;; Test "function" scope.
361 (regexp-quote "| ALL *Total time* | *1:00* |")
362 (org-test-with-temp-text-in-file
364 CLOCK: [2012-03-29 Thu 16:00]--[2012-03-29 Thu 17:00] => 1:00"
365 (let ((the-file (buffer-file-name)))
366 (org-test-with-temp-text-in-file ""
367 (test-org-clock-clocktable-contents
368 (format ":scope (lambda () (list %S))" the-file
))))))))
370 (ert-deftest test-org-clock
/clocktable
/maxlevel
()
371 "Test \":maxlevel\" parameter in Clock table."
373 (equal "| Headline | Time | |
374 |--------------+--------+------|
375 | *Total time* | *6:00* | |
376 |--------------+--------+------|
378 | \\_ Bar | | 2:00 |"
379 (org-test-with-temp-text
381 CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
383 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
384 (test-org-clock-clocktable-contents ":maxlevel 3"))))
386 (equal "| Headline | Time | |
387 |--------------+--------+------|
388 | *Total time* | *6:00* | |
389 |--------------+--------+------|
391 | \\_ Bar | | 2:00 |"
392 (org-test-with-temp-text
394 CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
396 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
397 (test-org-clock-clocktable-contents ":maxlevel 2"))))
399 (equal "| Headline | Time |
400 |--------------+--------|
401 | *Total time* | *6:00* |
402 |--------------+--------|
404 (org-test-with-temp-text
406 CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
408 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
409 (test-org-clock-clocktable-contents ":maxlevel 1"))))
410 ;; Special ":maxlevel 0" case: only report total file time.
412 (equal "| Headline | Time |
413 |--------------+--------|
414 | *Total time* | *6:00* |
415 |--------------+--------|"
416 (org-test-with-temp-text
418 CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
420 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
421 (test-org-clock-clocktable-contents ":maxlevel 0")))))
423 (ert-deftest test-org-clock
/clocktable
/formula
()
424 "Test \":formula\" parameter in Clock table."
425 ;; Test ":formula %". Handle various duration formats.
428 "| Headline | Time | % |
429 |--------------+--------+-------|
430 | *Total time* | *6:00* | 100.0 |
431 |--------------+--------+-------|
432 | Foo | 4:00 | 66.7 |
433 | Bar | 2:00 | 33.3 |"
434 (org-test-with-temp-text
436 CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
438 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
439 (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
442 "| Headline | Time | % |
443 |--------------+---------+-------|
444 | *Total time* | *28:00* | 100.0 |
445 |--------------+---------+-------|
446 | Foo | 26:00 | 92.9 |
447 | Bar | 2:00 | 7.1 |"
448 (org-test-with-temp-text
450 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
452 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
453 (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
454 ;; Properly align column with different depths.
456 (equal "| Headline | Time | | | % |
457 |---------------+--------+------+------+-------|
458 | *Total time* | *1:00* | | | 100.0 |
459 |---------------+--------+------+------+-------|
460 | foo | 1:00 | | | 100.0 |
461 | \\_ sub | | 0:15 | | 25.0 |
462 | \\_ sub2 | | 0:15 | | 25.0 |
463 | \\_ sub3 | | 0:30 | | 50.0 |
464 | \\_ subsub1 | | | 0:15 | 25.0 |
465 | \\_ subsub1 | | | 0:15 | 25.0 |"
466 (org-test-with-temp-text
470 CLOCK: [2017-03-18 Sat 15:00]--[2017-03-18 Sat 15:15] => 0:15
474 CLOCK: [2017-03-18 Sat 15:15]--[2017-03-18 Sat 15:30] => 0:15
479 CLOCK: [2017-03-18 Sat 13:00]--[2017-03-18 Sat 13:15] => 0:15
483 CLOCK: [2017-03-18 Sat 14:00]--[2017-03-18 Sat 14:15] => 0:15
485 (test-org-clock-clocktable-contents ":maxlevel 3 :formula %")))))
487 (ert-deftest test-org-clock
/clocktable
/lang
()
488 "Test \":lang\" parameter in Clock table."
489 ;; Test foreign translation
493 |--------------+---------|
494 | *Total time* | *26:00* |
495 |--------------+---------|
497 (org-test-with-temp-text
499 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
500 (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))))
503 "| En-tête | Durée |
504 |----------------+---------|
505 | *Durée totale* | *26:00* |
506 |----------------+---------|
508 (org-test-with-temp-text
510 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
511 (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr"))))
512 ;; No :lang parameter is equivalent to "en".
515 (org-test-with-temp-text
517 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
518 (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))
519 (org-test-with-temp-text
521 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
522 (test-org-clock-clocktable-contents ":maxlevel 1"))))
523 ;; Unknown translation fall backs to "en".
527 |--------------+---------|
528 | *Total time* | *26:00* |
529 |--------------+---------|
531 (org-test-with-temp-text
533 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
534 (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
536 (ert-deftest test-org-clock
/clocktable
/link
()
537 "Test \":link\" parameter in Clock table."
538 ;; If there is no file attached to the document, link directly to
543 |--------------+---------|
544 | *Total time* | *26:00* |
545 |--------------+---------|
546 | [[Foo][Foo]] | 26:00 |"
547 (org-test-with-temp-text
549 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
550 (test-org-clock-clocktable-contents ":link t"))))
551 ;; Otherwise, link to the headline in the current file.
555 |--------------+---------|
556 | *Total time* | *26:00* |
557 |--------------+---------|
558 | [[file:filename::Foo][Foo]] | 26:00 |"
559 (org-test-with-temp-text-in-file
561 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
562 (let ((file (buffer-file-name)))
563 (replace-regexp-in-string
564 (regexp-quote file
) "filename"
565 (test-org-clock-clocktable-contents ":link t"))))))
566 ;; Ignore TODO keyword, priority cookie, COMMENT and tags in
571 |--------------+---------|
572 | *Total time* | *26:00* |
573 |--------------+---------|
574 | [[Foo][Foo]] | 26:00 |"
575 (org-test-with-temp-text
577 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
578 (test-org-clock-clocktable-contents ":link t"))))
582 |--------------+---------|
583 | *Total time* | *26:00* |
584 |--------------+---------|
585 | [[Foo][Foo]] | 26:00 |"
586 (org-test-with-temp-text
588 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
589 (test-org-clock-clocktable-contents ":link t"))))
593 |--------------+---------|
594 | *Total time* | *26:00* |
595 |--------------+---------|
596 | [[Foo][Foo]] | 26:00 |"
597 (org-test-with-temp-text
599 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
600 (test-org-clock-clocktable-contents ":link t"))))
604 |--------------+---------|
605 | *Total time* | *26:00* |
606 |--------------+---------|
607 | [[Foo][Foo]] | 26:00 |"
608 (org-test-with-temp-text
610 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
611 (test-org-clock-clocktable-contents ":link t"))))
612 ;; Remove statistics cookie from headline description.
616 |--------------+---------|
617 | *Total time* | *26:00* |
618 |--------------+---------|
619 | [[Foo][Foo]] | 26:00 |"
620 (org-test-with-temp-text
622 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
623 (test-org-clock-clocktable-contents ":link t"))))
627 |--------------+---------|
628 | *Total time* | *26:00* |
629 |--------------+---------|
630 | [[Foo][Foo]] | 26:00 |"
631 (org-test-with-temp-text
633 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
634 (test-org-clock-clocktable-contents ":link t"))))
635 ;; Replace links with their description, or turn them into plain
636 ;; links if there is no description.
640 |--------------+---------|
641 | *Total time* | *26:00* |
642 |--------------+---------|
643 | [[Foo %5B%5Bhttp://orgmode.org%5D%5BOrg mode%5D%5D][Foo Org mode]] | 26:00 |"
644 (org-test-with-temp-text
645 "* Foo [[http://orgmode.org][Org mode]]
646 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
647 (test-org-clock-clocktable-contents ":link t"))))
651 |------------------------+---------|
652 | *Total time* | *26:00* |
653 |------------------------+---------|
654 | [[Foo %5B%5Bhttp://orgmode.org%5D%5D][Foo http://orgmode.org]] | 26:00 |"
655 (org-test-with-temp-text
656 "* Foo [[http://orgmode.org]]
657 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
658 (test-org-clock-clocktable-contents ":link t")))))
660 (ert-deftest test-org-clock
/clocktable
/compact
()
661 "Test \":compact\" parameter in Clock table."
662 ;; With :compact, all headlines are in the same column.
666 |--------------+---------|
667 | *Total time* | *26:00* |
668 |--------------+---------|
670 (org-test-with-temp-text
672 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
673 (test-org-clock-clocktable-contents ":compact t"))))
677 |--------------+---------|
678 | *Total time* | *52:00* |
679 |--------------+---------|
682 (org-test-with-temp-text
684 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
686 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
687 (test-org-clock-clocktable-contents ":compact t"))))
688 ;; :maxlevel does not affect :compact parameter.
692 |--------------+---------|
693 | *Total time* | *52:00* |
694 |--------------+---------|
697 (org-test-with-temp-text
699 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
701 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
702 (test-org-clock-clocktable-contents ":compact t :maxlevel 2"))))
703 ;; :compact implies a non-nil :indent parameter.
707 |--------------+---------|
708 | *Total time* | *52:00* |
709 |--------------+---------|
712 (org-test-with-temp-text
714 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
716 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
717 (test-org-clock-clocktable-contents ":compact t :indent nil"))))
718 ;; :compact implies a nil :level parameter.
722 |--------------+---------|
723 | *Total time* | *52:00* |
724 |--------------+---------|
727 (org-test-with-temp-text
729 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
731 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
732 (test-org-clock-clocktable-contents ":compact t :level t")))))
734 (ert-deftest test-org-clock
/clocktable
/properties
()
735 "Test \":properties\" parameter in Clock table."
736 ;; Include a new column with list properties.
739 "| A | Headline | Time |
740 |---+--------------+---------|
741 | | *Total time* | *26:00* |
742 |---+--------------+---------|
744 (org-test-with-temp-text
749 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
750 (test-org-clock-clocktable-contents ":properties (\"A\")"))))
753 "| A | Headline | Time | |
754 |---+--------------+---------+-------|
755 | | *Total time* | *52:00* | |
756 |---+--------------+---------+-------|
758 | 1 | \\_ Bar | | 26:00 |"
759 (org-test-with-temp-text
761 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
766 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
767 (test-org-clock-clocktable-contents ":properties (\"A\")"))))
768 ;; Handle missing properties.
771 "| A | Headline | Time |
772 |---+--------------+---------|
773 | | *Total time* | *26:00* |
774 |---+--------------+---------|
776 (org-test-with-temp-text
781 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
782 (test-org-clock-clocktable-contents ":properties (\"A\")")))))
784 (ert-deftest test-org-clock
/clocktable
/tcolumns
()
785 "Test \":tcolumns\" parameter in Clock table."
786 ;; When :tcolumns is smaller than the deepest headline level, lump
787 ;; lower levels in the last column.
791 |--------------+---------|
792 | *Total time* | *52:00* |
793 |--------------+---------|
796 (org-test-with-temp-text
798 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
800 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
801 (test-org-clock-clocktable-contents ":tcolumns 1"))))
802 ;; :tcolumns cannot create more columns than the deepest headline
806 "| Headline | Time | |
807 |--------------+---------+-------|
808 | *Total time* | *52:00* | |
809 |--------------+---------+-------|
811 | \\_ Bar | | 26:00 |"
812 (org-test-with-temp-text
814 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
816 CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
817 (test-org-clock-clocktable-contents ":tcolumns 3"))))
818 ;; Pathological case: when no headline contributes to the total
819 ;; time, there is only one time column.
821 (equal "| Headline | Time |
822 |--------------+--------|
823 | *Total time* | *0:00* |"
824 (org-test-with-temp-text
826 CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 11:09] => 0:00
828 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 13:09] => 0:00"
829 (test-org-clock-clocktable-contents ":tcolumns 2")))))
831 (ert-deftest test-org-clock
/clocktable
/step
()
832 "Test \":step\" parameter in Clock table."
833 ;; Regression test: week crossing month boundary before :wstart
837 Weekly report starting on: [2017-09-25 Mon]
839 |--------------+--------|
840 | *Total time* | *1:00* |
841 |--------------+--------|
843 (org-test-with-temp-text
845 CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
846 CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
847 CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00"
848 (let ((system-time-locale "en_US"))
849 (test-org-clock-clocktable-contents
850 ":step week :block 2017-09 :stepskip0 t")))))
853 Weekly report starting on: [2017-10-01 Sun]
855 |--------------+--------|
856 | *Total time* | *2:00* |
857 |--------------+--------|
860 Weekly report starting on: [2017-10-02 Mon]
862 |--------------+--------|
863 | *Total time* | *7:00* |
864 |--------------+--------|
867 Weekly report starting on: [2017-10-09 Mon]
869 |--------------+--------|
870 | *Total time* | *5:00* |
871 |--------------+--------|
874 (org-test-with-temp-text
876 CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
877 CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
878 CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
879 CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
880 CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
881 (let ((system-time-locale "en_US"))
882 (test-org-clock-clocktable-contents
883 ":step week :block 2017-10 :stepskip0 t")))))
887 Daily report: [2017-10-02 Mon]
889 |--------------+--------|
890 | *Total time* | *3:00* |
891 |--------------+--------|
894 Daily report: [2017-10-03 Tue]
896 |--------------+--------|
897 | *Total time* | *0:00* |
899 Daily report: [2017-10-04 Wed]
901 |--------------+--------|
902 | *Total time* | *0:00* |
904 Daily report: [2017-10-05 Thu]
906 |--------------+--------|
907 | *Total time* | *0:00* |
909 Daily report: [2017-10-06 Fri]
911 |--------------+--------|
912 | *Total time* | *0:00* |
914 Daily report: [2017-10-07 Sat]
916 |--------------+--------|
917 | *Total time* | *0:00* |
919 Daily report: [2017-10-08 Sun]
921 |--------------+--------|
922 | *Total time* | *4:00* |
923 |--------------+--------|
925 (org-test-with-temp-text
927 CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
928 CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
929 CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
930 CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
931 CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
932 (let ((system-time-locale "en_US"))
933 (test-org-clock-clocktable-contents
934 ":step day :block 2017-W40"))))))
936 (provide 'test-org-clock
)
937 ;;; test-org-clock.el end here