test-org-clock.el 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. ;;; test-org-clock.el --- Tests for org-clock.el
  2. ;; Copyright (C) 2012, 2014, 2015, 2019 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments
  7. ;;; Code:
  8. (defun org-test-clock-create-timestamp (input &optional inactive with-time)
  9. "Create a timestamp out of a date/time prompt string.
  10. INPUT is a string as expected in a date/time prompt, i.e \"+2d\"
  11. or \"2/5\".
  12. When optional argument INACTIVE is non-nil, return an inactive
  13. timestamp. When optional argument WITH-TIME is non-nil, also
  14. insert hours and minutes.
  15. Return the timestamp as a string."
  16. (org-element-interpret-data
  17. (let ((time (decode-time
  18. (apply #'encode-time
  19. (mapcar (lambda (el) (or el 0))
  20. (org-read-date-analyze
  21. input nil (decode-time (current-time))))))))
  22. (list 'timestamp
  23. (list :type (if inactive 'inactive 'active)
  24. :minute-start (and with-time (nth 1 time))
  25. :hour-start (and with-time (nth 2 time))
  26. :day-start (nth 3 time)
  27. :month-start (nth 4 time)
  28. :year-start (nth 5 time))))))
  29. (defun org-test-clock-create-clock (input1 &optional input2)
  30. "Create a clock line out of two date/time prompts.
  31. INPUT1 and INPUT2 are strings as expected in a date/time prompt,
  32. i.e \"+2d\" or \"2/5\". They respectively refer to start and end
  33. range. INPUT2 can be omitted if clock hasn't finished yet.
  34. Return the clock line as a string."
  35. (let* ((beg (org-test-clock-create-timestamp input1 t t))
  36. (end (and input2 (org-test-clock-create-timestamp input2 t t)))
  37. (sec-diff (and input2
  38. (floor (- (org-time-string-to-seconds end)
  39. (org-time-string-to-seconds beg))))))
  40. (concat org-clock-string " " beg
  41. (when end
  42. (concat "--" end " => "
  43. (format "%2d:%02d"
  44. (/ sec-diff 3600)
  45. (/ (mod sec-diff 3600) 60))))
  46. "\n")))
  47. (defun test-org-clock-clocktable-contents (options &optional initial)
  48. "Return contents of a Clock table for current buffer
  49. OPTIONS is a string of Clock table options. Optional argument
  50. INITIAL is a string specifying initial contents within the Clock
  51. table.
  52. Caption is ignored in contents. The clocktable doesn't appear in
  53. the buffer."
  54. (declare (indent 2))
  55. (goto-char (point-min))
  56. (save-excursion
  57. (insert "#+BEGIN: clocktable " options "\n")
  58. (when initial (insert initial))
  59. (unless (string-suffix-p "\n" initial) (insert "\n"))
  60. (insert "#+END:\n"))
  61. (unwind-protect
  62. (save-excursion
  63. (let ((org-duration-format 'h:mm)) (org-update-dblock))
  64. (forward-line)
  65. ;; Skip caption.
  66. (when (looking-at "#\\+CAPTION:") (forward-line))
  67. (buffer-substring-no-properties
  68. (point) (progn (search-forward "#+END:") (line-end-position 0))))
  69. ;; Remove clocktable.
  70. (delete-region (point) (search-forward "#+END:\n"))))
  71. ;;; Clock drawer
  72. (ert-deftest test-org-clock/into-drawer ()
  73. "Test `org-clock-into-drawer' specifications."
  74. ;; When `org-clock-into-drawer' is nil, do not use a clock drawer.
  75. (should-not
  76. (org-test-with-temp-text "* H"
  77. (let ((org-clock-into-drawer nil)
  78. (org-log-into-drawer nil))
  79. (org-clock-into-drawer))))
  80. (should-not
  81. (org-test-with-temp-text "* H"
  82. (let ((org-clock-into-drawer nil)
  83. (org-log-into-drawer t))
  84. (org-clock-into-drawer))))
  85. (should-not
  86. (org-test-with-temp-text "* H"
  87. (let ((org-clock-into-drawer nil)
  88. (org-log-into-drawer "BAR"))
  89. (org-clock-into-drawer))))
  90. ;; When `org-clock-into-drawer' is a string, use it
  91. ;; unconditionally.
  92. (should
  93. (equal "FOO"
  94. (org-test-with-temp-text "* H"
  95. (let ((org-clock-into-drawer "FOO")
  96. (org-log-into-drawer nil))
  97. (org-clock-into-drawer)))))
  98. (should
  99. (equal "FOO"
  100. (org-test-with-temp-text "* H"
  101. (let ((org-clock-into-drawer "FOO")
  102. (org-log-into-drawer t))
  103. (org-clock-into-drawer)))))
  104. (should
  105. (equal "FOO"
  106. (org-test-with-temp-text "* H"
  107. (let ((org-clock-into-drawer "FOO")
  108. (org-log-into-drawer "BAR"))
  109. (org-clock-into-drawer)))))
  110. ;; When `org-clock-into-drawer' is an integer, return it.
  111. (should
  112. (= 1
  113. (org-test-with-temp-text "* H"
  114. (let ((org-clock-into-drawer 1)
  115. (org-log-into-drawer nil))
  116. (org-clock-into-drawer)))))
  117. (should
  118. (= 1
  119. (org-test-with-temp-text "* H"
  120. (let ((org-clock-into-drawer 1)
  121. (org-log-into-drawer t))
  122. (org-clock-into-drawer)))))
  123. (should
  124. (= 1
  125. (org-test-with-temp-text "* H"
  126. (let ((org-clock-into-drawer 1)
  127. (org-log-into-drawer "BAR"))
  128. (org-clock-into-drawer)))))
  129. ;; Otherwise, any non-nil value defaults to `org-log-into-drawer' or
  130. ;; "LOGBOOK" if it is nil.
  131. (should
  132. (equal "LOGBOOK"
  133. (org-test-with-temp-text "* H"
  134. (let ((org-clock-into-drawer t)
  135. (org-log-into-drawer nil))
  136. (org-clock-into-drawer)))))
  137. (should
  138. (equal "LOGBOOK"
  139. (org-test-with-temp-text "* H"
  140. (let ((org-clock-into-drawer t)
  141. (org-log-into-drawer t))
  142. (org-clock-into-drawer)))))
  143. (should
  144. (equal "FOO"
  145. (org-test-with-temp-text "* H"
  146. (let ((org-clock-into-drawer t)
  147. (org-log-into-drawer "FOO"))
  148. (org-clock-into-drawer)))))
  149. ;; A non-nil "CLOCK_INTO_DRAWER" property overrides
  150. ;; `org-clock-into-drawer' value.
  151. (should
  152. (equal "LOGBOOK"
  153. (org-test-with-temp-text
  154. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:"
  155. (let ((org-clock-into-drawer nil)
  156. (org-log-into-drawer nil))
  157. (org-clock-into-drawer)))))
  158. (should
  159. (equal "FOO"
  160. (org-test-with-temp-text
  161. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:"
  162. (let ((org-clock-into-drawer nil)
  163. (org-log-into-drawer nil))
  164. (org-clock-into-drawer)))))
  165. (should-not
  166. (org-test-with-temp-text
  167. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:"
  168. (let ((org-clock-into-drawer t)
  169. (org-log-into-drawer nil))
  170. (org-clock-into-drawer))))
  171. ;; "CLOCK_INTO_DRAWER" can be inherited.
  172. (should
  173. (equal "LOGBOOK"
  174. (org-test-with-temp-text
  175. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:\n** H2<point>"
  176. (let ((org-clock-into-drawer nil)
  177. (org-log-into-drawer nil))
  178. (org-clock-into-drawer)))))
  179. (should
  180. (equal "FOO"
  181. (org-test-with-temp-text
  182. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:\n** H2<point>"
  183. (let ((org-clock-into-drawer nil)
  184. (org-log-into-drawer nil))
  185. (org-clock-into-drawer)))))
  186. (should-not
  187. (org-test-with-temp-text
  188. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:\n** H2<point>"
  189. (let ((org-clock-into-drawer t)
  190. (org-log-into-drawer nil))
  191. (org-clock-into-drawer)))))
  192. (ert-deftest test-org-clock/drawer-name ()
  193. "Test `org-clock-drawer-name' specifications."
  194. ;; A nil value for `org-clock-into-drawer' means no drawer is
  195. ;; expected whatsoever.
  196. (should-not
  197. (org-test-with-temp-text "* H"
  198. (let ((org-clock-into-drawer nil)
  199. (org-log-into-drawer nil))
  200. (org-clock-drawer-name))))
  201. (should-not
  202. (org-test-with-temp-text "* H"
  203. (let ((org-clock-into-drawer nil)
  204. (org-log-into-drawer t))
  205. (org-clock-drawer-name))))
  206. (should-not
  207. (org-test-with-temp-text "* H"
  208. (let ((org-clock-into-drawer nil)
  209. (org-log-into-drawer "FOO"))
  210. (org-clock-drawer-name))))
  211. ;; A string value for `org-clock-into-drawer' means to use it
  212. ;; unconditionally.
  213. (should
  214. (equal "FOO"
  215. (org-test-with-temp-text "* H"
  216. (let ((org-clock-into-drawer "FOO")
  217. (org-log-into-drawer nil))
  218. (org-clock-drawer-name)))))
  219. (should
  220. (equal "FOO"
  221. (org-test-with-temp-text "* H"
  222. (let ((org-clock-into-drawer "FOO")
  223. (org-log-into-drawer t))
  224. (org-clock-drawer-name)))))
  225. (should
  226. (equal "FOO"
  227. (org-test-with-temp-text "* H"
  228. (let ((org-clock-into-drawer "FOO")
  229. (org-log-into-drawer "BAR"))
  230. (org-clock-drawer-name)))))
  231. ;; When the value in `org-clock-into-drawer' is a number, re-use
  232. ;; `org-log-into-drawer' or use default "LOGBOOK" value.
  233. (should
  234. (equal "FOO"
  235. (org-test-with-temp-text "* H"
  236. (let ((org-clock-into-drawer 1)
  237. (org-log-into-drawer "FOO"))
  238. (org-clock-drawer-name)))))
  239. (should
  240. (equal "LOGBOOK"
  241. (org-test-with-temp-text "* H"
  242. (let ((org-clock-into-drawer 1)
  243. (org-log-into-drawer t))
  244. (org-clock-drawer-name)))))
  245. (should
  246. (equal "LOGBOOK"
  247. (org-test-with-temp-text "* H"
  248. (let ((org-clock-into-drawer 1)
  249. (org-log-into-drawer nil))
  250. (org-clock-drawer-name))))))
  251. ;;; Clocktable
  252. (ert-deftest test-org-clock/clocktable/insert ()
  253. "Test insert clocktable dynamic block with `org-dynamic-block-insert-dblock'."
  254. (should
  255. (equal
  256. "| Headline | Time |
  257. |--------------+--------|
  258. | *Total time* | *1:00* |
  259. |--------------+--------|
  260. | H1 | 1:00 |"
  261. (org-test-with-temp-text "* H1\n<point>"
  262. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  263. (goto-line 2)
  264. (require 'org-clock)
  265. (org-dynamic-block-insert-dblock "clocktable")
  266. (goto-line 1)
  267. (unwind-protect
  268. (save-excursion
  269. (when (search-forward "#+CAPTION:") (forward-line))
  270. (buffer-substring-no-properties
  271. (point) (progn (search-forward "#+END:") (line-end-position 0))))
  272. (delete-region (point) (search-forward "#+END:\n")))))))
  273. (ert-deftest test-org-clock/clocktable/ranges ()
  274. "Test ranges in Clock table."
  275. ;; Relative time: Previous two days.
  276. (should
  277. (equal
  278. "| Headline | Time | |
  279. |------------------------------+--------+------|
  280. | *Total time* | *8:00* | |
  281. |------------------------------+--------+------|
  282. | Relative times in clocktable | 8:00 | |
  283. | Foo | | 8:00 |"
  284. (org-test-with-temp-text
  285. "* Relative times in clocktable\n** Foo\n<point>"
  286. (insert (org-test-clock-create-clock "-3d 8:00" "-3d 12:00"))
  287. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  288. (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
  289. (test-org-clock-clocktable-contents
  290. ":tstart \"<-2d>\" :tend \"<today>\" :indent nil"))))
  291. ;; Relative time: Yesterday until now.
  292. (should
  293. (equal
  294. "| Headline | Time | |
  295. |------------------------------+--------+------|
  296. | *Total time* | *6:00* | |
  297. |------------------------------+--------+------|
  298. | Relative times in clocktable | 6:00 | |
  299. | Foo | | 6:00 |"
  300. (org-test-with-temp-text
  301. "* Relative times in clocktable\n** Foo\n<point>"
  302. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  303. (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
  304. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  305. (test-org-clock-clocktable-contents
  306. ":tstart \"<yesterday>\" :tend \"<tomorrow>\" :indent nil"))))
  307. ;; Test `untilnow' block.
  308. (should
  309. (equal
  310. "| Headline | Time | |
  311. |------------------------------+--------+------|
  312. | *Total time* | *6:00* | |
  313. |------------------------------+--------+------|
  314. | Relative times in clocktable | 6:00 | |
  315. | Foo | | 6:00 |"
  316. (org-test-with-temp-text
  317. "* Relative times in clocktable\n** Foo\n<point>"
  318. (insert (org-test-clock-create-clock "-10y 15:00" "-10y 18:00"))
  319. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  320. (test-org-clock-clocktable-contents ":block untilnow :indent nil")))))
  321. (ert-deftest test-org-clock/clocktable/match ()
  322. "Test \":match\" parameter in Clock table."
  323. ;; Test match filtering.
  324. (should
  325. (equal
  326. "| Headline | Time | |
  327. |--------------+--------+------|
  328. | *Total time* | *2:00* | |
  329. |--------------+--------+------|
  330. | H1 | | 2:00 |"
  331. (org-test-with-temp-text "** H1\n\n*** H2 :tag:\n\n*** H3\n<point>"
  332. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  333. (goto-line 4)
  334. (insert (org-test-clock-create-clock ". 2:00" ". 4:00"))
  335. (test-org-clock-clocktable-contents ":match \"tag\" :indent nil")))))
  336. (ert-deftest test-org-clock/clocktable/tags ()
  337. "Test \":tags\" parameter in Clock table."
  338. ;; Test tags column.
  339. (should
  340. (equal
  341. "| Tags | Headline | Time | |
  342. |------+--------------+--------+------|
  343. | | *Total time* | *1:00* | |
  344. |------+--------------+--------+------|
  345. | tag | H1 | | 1:00 |"
  346. (org-test-with-temp-text "** H1 :tag:\n\n*** H2 \n<point>"
  347. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  348. (goto-line 4)
  349. (test-org-clock-clocktable-contents ":tags t :indent nil")))))
  350. (ert-deftest test-org-clock/clocktable/scope ()
  351. "Test \":scope\" parameter in Clock table."
  352. ;; Test `file-with-archives' scope. In particular, preserve "TBLFM"
  353. ;; line, and ignore "file" column.
  354. (should
  355. (equal
  356. "| Headline | Time | |
  357. |--------------+--------+-----|
  358. | *Total time* | *8:40* | foo |
  359. |--------------+--------+-----|
  360. | Test | 8:40 | foo |
  361. #+TBLFM: $3=string(\"foo\")"
  362. (org-test-with-temp-text-in-file
  363. "* Test
  364. CLOCK: [2012-03-29 Thu 8:00]--[2012-03-29 Thu 16:40] => 8:40"
  365. (test-org-clock-clocktable-contents ":scope file-with-archives"
  366. "#+TBLFM: $3=string(\"foo\")"))))
  367. ;; Test "function" scope.
  368. (should
  369. (string-match-p
  370. (regexp-quote "| ALL *Total time* | *1:00* |")
  371. (org-test-with-temp-text-in-file
  372. "* Test
  373. CLOCK: [2012-03-29 Thu 16:00]--[2012-03-29 Thu 17:00] => 1:00"
  374. (let ((the-file (buffer-file-name)))
  375. (org-test-with-temp-text-in-file ""
  376. (test-org-clock-clocktable-contents
  377. (format ":scope (lambda () (list %S))" the-file))))))))
  378. (ert-deftest test-org-clock/clocktable/maxlevel ()
  379. "Test \":maxlevel\" parameter in Clock table."
  380. (should
  381. (equal "| Headline | Time | |
  382. |--------------+--------+------|
  383. | *Total time* | *6:00* | |
  384. |--------------+--------+------|
  385. | Foo | 6:00 | |
  386. | \\_ Bar | | 2:00 |"
  387. (org-test-with-temp-text
  388. "* Foo
  389. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  390. ** Bar
  391. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  392. (test-org-clock-clocktable-contents ":maxlevel 3"))))
  393. (should
  394. (equal "| Headline | Time | |
  395. |--------------+--------+------|
  396. | *Total time* | *6:00* | |
  397. |--------------+--------+------|
  398. | Foo | 6:00 | |
  399. | \\_ Bar | | 2:00 |"
  400. (org-test-with-temp-text
  401. "* Foo
  402. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  403. ** Bar
  404. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  405. (test-org-clock-clocktable-contents ":maxlevel 2"))))
  406. (should
  407. (equal "| Headline | Time |
  408. |--------------+--------|
  409. | *Total time* | *6:00* |
  410. |--------------+--------|
  411. | Foo | 6:00 |"
  412. (org-test-with-temp-text
  413. "* Foo
  414. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  415. ** Bar
  416. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  417. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  418. ;; Special ":maxlevel 0" case: only report total file time.
  419. (should
  420. (equal "| Headline | Time |
  421. |--------------+--------|
  422. | *Total time* | *6:00* |
  423. |--------------+--------|"
  424. (org-test-with-temp-text
  425. "* Foo
  426. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  427. ** Bar
  428. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  429. (test-org-clock-clocktable-contents ":maxlevel 0")))))
  430. (ert-deftest test-org-clock/clocktable/formula ()
  431. "Test \":formula\" parameter in Clock table."
  432. ;; Test ":formula %". Handle various duration formats.
  433. (should
  434. (equal
  435. "| Headline | Time | % |
  436. |--------------+--------+-------|
  437. | *Total time* | *6:00* | 100.0 |
  438. |--------------+--------+-------|
  439. | Foo | 4:00 | 66.7 |
  440. | Bar | 2:00 | 33.3 |"
  441. (org-test-with-temp-text
  442. "* Foo
  443. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  444. * Bar
  445. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  446. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
  447. (should
  448. (equal
  449. "| Headline | Time | % |
  450. |--------------+---------+-------|
  451. | *Total time* | *28:00* | 100.0 |
  452. |--------------+---------+-------|
  453. | Foo | 26:00 | 92.9 |
  454. | Bar | 2:00 | 7.1 |"
  455. (org-test-with-temp-text
  456. "* Foo
  457. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  458. * Bar
  459. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  460. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
  461. ;; Properly align column with different depths.
  462. (should
  463. (equal "| Headline | Time | | | % |
  464. |---------------+--------+------+------+-------|
  465. | *Total time* | *1:00* | | | 100.0 |
  466. |---------------+--------+------+------+-------|
  467. | foo | 1:00 | | | 100.0 |
  468. | \\_ sub | | 0:15 | | 25.0 |
  469. | \\_ sub2 | | 0:15 | | 25.0 |
  470. | \\_ sub3 | | 0:30 | | 50.0 |
  471. | \\_ subsub1 | | | 0:15 | 25.0 |
  472. | \\_ subsub1 | | | 0:15 | 25.0 |"
  473. (org-test-with-temp-text
  474. "* foo
  475. ** sub
  476. :LOGBOOK:
  477. CLOCK: [2017-03-18 Sat 15:00]--[2017-03-18 Sat 15:15] => 0:15
  478. :END:
  479. ** sub2
  480. :LOGBOOK:
  481. CLOCK: [2017-03-18 Sat 15:15]--[2017-03-18 Sat 15:30] => 0:15
  482. :END:
  483. ** sub3
  484. *** subsub1
  485. :LOGBOOK:
  486. CLOCK: [2017-03-18 Sat 13:00]--[2017-03-18 Sat 13:15] => 0:15
  487. :END:
  488. *** subsub1
  489. :LOGBOOK:
  490. CLOCK: [2017-03-18 Sat 14:00]--[2017-03-18 Sat 14:15] => 0:15
  491. :END:"
  492. (test-org-clock-clocktable-contents ":maxlevel 3 :formula %")))))
  493. (ert-deftest test-org-clock/clocktable/lang ()
  494. "Test \":lang\" parameter in Clock table."
  495. ;; Test foreign translation
  496. (should
  497. (equal
  498. "| Headline | Time |
  499. |--------------+---------|
  500. | *Total time* | *26:00* |
  501. |--------------+---------|
  502. | Foo | 26:00 |"
  503. (org-test-with-temp-text
  504. "* Foo
  505. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  506. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))))
  507. (should
  508. (equal
  509. "| En-tête | Durée |
  510. |----------------+---------|
  511. | *Durée totale* | *26:00* |
  512. |----------------+---------|
  513. | Foo | 26:00 |"
  514. (org-test-with-temp-text
  515. "* Foo
  516. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  517. (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr"))))
  518. ;; No :lang parameter is equivalent to "en".
  519. (should
  520. (equal
  521. (org-test-with-temp-text
  522. "* Foo
  523. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  524. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))
  525. (org-test-with-temp-text
  526. "* Foo
  527. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  528. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  529. ;; Unknown translation fall backs to "en".
  530. (should
  531. (equal
  532. "| Headline | Time |
  533. |--------------+---------|
  534. | *Total time* | *26:00* |
  535. |--------------+---------|
  536. | Foo | 26:00 |"
  537. (org-test-with-temp-text
  538. "* Foo
  539. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  540. (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
  541. (ert-deftest test-org-clock/clocktable/link ()
  542. "Test \":link\" parameter in Clock table."
  543. ;; If there is no file attached to the document, link directly to
  544. ;; the headline.
  545. (let (org-link-descriptive)
  546. (should
  547. (equal
  548. "| Headline | Time |
  549. |--------------+---------|
  550. | *Total time* | *26:00* |
  551. |--------------+---------|
  552. | [[Foo][Foo]] | 26:00 |"
  553. (org-test-with-temp-text
  554. "* Foo
  555. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  556. (test-org-clock-clocktable-contents ":link t"))))
  557. ;; Otherwise, link to the headline in the current file.
  558. (should
  559. (equal
  560. "| Headline | Time |
  561. |-----------------------------+---------|
  562. | *Total time* | *26:00* |
  563. |-----------------------------+---------|
  564. | [[file:filename::Foo][Foo]] | 26:00 |"
  565. (org-test-with-temp-text
  566. (org-test-with-temp-text-in-file
  567. "* Foo
  568. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  569. (let ((file (buffer-file-name)))
  570. (replace-regexp-in-string
  571. (regexp-quote file) "filename"
  572. (test-org-clock-clocktable-contents ":link t :lang en"))))
  573. (org-table-align)
  574. (buffer-substring-no-properties (point-min) (point-max)))))
  575. ;; Ignore TODO keyword, priority cookie, COMMENT and tags in
  576. ;; headline.
  577. (should
  578. (equal
  579. "| Headline | Time |
  580. |--------------+---------|
  581. | *Total time* | *26:00* |
  582. |--------------+---------|
  583. | [[Foo][Foo]] | 26:00 |"
  584. (org-test-with-temp-text
  585. "* TODO Foo
  586. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  587. (test-org-clock-clocktable-contents ":link t :lang en"))))
  588. (should
  589. (equal
  590. "| Headline | Time |
  591. |--------------+---------|
  592. | *Total time* | *26:00* |
  593. |--------------+---------|
  594. | [[Foo][Foo]] | 26:00 |"
  595. (org-test-with-temp-text
  596. "* [#A] Foo
  597. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  598. (test-org-clock-clocktable-contents ":link t :lang en"))))
  599. (should
  600. (equal
  601. "| Headline | Time |
  602. |--------------+---------|
  603. | *Total time* | *26:00* |
  604. |--------------+---------|
  605. | [[Foo][Foo]] | 26:00 |"
  606. (org-test-with-temp-text
  607. "* COMMENT Foo
  608. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  609. (test-org-clock-clocktable-contents ":link t"))))
  610. (should
  611. (equal
  612. "| Headline | Time |
  613. |--------------+---------|
  614. | *Total time* | *26:00* |
  615. |--------------+---------|
  616. | [[Foo][Foo]] | 26:00 |"
  617. (org-test-with-temp-text
  618. "* Foo :tag:
  619. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  620. (test-org-clock-clocktable-contents ":link t :lang en"))))
  621. ;; Remove statistics cookie from headline description.
  622. (should
  623. (equal
  624. "| Headline | Time |
  625. |--------------+---------|
  626. | *Total time* | *26:00* |
  627. |--------------+---------|
  628. | [[Foo][Foo]] | 26:00 |"
  629. (org-test-with-temp-text
  630. "* Foo [50%]
  631. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  632. (test-org-clock-clocktable-contents ":link t :lang en"))))
  633. (should
  634. (equal
  635. "| Headline | Time |
  636. |--------------+---------|
  637. | *Total time* | *26:00* |
  638. |--------------+---------|
  639. | [[Foo][Foo]] | 26:00 |"
  640. (org-test-with-temp-text
  641. "* Foo [1/2]
  642. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  643. (test-org-clock-clocktable-contents ":link t :lang en"))))
  644. ;; Replace links with their description, or turn them into plain
  645. ;; links if there is no description.
  646. (should
  647. (equal
  648. "| Headline | Time |
  649. |-----------------------------------------------------------+---------|
  650. | *Total time* | *26:00* |
  651. |-----------------------------------------------------------+---------|
  652. | [[Foo [[https://orgmode.org\\][Org mode]\\]][Foo Org mode]] | 26:00 |"
  653. (org-test-with-temp-text
  654. "* Foo [[https://orgmode.org][Org mode]]
  655. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  656. (test-org-clock-clocktable-contents ":link t :lang en"))))
  657. (should
  658. (equal
  659. "| Headline | Time |
  660. |-----------------------------------------------------------+---------|
  661. | *Total time* | *26:00* |
  662. |-----------------------------------------------------------+---------|
  663. | [[Foo [[https://orgmode.org]\\]][Foo https://orgmode.org]] | 26:00 |"
  664. (org-test-with-temp-text
  665. "* Foo [[https://orgmode.org]]
  666. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  667. (test-org-clock-clocktable-contents ":link t :lang en"))))))
  668. (ert-deftest test-org-clock/clocktable/compact ()
  669. "Test \":compact\" parameter in Clock table."
  670. ;; With :compact, all headlines are in the same column.
  671. (should
  672. (equal
  673. "| Headline | Time |
  674. |--------------+---------|
  675. | *Total time* | *26:00* |
  676. |--------------+---------|
  677. | Foo | 26:00 |"
  678. (org-test-with-temp-text
  679. "* Foo
  680. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  681. (test-org-clock-clocktable-contents ":compact t"))))
  682. (should
  683. (equal
  684. "| Headline | Time |
  685. |--------------+---------|
  686. | *Total time* | *52:00* |
  687. |--------------+---------|
  688. | Foo | 52:00 |
  689. | \\_ Bar | 26:00 |"
  690. (org-test-with-temp-text
  691. "* Foo
  692. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  693. ** Bar
  694. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  695. (test-org-clock-clocktable-contents ":compact t"))))
  696. ;; :maxlevel does not affect :compact parameter.
  697. (should
  698. (equal
  699. "| Headline | Time |
  700. |--------------+---------|
  701. | *Total time* | *52:00* |
  702. |--------------+---------|
  703. | Foo | 52:00 |
  704. | \\_ Bar | 26:00 |"
  705. (org-test-with-temp-text
  706. "* Foo
  707. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  708. ** Bar
  709. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  710. (test-org-clock-clocktable-contents ":compact t :maxlevel 2"))))
  711. ;; :compact implies a non-nil :indent parameter.
  712. (should
  713. (equal
  714. "| Headline | Time |
  715. |--------------+---------|
  716. | *Total time* | *52:00* |
  717. |--------------+---------|
  718. | Foo | 52:00 |
  719. | \\_ Bar | 26:00 |"
  720. (org-test-with-temp-text
  721. "* Foo
  722. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  723. ** Bar
  724. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  725. (test-org-clock-clocktable-contents ":compact t :indent nil"))))
  726. ;; :compact implies a nil :level parameter.
  727. (should
  728. (equal
  729. "| Headline | Time |
  730. |--------------+---------|
  731. | *Total time* | *52:00* |
  732. |--------------+---------|
  733. | Foo | 52:00 |
  734. | \\_ Bar | 26:00 |"
  735. (org-test-with-temp-text
  736. "* Foo
  737. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  738. ** Bar
  739. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  740. (test-org-clock-clocktable-contents ":compact t :level t")))))
  741. (ert-deftest test-org-clock/clocktable/properties ()
  742. "Test \":properties\" parameter in Clock table."
  743. ;; Include a new column with list properties.
  744. (should
  745. (equal
  746. "| A | Headline | Time |
  747. |---+--------------+---------|
  748. | | *Total time* | *26:00* |
  749. |---+--------------+---------|
  750. | 1 | Foo | 26:00 |"
  751. (org-test-with-temp-text
  752. "* Foo
  753. :PROPERTIES:
  754. :A: 1
  755. :END:
  756. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  757. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  758. (should
  759. (equal
  760. "| A | Headline | Time | |
  761. |---+--------------+---------+-------|
  762. | | *Total time* | *52:00* | |
  763. |---+--------------+---------+-------|
  764. | | Foo | 52:00 | |
  765. | 1 | \\_ Bar | | 26:00 |"
  766. (org-test-with-temp-text
  767. "* Foo
  768. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  769. ** Bar
  770. :PROPERTIES:
  771. :A: 1
  772. :END:
  773. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  774. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  775. ;; Handle missing properties.
  776. (should
  777. (equal
  778. "| A | Headline | Time |
  779. |---+--------------+---------|
  780. | | *Total time* | *26:00* |
  781. |---+--------------+---------|
  782. | 1 | Foo | 26:00 |"
  783. (org-test-with-temp-text
  784. "* Foo
  785. :PROPERTIES:
  786. :A: 1
  787. :END:
  788. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  789. (test-org-clock-clocktable-contents ":properties (\"A\")")))))
  790. (ert-deftest test-org-clock/clocktable/tcolumns ()
  791. "Test \":tcolumns\" parameter in Clock table."
  792. ;; When :tcolumns is smaller than the deepest headline level, lump
  793. ;; lower levels in the last column.
  794. (should
  795. (equal
  796. "| Headline | Time |
  797. |--------------+---------|
  798. | *Total time* | *52:00* |
  799. |--------------+---------|
  800. | Foo | 52:00 |
  801. | \\_ Bar | 26:00 |"
  802. (org-test-with-temp-text
  803. "* Foo
  804. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  805. ** Bar
  806. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  807. (test-org-clock-clocktable-contents ":tcolumns 1"))))
  808. ;; :tcolumns cannot create more columns than the deepest headline
  809. ;; level.
  810. (should
  811. (equal
  812. "| Headline | Time | |
  813. |--------------+---------+-------|
  814. | *Total time* | *52:00* | |
  815. |--------------+---------+-------|
  816. | Foo | 52:00 | |
  817. | \\_ Bar | | 26:00 |"
  818. (org-test-with-temp-text
  819. "* Foo
  820. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  821. ** Bar
  822. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  823. (test-org-clock-clocktable-contents ":tcolumns 3"))))
  824. ;; Pathological case: when no headline contributes to the total
  825. ;; time, there is only one time column.
  826. (should
  827. (equal "| Headline | Time |
  828. |--------------+--------|
  829. | *Total time* | *0:00* |"
  830. (org-test-with-temp-text
  831. "* Foo
  832. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 11:09] => 0:00
  833. ** Bar
  834. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 13:09] => 0:00"
  835. (test-org-clock-clocktable-contents ":tcolumns 2")))))
  836. (ert-deftest test-org-clock/clocktable/step ()
  837. "Test \":step\" parameter in Clock table."
  838. ;; Regression test: week crossing month boundary before :wstart
  839. ;; day-of-week.
  840. (should
  841. (equal "
  842. Weekly report starting on: [2017-09-25 Mon]
  843. | Headline | Time |
  844. |--------------+--------|
  845. | *Total time* | *1:00* |
  846. |--------------+--------|
  847. | Foo | 1:00 |"
  848. (org-test-with-temp-text
  849. "* Foo
  850. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  851. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  852. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00"
  853. (let ((system-time-locale "en_US"))
  854. (test-org-clock-clocktable-contents
  855. ":step week :block 2017-09 :stepskip0 t")))))
  856. (should
  857. (equal "
  858. Weekly report starting on: [2017-10-01 Sun]
  859. | Headline | Time |
  860. |--------------+--------|
  861. | *Total time* | *2:00* |
  862. |--------------+--------|
  863. | Foo | 2:00 |
  864. Weekly report starting on: [2017-10-02 Mon]
  865. | Headline | Time |
  866. |--------------+--------|
  867. | *Total time* | *7:00* |
  868. |--------------+--------|
  869. | Foo | 7:00 |
  870. Weekly report starting on: [2017-10-09 Mon]
  871. | Headline | Time |
  872. |--------------+--------|
  873. | *Total time* | *5:00* |
  874. |--------------+--------|
  875. | Foo | 5:00 |
  876. "
  877. (org-test-with-temp-text
  878. "* Foo
  879. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  880. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  881. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
  882. CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
  883. CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
  884. (let ((system-time-locale "en_US"))
  885. (test-org-clock-clocktable-contents
  886. ":step week :block 2017-10 :stepskip0 t")))))
  887. ;; :step day
  888. (should
  889. (equal "
  890. Daily report: [2017-10-02 Mon]
  891. | Headline | Time |
  892. |--------------+--------|
  893. | *Total time* | *3:00* |
  894. |--------------+--------|
  895. | Foo | 3:00 |
  896. Daily report: [2017-10-03 Tue]
  897. | Headline | Time |
  898. |--------------+--------|
  899. | *Total time* | *0:00* |
  900. Daily report: [2017-10-04 Wed]
  901. | Headline | Time |
  902. |--------------+--------|
  903. | *Total time* | *0:00* |
  904. Daily report: [2017-10-05 Thu]
  905. | Headline | Time |
  906. |--------------+--------|
  907. | *Total time* | *0:00* |
  908. Daily report: [2017-10-06 Fri]
  909. | Headline | Time |
  910. |--------------+--------|
  911. | *Total time* | *0:00* |
  912. Daily report: [2017-10-07 Sat]
  913. | Headline | Time |
  914. |--------------+--------|
  915. | *Total time* | *0:00* |
  916. Daily report: [2017-10-08 Sun]
  917. | Headline | Time |
  918. |--------------+--------|
  919. | *Total time* | *4:00* |
  920. |--------------+--------|
  921. | Foo | 4:00 |"
  922. (org-test-with-temp-text
  923. "* Foo
  924. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  925. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  926. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
  927. CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
  928. CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
  929. (let ((system-time-locale "en_US"))
  930. (test-org-clock-clocktable-contents
  931. ":step day :block 2017-W40")))))
  932. ;; Regression test: take :tstart and :tend hours into consideration.
  933. (should
  934. (equal "
  935. Weekly report starting on: [2017-12-25 Mon]
  936. | Headline | Time |
  937. |--------------+--------|
  938. | *Total time* | *8:00* |
  939. |--------------+--------|
  940. | Foo | 8:00 |"
  941. (org-test-with-temp-text
  942. "* Foo
  943. CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] => 8:00"
  944. (let ((system-time-locale "en_US"))
  945. (test-org-clock-clocktable-contents
  946. (concat ":step week :tstart \"<2017-12-25 Mon>\" "
  947. ":tend \"<2017-12-27 Wed 23:59>\""))))))
  948. (should
  949. (equal "
  950. Daily report: [2017-12-27 Wed]
  951. | Headline | Time |
  952. |--------------+--------|
  953. | *Total time* | *8:00* |
  954. |--------------+--------|
  955. | Foo | 8:00 |"
  956. (org-test-with-temp-text
  957. "* Foo
  958. CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] => 8:00"
  959. (let ((system-time-locale "en_US"))
  960. (test-org-clock-clocktable-contents
  961. (concat ":step day :tstart \"<2017-12-25 Mon>\" "
  962. ":tend \"<2017-12-27 Wed 23:59>\" :stepskip0 t"))))))
  963. ;; Test :step week", without or with ":wstart" parameter.
  964. (should
  965. (equal "
  966. Weekly report starting on: [2012-03-26 Mon]
  967. | Headline | Time |
  968. |--------------+--------|
  969. | *Total time* | *8:00* |
  970. |--------------+--------|
  971. | Foo | 8:00 |
  972. Weekly report starting on: [2012-04-02 Mon]
  973. | Headline | Time |
  974. |--------------+--------|
  975. | *Total time* | *8:00* |
  976. |--------------+--------|
  977. | Foo | 8:00 |
  978. "
  979. (org-test-with-temp-text
  980. "* Foo
  981. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  982. CLOCK: [2012-04-03 Thu 08:00]--[2012-04-03 Thu 16:00] => 8:00"
  983. (let ((system-time-locale "en_US"))
  984. (test-org-clock-clocktable-contents
  985. ":step week :block 2012 :stepskip0 t")))))
  986. (should
  987. (equal "
  988. Weekly report starting on: [2012-03-29 Thu]
  989. | Headline | Time |
  990. |--------------+---------|
  991. | *Total time* | *16:00* |
  992. |--------------+---------|
  993. | Foo | 16:00 |
  994. "
  995. (org-test-with-temp-text
  996. "* Foo
  997. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  998. CLOCK: [2012-04-03 Thu 08:00]--[2012-04-03 Thu 16:00] => 8:00"
  999. (let ((system-time-locale "en_US"))
  1000. (test-org-clock-clocktable-contents
  1001. ":step week :wstart 4 :block 2012 :stepskip0 t")))))
  1002. ;; Test ":step month" without and with ":mstart".
  1003. (should
  1004. (equal "
  1005. Monthly report starting on: [2014-03-01 Sat]
  1006. | Headline | Time |
  1007. |--------------+--------|
  1008. | *Total time* | *8:00* |
  1009. |--------------+--------|
  1010. | Foo | 8:00 |
  1011. Monthly report starting on: [2014-04-01 Tue]
  1012. | Headline | Time |
  1013. |--------------+--------|
  1014. | *Total time* | *8:00* |
  1015. |--------------+--------|
  1016. | Foo | 8:00 |
  1017. "
  1018. (org-test-with-temp-text
  1019. "* Foo
  1020. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00
  1021. CLOCK: [2014-04-03 Thu 08:00]--[2014-04-03 Thu 16:00] => 8:00"
  1022. (let ((system-time-locale "en_US"))
  1023. (test-org-clock-clocktable-contents
  1024. ":step month :block 2014 :stepskip0 t")))))
  1025. (should
  1026. (equal "
  1027. Monthly report starting on: [2014-03-04 Tue]
  1028. | Headline | Time |
  1029. |--------------+---------|
  1030. | *Total time* | *16:00* |
  1031. |--------------+---------|
  1032. | Foo | 16:00 |
  1033. "
  1034. (org-test-with-temp-text
  1035. "* Foo
  1036. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00
  1037. CLOCK: [2014-04-03 Thu 08:00]--[2014-04-03 Thu 16:00] => 8:00"
  1038. (let ((system-time-locale "en_US"))
  1039. (test-org-clock-clocktable-contents
  1040. ":step month :mstart 4 :block 2014 :stepskip0 t")))))
  1041. ;; Test ":step year".
  1042. (should
  1043. (equal "
  1044. Annual report starting on: [2012-01-01 Sun]
  1045. | Headline | Time |
  1046. |--------------+--------|
  1047. | *Total time* | *8:00* |
  1048. |--------------+--------|
  1049. | Foo | 8:00 |
  1050. Annual report starting on: [2014-01-01 Wed]
  1051. | Headline | Time |
  1052. |--------------+--------|
  1053. | *Total time* | *8:00* |
  1054. |--------------+--------|
  1055. | Foo | 8:00 |
  1056. "
  1057. (org-test-with-temp-text
  1058. "* Foo
  1059. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  1060. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00"
  1061. (let ((system-time-locale "en_US"))
  1062. (test-org-clock-clocktable-contents
  1063. ":step year :block untilnow :stepskip0 t")))))
  1064. ;; Regression test: Respect DST
  1065. (should
  1066. (equal "
  1067. Daily report: [2018-10-29 Mon]
  1068. | Headline | Time |
  1069. |--------------+--------|
  1070. | *Total time* | *8:00* |
  1071. |--------------+--------|
  1072. | Foo | 8:00 |
  1073. "
  1074. (org-test-with-temp-text
  1075. "* Foo
  1076. CLOCK: [2018-10-29 Mon 08:00]--[2018-10-29 Mon 16:00] => 8:00"
  1077. (let ((system-time-locale "en_US"))
  1078. (test-org-clock-clocktable-contents
  1079. (concat ":step day "
  1080. ":stepskip0 t "
  1081. ":tstart \"2018-10-01\" "
  1082. ":tend \"2018-11-01\"")))))))
  1083. (ert-deftest test-org-clock/clocktable/extend-today-until ()
  1084. "Test assignment of clock time to days in presence of \"org-extend-today-until\"."
  1085. ;; Basic test of :block with org-extend-today-until - the report for
  1086. ;; 2017-09-30 should include the time clocked on 2017-10-01 before
  1087. ;; 04:00.
  1088. (should
  1089. (equal "| Headline | Time |
  1090. |--------------+--------|
  1091. | *Total time* | *2:00* |
  1092. |--------------+--------|
  1093. | Foo | 2:00 |"
  1094. (org-test-with-temp-text
  1095. "* Foo
  1096. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  1097. CLOCK: [2017-10-01 Sun 02:00]--[2017-10-01 Sun 03:00] => 1:00
  1098. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00"
  1099. (setq-local org-extend-today-until 4)
  1100. (let ((system-time-locale "en_US"))
  1101. (test-org-clock-clocktable-contents
  1102. ":block 2017-09-30")))))
  1103. ;; Week-length block - time on Monday before 04:00 should be
  1104. ;; assigned to previous week.
  1105. (should
  1106. (equal "
  1107. Weekly report starting on: [2017-10-01 Sun]
  1108. | Headline | Time |
  1109. |--------------+--------|
  1110. | *Total time* | *2:00* |
  1111. |--------------+--------|
  1112. | Foo | 2:00 |
  1113. Weekly report starting on: [2017-10-02 Mon]
  1114. | Headline | Time |
  1115. |--------------+--------|
  1116. | *Total time* | *2:00* |
  1117. |--------------+--------|
  1118. | Foo | 2:00 |
  1119. "
  1120. (org-test-with-temp-text
  1121. "* Foo
  1122. CLOCK: [2017-10-01 Sun 12:00]--[2017-10-01 Sun 13:00] => 1:00
  1123. CLOCK: [2017-10-02 Mon 02:00]--[2017-10-02 Mon 03:00] => 1:00
  1124. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 13:00] => 2:00"
  1125. (setq-local org-extend-today-until 4)
  1126. (let ((system-time-locale "en_US"))
  1127. (test-org-clock-clocktable-contents
  1128. ":step week :block 2017-10 :stepskip0 t"))))))
  1129. (provide 'test-org-clock)
  1130. ;;; test-org-clock.el end here