* ob-php.el (supporting PHP in Org-mode Babel): Add.
[org-mode/org-tableheadings.git] / testing / lisp / test-org-lint.el
blob7c4af0530e276a78ae0f8621267796ba9a4bdef2
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))))
314 (should-not
315 (org-test-with-temp-text "Text[fn:1:inline reference]"
316 (org-lint '(undefined-footnote-reference))))
317 (should-not
318 (org-test-with-temp-text "Text[fn::anonymous reference]"
319 (org-lint '(undefined-footnote-reference)))))
321 (ert-deftest test-org-lint/unreferenced-footnote-definition ()
322 "Test `org-lint-unreferenced-footnote-definition' checker."
323 (should
324 (org-test-with-temp-text "[fn:1] Definition"
325 (org-lint '(unreferenced-footnote-definition))))
326 (should-not
327 (org-test-with-temp-text "Text[fn:1]\n[fn:1] Definition"
328 (org-lint '(unreferenced-footnote-definition)))))
330 (ert-deftest test-org-lint/colon-in-name ()
331 "Test `org-lint-colon-in-name' checker."
332 (should
333 (org-test-with-temp-text "#+name: tab:name\n| a |"
334 (org-lint '(colon-in-name))))
335 (should-not
336 (org-test-with-temp-text "#+name: name\n| a |"
337 (org-lint '(colon-in-name)))))
339 (ert-deftest test-org-lint/misplaced-planning-info ()
340 "Test `org-lint-misplaced-planning-info' checker."
341 (should
342 (org-test-with-temp-text "SCHEDULED: <2012-03-29 thu.>"
343 (org-lint '(misplaced-planning-info))))
344 (should
345 (org-test-with-temp-text "
347 Text
348 SCHEDULED: <2012-03-29 thu.>"
349 (org-lint '(misplaced-planning-info))))
350 (should-not
351 (org-test-with-temp-text "
353 SCHEDULED: <2012-03-29 thu.>"
354 (org-lint '(misplaced-planning-info)))))
356 (ert-deftest test-org-lint/incomplete-drawer ()
357 "Test `org-lint-incomplete-drawer' checker."
358 (should
359 (org-test-with-temp-text ":DRAWER:"
360 (org-lint '(incomplete-drawer))))
361 (should-not
362 (org-test-with-temp-text ":DRAWER:\n:END:"
363 (org-lint '(incomplete-drawer)))))
365 (ert-deftest test-org-lint/indented-diary-sexp ()
366 "Test `org-lint-indented-diary-sexp' checker."
367 (should
368 (org-test-with-temp-text " %%(foo)"
369 (org-lint '(indented-diary-sexp))))
370 (should-not
371 (org-test-with-temp-text "%%(foo)"
372 (org-lint '(indented-diary-sexp)))))
374 (ert-deftest test-org-lint/invalid-block ()
375 "Test `org-lint-invalid-block' checker."
376 (should
377 (org-test-with-temp-text "#+begin_foo"
378 (org-lint '(invalid-block))))
379 (should-not
380 (org-test-with-temp-text "#+begin_foo\n#+end_foo"
381 (org-lint '(invalid-block)))))
383 (ert-deftest test-org-lint/invalid-keyword-syntax ()
384 "Test `org-lint-invalid-keyword-syntax' checker."
385 (should
386 (org-test-with-temp-text "#+keyword"
387 (org-lint '(invalid-keyword-syntax))))
388 (should-not
389 (org-test-with-temp-text "#+keyword:"
390 (org-lint '(invalid-keyword-syntax)))))
392 (ert-deftest test-org-lint/extraneous-element-in-footnote-section ()
393 "Test `org-lint-extraneous-element-in-footnote-section' checker."
394 (should
395 (org-test-with-temp-text "* Footnotes\nI'm not a footnote definition"
396 (let ((org-footnote-section "Footnotes"))
397 (org-lint '(extraneous-element-in-footnote-section)))))
398 (should-not
399 (org-test-with-temp-text "* Footnotes\n[fn:1] I'm a footnote definition"
400 (let ((org-footnote-section "Footnotes"))
401 (org-lint '(extraneous-element-in-footnote-section))))))
403 (ert-deftest test-org-lint/quote-section ()
404 "Test `org-lint-quote-section' checker."
405 (should
406 (org-test-with-temp-text "* QUOTE H"
407 (org-lint '(quote-section))))
408 (should
409 (org-test-with-temp-text "* COMMENT QUOTE H"
410 (org-lint '(quote-section)))))
412 (ert-deftest test-org-lint/file-application ()
413 "Test `org-lint-file-application' checker."
414 (should
415 (org-test-with-temp-text "[[file+emacs:foo.org]]"
416 (org-lint '(file-application)))))
418 (ert-deftest test-org-lint/wrong-header-argument ()
419 "Test `org-lint-wrong-header-argument' checker."
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 "call_foo[barbaz yes]()"
428 (org-lint '(wrong-header-argument))))
429 (should
430 (org-test-with-temp-text "call_foo[:barbaz yes]()"
431 (org-lint '(wrong-header-argument))))
432 (should
433 (org-test-with-temp-text "#+property: header-args barbaz yes"
434 (org-lint '(wrong-header-argument))))
435 (should
436 (org-test-with-temp-text "#+property: header-args :barbaz yes"
437 (org-lint '(wrong-header-argument))))
438 (should
439 (org-test-with-temp-text "
441 :PROPERTIES:
442 :HEADER-ARGS: barbaz yes
443 :END:"
444 (org-lint '(wrong-header-argument))))
445 (should
446 (org-test-with-temp-text "
448 :PROPERTIES:
449 :HEADER-ARGS: :barbaz yes
450 :END:"
451 (org-lint '(wrong-header-argument))))
452 (should
453 (org-test-with-temp-text "
454 #+header: :barbaz yes
455 #+begin_src emacs-lisp
456 \(+ 1 1)
457 #+end_src"
458 (org-lint '(wrong-header-argument))))
459 (should
460 (org-test-with-temp-text "src_emacs-lisp[barbaz yes]{}"
461 (org-lint '(wrong-header-argument))))
462 (should
463 (org-test-with-temp-text "src_emacs-lisp[:barbaz yes]{}"
464 (org-lint '(wrong-header-argument)))))
466 (ert-deftest test-org-lint/wrong-header-value ()
467 "Test `org-lint-wrong-header-value' checker."
468 (should
469 (org-test-with-temp-text "
470 #+header: :cache maybe
471 #+begin_src emacs-lisp
472 \(+ 1 1)
473 #+end_src"
474 (org-lint '(wrong-header-value))))
475 (should
476 (org-test-with-temp-text "
477 #+header: :exports both none
478 #+begin_src emacs-lisp
479 \(+ 1 1)
480 #+end_src"
481 (org-lint '(wrong-header-value))))
482 (should-not
483 (org-test-with-temp-text "
484 #+header: :cache yes
485 #+begin_src emacs-lisp
486 \(+ 1 1)
487 #+end_src"
488 (org-lint '(wrong-header-value)))))
490 (ert-deftest test-org-lint/empty-headline-with-tags ()
491 "Test `org-lint-empty-headline-with-tags' checker."
492 (should
493 (org-test-with-temp-text "* :tag:"
494 (org-lint '(empty-headline-with-tags))))
495 (should
496 (org-test-with-temp-text "* :tag: "
497 (org-lint '(empty-headline-with-tags))))
498 (should-not
499 (org-test-with-temp-text "* notag: "
500 (org-lint '(empty-headline-with-tags)))))
502 (provide 'test-org-lint)
503 ;;; test-org-lint.el ends here