org-duration: Fix copyright
[org-mode/org-tableheadings.git] / testing / lisp / test-org-lint.el
blob005828e4b5cd9056acc789b619264e8baab01dc4
1 ;;; test-org-lint.el --- Tests for Org Lint -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2016 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Code:
22 (ert-deftest test-org-lint/duplicate-custom-id ()
23 "Test `org-lint-duplicate-custom-id' checker."
24 (should
25 (org-test-with-temp-text "
26 * H1
27 :PROPERTIES:
28 :CUSTOM_ID: foo
29 :END:
31 * H2
32 :PROPERTIES:
33 :CUSTOM_ID: foo
34 :END:"
35 (org-lint '(duplicate-custom-id))))
36 (should-not
37 (org-test-with-temp-text "
38 * H1
39 :PROPERTIES:
40 :CUSTOM_ID: foo
41 :END:
43 * H2
44 :PROPERTIES:
45 :CUSTOM_ID: bar
46 :END:"
47 (org-lint '(duplicate-custom-id)))))
49 (ert-deftest test-org-lint/duplicate-name ()
50 "Test `org-lint-duplicate-name' checker."
51 (should
52 (org-test-with-temp-text "
53 #+name: foo
54 Paragraph1
56 #+name: foo
57 Paragraph 2"
58 (org-lint '(duplicate-name))))
59 (should-not
60 (org-test-with-temp-text "
61 #+name: foo
62 Paragraph1
64 #+name: bar
65 Paragraph 2"
66 (org-lint '(duplicate-name)))))
68 (ert-deftest test-org-lint/duplicate-target ()
69 "Test `org-lint-duplicate-target' checker."
70 (should
71 (org-test-with-temp-text "<<foo>> <<foo>>"
72 (org-lint '(duplicate-target))))
73 (should-not
74 (org-test-with-temp-text "<<foo>> <<bar>>"
75 (org-lint '(duplicate-target)))))
77 (ert-deftest test-org-lint/duplicate-footnote-definition ()
78 "Test `org-lint-duplicate-footnote-definition' checker."
79 (should
80 (org-test-with-temp-text "
81 \[fn:1] Definition 1
83 \[fn:1] Definition 2"
84 (org-lint '(duplicate-footnote-definition))))
85 (should-not
86 (org-test-with-temp-text "
87 \[fn:1] Definition 1
89 \[fn:2] Definition 2"
90 (org-lint '(duplicate-footnote-definition)))))
92 (ert-deftest test-org-lint/orphaned-affiliated-keywords ()
93 "Test `org-lint-orphaned-affiliated-keywords' checker."
94 (should
95 (org-test-with-temp-text "#+name: foo"
96 (org-lint '(orphaned-affiliated-keywords)))))
98 (ert-deftest test-org-lint/deprecated-export-blocks ()
99 "Test `org-lint-deprecated-export-blocks' checker."
100 (should
101 (org-test-with-temp-text "
102 #+begin_latex
104 #+end_latex"
105 (org-lint '(deprecated-export-blocks)))))
107 (ert-deftest test-org-lint/deprecated-header-syntax ()
108 "Test `org-lint-deprecated-header-syntax' checker."
109 (should
110 (org-test-with-temp-text "#+property: cache yes"
111 (org-lint '(deprecated-header-syntax))))
112 (should
113 (org-test-with-temp-text "
115 :PROPERTIES:
116 :cache: yes
117 :END:"
118 (org-lint '(deprecated-header-syntax)))))
120 (ert-deftest test-org-lint/missing-language-in-src-block ()
121 "Test `org-lint-missing-language-in-src-block' checker."
122 (should
123 (org-test-with-temp-text "
124 #+begin_src
126 #+end_src"
127 (org-lint '(missing-language-in-src-block)))))
129 (ert-deftest test-org-lint/missing-backend-in-export-block ()
130 "Test `org-lint-missing-backend-in-export-block' checker."
131 (should
132 (org-test-with-temp-text "
133 #+begin_export
135 #+end_export"
136 (org-lint '(missing-backend-in-export-block)))))
138 (ert-deftest test-org-lint/invalid-babel-call-block ()
139 "Test `org-lint-invalid-babel-call-block' checker."
140 (should
141 (org-test-with-temp-text "#+call:"
142 (org-lint '(invalid-babel-call-block))))
143 (should
144 (org-test-with-temp-text "#+call: foo() [:exports code]"
145 (org-lint '(invalid-babel-call-block)))))
147 (ert-deftest test-org-lint/deprecated-category-setup ()
148 "Test `org-lint-deprecated-category-setup' checker."
149 (should
150 (org-test-with-temp-text "#+category: foo\n#+category: bar"
151 (org-lint '(deprecated-category-setup)))))
153 (ert-deftest test-org-lint/invalid-coderef-link ()
154 "Test `org-lint-invalid-coderef-link' checker."
155 (should
156 (org-test-with-temp-text "[[(unknown)]]"
157 (org-lint '(invalid-coderef-link))))
158 (should-not
159 (org-test-with-temp-text "[[(foo)]]
160 #+begin_src emacs-lisp -l \"; ref:%s\"
161 (+ 1 1) ; ref:foo
162 #+end_src"
163 (org-lint '(invalid-coderef-link)))))
165 (ert-deftest test-org-lint/invalid-custom-id-link ()
166 "Test `org-lint-invalid-custom-id-link' checker."
167 (should
168 (org-test-with-temp-text "[[#unknown]]"
169 (org-lint '(invalid-custom-id-link))))
170 (should-not
171 (org-test-with-temp-text "[[#foo]]
173 :PROPERTIES:
174 :CUSTOM_ID: foo
175 :END:"
176 (org-lint '(invalid-custom-id-link)))))
178 (ert-deftest test-org-lint/invalid-fuzzy-link ()
179 "Test `org-lint-invalid-fuzzy-link' checker."
180 (should
181 (org-test-with-temp-text "[[*unknown]]"
182 (org-lint '(invalid-fuzzy-link))))
183 (should-not
184 (org-test-with-temp-text "[[*foo]]\n* foo"
185 (org-lint '(invalid-fuzzy-link))))
186 (should
187 (org-test-with-temp-text "[[unknown]]"
188 (org-lint '(invalid-fuzzy-link))))
189 (should-not
190 (org-test-with-temp-text "[[foo]]\n#+name: foo\nParagraph"
191 (org-lint '(invalid-fuzzy-link))))
192 (should-not
193 (org-test-with-temp-text "[[foo]]\n<<foo>>"
194 (org-lint '(invalid-fuzzy-link)))))
196 (ert-deftest test-org-lint/special-property-in-properties-drawer ()
197 "Test `org-lint-special-property-in-properties-drawer' checker."
198 (should
199 (org-test-with-temp-text "
201 :PROPERTIES:
202 :TODO: foo
203 :END:"
204 (org-lint '(special-property-in-properties-drawer)))))
206 (ert-deftest test-org-lint/obsolete-properties-drawer ()
207 "Test `org-lint-obsolete-properties-drawer' checker."
208 (should
209 (org-test-with-temp-text "
211 Paragraph
212 :PROPERTIES:
213 :SOMETHING: foo
214 :END:"
215 (org-lint '(obsolete-properties-drawer))))
216 (should
217 (org-test-with-temp-text "
219 :PROPERTIES:
220 This is not a node property
221 :END:"
222 (org-lint '(obsolete-properties-drawer)))))
224 (ert-deftest test-org-lint/invalid-effort-property ()
225 "Test `org-lint-invalid-effort-property' checker."
226 (should
227 (org-test-with-temp-text "* H\n:PROPERTIES:\n:EFFORT: something\n:END:"
228 (org-lint '(invalid-effort-property))))
229 (should-not
230 (org-test-with-temp-text "* H\n:PROPERTIES:\n:EFFORT: 1:23\n:END:"
231 (org-lint '(invalid-effort-property)))))
233 (ert-deftest test-org-lint/link-to-local-file ()
234 "Test `org-lint-link-to-local-file' checker."
235 (should
236 (org-test-with-temp-text "[[file:/Idonotexist.org]]"
237 (org-lint '(link-to-local-file)))))
239 (ert-deftest test-org-lint/non-existent-setupfile-parameter ()
240 "Test `org-lint-non-existent-setupfile-parameter' checker."
241 (should
242 (org-test-with-temp-text "#+setupfile: Idonotexist.org"
243 (org-lint '(non-existent-setupfile-parameter)))))
245 (ert-deftest test-org-lint/wrong-include-link-parameter ()
246 "Test `org-lint-wrong-include-link-parameter' checker."
247 (should
248 (org-test-with-temp-text "#+include:"
249 (org-lint '(wrong-include-link-parameter))))
250 (should
251 (org-test-with-temp-text "#+include: Idonotexist.org"
252 (org-lint '(wrong-include-link-parameter))))
253 (should
254 (org-test-with-temp-text-in-file ""
255 (let ((file (buffer-file-name)))
256 (org-test-with-temp-text (format "#+include: \"%s::#foo\"" file)
257 (org-lint '(wrong-include-link-parameter))))))
258 (should-not
259 (org-test-with-temp-text-in-file "* foo"
260 (let ((file (buffer-file-name)))
261 (org-test-with-temp-text (format "#+include: \"%s::*foo\"" file)
262 (org-lint '(wrong-include-link-parameter)))))))
264 (ert-deftest test-org-lint/obsolete-include-markup ()
265 "Test `org-lint-obsolete-include-markup' checker."
266 (should
267 (org-test-with-temp-text-in-file ""
268 (let ((file (buffer-file-name)))
269 (org-test-with-temp-text (format "#+include: \"%s\" html" file)
270 (org-lint '(obsolete-include-markup))))))
271 (should-not
272 (org-test-with-temp-text-in-file ""
273 (let ((file (buffer-file-name)))
274 (org-test-with-temp-text (format "#+include: \"%s\" export html" file)
275 (org-lint '(obsolete-include-markup)))))))
277 (ert-deftest test-org-lint/unknown-options-item ()
278 "Test `org-lint-unknown-options-item' checker."
279 (should
280 (org-test-with-temp-text "#+options: foobarbaz:t"
281 (org-lint '(unknown-options-item)))))
283 (ert-deftest test-org-lint/invalid-macro-argument-and-template ()
284 "Test `org-lint-invalid-macro-argument-and-template' checker."
285 (should
286 (org-test-with-temp-text "{{{undefined()}}}"
287 (org-lint '(invalid-macro-argument-and-template))))
288 (should
289 (org-test-with-temp-text
290 "#+macro: wrongsignature $1 $2\n{{{wrongsignature(1, 2, 3)}}}"
291 (org-lint '(invalid-macro-argument-and-template))))
292 (should
293 (org-test-with-temp-text "#+macro:"
294 (org-lint '(invalid-macro-argument-and-template))))
295 (should
296 (org-test-with-temp-text "#+macro: missingtemplate"
297 (org-lint '(invalid-macro-argument-and-template))))
298 (should
299 (org-test-with-temp-text "#+macro: unusedplaceholders $1 $3"
300 (org-lint '(invalid-macro-argument-and-template))))
301 (should-not
302 (org-test-with-temp-text
303 "#+macro: valid $1 $2\n{{{valid(1, 2)}}}"
304 (org-lint '(invalid-macro-argument-and-template)))))
306 (ert-deftest test-org-lint/undefined-footnote-reference ()
307 "Test `org-lint-undefined-footnote-reference' checker."
308 (should
309 (org-test-with-temp-text "Text[fn:1]"
310 (org-lint '(undefined-footnote-reference))))
311 (should-not
312 (org-test-with-temp-text "Text[fn:1]\n[fn:1] Definition"
313 (org-lint '(undefined-footnote-reference)))))
315 (ert-deftest test-org-lint/unreferenced-footnote-definition ()
316 "Test `org-lint-unreferenced-footnote-definition' checker."
317 (should
318 (org-test-with-temp-text "[fn:1] Definition"
319 (org-lint '(unreferenced-footnote-definition))))
320 (should-not
321 (org-test-with-temp-text "Text[fn:1]\n[fn:1] Definition"
322 (org-lint '(unreferenced-footnote-definition)))))
324 (ert-deftest test-org-lint/colon-in-name ()
325 "Test `org-lint-colon-in-name' checker."
326 (should
327 (org-test-with-temp-text "#+name: tab:name\n| a |"
328 (org-lint '(colon-in-name))))
329 (should-not
330 (org-test-with-temp-text "#+name: name\n| a |"
331 (org-lint '(colon-in-name)))))
333 (ert-deftest test-org-lint/misplaced-planning-info ()
334 "Test `org-lint-misplaced-planning-info' checker."
335 (should
336 (org-test-with-temp-text "SCHEDULED: <2012-03-29 thu.>"
337 (org-lint '(misplaced-planning-info))))
338 (should
339 (org-test-with-temp-text "
341 Text
342 SCHEDULED: <2012-03-29 thu.>"
343 (org-lint '(misplaced-planning-info))))
344 (should-not
345 (org-test-with-temp-text "
347 SCHEDULED: <2012-03-29 thu.>"
348 (org-lint '(misplaced-planning-info)))))
350 (ert-deftest test-org-lint/incomplete-drawer ()
351 "Test `org-lint-incomplete-drawer' checker."
352 (should
353 (org-test-with-temp-text ":DRAWER:"
354 (org-lint '(incomplete-drawer))))
355 (should-not
356 (org-test-with-temp-text ":DRAWER:\n:END:"
357 (org-lint '(incomplete-drawer)))))
359 (ert-deftest test-org-lint/indented-diary-sexp ()
360 "Test `org-lint-indented-diary-sexp' checker."
361 (should
362 (org-test-with-temp-text " %%(foo)"
363 (org-lint '(indented-diary-sexp))))
364 (should-not
365 (org-test-with-temp-text "%%(foo)"
366 (org-lint '(indented-diary-sexp)))))
368 (ert-deftest test-org-lint/invalid-block ()
369 "Test `org-lint-invalid-block' checker."
370 (should
371 (org-test-with-temp-text "#+begin_foo"
372 (org-lint '(invalid-block))))
373 (should-not
374 (org-test-with-temp-text "#+begin_foo\n#+end_foo"
375 (org-lint '(invalid-block)))))
377 (ert-deftest test-org-lint/invalid-keyword-syntax ()
378 "Test `org-lint-invalid-keyword-syntax' checker."
379 (should
380 (org-test-with-temp-text "#+keyword"
381 (org-lint '(invalid-keyword-syntax))))
382 (should-not
383 (org-test-with-temp-text "#+keyword:"
384 (org-lint '(invalid-keyword-syntax)))))
386 (ert-deftest test-org-lint/extraneous-element-in-footnote-section ()
387 "Test `org-lint-extraneous-element-in-footnote-section' checker."
388 (should
389 (org-test-with-temp-text "* Footnotes\nI'm not a footnote definition"
390 (let ((org-footnote-section "Footnotes"))
391 (org-lint '(extraneous-element-in-footnote-section)))))
392 (should-not
393 (org-test-with-temp-text "* Footnotes\n[fn:1] I'm a footnote definition"
394 (let ((org-footnote-section "Footnotes"))
395 (org-lint '(extraneous-element-in-footnote-section))))))
397 (ert-deftest test-org-lint/quote-section ()
398 "Test `org-lint-quote-section' checker."
399 (should
400 (org-test-with-temp-text "* QUOTE H"
401 (org-lint '(quote-section))))
402 (should
403 (org-test-with-temp-text "* COMMENT QUOTE H"
404 (org-lint '(quote-section)))))
406 (ert-deftest test-org-lint/file-application ()
407 "Test `org-lint-file-application' checker."
408 (should
409 (org-test-with-temp-text "[[file+emacs:foo.org]]"
410 (org-lint '(file-application)))))
412 (ert-deftest test-org-lint/wrong-header-argument ()
413 "Test `org-lint-wrong-header-argument' checker."
414 (should
415 (org-test-with-temp-text "#+call: foo() barbaz yes"
416 (org-lint '(wrong-header-argument))))
417 (should
418 (org-test-with-temp-text "#+call: foo() :barbaz yes"
419 (org-lint '(wrong-header-argument))))
420 (should
421 (org-test-with-temp-text "call_foo[barbaz yes]()"
422 (org-lint '(wrong-header-argument))))
423 (should
424 (org-test-with-temp-text "call_foo[:barbaz yes]()"
425 (org-lint '(wrong-header-argument))))
426 (should
427 (org-test-with-temp-text "#+property: header-args barbaz yes"
428 (org-lint '(wrong-header-argument))))
429 (should
430 (org-test-with-temp-text "#+property: header-args :barbaz yes"
431 (org-lint '(wrong-header-argument))))
432 (should
433 (org-test-with-temp-text "
435 :PROPERTIES:
436 :HEADER-ARGS: barbaz yes
437 :END:"
438 (org-lint '(wrong-header-argument))))
439 (should
440 (org-test-with-temp-text "
442 :PROPERTIES:
443 :HEADER-ARGS: :barbaz yes
444 :END:"
445 (org-lint '(wrong-header-argument))))
446 (should
447 (org-test-with-temp-text "
448 #+header: :barbaz yes
449 #+begin_src emacs-lisp
450 \(+ 1 1)
451 #+end_src"
452 (org-lint '(wrong-header-argument))))
453 (should
454 (org-test-with-temp-text "src_emacs-lisp[barbaz yes]{}"
455 (org-lint '(wrong-header-argument))))
456 (should
457 (org-test-with-temp-text "src_emacs-lisp[:barbaz yes]{}"
458 (org-lint '(wrong-header-argument)))))
460 (ert-deftest test-org-lint/wrong-header-value ()
461 "Test `org-lint-wrong-header-value' checker."
462 (should
463 (org-test-with-temp-text "
464 #+header: :cache maybe
465 #+begin_src emacs-lisp
466 \(+ 1 1)
467 #+end_src"
468 (org-lint '(wrong-header-value))))
469 (should
470 (org-test-with-temp-text "
471 #+header: :exports both none
472 #+begin_src emacs-lisp
473 \(+ 1 1)
474 #+end_src"
475 (org-lint '(wrong-header-value))))
476 (should-not
477 (org-test-with-temp-text "
478 #+header: :cache yes
479 #+begin_src emacs-lisp
480 \(+ 1 1)
481 #+end_src"
482 (org-lint '(wrong-header-value)))))
484 (ert-deftest test-org-lint/empty-headline-with-tags ()
485 "Test `org-lint-empty-headline-with-tags' checker."
486 (should
487 (org-test-with-temp-text "* :tag:"
488 (org-lint '(empty-headline-with-tags))))
489 (should
490 (org-test-with-temp-text "* :tag: "
491 (org-lint '(empty-headline-with-tags))))
492 (should-not
493 (org-test-with-temp-text "* notag: "
494 (org-lint '(empty-headline-with-tags)))))
496 (provide 'test-org-lint)
497 ;;; test-org-lint.el ends here