test-org-clock.el 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. (string-match-p
  842. "
  843. .*?\\[2017-09-25 .*
  844. .*
  845. .*
  846. |.*?| \\*1:00\\* |
  847. .*
  848. | Foo +| 1:00 +|"
  849. (org-test-with-temp-text
  850. "* Foo
  851. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  852. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  853. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00"
  854. (let ((system-time-locale "en_US"))
  855. (test-org-clock-clocktable-contents
  856. ":step week :block 2017-09 :stepskip0 t")))))
  857. (should
  858. (string-match-p
  859. "
  860. .*?\\[2017-10-01 .*
  861. .*
  862. .*
  863. |.*?| \\*2:00\\* |
  864. .*
  865. | Foo +| 2:00 |
  866. .*?\\[2017-10-02 .*
  867. .*
  868. .*
  869. |.*?| \\*7:00\\* |
  870. .*
  871. | Foo +| 7:00 +|
  872. .*?\\[2017-10-09 .*
  873. .*
  874. .*
  875. |.*?| \\*5:00\\* |
  876. .*
  877. | Foo +| 5:00 +|
  878. "
  879. (org-test-with-temp-text
  880. "* Foo
  881. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  882. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  883. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
  884. CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
  885. CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
  886. (let ((system-time-locale "en_US"))
  887. (test-org-clock-clocktable-contents
  888. ":step week :block 2017-10 :stepskip0 t")))))
  889. ;; :step day
  890. (should
  891. (string-match-p
  892. "
  893. .*?\\[2017-10-02 .*
  894. .*
  895. .*
  896. |.*?| \\*3:00\\* |
  897. .*
  898. | Foo +| 3:00 +|
  899. .*?\\[2017-10-03 .*
  900. .*
  901. .*
  902. |.*?| \\*0:00\\* |
  903. .*?\\[2017-10-04 .*
  904. .*
  905. .*
  906. |.*?| \\*0:00\\* |
  907. .*?\\[2017-10-05 .*
  908. .*
  909. .*
  910. |.*?| \\*0:00\\* |
  911. .*?\\[2017-10-06 .*
  912. .*
  913. .*
  914. |.*?| \\*0:00\\* |
  915. .*?\\[2017-10-07 .*
  916. .*
  917. .*
  918. |.*?| \\*0:00\\* |
  919. .*?\\[2017-10-08 .*
  920. .*
  921. .*
  922. |.*?| \\*4:00\\* |
  923. .*
  924. | Foo +| 4:00 +|"
  925. (org-test-with-temp-text
  926. "* Foo
  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")))))
  935. ;; Regression test: take :tstart and :tend hours into consideration.
  936. (should
  937. (string-match-p
  938. "
  939. .*?\\[2017-12-25 .*
  940. .*
  941. .*
  942. |.*?| \\*8:00\\* |
  943. .*
  944. | Foo +| 8:00 +|"
  945. (org-test-with-temp-text
  946. "* Foo
  947. CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] => 8:00"
  948. (let ((system-time-locale "en_US"))
  949. (test-org-clock-clocktable-contents
  950. (concat ":step week :tstart \"<2017-12-25 Mon>\" "
  951. ":tend \"<2017-12-27 Wed 23:59>\""))))))
  952. (should
  953. (string-match-p
  954. "
  955. .*?\\[2017-12-27 .*
  956. .*
  957. .*
  958. |.*?| \\*8:00\\* |
  959. .*
  960. | Foo +| 8:00 +|"
  961. (org-test-with-temp-text
  962. "* Foo
  963. CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] => 8:00"
  964. (let ((system-time-locale "en_US"))
  965. (test-org-clock-clocktable-contents
  966. (concat ":step day :tstart \"<2017-12-25 Mon>\" "
  967. ":tend \"<2017-12-27 Wed 23:59>\" :stepskip0 t"))))))
  968. ;; Test :step week", without or with ":wstart" parameter.
  969. (should
  970. (string-match-p
  971. "
  972. .*?\\[2012-03-26 .*
  973. .*
  974. .*
  975. |.*?| \\*8:00\\* |
  976. .*
  977. | Foo +| 8:00 +|
  978. .*?\\[2012-04-02 .*
  979. .*
  980. .*
  981. |.*?| \\*8:00\\* |
  982. .*
  983. | Foo +| 8:00 +|
  984. "
  985. (org-test-with-temp-text
  986. "* Foo
  987. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  988. CLOCK: [2012-04-03 Thu 08:00]--[2012-04-03 Thu 16:00] => 8:00"
  989. (let ((system-time-locale "en_US"))
  990. (test-org-clock-clocktable-contents
  991. ":step week :block 2012 :stepskip0 t")))))
  992. (should
  993. (string-match-p
  994. "
  995. .*?\\[2012-03-29 .*
  996. .*
  997. .*
  998. |.*?| \\*16:00\\* |
  999. .*
  1000. | Foo +| 16:00 +|
  1001. "
  1002. (org-test-with-temp-text
  1003. "* Foo
  1004. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  1005. CLOCK: [2012-04-03 Thu 08:00]--[2012-04-03 Thu 16:00] => 8:00"
  1006. (let ((system-time-locale "en_US"))
  1007. (test-org-clock-clocktable-contents
  1008. ":step week :wstart 4 :block 2012 :stepskip0 t")))))
  1009. ;; Test ":step month" without and with ":mstart".
  1010. (should
  1011. (string-match-p
  1012. "
  1013. .*?\\[2014-03-01 .*
  1014. .*
  1015. .*
  1016. |.*?| \\*8:00\\* |
  1017. .*
  1018. | Foo +| 8:00 +|
  1019. .*?\\[2014-04-01 .*
  1020. .*
  1021. .*
  1022. |.*?| \\*8:00\\* |
  1023. .*
  1024. | Foo +| 8:00 +|
  1025. "
  1026. (org-test-with-temp-text
  1027. "* Foo
  1028. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00
  1029. CLOCK: [2014-04-03 Thu 08:00]--[2014-04-03 Thu 16:00] => 8:00"
  1030. (let ((system-time-locale "en_US"))
  1031. (test-org-clock-clocktable-contents
  1032. ":step month :block 2014 :stepskip0 t")))))
  1033. (should
  1034. (string-match-p
  1035. "
  1036. .*?\\[2014-03-04 .*
  1037. .*
  1038. .*
  1039. |.*?| \\*16:00\\* |
  1040. .*
  1041. | Foo +| 16:00 +|
  1042. "
  1043. (org-test-with-temp-text
  1044. "* Foo
  1045. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00
  1046. CLOCK: [2014-04-03 Thu 08:00]--[2014-04-03 Thu 16:00] => 8:00"
  1047. (let ((system-time-locale "en_US"))
  1048. (test-org-clock-clocktable-contents
  1049. ":step month :mstart 4 :block 2014 :stepskip0 t")))))
  1050. ;; Test ":step year".
  1051. (should
  1052. (string-match-p
  1053. "
  1054. .*?\\[2012-01-01 .*
  1055. .*
  1056. .*
  1057. |.*?| \\*8:00\\* |
  1058. .*
  1059. | Foo +| 8:00 +|
  1060. .*?\\[2014-01-01 .*
  1061. .*
  1062. .*
  1063. |.*?| \\*8:00\\* |
  1064. .*
  1065. | Foo +| 8:00 +|
  1066. "
  1067. (org-test-with-temp-text
  1068. "* Foo
  1069. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  1070. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00"
  1071. (let ((system-time-locale "en_US"))
  1072. (test-org-clock-clocktable-contents
  1073. ":step year :block untilnow :stepskip0 t")))))
  1074. ;; Regression test: Respect DST
  1075. (should
  1076. (string-match-p
  1077. "
  1078. .*?\\[2018-10-29 .*
  1079. .*
  1080. .*
  1081. |.*?| \\*8:00\\* |
  1082. .*
  1083. | Foo +| 8:00 +|
  1084. "
  1085. (org-test-with-temp-text
  1086. "* Foo
  1087. CLOCK: [2018-10-29 Mon 08:00]--[2018-10-29 Mon 16:00] => 8:00"
  1088. (let ((system-time-locale "en_US"))
  1089. (test-org-clock-clocktable-contents
  1090. (concat ":step day "
  1091. ":stepskip0 t "
  1092. ":tstart \"2018-10-01\" "
  1093. ":tend \"2018-11-01\"")))))))
  1094. (ert-deftest test-org-clock/clocktable/extend-today-until ()
  1095. "Test assignment of clock time to days in presence of \"org-extend-today-until\"."
  1096. ;; Basic test of :block with org-extend-today-until - the report for
  1097. ;; 2017-09-30 should include the time clocked on 2017-10-01 before
  1098. ;; 04:00.
  1099. (should
  1100. (equal "| Headline | Time |
  1101. |--------------+--------|
  1102. | *Total time* | *2:00* |
  1103. |--------------+--------|
  1104. | Foo | 2:00 |"
  1105. (org-test-with-temp-text
  1106. "* Foo
  1107. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  1108. CLOCK: [2017-10-01 Sun 02:00]--[2017-10-01 Sun 03:00] => 1:00
  1109. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00"
  1110. (setq-local org-extend-today-until 4)
  1111. (let ((system-time-locale "en_US"))
  1112. (test-org-clock-clocktable-contents
  1113. ":block 2017-09-30")))))
  1114. ;; Week-length block - time on Monday before 04:00 should be
  1115. ;; assigned to previous week.
  1116. (should
  1117. (string-match-p "
  1118. .*? \\[2017-10-01 .*
  1119. .*
  1120. .*
  1121. |.*?| \\*2:00\\* |
  1122. .*
  1123. | Foo +| 2:00 |
  1124. .*? \\[2017-10-02 .*
  1125. .*
  1126. .*
  1127. |.*?| \\*2:00\\* |
  1128. .*
  1129. | Foo +| 2:00 |
  1130. "
  1131. (org-test-with-temp-text
  1132. "* Foo
  1133. CLOCK: [2017-10-01 Sun 12:00]--[2017-10-01 Sun 13:00] => 1:00
  1134. CLOCK: [2017-10-02 Mon 02:00]--[2017-10-02 Mon 03:00] => 1:00
  1135. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 13:00] => 2:00"
  1136. (setq-local org-extend-today-until 4)
  1137. (let ((system-time-locale "en_US"))
  1138. (test-org-clock-clocktable-contents
  1139. ":step week :block 2017-10 :stepskip0 t"))))))
  1140. (ert-deftest test-org-clock/clocktable/hidefiles ()
  1141. "Test \":hidefiles\" parameter in Clock table."
  1142. ;; Test that hidefiles removes the file column.
  1143. (should
  1144. (equal
  1145. "| Headline | Time |
  1146. |--------------+--------|
  1147. | *Total time* | *1:00* |
  1148. |--------------+--------|
  1149. | Test | 1:00 |"
  1150. (org-test-with-temp-text-in-file
  1151. "* Test
  1152. CLOCK: [2012-03-29 Thu 16:00]--[2012-03-29 Thu 17:00] => 1:00"
  1153. (let ((the-file (buffer-file-name)))
  1154. (org-test-with-temp-text-in-file ""
  1155. (test-org-clock-clocktable-contents
  1156. (format ":hidefiles t :scope (lambda () (list %S))" the-file))))))))
  1157. (provide 'test-org-clock)
  1158. ;;; test-org-clock.el end here