/
clojure.test-api.html
992 lines (785 loc) · 40 KB
/
clojure.test-api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>clojure.test - Clojure v1.1 API documentation</title>
<link rel="icon" href="../static/favicon.png" />
<link rel="shortcut icon" href="../static/favicon.png" />
<link rel="stylesheet" href="../static/clojure.css" type="text/css" media="all" />
<link rel="stylesheet" href="../static/wiki.css" type="text/css" media="all" />
<link rel="stylesheet" href="../static/internal.css" type="text/css" media="all" />
<style>.menuWrapper{height: 36px;}</style>
</head>
<!--
This document was auto-generated from the source by the clojure autodoc system.
To report errors or ask questions about the overall documentation structure, formatting,
etc., contact Tom Faulhaber (google mail name: tomfaulhaber).
For errors in the documentation of a particular namespace, contact the author of that
namespace.
-->
<body>
<div id="AllContentContainer">
<div id="Header">
<a href="index.html" id="Logo"><img src="../static/clojure-icon.gif" width="100" height="100" alt="Clojure" /></a>
<h1><a href="index.html" id="page-header" title="page header title">Clojure Core API Reference</a></h1>
</div>
<div id="leftcolumn"><div style="text-align: center;"></div>
<div class="menu">
<div class="WikiCustomNav WikiElement wiki">
<span class="toc-header"><span id="project-name">Clojure</span> <span id="version">v1.1</span> API</span><br />
<ul>
<li><a href="index.html" class="wiki_link">Overview</a></li>
<li><a href="api-index.html" class="wiki_link">API Index</a></li>
</ul>
<div class="NamespaceTOC">
<span class="toc-header">Namespaces</span>
<ul id="left-sidebar-list">
<li><a class="wiki_link" href="clojure.core-api.html">clojure.core</a></li><li><a class="wiki_link" href="clojure.inspector-api.html">clojure.inspector</a></li><li><a class="wiki_link" href="clojure.main-api.html">clojure.main</a></li><li><a class="wiki_link" href="clojure.set-api.html">clojure.set</a></li><li><a class="wiki_link" href="clojure.stacktrace-api.html">clojure.stacktrace</a></li><li><a class="wiki_link" href="clojure.template-api.html">clojure.template</a></li><li><a class="wiki_link" href="clojure.test-api.html">clojure.test</a></li><li><a class="wiki_link" href="clojure.walk-api.html">clojure.walk</a></li><li><a class="wiki_link" href="clojure.xml-api.html">clojure.xml</a></li><li><a class="wiki_link" href="clojure.zip-api.html">clojure.zip</a></li>
</ul>
</div>
<div class="BranchTOC">
<span class="toc-header">Other Versions</span>
<ul id="left-sidebar-branch-list">
<li><a class="wiki_link" href="../index.html">v1.11 (stable)</a></li><li><a class="wiki_link" href="../branch-master/index.html">v1.12 (in development)</a></li><li><a class="wiki_link" href="../branch-clojure-1.10.3/index.html">v1.10.3 (legacy)</a></li><li><a class="wiki_link" href="../branch-clojure-1.9.0/index.html">v1.9 (legacy)</a></li><li><a class="wiki_link" href="../branch-clojure-1.8.0/index.html">v1.8 (legacy)</a></li><li><a class="wiki_link" href="../branch-clojure-1.7.0/index.html">v1.7 (legacy)</a></li><li><a class="wiki_link" href="../branch-clojure-1.6.0/index.html">v1.6 (legacy)</a></li><li><a class="wiki_link" href="../branch-clojure-1.5.0/index.html">v1.5 (legacy)</a></li><li><a class="wiki_link" href="../branch-clojure-1.4.0/index.html">v1.4 (legacy)</a></li><li><a class="wiki_link" href="../branch-1.3.x/index.html">v1.3 (legacy)</a></li><li><a class="wiki_link" href="../branch-1.2.x/index.html">v1.2 (legacy)</a></li>
</ul>
</div>
<a class="wiki_link" href="https://clojure.org">Clojure Home</a>
</div>
</div>
</div>
<div id="rightcolumn">
<div id="Content">
<div class="contentBox"><div class="innerContentBox">
<div class="wiki wikiPage" id="content_view">
<div id="right-sidebar"><div id="toc">
<h1 class="nopad">Table of Contents</h1>
<div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#toc0">Overview</a>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#"></a>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#"></a>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#var-section">Vars and Functions</a>
<div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/*load-tests*" class="toc-entry-anchor">*load-tests*</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/*stack-trace-depth*" class="toc-entry-anchor">*stack-trace-depth*</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/are" class="toc-entry-anchor">are</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/assert-any" class="toc-entry-anchor">assert-any</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/assert-predicate" class="toc-entry-anchor">assert-predicate</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/compose-fixtures" class="toc-entry-anchor">compose-fixtures</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/deftest" class="toc-entry-anchor">deftest</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/deftest-" class="toc-entry-anchor">deftest-</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/file-position" class="toc-entry-anchor">file-position</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/function?" class="toc-entry-anchor">function?</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/get-possibly-unbound-var" class="toc-entry-anchor">get-possibly-unbound-var</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/inc-report-counter" class="toc-entry-anchor">inc-report-counter</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/is" class="toc-entry-anchor">is</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/join-fixtures" class="toc-entry-anchor">join-fixtures</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/report" class="toc-entry-anchor">report</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/run-all-tests" class="toc-entry-anchor">run-all-tests</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/run-tests" class="toc-entry-anchor">run-tests</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/set-test" class="toc-entry-anchor">set-test</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/successful?" class="toc-entry-anchor">successful?</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/test-all-vars" class="toc-entry-anchor">test-all-vars</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/test-ns" class="toc-entry-anchor">test-ns</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/test-var" class="toc-entry-anchor">test-var</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/testing" class="toc-entry-anchor">testing</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/testing-contexts-str" class="toc-entry-anchor">testing-contexts-str</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/testing-vars-str" class="toc-entry-anchor">testing-vars-str</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/try-expr" class="toc-entry-anchor">try-expr</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/use-fixtures" class="toc-entry-anchor">use-fixtures</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/with-test" class="toc-entry-anchor">with-test</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test/with-test-out" class="toc-entry-anchor">with-test-out</a>
</div>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#"></a>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#clojure.test.junit">clojure.test.junit</a>
<div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test.junit/with-junit-output" class="toc-entry-anchor">with-junit-output</a>
</div>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#clojure.test.tap">clojure.test.tap</a>
<div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test.tap/print-tap-diagnostic" class="toc-entry-anchor">print-tap-diagnostic</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test.tap/print-tap-fail" class="toc-entry-anchor">print-tap-fail</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test.tap/print-tap-pass" class="toc-entry-anchor">print-tap-pass</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test.tap/print-tap-plan" class="toc-entry-anchor">print-tap-plan</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.test.tap/with-tap-output" class="toc-entry-anchor">with-tap-output</a>
</div>
</div>
</div>
</div>
<div id="content-tag"><h1 id="overview">API for <span id="clojure.test">clojure.test</span>
- <span id="header-project">Clojure</span> <span id="header-version">v1.1</span><span id="header-status-block"> (<span id="header-status">legacy</span>)</span>
</h1>
<span id="author-line">by <span id="author-name">Stuart Sierra, with contributions and suggestions by
Chas Emerick, Allen Rohner, and Stuart Halloway</span><br /></span>
<br />Full namespace name: <span id="long-name">clojure.test</span>
<p></p>
<h2>Overview</h2>
<pre id="namespace-docstr">A unit testing framework.
ASSERTIONS
The core of the library is the "is" macro, which lets you make
assertions of any arbitrary expression:
(is (= 4 (+ 2 2)))
(is (instance? Integer 256))
(is (.startsWith "abcde" "ab"))
You can type an "is" expression directly at the REPL, which will
print a message if it fails.
user> (is (= 5 (+ 2 2)))
FAIL in (:1)
expected: (= 5 (+ 2 2))
actual: (not (= 5 4))
false
The "expected:" line shows you the original expression, and the
"actual:" shows you what actually happened. In this case, it
shows that (+ 2 2) returned 4, which is not = to 5. Finally, the
"false" on the last line is the value returned from the
expression. The "is" macro always returns the result of the
inner expression.
There are two special assertions for testing exceptions. The
"(is (thrown? c ...))" form tests if an exception of class c is
thrown:
(is (thrown? ArithmeticException (/ 1 0)))
"(is (thrown-with-msg? c re ...))" does the same thing and also
tests that the message on the exception matches the regular
expression re:
(is (thrown-with-msg? ArithmeticException #"Divide by zero"
(/ 1 0)))
DOCUMENTING TESTS
"is" takes an optional second argument, a string describing the
assertion. This message will be included in the error report.
(is (= 5 (+ 2 2)) "Crazy arithmetic")
In addition, you can document groups of assertions with the
"testing" macro, which takes a string followed by any number of
assertions. The string will be included in failure reports.
Calls to "testing" may be nested, and all of the strings will be
joined together with spaces in the final report, in a style
similar to RSpec <<a href="http://rspec.info/">http://rspec.info/</a>>
(testing "Arithmetic"
(testing "with positive integers"
(is (= 4 (+ 2 2)))
(is (= 7 (+ 3 4))))
(testing "with negative integers"
(is (= -4 (+ -2 -2)))
(is (= -1 (+ 3 -4)))))
Note that, unlike RSpec, the "testing" macro may only be used
INSIDE a "deftest" or "with-test" form (see below).
DEFINING TESTS
There are two ways to define tests. The "with-test" macro takes
a defn or def form as its first argument, followed by any number
of assertions. The tests will be stored as metadata on the
definition.
(with-test
(defn my-function [x y]
(+ x y))
(is (= 4 (my-function 2 2)))
(is (= 7 (my-function 3 4))))
As of Clojure SVN rev. 1221, this does not work with defmacro.
See <a href="http://code.google.com/p/clojure/issues/detail?id=51">http://code.google.com/p/clojure/issues/detail?id=51</a>
The other way lets you define tests separately from the rest of
your code, even in a different namespace:
(deftest addition
(is (= 4 (+ 2 2)))
(is (= 7 (+ 3 4))))
(deftest subtraction
(is (= 1 (- 4 3)))
(is (= 3 (- 7 4))))
This creates functions named "addition" and "subtraction", which
can be called like any other function. Therefore, tests can be
grouped and composed, in a style similar to the test framework in
Peter Seibel's "Practical Common Lisp"
<<a href="http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html">http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html</a>>
(deftest arithmetic
(addition)
(subtraction))
The names of the nested tests will be joined in a list, like
"(arithmetic addition)", in failure reports. You can use nested
tests to set up a context shared by several tests.
RUNNING TESTS
Run tests with the function "(run-tests namespaces...)":
(run-tests 'your.namespace 'some.other.namespace)
If you don't specify any namespaces, the current namespace is
used. To run all tests in all namespaces, use "(run-all-tests)".
By default, these functions will search for all tests defined in
a namespace and run them in an undefined order. However, if you
are composing tests, as in the "arithmetic" example above, you
probably do not want the "addition" and "subtraction" tests run
separately. In that case, you must define a special function
named "test-ns-hook" that runs your tests in the correct order:
(defn test-ns-hook []
(arithmetic))
OMITTING TESTS FROM PRODUCTION CODE
You can bind the variable "*load-tests*" to false when loading or
compiling code in production. This will prevent any tests from
being created by "with-test" or "deftest".
FIXTURES (new)
Fixtures allow you to run code before and after tests, to set up
the context in which tests should be run.
A fixture is just a function that calls another function passed as
an argument. It looks like this:
(defn my-fixture [f]
Perform setup, establish bindings, whatever.
(f) Then call the function we were passed.
Tear-down / clean-up code here.
)
Fixtures are attached to namespaces in one of two ways. "each"
fixtures are run repeatedly, once for each test function created
with "deftest" or "with-test". "each" fixtures are useful for
establishing a consistent before/after state for each test, like
clearing out database tables.
"each" fixtures can be attached to the current namespace like this:
(use-fixtures :each fixture1 fixture2 ...)
The fixture1, fixture2 are just functions like the example above.
They can also be anonymous functions, like this:
(use-fixtures :each (fn [f] setup... (f) cleanup...))
The other kind of fixture, a "once" fixture, is only run once,
around ALL the tests in the namespace. "once" fixtures are useful
for tasks that only need to be performed once, like establishing
database connections, or for time-consuming tasks.
Attach "once" fixtures to the current namespace like this:
(use-fixtures :once fixture1 fixture2 ...)
SAVING TEST OUTPUT TO A FILE
All the test reporting functions write to the var *test-out*. By
default, this is the same as *out*, but you can rebind it to any
PrintWriter. For example, it could be a file opened with
clojure.contrib.duck-streams/writer.
EXTENDING TEST-IS (ADVANCED)
You can extend the behavior of the "is" macro by defining new
methods for the "assert-expr" multimethod. These methods are
called during expansion of the "is" macro, so they should return
quoted forms to be evaluated.
You can plug in your own test-reporting framework by rebinding
the "report" function: (report event)
The 'event' argument is a map. It will always have a :type key,
whose value will be a keyword signaling the type of event being
reported. Standard events with :type value of :pass, :fail, and
:error are called when an assertion passes, fails, and throws an
exception, respectively. In that case, the event will also have
the following keys:
:expected The form that was expected to be true
:actual A form representing what actually occurred
:message The string message given as an argument to 'is'
The "testing" strings will be a list in "*testing-contexts*", and
the vars being tested will be a list in "*testing-vars*".
Your "report" function should wrap any printing calls in the
"with-test-out" macro, which rebinds *out* to the current value
of *test-out*.
For additional event types, see the examples in the code.</pre>
<br />
<div id="var-section">
<p></p>
<h2>Public Variables and Functions</h2>
<div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/*load-tests*">*load-tests*</h2>
<span id="var-type">var</span><br />
<pre id="var-usage"></pre>
<pre id="var-docstr">True by default. If set to false, no test functions will
be created by deftest, set-test, or with-test. Use this to omit
tests when compiling or loading production code.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L239">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/*stack-trace-depth*">*stack-trace-depth*</h2>
<span id="var-type">var</span><br />
<pre id="var-usage"></pre>
<pre id="var-docstr">The maximum depth of stack traces to print when an Exception
is thrown during a test. Defaults to nil, which means print the
complete stack trace.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L245">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/are">are</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (are argv expr & args)
</pre>
<pre id="var-docstr">Checks multiple assertions with a template expression.
See clojure.template/do-template for an explanation of
templates.
Example: (are [x y] (= x y)
2 (+ 1 1)
4 (* 2 2))
Expands to:
(do (is (= 2 (+ 1 1)))
(is (= 4 (* 2 2))))
Note: This breaks some reporting features, such as line numbers.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L518">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/assert-any">assert-any</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (assert-any msg form)
</pre>
<pre id="var-docstr">Returns generic assertion code for any test, including macros, Java
method calls, or isolated symbols.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L404">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/assert-predicate">assert-predicate</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (assert-predicate msg form)
</pre>
<pre id="var-docstr">Returns generic assertion code for any functional predicate. The
'expected' argument to 'report' will contains the original form, the
'actual' argument will contain the form with all its sub-forms
evaluated. If the predicate returns false, the 'actual' form will
be wrapped in (not...).</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L386">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/compose-fixtures">compose-fixtures</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (compose-fixtures f1 f2)
</pre>
<pre id="var-docstr">Composes two fixture functions, creating a new fixture function
that combines their behavior.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L618">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/deftest">deftest</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (deftest name & body)
</pre>
<pre id="var-docstr">Defines a test function with no arguments. Test functions may call
other tests, so tests may be composed. If you compose tests, you
should also define a function named test-ns-hook; run-tests will
call test-ns-hook instead of testing all vars.
Note: Actually, the test body goes in the :test metadata on the var,
and the real function (the value of the var) calls test-var on
itself.
When *load-tests* is false, deftest is ignored.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L557">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/deftest-">deftest-</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (deftest- name & body)
</pre>
<pre id="var-docstr">Like deftest but creates a private var.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L573">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/file-position">file-position</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (file-position n)
</pre>
<pre id="var-docstr">Returns a vector [filename line-number] for the nth call up the
stack.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L275">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/function?">function?</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (function? x)
</pre>
<pre id="var-docstr">Returns true if argument is a function or a symbol that resolves to
a function (not a macro).</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L375">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/get-possibly-unbound-var">get-possibly-unbound-var</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (get-possibly-unbound-var v)
</pre>
<pre id="var-docstr">Like var-get but returns nil if the var is unbound.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L368">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/inc-report-counter">inc-report-counter</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (inc-report-counter name)
</pre>
<pre id="var-docstr">Increments the named counter in *report-counters*, a ref to a map.
Does nothing if *report-counters* is nil.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L300">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/is">is</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (is form)
(is form msg)
</pre>
<pre id="var-docstr">Generic assertion macro. 'form' is any predicate test.
'msg' is an optional message to attach to the assertion.
Example: (is (= 4 (+ 2 2)) "Two plus two should be 4")
Special forms:
(is (thrown? c body)) checks that an instance of c is thrown from
body, fails if not; then returns the thing thrown.
(is (thrown-with-msg? c re body)) checks that an instance of c is
thrown AND that the message on the exception matches (with
re-matches) the regular expression re.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L501">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/join-fixtures">join-fixtures</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (join-fixtures fixtures)
</pre>
<pre id="var-docstr">Composes a collection of fixtures, in order. Always returns a valid
fixture function, even if the collection is empty.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L624">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/report">report</h2>
<span id="var-type">multimethod</span><br />
<pre id="var-usage">No usage documentation available</pre>
<pre id="var-docstr">Generic reporting function, may be overridden to plug in
different report formats (e.g., TAP, JUnit). Assertions such as
'is' call 'report' to indicate results. The argument given to
'report' will be a map with a :type key. See the documentation at
the top of test_is.clj for more information on the types of
arguments for 'report'.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L312">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/run-all-tests">run-all-tests</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (run-all-tests)
(run-all-tests re)
</pre>
<pre id="var-docstr">Runs all tests in all namespaces; prints results.
Optional argument is a regular expression; only namespaces with
names matching the regular expression (with re-matches) will be
tested.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L695">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/run-tests">run-tests</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (run-tests)
(run-tests & namespaces)
</pre>
<pre id="var-docstr">Runs all tests in the given namespaces; prints results.
Defaults to current namespace if none given. Returns a map
summarizing test results.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L684">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/set-test">set-test</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (set-test name & body)
</pre>
<pre id="var-docstr">Experimental.
Sets :test metadata of the named var to a fn with the given body.
The var must already exist. Does not modify the value of the var.
When *load-tests* is false, set-test is ignored.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L581">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/successful?">successful?</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (successful? summary)
</pre>
<pre id="var-docstr">Returns true if the given test summary indicates all tests
were successful, false otherwise.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L703">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/test-all-vars">test-all-vars</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (test-all-vars ns)
</pre>
<pre id="var-docstr">Calls test-var on every var interned in the namespace, with fixtures.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L649">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/test-ns">test-ns</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (test-ns ns)
</pre>
<pre id="var-docstr">If the namespace defines a function named test-ns-hook, calls that.
Otherwise, calls test-all-vars on the namespace. 'ns' is a
namespace object or a symbol.
Internally binds *report-counters* to a ref initialized to
*inital-report-counters*. Returns the final, dereferenced state of
*report-counters*.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L660">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/test-var">test-var</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (test-var v)
</pre>
<pre id="var-docstr">If v has a function in its :test metadata, calls that function,
with *testing-vars* bound to (conj *testing-vars* v).</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L635">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/testing">testing</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (testing string & body)
</pre>
<pre id="var-docstr">Adds a new string to the list of testing contexts. May be nested,
but must occur inside a test function (deftest).</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L534">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/testing-contexts-str">testing-contexts-str</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (testing-contexts-str)
</pre>
<pre id="var-docstr">Returns a string representation of the current test context. Joins
strings in *testing-contexts* with spaces.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L294">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/testing-vars-str">testing-vars-str</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (testing-vars-str)
</pre>
<pre id="var-docstr">Returns a string representation of the current test. Renders names
in *testing-vars* as a list, then the source file and line of
current assertion.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L282">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/try-expr">try-expr</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (try-expr msg form)
</pre>
<pre id="var-docstr">Used by the 'is' macro to catch unexpected exceptions.
You don't call this.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L486">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/use-fixtures">use-fixtures</h2>
<span id="var-type">multimethod</span><br />
<pre id="var-usage">No usage documentation available</pre>
<pre id="var-docstr">Wrap test runs in a fixture function to perform setup and
teardown. Using a fixture-type of :each wraps every test
individually, while:once wraps the whole run in a single function.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L601">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/with-test">with-test</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (with-test definition & body)
</pre>
<pre id="var-docstr">Takes any definition form (that returns a Var) as the first argument.
Remaining body goes in the :test metadata function for that Var.
When *load-tests* is false, only evaluates the definition, ignoring
the tests.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L545">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test/with-test-out">with-test-out</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (with-test-out & body)
</pre>
<pre id="var-docstr">Runs body with *out* bound to the value of *test-out*.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/607389029cfec50f32b73c00a6f66d0a1dbcda23/src/clj/clojure/test.clj#L265">Source</a>
</div>
</div>
<br />
<h2 id="clojure.test.junit">clojure.test.junit</h2>
<pre id="namespace-docstr">clojure.test extension for JUnit-compatible XML output.
JUnit (<a href="http://junit.org/">http://junit.org/</a>) is the most popular unit-testing library
for Java. As such, tool support for JUnit output formats is
common. By producing compatible output from tests, this tool
support can be exploited.
To use, wrap any calls to clojure.test/run-tests in the
with-junit-output macro, like this:
(use 'clojure.test)
(use 'clojure.contrib.test.junit)
(with-junit-output
(run-tests 'my.cool.library))
To write the output to a file, rebind clojure.test/*test-out* to
your own PrintWriter (perhaps opened using
clojure.contrib.duck-streams/writer).</pre>
<br />
<div id="var-section">
<p></p>
<h2>Public Variables and Functions</h2>
<div id="var-entry">
<br />
<hr />
<h2 id="clojure.test.junit/with-junit-output">with-junit-output</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (with-junit-output & body)
</pre>
<pre id="var-docstr">Execute body with modified test-is reporting functions that write
JUnit-compatible XML output.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/76e7c4317dc3eac80c4908ac5e5fb885e302b2a4/src/clj/clojure/test/junit.clj#L182">Source</a>
</div>
</div>
<br />
<h2 id="clojure.test.tap">clojure.test.tap</h2>
<pre id="namespace-docstr">clojure.test extensions for the Test Anything Protocol (TAP)
TAP is a simple text-based syntax for reporting test results. TAP
was originally develped for Perl, and now has implementations in
several languages. For more information on TAP, see
<a href="http://testanything.org/">http://testanything.org/</a> and
<a href="http://search.cpan.org/~petdance/TAP-1.0.0/TAP.pm">http://search.cpan.org/~petdance/TAP-1.0.0/TAP.pm</a>
To use this library, wrap any calls to
clojure.test/run-tests in the with-tap-output macro,
like this:
(use 'clojure.test)
(use 'clojure.test.tap)
(with-tap-output
(run-tests 'my.cool.library))</pre>
<br />
<div id="var-section">
<p></p>
<h2>Public Variables and Functions</h2>
<div id="var-entry">
<br />
<hr />
<h2 id="clojure.test.tap/print-tap-diagnostic">print-tap-diagnostic</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (print-tap-diagnostic data)
</pre>
<pre id="var-docstr">Prints a TAP diagnostic line. data is a (possibly multi-line)
string.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/76e7c4317dc3eac80c4908ac5e5fb885e302b2a4/src/clj/clojure/test/tap.clj#L50">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test.tap/print-tap-fail">print-tap-fail</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (print-tap-fail msg)
</pre>
<pre id="var-docstr">Prints a TAP 'not ok' line. msg is a string, with no line breaks</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/76e7c4317dc3eac80c4908ac5e5fb885e302b2a4/src/clj/clojure/test/tap.clj#L62">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test.tap/print-tap-pass">print-tap-pass</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (print-tap-pass msg)
</pre>
<pre id="var-docstr">Prints a TAP 'ok' line. msg is a string, with no line breaks</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/76e7c4317dc3eac80c4908ac5e5fb885e302b2a4/src/clj/clojure/test/tap.clj#L57">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test.tap/print-tap-plan">print-tap-plan</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (print-tap-plan n)
</pre>
<pre id="var-docstr">Prints a TAP plan line like '1..n'. n is the number of tests</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/76e7c4317dc3eac80c4908ac5e5fb885e302b2a4/src/clj/clojure/test/tap.clj#L45">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.test.tap/with-tap-output">with-tap-output</h2>
<span id="var-type">macro</span><br />
<pre id="var-usage">Usage: (with-tap-output & body)
</pre>
<pre id="var-docstr">Execute body with modified test reporting functions that produce
TAP output</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/clojure/blob/76e7c4317dc3eac80c4908ac5e5fb885e302b2a4/src/clj/clojure/test/tap.clj#L106">Source</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="foot">
<div id="copyright" style="text-align: center;">Copyright 2007-2022 by Rich Hickey</div>
</div>
</div>
<div id="DesignedBy">Logo & site design by <a href="http://www.tomhickey.com" title="Visit Tom Hickey's website.">Tom Hickey</a>.<br />
Clojure auto-documentation system by Tom Faulhaber.</div>
</div>
<!-- /AllContentContainer -->
</body>
</html>