forked from catchorg/Catch2
Compare commits
1864 Commits
v2.0.0-dev
...
add_cstdin
Author | SHA1 | Date | |
---|---|---|---|
181265e9a6 | |||
97c48e0c34 | |||
9c9f35068e | |||
1bd233866c | |||
f993b702c6 | |||
caf1264588 | |||
a6d59b62b2 | |||
cc0e91472a | |||
3bd0c58878 | |||
a63ad74554 | |||
5f9109a8dc | |||
5a1ef7e4a6 | |||
bea58bf8bb | |||
34d9724058 | |||
5d269045b2 | |||
95a1206805 | |||
6f9f1465c3 | |||
8730260457 | |||
bdfa920f93 | |||
a369267874 | |||
1f381a1f62 | |||
165647abbc | |||
7e4ec432d0 | |||
078201fcf4 | |||
8110ee9206 | |||
fa9416426a | |||
338e4ec1f8 | |||
372b7575f6 | |||
d32fca4a49 | |||
a0ece7b252 | |||
0a810c5e59 | |||
d0177ee686 | |||
173539ab9e | |||
8822e28772 | |||
ff9506cedd | |||
0c13d021da | |||
3644b4135d | |||
1c4f52b24a | |||
231c58a048 | |||
5efd327dd4 | |||
40dd9dd3f4 | |||
4142e699c2 | |||
9e445930cc | |||
2dc657cd1f | |||
cca5923502 | |||
8c952bd076 | |||
85c00eb946 | |||
3a18a688a0 | |||
605a34765a | |||
abb669d4fd | |||
dcafc605f3 | |||
7a2a6c632f | |||
359cd6187d | |||
9c72b303d9 | |||
6044f021cf | |||
5d7883b551 | |||
04a54b0e87 | |||
48f3226974 | |||
af8b54ecd5 | |||
07bec74096 | |||
316025a0d8 | |||
33aeb603fe | |||
fc3d11b1d1 | |||
1ef65d60f1 | |||
ed6b38b096 | |||
5a49285e9c | |||
ae475a3c19 | |||
d60fbe49be | |||
a733b58cd2 | |||
d9b0a38f81 | |||
40c8909a49 | |||
91ea25e51a | |||
e2d07d35f4 | |||
d2cb934d28 | |||
7752229105 | |||
722c197855 | |||
198808a24e | |||
198713e5dc | |||
b84067ea6f | |||
332de39cd4 | |||
c410e2596c | |||
4c1cf4aa67 | |||
745cc82cd3 | |||
07dfb4b070 | |||
5e86ead366 | |||
9dc229693d | |||
db57a4956f | |||
48177831ee | |||
ee3bbecf51 | |||
431dcf36ea | |||
e882cb8eb1 | |||
c2bc321607 | |||
ea9029c478 | |||
c65e5b6514 | |||
880285b433 | |||
07cdef2096 | |||
5baa29b6b9 | |||
291b35b389 | |||
f526ff0fc3 | |||
17a04f88d9 | |||
90e6905050 | |||
6bdc7e1a65 | |||
7b93a2014c | |||
98bb638fb2 | |||
05e85c5652 | |||
b520257676 | |||
574d042821 | |||
c742ea9ad9 | |||
a243cbae52 | |||
79d1e82381 | |||
4f09f1120b | |||
9934b7de13 | |||
7a89916198 | |||
61f803126d | |||
d698776ec5 | |||
f25236ff43 | |||
8cdaebe964 | |||
1a56ba851b | |||
9abe49ec53 | |||
195a6ac941 | |||
be948f1fd0 | |||
4e006a93ff | |||
73d8fb5bca | |||
0a33405983 | |||
cb551b4f6d | |||
4b78157981 | |||
46b3f7ee5f | |||
f9f4e58dfb | |||
d5bfce4d84 | |||
c43947eb47 | |||
423e1d2ebb | |||
3c06bcb374 | |||
a51fd07bd0 | |||
8ac86495de | |||
d750da13a8 | |||
c045733d05 | |||
9fea3d253f | |||
797c3e7318 | |||
6206db5a73 | |||
78e33ce51f | |||
1a8a793178 | |||
a4e4e82474 | |||
6227ca317e | |||
081a1e9aba | |||
4d8acafecb | |||
cf6dd937ab | |||
2ce64d1d8f | |||
7882f7359e | |||
0e176c318b | |||
c1c72c7e05 | |||
06092f727d | |||
4acc520f76 | |||
18c58667d7 | |||
634cdb4efe | |||
38879296a7 | |||
81f612c96c | |||
913f79a661 | |||
06f74a0f8e | |||
61d0f7a9af | |||
9b01c404f5 | |||
f206162b2d | |||
05d4ec62c8 | |||
4dd5e2eece | |||
f9facc1881 | |||
2ebc041903 | |||
529eec97bb | |||
ff5b311898 | |||
4a2eb90302 | |||
715cd25081 | |||
1d4b42ad7b | |||
72f0372664 | |||
4396a9119f | |||
bda4b7df84 | |||
0c722564c3 | |||
33ffc3b6fc | |||
fc5552d27b | |||
7cf2f88e50 | |||
a9ed2c235d | |||
a1e5934aa9 | |||
190f71792a | |||
c912f62fc4 | |||
aa3c7be434 | |||
b0279e0c14 | |||
9afb6ce138 | |||
efb54926ee | |||
7a2f9f4633 | |||
79e4cd1af4 | |||
635db2785f | |||
51888d360a | |||
f83332d89b | |||
b5dbdc858d | |||
e53a75b425 | |||
4ff8b27bb6 | |||
d861e73f86 | |||
dc86d51af2 | |||
5121660e7f | |||
ce556fd646 | |||
b6ff2c3dda | |||
875299cff0 | |||
39d3de17f3 | |||
fff494c10a | |||
103cb16696 | |||
244680d512 | |||
f4af9f6926 | |||
57c9c935ee | |||
98a6c69e1e | |||
d3199c42c2 | |||
eeee4a49af | |||
0d1bdea69f | |||
3ab981fa21 | |||
54e89e8364 | |||
88b28ab592 | |||
ef3374ed81 | |||
f2f585b478 | |||
b5547f2ef6 | |||
93882f7fab | |||
4752545a69 | |||
fae0be25b3 | |||
899554bff2 | |||
b4efa4751a | |||
22547a3c5f | |||
8baf9c05a3 | |||
ccd67b293d | |||
6b55f5d780 | |||
c9c3b74805 | |||
8711b63a0a | |||
72a09de236 | |||
f0a89b7345 | |||
f00b6e2019 | |||
45577a1f4c | |||
cbb6764fb1 | |||
156e6fdfa9 | |||
187bf6db2b | |||
cde26de803 | |||
3cc0c033e4 | |||
840acedf62 | |||
9f2dca5384 | |||
602e484f02 | |||
08939cc8bb | |||
3bfe900bbc | |||
d30d0c01a7 | |||
dcf9479c85 | |||
c49faa62dd | |||
c097609115 | |||
9d6fffb922 | |||
153965a655 | |||
0ac9f44985 | |||
b9baae6d93 | |||
c95072408f | |||
8cb8f0b08b | |||
9952f29f01 | |||
2db1cf3404 | |||
fabe614ba8 | |||
acdb85c398 | |||
726fdd7f8e | |||
0ccb1c30c6 | |||
dd12ce8141 | |||
d32e89eb84 | |||
ce6aca81ad | |||
61489e863e | |||
2287d225e5 | |||
4eb00afe69 | |||
e86f84b8ef | |||
d012735c6e | |||
67caef6f45 | |||
f41d761674 | |||
edc2f6e8a3 | |||
b2ac27423a | |||
a754cb9062 | |||
5f38cc39fa | |||
b892ab133c | |||
0c9fe16537 | |||
d02ea5adee | |||
9b4e69333f | |||
4d9bfb2951 | |||
c4df47c246 | |||
9200b4078b | |||
6603f1d972 | |||
62d8913d67 | |||
8780425385 | |||
7800fe9708 | |||
141e384c60 | |||
f1239b2045 | |||
912df7df35 | |||
931f41b4d6 | |||
70c4ec78fb | |||
455ae0c561 | |||
2520ad4b6e | |||
e539e1cb52 | |||
3c5c86a4e4 | |||
514206df36 | |||
becab0cf74 | |||
12d14a3c63 | |||
f17725a186 | |||
ec2d5013fb | |||
342ef5ca7e | |||
5ac1ffe9ee | |||
3087e19cc7 | |||
6456ee8b01 | |||
905bf438ae | |||
0fdee1c273 | |||
22750cde0e | |||
bf5c58adf6 | |||
06cf2a4724 | |||
4436a60456 | |||
36b4a71ff0 | |||
b406ad52a7 | |||
de67278e14 | |||
1d9696d22d | |||
ed1f343a41 | |||
200a487cf2 | |||
fce42b62ad | |||
4e6d306742 | |||
c6c46a168f | |||
48a889859b | |||
d65ee04b74 | |||
928e198ef2 | |||
3e9c6fec22 | |||
13670f535f | |||
c6640e4f47 | |||
23f0d94b4f | |||
77c7e9803e | |||
1d79683ea8 | |||
eb452e9b35 | |||
2deafc33e9 | |||
5250cf6d58 | |||
426954032f | |||
f02c2678a1 | |||
21b99d6f58 | |||
d42e7a23a0 | |||
7bb00a42be | |||
fb4153e05e | |||
e8e28ba401 | |||
ee1435793e | |||
3f8cae8025 | |||
2c82f82ee2 | |||
785436cd74 | |||
f314fa1f8c | |||
013edc208b | |||
10fb93cce8 | |||
4dcf8382c7 | |||
efd8cc8777 | |||
12bca890b7 | |||
317db82396 | |||
cf5ccaa9df | |||
b3a84c7983 | |||
c0f866c7cf | |||
29caae5ce5 | |||
ea49210eae | |||
e4719fb51c | |||
290c1b60e6 | |||
e5938007f7 | |||
ab3fe0053d | |||
432d03d1aa | |||
9ac9fb164e | |||
07018e2fba | |||
ff0a5227ca | |||
54edab53bf | |||
0a8516aeea | |||
928ecbaccf | |||
1cbbc5d2cb | |||
7f3297f7e8 | |||
7ff54ebc06 | |||
ca8546efc6 | |||
4113a12c69 | |||
edad4d0af7 | |||
88c27ffaf2 | |||
d2ee7100d2 | |||
03ce304102 | |||
7040f03b54 | |||
1554251f97 | |||
2b54f1e7a6 | |||
2c84854b90 | |||
3579c055c8 | |||
3ec63324a8 | |||
7d0770adf2 | |||
74db06199b | |||
52a3144145 | |||
a62974eb6a | |||
a0d84654dd | |||
557e5118f1 | |||
0a3f511cfe | |||
9ef510b769 | |||
1b1f3a88bc | |||
02ab64da2e | |||
77df08b44d | |||
79c2daa4a0 | |||
1e0dc61d16 | |||
02e5951f11 | |||
1ecc79bb56 | |||
73cae40a90 | |||
6c4c961207 | |||
340a61af50 | |||
3d1cf95b32 | |||
6f21a3609c | |||
bf61a418cb | |||
849002aec0 | |||
4eb9af51af | |||
78e4fbdb12 | |||
a7533707ff | |||
28a33497be | |||
70f5392210 | |||
61461dfd1d | |||
c064322a9d | |||
a14d67cace | |||
4ce8a23edd | |||
c1b59b7071 | |||
c77ba5314a | |||
65c9a1d31a | |||
fa31d58934 | |||
9ac8cad2d1 | |||
c71f42cc29 | |||
e6da4e10ae | |||
816f69416b | |||
aee31d0620 | |||
c9371865d4 | |||
5741de9ccd | |||
0e2895934c | |||
a01073d871 | |||
02839ba934 | |||
8d6a1c27ef | |||
41ad0fda11 | |||
d9f72868b2 | |||
c7241bb76e | |||
1d04427fcd | |||
aba114d6fe | |||
0221148ac3 | |||
9f091cbe9d | |||
4c1e896d47 | |||
2c04850f88 | |||
c9027375a3 | |||
2ae28fc852 | |||
f9ec34ce01 | |||
96790b1d23 | |||
86f86c4c23 | |||
023b5306b4 | |||
9137e591fa | |||
f50a06affa | |||
4cc247cc70 | |||
8ee422d6bf | |||
0c0f73a48d | |||
61e16416a9 | |||
074017f5ad | |||
0a89e7f0c4 | |||
28f6698ec8 | |||
b36f8daaad | |||
d86cb5f95d | |||
5eb7aa4f90 | |||
35cba5486d | |||
eb911aa995 | |||
313071e8fe | |||
f9bb2668e4 | |||
baf0cd0be4 | |||
c0d0a50bdb | |||
cbcab2dbcd | |||
ea44e73961 | |||
d61fe3ecc3 | |||
b325c6d81e | |||
d4a3cd9992 | |||
342dd3445c | |||
23760327ae | |||
48f220b68a | |||
031a57e7b7 | |||
cdf4748d1c | |||
520b6dace9 | |||
2cb5210caf | |||
2dc5a5f402 | |||
04166514fe | |||
e8cdfdca87 | |||
a5abec9cb5 | |||
f1d7a10e06 | |||
e50e10ef8f | |||
2c269eb633 | |||
4b5812e932 | |||
9f44bd57f1 | |||
6734c0aa64 | |||
037ddbc75c | |||
6d803cba5d | |||
551946c45b | |||
653764d53b | |||
3afea8128a | |||
749d953712 | |||
4b50b13970 | |||
1ee0940427 | |||
29050daec0 | |||
e5e9afad16 | |||
8b27041fbe | |||
c12170ff69 | |||
3eade52fc0 | |||
2dbe63a6ba | |||
477540760a | |||
b435e391c4 | |||
971b1fc32a | |||
6798c139a6 | |||
7111b2a8e2 | |||
5509ceff60 | |||
74f2f4ba5e | |||
ba81505168 | |||
f5b413aa58 | |||
4e8832fc88 | |||
bdd1e5c613 | |||
1d269211bd | |||
0acb371b92 | |||
045feff834 | |||
965afc4b2e | |||
77643ce2e5 | |||
552af8920d | |||
ce54ec185f | |||
c787b1edc9 | |||
a091853f4a | |||
be813faaa0 | |||
4b51d0dd3b | |||
6350851f9a | |||
21c97f2fad | |||
5b1a6ae00a | |||
b9fe8a208f | |||
c19b8ec5d7 | |||
230f23e6ee | |||
88504e5332 | |||
4da0c18526 | |||
1d746a15ac | |||
19cbdebb0e | |||
f30a9e3feb | |||
e7740316e3 | |||
72525a3053 | |||
1982c0d5ee | |||
0442229dc9 | |||
130bf835b5 | |||
c3e8ae642f | |||
3bd5fd6bc5 | |||
f36e059453 | |||
677adf8ade | |||
bfe5553416 | |||
c673db7a4e | |||
b10a19545b | |||
e5ccb79bf8 | |||
3610eb81b1 | |||
bd1e76cc3a | |||
166c520598 | |||
a29deeb129 | |||
1cef51b69b | |||
79c1bf9301 | |||
4f14922aa3 | |||
0fa133a0c5 | |||
447b39cae0 | |||
851a0e907e | |||
93312b369e | |||
d913837a5d | |||
a9941d4231 | |||
39e13bf530 | |||
fefa001bb6 | |||
135103bacf | |||
2baa472bcc | |||
f97436a1f7 | |||
dd5652933a | |||
3a15433d52 | |||
67a9561fb5 | |||
2f31f9037d | |||
33bcdc6bf5 | |||
74b397e6b8 | |||
730ec39a74 | |||
71328bae90 | |||
ed9ef85a34 | |||
e4474021ff | |||
79a5cd795c | |||
b8ae2878b4 | |||
dc3c22f9ec | |||
735f46ed6d | |||
39aabede62 | |||
d7ced69db2 | |||
f797ae7a8f | |||
40b9df567f | |||
c6352c3e1f | |||
4035beb988 | |||
8c3970465d | |||
f57689f888 | |||
967b82231c | |||
7b9bf633be | |||
4c8454b5ec | |||
8878f90323 | |||
0c7f96ba63 | |||
923bcc5d6f | |||
b6a3e2e26b | |||
6ffac61719 | |||
4b2bc8757c | |||
faffc29253 | |||
4ea18d6d17 | |||
c44d9cc718 | |||
b9853b4b35 | |||
853565bfb8 | |||
3f9e779542 | |||
863cc6a155 | |||
b601b7faca | |||
b841650253 | |||
1d01464730 | |||
c522e88afa | |||
b1df96e7e4 | |||
a4dfcf9042 | |||
9e172c707e | |||
b0214ff862 | |||
2454cfffb7 | |||
0098a76fef | |||
340ff00058 | |||
60dfec559f | |||
8b89a60bf6 | |||
99d70c0c9d | |||
d1625f30b1 | |||
8f44e09a72 | |||
31d4831245 | |||
08fb5cbab2 | |||
5ad1a4fe61 | |||
2c1c02f7e7 | |||
8851e779cf | |||
2d4f8ac8e6 | |||
9155a9ff20 | |||
cc18bd719d | |||
90aeffb97d | |||
c2453c2bf8 | |||
a822cb9717 | |||
c26693df23 | |||
33ad1ee2ac | |||
f9fdc96cbf | |||
360b82620e | |||
2a8e317cfb | |||
6a08d401aa | |||
9677df6d8b | |||
ed7eaf2df3 | |||
24559493bf | |||
7500ad1ffd | |||
1a97af45f1 | |||
2e480b6e56 | |||
f16be402f7 | |||
e418e75c74 | |||
6a46b344c0 | |||
e7eb749815 | |||
c1bb699d45 | |||
bf1e902ca1 | |||
49b55d53e4 | |||
07fb96d42c | |||
34d9a588bb | |||
05d7014e75 | |||
aa28a917cb | |||
b0531404e4 | |||
60cc4c293d | |||
6dc8345261 | |||
24b83edf8a | |||
b824d06844 | |||
e7aa432850 | |||
81aa2d5582 | |||
9d591f19ff | |||
a4ac07d104 | |||
8b0845b1a2 | |||
c5037743e6 | |||
9d6ac62aff | |||
ed0ea30149 | |||
35098a62d8 | |||
ba57c17310 | |||
4e0af77e29 | |||
eaf7113fd3 | |||
d090074da7 | |||
d218d6f9e2 | |||
ef92178058 | |||
125d4b4164 | |||
c9b4867441 | |||
258cac63f8 | |||
5f6990d746 | |||
5ca68829e1 | |||
ac54ba7e12 | |||
95c0c88d84 | |||
6efeecc179 | |||
6b3c563c38 | |||
a004423c7f | |||
4b344f11ea | |||
87d0197cbd | |||
4565b826cf | |||
250d9b9c72 | |||
90d6fd849e | |||
13917c44b4 | |||
e6d947f6d4 | |||
80b0d6975c | |||
36131f7ffa | |||
f52018205d | |||
b32d2fa016 | |||
a25c1a24af | |||
e28018c659 | |||
2a25a267ea | |||
7f58840163 | |||
3b0f8c7ff0 | |||
2840ce1e70 | |||
ed9be5a00b | |||
273111d1a6 | |||
a862924601 | |||
0e77adee05 | |||
b74996a29c | |||
de53773e46 | |||
314bb7e632 | |||
9221a6ff65 | |||
657ebf5db2 | |||
480f3f418b | |||
3ceaad7d66 | |||
5c502320e8 | |||
f3fe2dcb11 | |||
8b5f6e26d3 | |||
c24f7e5b34 | |||
7dae3efad2 | |||
a71721801e | |||
2cd5e70012 | |||
392e44ec21 | |||
317145514f | |||
f2b9508081 | |||
1d1ccf8f3c | |||
41bbaa6d57 | |||
66ab942903 | |||
d05a8e2e24 | |||
1356788ea8 | |||
21d284df34 | |||
668454b36b | |||
458241cc90 | |||
fa160cf3f2 | |||
a17b9f754a | |||
c2852c9944 | |||
4394d3ae65 | |||
4b2f1da02a | |||
0c6fda6e7d | |||
bad8b7c866 | |||
964303706a | |||
54882dbb11 | |||
b4a61cfd29 | |||
d86834e5b5 | |||
39e093021c | |||
e867ce7769 | |||
f7fbbac601 | |||
ddde2f5e33 | |||
d5e87eabbb | |||
29d4b3768c | |||
ae0ba81423 | |||
03ef6b9f9a | |||
579dcd1a76 | |||
eb267b424b | |||
2528247351 | |||
f56832d3ea | |||
601ca1c670 | |||
a39154e115 | |||
7c622a79d4 | |||
04cbbb8a4b | |||
f64487bf70 | |||
27f1756d8e | |||
824ffe6525 | |||
d5e08a4beb | |||
ed967fd7fc | |||
7030d7740d | |||
7efbc83ae0 | |||
9e498278be | |||
14533f5bb6 | |||
895d0a0696 | |||
094d840efe | |||
a595066ff9 | |||
cb25c4a8a3 | |||
b93cf932fb | |||
eef6c9b79b | |||
b5a287f09f | |||
e1a0cce82b | |||
75b711a360 | |||
db32550898 | |||
e78b4f6be7 | |||
9766a7b200 | |||
7c816c7c0b | |||
04c171f91f | |||
fe405034b8 | |||
2ccc48e108 | |||
6020f8f27c | |||
26622f1620 | |||
c086746cc9 | |||
0c223bb751 | |||
19ecad6f68 | |||
33c58dad41 | |||
68061bbed4 | |||
e83c9fb674 | |||
b8221c8350 | |||
31ff89709f | |||
5b8cccaf6a | |||
4aefbbcd02 | |||
53434a2f32 | |||
2a93a65bc2 | |||
dd35430a2b | |||
bbbc7a0d7f | |||
89fab65382 | |||
1bd7cac09f | |||
9b5fc9eaea | |||
630ba26278 | |||
26b2c3e7e2 | |||
87a8b61d5a | |||
ca27b0dcc5 | |||
87c8055176 | |||
46cc551b7a | |||
f34aacfe5f | |||
0d3e933d71 | |||
02a998598c | |||
8ea45bf50c | |||
beb8c3a99d | |||
656b15d37b | |||
5198fd3c9a | |||
08f8a81b2c | |||
0d8eeec557 | |||
d3c0b36487 | |||
95a2e54702 | |||
6badd7d9ed | |||
60cfaa38fb | |||
38a0dfca6d | |||
b014d988fe | |||
7a0f8ff4b8 | |||
efbfaa1704 | |||
c4e5b05cfc | |||
0fdeb10c65 | |||
783ab5ef87 | |||
8d50f04419 | |||
804e2df099 | |||
0470794a68 | |||
5150fa4476 | |||
d776a93a39 | |||
c078373f3f | |||
517839fb3f | |||
b955355ec4 | |||
c5ec936a72 | |||
8d44c2450c | |||
7c97554565 | |||
e1e6872c4c | |||
3836aa9ceb | |||
3f2ada03d5 | |||
7892954c99 | |||
54a7eb1aed | |||
151dccbd31 | |||
4d63c36402 | |||
a25d83d8c4 | |||
f7d7aa9eb2 | |||
ca5af2e85b | |||
904c47a634 | |||
afc8b28c07 | |||
a6baa6dda6 | |||
5c9367d4f1 | |||
ab0ca2f566 | |||
3a3efebd16 | |||
f52a58e857 | |||
007efc173a | |||
89e857349b | |||
c2daf468bb | |||
64d7f9b98a | |||
121f04ffcf | |||
0e7e6b210a | |||
a15ffb735d | |||
727b26ab35 | |||
9de6eae6bb | |||
d1ffaf55a1 | |||
33b47f7309 | |||
8d1e7ca896 | |||
e601a5dc4f | |||
e9caeb7d0b | |||
6e270958a2 | |||
50b2cfa5de | |||
34e7a5e0cf | |||
04f18d996b | |||
3bb9fcd916 | |||
c3013a6251 | |||
40e35d4318 | |||
b83a12b12c | |||
d33af93e17 | |||
25c5ae240c | |||
260263b9bf | |||
cf6575576f | |||
a1be19aa1b | |||
c745adb81c | |||
06c135706e | |||
ae1d21315c | |||
6a2c025bfc | |||
2441c2faab | |||
442283ee11 | |||
3f81dd753a | |||
f8794634c2 | |||
d6b2a3793b | |||
548de655fd | |||
89f18f15ca | |||
3c7e737a7b | |||
e880da93bd | |||
3e01d4b239 | |||
06c32862b3 | |||
ab520f4e97 | |||
32617f42d0 | |||
17c4b2d093 | |||
db1a0465dc | |||
b2a6523d85 | |||
b009d190bf | |||
ac83087bc2 | |||
123b449f8d | |||
6ad743a62b | |||
0f47fe16bd | |||
82baef62e2 | |||
0fbf4f3e15 | |||
ad3f50bbc1 | |||
13e01d273a | |||
2788897051 | |||
2945b80f61 | |||
63b7d6f98e | |||
c50ba09cde | |||
c165bd15c5 | |||
4f0de7bbad | |||
21b24e8326 | |||
0b2874b6b1 | |||
e6ea53ab49 | |||
338572a4f7 | |||
70836d49ba | |||
db148c42d7 | |||
cd7d7a1c67 | |||
86e19b952d | |||
bce5b364d3 | |||
34bc56340d | |||
c3a5e21648 | |||
bd9520c0f9 | |||
a3ffc20f57 | |||
b86ab20154 | |||
1327946785 | |||
a49ab0a162 | |||
3b297cf9b5 | |||
66fe591477 | |||
ea6db67063 | |||
a7b3e087a0 | |||
ddd0e7218d | |||
49e000b505 | |||
2e1ce37faa | |||
d0257fc1ff | |||
df2379218b | |||
7134ad9913 | |||
827733fe81 | |||
2f4a7dda68 | |||
6c3a5ef625 | |||
c770a9c8b5 | |||
d63681f707 | |||
2b696c4388 | |||
17281c09c3 | |||
26f78f96aa | |||
c381b49c60 | |||
acf975cab1 | |||
ec7280379e | |||
21868deeab | |||
4005d87460 | |||
0dc30e51c0 | |||
0c62a50392 | |||
68cf4ca883 | |||
9c07e2a416 | |||
a4c31ecd16 | |||
1cc05122d7 | |||
add7068f21 | |||
ebeeaaeec6 | |||
69bd213c40 | |||
5fbf04cd59 | |||
8b42acc328 | |||
29b441949c | |||
70ef2f7f12 | |||
248f922465 | |||
91ee07e08c | |||
6eb04667ad | |||
604ededf77 | |||
918aa327fa | |||
0fea081ad1 | |||
90e2549cec | |||
82cc5bc034 | |||
fef4f217b1 | |||
e341b11467 | |||
443fa0fc88 | |||
4385951a55 | |||
7c6de33977 | |||
e1a43b5b0f | |||
8e56b8b0ec | |||
6923a168a1 | |||
c9067b2253 | |||
d36c15c3ca | |||
302e2c0b06 | |||
019b0a0fe0 | |||
9ff2b81164 | |||
d6f7f1fbed | |||
6ddd84a67a | |||
09b66ccfde | |||
d1cb727e85 | |||
e6b9b854b5 | |||
478c324534 | |||
eabb8a6af7 | |||
ae10e4ef72 | |||
2c6ace04a7 | |||
7c48ea6016 | |||
ca4c6218d4 | |||
ac4958395c | |||
316a5c0572 | |||
c781301cd4 | |||
c46deee024 | |||
4f47d1c6c1 | |||
2bcf1b3db6 | |||
be44cfa63b | |||
85b129c741 | |||
0f39438aae | |||
c582e351ce | |||
d2cddfc9c5 | |||
557b336125 | |||
141761745a | |||
3136c4fb6a | |||
74e0e737a6 | |||
0685216175 | |||
fc320f6b8f | |||
5290d4bedc | |||
7ada02e21e | |||
849f2848bd | |||
2fbd66c51c | |||
51b29ced1a | |||
9a558171d8 | |||
c5c688820c | |||
6a08225863 | |||
4327baba40 | |||
50cc14c94c | |||
87b745da66 | |||
7d0b205564 | |||
8fb1219013 | |||
23c80bcc92 | |||
a2c8dce85c | |||
1e379de9d7 | |||
4eea438b73 | |||
407ee0af2f | |||
060a41ec7b | |||
90825a4f7a | |||
9e8ae7d470 | |||
84856844e1 | |||
01ef7076f5 | |||
ae14a47360 | |||
f2b23db6d1 | |||
1aa98c76ac | |||
3195c242c2 | |||
31906d83ec | |||
91fa55303b | |||
7c9f92bc1c | |||
a92a7d0229 | |||
e4d61e4cd8 | |||
9ba48e2c9b | |||
2cc0c71856 | |||
28663fb959 | |||
d2d418a9cb | |||
c8db4e77c4 | |||
1c5749669e | |||
3109add95c | |||
adb4789136 | |||
75200e199e | |||
a5a22cdadb | |||
535da5c513 | |||
2331249a8d | |||
319cb9e1da | |||
b8b765d55e | |||
a0ebd63806 | |||
4bd2c3ad6a | |||
c38a5caa2e | |||
ebc5609484 | |||
fcda35f645 | |||
02ee130bd0 | |||
815f99541d | |||
da0062f7c1 | |||
de42f8a93e | |||
af84f1350e | |||
fc2066bf18 | |||
2bcff9dd35 | |||
3beccfb429 | |||
af8b2538a6 | |||
a156440b19 | |||
dab0296b64 | |||
9f4c4777a5 | |||
293012a002 | |||
e2b3443fe7 | |||
7b865daccc | |||
14362533bb | |||
a5bb3e3d91 | |||
923db16322 | |||
fbbaadb704 | |||
dd1f0f1c72 | |||
d27d580d0b | |||
6da00c1b64 | |||
fe967b1f41 | |||
f2c2711bdc | |||
b77ab74b72 | |||
4038ee6bc6 | |||
789f3591ef | |||
6e8d769775 | |||
1189a73be2 | |||
071bacad5e | |||
addf799040 | |||
155274f0df | |||
18d597cf10 | |||
6629c11ef8 | |||
c6bf56b3d5 | |||
623e348d9e | |||
46f767e602 | |||
ce42deb72f | |||
46a70071a7 | |||
378cc1a670 | |||
e2d863b090 | |||
ebe6a07c23 | |||
edcfd7fc62 | |||
738818ae1d | |||
2c869e17e4 | |||
0ab11aa9b4 | |||
7a6af7ba76 | |||
fa096b26d1 | |||
820b1f12bf | |||
6070745cab | |||
3d9e7db2e0 | |||
cf55cfd76f | |||
3701c2e2e6 | |||
7dc7d77af2 | |||
06bc20cf37 | |||
7a4beed6a6 | |||
67b4ada6b0 | |||
119569a67e | |||
ab713894cc | |||
69fc94d6f8 | |||
49cd7c96b4 | |||
e998d152cc | |||
42a5903188 | |||
c071f07e1a | |||
53776a90cf | |||
4511dc0c16 | |||
e7c3bdb351 | |||
9aab958667 | |||
8cd58f75ec | |||
d5a69cd400 | |||
1d13d88833 | |||
de0674c116 | |||
3d7282c2bd | |||
e5c0e3322d | |||
dc8c8e957f | |||
ba9193370b | |||
7b70b11c23 | |||
ab80277a86 | |||
7e7ab0e28b | |||
425957dc63 | |||
d017f6d18f | |||
91244d30a7 | |||
62b3f6c3c2 | |||
e7c26f09d1 | |||
a22b7df46c | |||
032068b889 | |||
2aed6233cf | |||
fb74bb133c | |||
0b42ada60d | |||
c424ca47f9 | |||
52f3abadbb | |||
53281b471f | |||
03ffc1014c | |||
87739ad3fe | |||
0c27554af5 | |||
11488e63b6 | |||
820271bf24 | |||
56d4510138 | |||
c0d3a2e08f | |||
2c3018a9d5 | |||
9a6551b22b | |||
800f1b1d3d | |||
9cf5897a11 | |||
6f32c67ea7 | |||
7eea3ab245 | |||
80af9ca687 | |||
33286fdc37 | |||
2f631bb808 | |||
25cc09dcec | |||
f9dce28e7d | |||
b87caafd91 | |||
bbbd5c4e08 | |||
f41051f22a | |||
e90d5a86e4 | |||
dbc1295354 | |||
f2cfc2b852 | |||
c365ac392b | |||
e640c3837a | |||
b468d7cbff | |||
7142d5a8c9 | |||
1967feac49 | |||
f0b7b0ca11 | |||
4b1252547c | |||
10067a47da | |||
e340ab8db6 | |||
ce2560ca95 | |||
00347f1e79 | |||
a5a2d08fbb | |||
97602b248b | |||
e28e162795 | |||
90378f4a59 | |||
84f8e806b8 | |||
732e4b06db | |||
0c43f98fa2 | |||
bd703dd74b | |||
99602787cd | |||
bfb4ee1597 | |||
31537c43d9 | |||
96355da34e | |||
71fce429af | |||
d13e094598 | |||
d30f1dda02 | |||
3bce8ba14b | |||
e680c4b9fb | |||
f1e14a1168 | |||
92ad9ee355 | |||
e2862a8d71 | |||
1161011dd0 | |||
53a83e855e | |||
9c741fe960 | |||
979bbf03bb | |||
33ce3f3953 | |||
87a9424c9d | |||
00cb0035c9 | |||
6267b06089 | |||
9837c35df1 | |||
46066ede17 | |||
6981783178 | |||
08c8df1e3b | |||
daeb5a87e6 | |||
f2ee4f17ad | |||
182fc3e46e | |||
6b5b72651d | |||
f45bb00351 | |||
7c37501b07 | |||
4a1ca1ab55 | |||
e02d9e788f | |||
541f1ed1b3 | |||
346723c9b6 | |||
5a74fcc9c9 | |||
9d5d719868 | |||
91b617c462 | |||
45e552528d | |||
3978e9653b | |||
d6fce7bf34 | |||
c3c82f539c | |||
c7653811a6 | |||
79417b9afc | |||
11cdd72db9 | |||
0c39409da7 | |||
edfac75347 | |||
ac94bd0520 | |||
d4eec016a9 | |||
36fb856163 | |||
4e32e0a563 | |||
1e2270b370 | |||
5096e39297 | |||
15ccced6da | |||
682617b5b7 | |||
15150c7b46 | |||
5ce355a38c | |||
edde6f4736 | |||
6bc5d172ee | |||
3079b514d4 | |||
e99f1efd28 | |||
b9dd1936e5 | |||
293d617c49 | |||
7be35af167 | |||
02f13cf95a | |||
43428c6093 | |||
08147a23f9 | |||
8af8704089 | |||
3816e99d0c | |||
b77cec05c0 | |||
54089c4c8c | |||
296d447452 | |||
0531965349 | |||
a1cdff4f18 | |||
4611125801 | |||
e509012e64 | |||
448825db03 | |||
0fff8e7791 | |||
68a3c129ac | |||
1ce5ec9b74 | |||
37a4e32319 | |||
0424c9a62c | |||
d633072794 | |||
51ed08be22 | |||
1701325caa | |||
7aee973a4a | |||
99575b45db | |||
1a03918455 | |||
bd667f4d69 | |||
28db5ed4c9 | |||
7d2451f119 | |||
5bf6e47381 | |||
29b3b7ae6b | |||
ef5fd8d42f | |||
693647c43f | |||
288387fa10 | |||
165de9b072 | |||
bf4771a7ed | |||
7012a31a39 | |||
269303d9d9 | |||
e8bfd882e8 | |||
2bd0722470 | |||
45ebf17ec7 | |||
093b72416d | |||
c99a346490 | |||
359a54b6bd | |||
711d750ca7 | |||
95f7712808 | |||
dbbab8727c | |||
5d4061af12 | |||
9ccea82d7f | |||
dd3d27de57 | |||
7f229b4ff1 | |||
c03b23c84b | |||
17686ba571 | |||
d75e9b3c0f | |||
67308bb606 | |||
16dc219704 | |||
63d1a96908 | |||
061f1f836a | |||
5929d9530c | |||
e46a70f829 | |||
64a9c02315 | |||
61f4c7ab85 | |||
50fefd059a | |||
a2baabbf71 | |||
6f9cdd6583 | |||
d9e99dc2ca | |||
804a2118c2 | |||
aa1e470058 | |||
8d5d54e529 | |||
73d533ff5c | |||
899c5ed3df | |||
084b1d5fe6 | |||
4109870435 | |||
2988e9f6cf | |||
bc02ada4b0 | |||
61e1ea9185 | |||
b275ead8c3 | |||
b0381e42b2 | |||
8989c9b560 | |||
d084162b2f | |||
0387fb64ce | |||
75200b462c | |||
17e09be3b9 | |||
1c99b0ff81 | |||
64a0f466ec | |||
47602ac556 | |||
d1e7344f16 | |||
3ed5441067 | |||
bdee512057 | |||
188b3e6511 | |||
bbf70ca74b | |||
23f023f9ed | |||
c1720d0c42 | |||
d54c2258e0 | |||
b3faceede2 | |||
e7fce90b49 | |||
799c7a2eed | |||
9bc15939a5 | |||
461843b1f0 | |||
5b4ffd3c93 | |||
21a1cd5683 | |||
4902cd7215 | |||
18ff34788c | |||
d0de666362 | |||
6ccd467094 | |||
34dcd2c436 | |||
16656c4c9e | |||
862955d657 | |||
df019cc113 | |||
695e6eafc5 | |||
59087f74d9 | |||
557e47c3ca | |||
62460fafe6 | |||
ac0a83a35d | |||
77f29c2f1c | |||
c6a89f14c2 | |||
a9d5b7193d | |||
396e0951c8 | |||
68860ff129 | |||
99b37a4c62 | |||
1dccd26de7 | |||
3f3238edf0 | |||
450dd0562b | |||
00d4f5d3c6 | |||
2d906a92cb | |||
489a41012e | |||
eccbffec0f | |||
c51f2edfb1 | |||
de6bfb5c25 | |||
87950d9cfa | |||
d0eb9dfb9b | |||
03d122a35c | |||
1d9b506e39 | |||
779e83bc20 | |||
544c7d7cbf | |||
8b3c09c137 | |||
b7f41237b1 | |||
1faccd601d | |||
ab98afe68b | |||
054d356332 | |||
0144ae9ad2 | |||
e1307016f0 | |||
6b9ca0888a | |||
9f8b848fe5 | |||
aaaac35d92 | |||
6cede0101a | |||
f1faaa9c10 | |||
9e1bdca466 | |||
be49a539e4 | |||
558bbe7d24 | |||
f4881f172a | |||
de06340e7d | |||
4dd6e81d0f | |||
9e6d7bbf00 | |||
dfb025cf08 | |||
c638c57209 | |||
a575536abe | |||
1eb42eed97 | |||
46e99e258f | |||
a212fb440b | |||
1e98c820bb | |||
bcfa9b1775 | |||
a3876adba6 | |||
2a4725b40e | |||
a81c01d4f9 | |||
60b05b2041 | |||
232ea3c456 | |||
a5c900d077 | |||
8b01883854 | |||
86da2846af | |||
ef9150fe6f | |||
84fa76e985 | |||
fcd91c7d6b | |||
efbf50fc7d | |||
64fd5b8058 | |||
ee73989f9b | |||
646e1f608d | |||
6f75acbfb5 | |||
9c3cc4a076 | |||
f3972f0695 | |||
38e1731f69 | |||
0947752a44 | |||
0646e0283c | |||
90663b2e75 | |||
7667a7d89c | |||
9773d89ab4 | |||
2067c8d3bd | |||
1742ab76a2 | |||
898d111f72 | |||
5202993555 | |||
f061dabbad | |||
1a501fcb48 | |||
94121a5f6d | |||
92e25049cf | |||
fdcd46420e | |||
7c25dae9ea | |||
7f18282d17 | |||
1cdaa48a0b | |||
1a63fad8d6 | |||
d6f2fd486c | |||
5884ec1e28 | |||
eb783fc20e | |||
38248f3f2c | |||
c9de7dd12d | |||
52cbb507ab | |||
83bfae1a50 | |||
f7f592dfc9 | |||
78804ea304 | |||
b93284716e | |||
15cf3caace | |||
12a8dfa2f2 | |||
797d3b04df | |||
82b8744b8c | |||
ce80358306 | |||
283e2e6d41 | |||
d6c7392b24 | |||
9ee4c1db52 | |||
5347ff9e5f | |||
76790604f5 | |||
e21c6aa94d | |||
7a59d5027f | |||
c8941cccb5 | |||
5eeb6aa361 | |||
1c1b447ede | |||
e1d81174db | |||
4846ad59e1 | |||
ff2b3c85a7 | |||
b55424d3b2 | |||
e69c7ce297 | |||
7be8ba36c1 | |||
ad120965cf | |||
f460a7d8f9 | |||
ebf89000f1 | |||
7d00cb83f1 | |||
e69afb6252 | |||
9fb38fcc14 | |||
0f49a600b0 | |||
5c0efa1cfc | |||
1579744ddd | |||
9b0e740e31 | |||
1af60ef5ab | |||
3743295ca8 | |||
ed582bde4d | |||
6c1145d922 | |||
b957eb4172 | |||
0eb99fb569 | |||
bf221583b1 | |||
44722f9ed3 | |||
35a57b070f | |||
1dce91d78e | |||
b8553d62a3 | |||
504607701b | |||
788f81230f | |||
c5301bf8bf | |||
d2a130f243 | |||
7be8a41adf | |||
021fcee636 | |||
3a47b8b072 | |||
2771a8ee9a | |||
7abd7db2c8 | |||
88d7b8da25 | |||
df0b0e64e1 | |||
4c7b7d04fe | |||
90988f578c | |||
e5fe3e877a | |||
6c5c4c43a0 | |||
c323658483 | |||
db570b7e24 | |||
0074926e5c | |||
6496c51c95 | |||
3dd523bdf5 | |||
8d5d49299b | |||
d0287e3b56 | |||
dd99a66cf4 | |||
ae590fe216 | |||
7f791fa08f | |||
0510d4755f | |||
e92b9c07c3 | |||
88a6ff0b65 | |||
9e7c281e6e | |||
64be2ad96c | |||
c651f239f0 | |||
43769a19f7 | |||
200d3ad824 | |||
aa7b0c9104 | |||
375f2052bd | |||
dc6b83bec9 | |||
f00257e374 | |||
414dcae34a | |||
d2d8455b57 | |||
ab30621138 | |||
1ca8f43b01 | |||
dfb83f20e9 | |||
319bddd5b8 | |||
931441251e | |||
ea1f326261 | |||
3641706923 | |||
3b801c4fda | |||
e11508b48a | |||
886d799b79 | |||
8b78087412 | |||
6c99b04c87 | |||
0a34cc201e | |||
11c89a5f7d | |||
dc3e7f9cf7 | |||
d14b7563c2 | |||
a3d3a633b2 | |||
8d4796309f | |||
552589f25b | |||
95c849f613 | |||
352853ed7e | |||
b11175548a | |||
d38f782995 | |||
dc8a8e6371 | |||
9d1858b195 | |||
1d1f8dc992 | |||
1466686ade | |||
93db01c647 | |||
2e285b9579 | |||
d2ddb997a7 | |||
865d5f59b4 | |||
05cd05743a | |||
950ccf4749 | |||
cf4b7eead9 | |||
7b6e49d795 | |||
0c5df42c28 | |||
4e57661919 | |||
5a8f9c84dd | |||
f988b4eb35 | |||
c8d765a575 | |||
da783abee9 | |||
c0267e5c20 | |||
bb84f0788a | |||
e84768fff1 | |||
31673ee0ca | |||
34d7a33574 | |||
082c3b84bc | |||
ef2e112561 | |||
a90305f857 | |||
543c9d3a67 | |||
ca8470fbad | |||
355b3f9952 | |||
7cbd0b587a | |||
2f15ccd4d3 | |||
8f3fc15b73 | |||
e13d9cab02 | |||
414e2fa946 | |||
b5ef68b044 | |||
681f5daa13 | |||
3b6fda3c1b | |||
1b2fa601c6 | |||
39bfc6e82b | |||
ba6d33fb8c | |||
4be81d3588 | |||
5201e92564 | |||
5e484862f2 | |||
5713381d06 | |||
1ab6be30a2 | |||
126850e76b | |||
5e8df1c384 | |||
44dbda9f01 | |||
ca2455e6e6 | |||
42213d4c31 | |||
62dae592c3 | |||
9a5705411a | |||
a1aefce6e4 | |||
d5959907f5 | |||
31e6499e64 | |||
b0f4f16ee0 | |||
1e3ddbb496 | |||
15ad95c8db | |||
00a10d5a5e | |||
0d687a15d3 | |||
bdf431c400 | |||
a0359980f0 | |||
8d4074aad9 | |||
f0f40a0dbf | |||
fa4fd7f296 | |||
07c84adfba | |||
8d854c689b | |||
f0909dfe02 | |||
de36b2ada6 | |||
9700ee4fc0 | |||
bbda8cd77c | |||
4575594bbf | |||
c053dca26e | |||
3d7104c124 | |||
6441c20a2c | |||
5774c4f9c2 | |||
2bc33dd04d | |||
cd76f5730c | |||
f5910f38ef | |||
421ab16062 | |||
161dd4ed24 | |||
13ea4225e7 | |||
2c43620d9b | |||
8be1df243e | |||
32eb90b9bd | |||
702cfdaf6e | |||
e41e8e8384 | |||
af3f2499bc | |||
c3a1143d23 | |||
f580591bf8 | |||
fc88313d45 | |||
3979845d5f | |||
88d2bac624 | |||
ed33e9787e | |||
f466d9a1ed | |||
a7a9ee5552 | |||
0cf05d54a6 | |||
11887fbbab | |||
347be87126 | |||
4da655c1b0 | |||
c4d1aa9033 | |||
495d2458e0 | |||
3035120dc7 | |||
584e04d480 | |||
673dcc16a9 | |||
0c122c135d | |||
d19b7292b3 | |||
5e063616df | |||
aa9d635014 | |||
7c5a21fb7d | |||
533cdc6bc1 | |||
51e281a684 | |||
24851dff99 | |||
a4fd96fbaa | |||
12c57cedda | |||
45a465713e | |||
dfa817ae73 | |||
57c346a46d | |||
67f734c799 | |||
b76e80ed3d | |||
a3632facf3 | |||
7d0db6b8e9 | |||
8a7493cd88 | |||
b5a5d9a6f8 | |||
8c32d0b644 | |||
28d1955ea8 | |||
20211a33e6 | |||
e3941a9ad2 | |||
da86ddc620 | |||
4b614ee1d1 | |||
5461242ffe | |||
e344984a1b | |||
db44964e27 | |||
2800adba25 | |||
ae1547e202 | |||
73a1623eaf | |||
c411c131cb | |||
091595780e | |||
f417995afc | |||
9329d97a43 | |||
8141a7836f | |||
5323202652 | |||
f052762c11 | |||
401ad7a189 | |||
63c097a077 | |||
87c125ecb8 | |||
3b965aa501 | |||
e54dcdac8b | |||
e4a898eaaa | |||
c39109dce3 | |||
a8a1c379c0 | |||
e08a4ed99e | |||
fcba30569c | |||
4353614df7 | |||
f36817ef83 | |||
812bf21740 | |||
baf3d2f360 | |||
b083b04126 | |||
505d2f8977 | |||
f18366150e | |||
fe725648a7 | |||
b0c379f621 | |||
c443afcca0 | |||
502da4b38d | |||
8da845810d | |||
61e838edf2 | |||
516dbc83bc | |||
b9339333df | |||
61e29b5630 | |||
54fb6f2d23 | |||
a077ebae4c | |||
2bbba4f544 | |||
29cdd6c526 | |||
dfb7217613 | |||
f6ae45122b | |||
d5d2bee4c5 | |||
85de0727d4 | |||
4ecb2e112e | |||
97a8640cbf | |||
033e078320 | |||
9796a77a37 | |||
98d4c49d1c | |||
a096e4b3f2 | |||
4b3730de8a | |||
6acdacfde0 | |||
a3cba7a0d5 | |||
9796846ad0 | |||
74d3dfd4cc | |||
e34754e433 | |||
55b71bebf1 | |||
b0857e846f | |||
a06b6dc3ea | |||
0adb04807a | |||
f80f28e09a | |||
484eee973c | |||
d09fe4459d | |||
e484236825 | |||
e7c23b73da | |||
3537b7858f | |||
b74d4ca96d | |||
8dbaac61ff | |||
a0dbc62955 | |||
cecee3459a | |||
030321e3e0 | |||
5f961af70e | |||
0b1f1b1003 | |||
24e6d5fa33 | |||
13370bddf2 | |||
36f02d76d6 | |||
07ac9b92e4 | |||
0d3fc59f6d | |||
56e1075613 | |||
868e125d49 | |||
c9cdb9a48f | |||
5fd1d7174c | |||
3a4c765030 | |||
a20b286999 | |||
e28763ad05 | |||
b2dd48f0c0 | |||
7a562d39b2 | |||
fa9c4207f1 | |||
4f9123dc20 | |||
19ab2117c5 | |||
4acf112c19 | |||
53f6d3fc8e | |||
cf76a795cc | |||
811f4d13d7 | |||
7423a481eb | |||
46c7c9d3a0 | |||
b119ebdde1 | |||
1c43fb64c1 | |||
8b40c26434 | |||
fe05062f9e | |||
31cc62e6b7 | |||
a49e6fdc27 | |||
2d91035404 | |||
accf9859b4 | |||
22ac9d2184 | |||
00af677577 | |||
ae21020640 | |||
11f716f28d | |||
c3ddd4a7e2 | |||
c43ce85416 | |||
4220f2eef2 | |||
c1a91caf00 | |||
96c5de678d | |||
e68485e196 | |||
88e912b4d1 | |||
44244713f1 | |||
eea9e1efd7 | |||
2a3606f8e3 | |||
a6cf19abff | |||
601b2888ec | |||
3049445d78 | |||
c672512979 | |||
57b4e0b64c | |||
06586b7180 | |||
93b3d2cb8f | |||
a90473df28 | |||
75a77b6f8c | |||
5af918eefd | |||
c9d9699ca8 | |||
296955c437 | |||
664cbf702c | |||
fb6700df54 | |||
05b1ca2884 | |||
da6c2a6914 | |||
c2b7bd15c0 | |||
ba6845a865 | |||
2eb93f47f7 | |||
276393e4e5 | |||
c7d9f02d5b | |||
9c07718b5f | |||
5ca44b6872 | |||
a04bd6d436 | |||
784f6dfb34 | |||
7818e2666d | |||
cd30dd1a70 | |||
8e8c0c1675 | |||
b6e7c9bd7a | |||
180d9242f5 | |||
b7bd52cc98 | |||
b07a2bdf87 | |||
c03e8fce92 | |||
27640a5a96 | |||
dd3867bbcd | |||
387f8d254d | |||
c65eccd68e | |||
61c5675c11 | |||
70e4af9d44 | |||
8f41bdb92d | |||
7fa5d9ca94 | |||
feaf355489 | |||
2ce6c74f8f | |||
9688891868 | |||
4f21bb72ff | |||
b435e0d7c7 | |||
ba0a09fd9e |
4
.bazelrc
Normal file
4
.bazelrc
Normal file
@ -0,0 +1,4 @@
|
||||
build:gcc9 --cxxopt=-std=c++2a
|
||||
build:clang13 --cxxopt=-std=c++17
|
||||
build:vs2019 --cxxopt=/std:c++17
|
||||
build:vs2022 --cxxopt=/std:c++17
|
25
.clang-format
Normal file
25
.clang-format
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
AccessModifierOffset: '-4'
|
||||
AlignEscapedNewlines: Left
|
||||
AllowAllConstructorInitializersOnNextLine: 'true'
|
||||
BinPackArguments: 'false'
|
||||
BinPackParameters: 'false'
|
||||
BreakConstructorInitializers: AfterColon
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
DerivePointerAlignment: 'false'
|
||||
FixNamespaceComments: 'true'
|
||||
IncludeBlocks: Regroup
|
||||
IndentCaseLabels: 'false'
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: '4'
|
||||
Language: Cpp
|
||||
NamespaceIndentation: All
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeCtorInitializerColon: 'false'
|
||||
SpaceInEmptyParentheses: 'false'
|
||||
SpacesInParentheses: 'true'
|
||||
Standard: Cpp11
|
||||
TabWidth: '4'
|
||||
UseTab: Never
|
||||
|
||||
...
|
94
.conan/build.py
Normal file
94
.conan/build.py
Normal file
@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import re
|
||||
from cpt.packager import ConanMultiPackager
|
||||
from cpt.ci_manager import CIManager
|
||||
from cpt.printer import Printer
|
||||
|
||||
|
||||
class BuilderSettings(object):
|
||||
@property
|
||||
def username(self):
|
||||
""" Set catchorg as package's owner
|
||||
"""
|
||||
return os.getenv("CONAN_USERNAME", "catchorg")
|
||||
|
||||
@property
|
||||
def login_username(self):
|
||||
""" Set Bintray login username
|
||||
"""
|
||||
return os.getenv("CONAN_LOGIN_USERNAME", "horenmar")
|
||||
|
||||
@property
|
||||
def upload(self):
|
||||
""" Set Catch2 repository to be used on upload.
|
||||
The upload server address could be customized by env var
|
||||
CONAN_UPLOAD. If not defined, the method will check the branch name.
|
||||
Only devel or CONAN_STABLE_BRANCH_PATTERN will be accepted.
|
||||
The devel branch will be pushed to testing channel, because it does
|
||||
not match the stable pattern. Otherwise it will upload to stable
|
||||
channel.
|
||||
"""
|
||||
return os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/catchorg/catch2")
|
||||
|
||||
@property
|
||||
def upload_only_when_stable(self):
|
||||
""" Force to upload when running over tag branch
|
||||
"""
|
||||
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "True").lower() in ["true", "1", "yes"]
|
||||
|
||||
@property
|
||||
def stable_branch_pattern(self):
|
||||
""" Only upload the package the branch name is like a tag
|
||||
"""
|
||||
return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+")
|
||||
|
||||
@property
|
||||
def reference(self):
|
||||
""" Read project version from branch create Conan reference
|
||||
"""
|
||||
return os.getenv("CONAN_REFERENCE", "catch2/{}".format(self._version))
|
||||
|
||||
@property
|
||||
def channel(self):
|
||||
""" Default Conan package channel when not stable
|
||||
"""
|
||||
return os.getenv("CONAN_CHANNEL", "testing")
|
||||
|
||||
@property
|
||||
def _version(self):
|
||||
""" Get version name from cmake file
|
||||
"""
|
||||
pattern = re.compile(r"project\(Catch2 LANGUAGES CXX VERSION (\d+\.\d+\.\d+)\)")
|
||||
version = "latest"
|
||||
with open("CMakeLists.txt") as file:
|
||||
for line in file:
|
||||
result = pattern.search(line)
|
||||
if result:
|
||||
version = result.group(1)
|
||||
return version
|
||||
|
||||
@property
|
||||
def _branch(self):
|
||||
""" Get branch name from CI manager
|
||||
"""
|
||||
printer = Printer(None)
|
||||
ci_manager = CIManager(printer)
|
||||
return ci_manager.get_branch()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
settings = BuilderSettings()
|
||||
builder = ConanMultiPackager(
|
||||
reference=settings.reference,
|
||||
channel=settings.channel,
|
||||
upload=settings.upload,
|
||||
upload_only_when_stable=False,
|
||||
stable_branch_pattern=settings.stable_branch_pattern,
|
||||
login_username=settings.login_username,
|
||||
username=settings.username,
|
||||
test_folder=os.path.join(".conan", "test_package"))
|
||||
builder.add()
|
||||
builder.run()
|
12
.conan/test_package/CMakeLists.txt
Normal file
12
.conan/test_package/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.2.0)
|
||||
project(test_package CXX)
|
||||
|
||||
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
|
||||
conan_basic_setup()
|
||||
|
||||
find_package(Catch2 REQUIRED CONFIG)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} Catch2::Catch2WithMain)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
|
20
.conan/test_package/conanfile.py
Normal file
20
.conan/test_package/conanfile.py
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from conans import ConanFile, CMake
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "cmake_find_package_multi", "cmake"
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
assert os.path.isfile(os.path.join(
|
||||
self.deps_cpp_info["catch2"].rootpath, "licenses", "LICENSE.txt"))
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
self.run("%s -s" % bin_path, run_environment=True)
|
13
.conan/test_package/test_package.cpp
Normal file
13
.conan/test_package/test_package.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
int Factorial( int number ) {
|
||||
return number <= 1 ? 1 : Factorial( number - 1 ) * number;
|
||||
}
|
||||
|
||||
TEST_CASE( "Factorial Tests", "[single-file]" ) {
|
||||
REQUIRE( Factorial(0) == 1 );
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
13
.gitattributes
vendored
13
.gitattributes
vendored
@ -8,4 +8,15 @@
|
||||
*.hpp text
|
||||
|
||||
# Windows specific files should retain windows line-endings
|
||||
*.sln text eol=crlf
|
||||
*.sln text eol=crlf
|
||||
|
||||
# Keep executable scripts with LFs so they can be run after being
|
||||
# checked out on Windows
|
||||
*.py text eol=lf
|
||||
|
||||
|
||||
# Keep the single include header with LFs to make sure it is uploaded,
|
||||
# hashed etc with LF
|
||||
single_include/**/*.hpp eol=lf
|
||||
# Also keep the LICENCE file with LFs for the same reason
|
||||
LICENCE.txt eol=lf
|
||||
|
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
github: "horenmar"
|
||||
custom: "https://www.paypal.me/horenmar"
|
29
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
29
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create an issue that documents a bug
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Reproduction steps**
|
||||
Steps to reproduce the bug.
|
||||
<!-- Usually this means a small and self-contained piece of code that uses Catch and specifying compiler flags if relevant. -->
|
||||
|
||||
|
||||
**Platform information:**
|
||||
<!-- Fill in any extra information that might be important for your issue. -->
|
||||
- OS: **Windows NT**
|
||||
- Compiler+version: **GCC v2.9.5**
|
||||
- Catch version: **v1.2.3**
|
||||
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
14
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Create an issue that requests a feature or other improvement
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Description**
|
||||
Describe the feature/change you request and why do you want it.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
29
.github/issue_template.md
vendored
29
.github/issue_template.md
vendored
@ -1,29 +0,0 @@
|
||||
## Description
|
||||
<!--
|
||||
If your issue is a bugreport, this means describing what you did,
|
||||
what did you want to happen and what actually did happen.
|
||||
|
||||
If your issue is a feature request, describe the feature and why do you
|
||||
want it.
|
||||
-->
|
||||
|
||||
|
||||
### Steps to reproduce
|
||||
<!--
|
||||
This is only relevant for bug reports, but if you do have one,
|
||||
please provide a minimal set of steps to reproduce the problem.
|
||||
|
||||
Usually this means providing a small and self-contained code using Catch
|
||||
and specifying compiler flags/tools used if relevant.
|
||||
-->
|
||||
|
||||
|
||||
### Extra information
|
||||
<!--
|
||||
Fill in any extra information that might be important for your issue.
|
||||
|
||||
If your issue is a bugreport, definitely fill out at least the following.
|
||||
-->
|
||||
* Catch version: **v42.42.42**
|
||||
* Operating System: **Joe's discount operating system**
|
||||
* Compiler+version: **Hidden Dragon v1.2.3**
|
2
.github/pull_request_template.md
vendored
2
.github/pull_request_template.md
vendored
@ -12,7 +12,7 @@ at docs/contributing.md. It will tell you how to properly test your changes.
|
||||
<!--
|
||||
Describe the what and the why of your pull request. Remember that these two
|
||||
are usually a bit different. As an example, if you have made various changes
|
||||
to decrease the number of new strings allocated, thats what. The why probably
|
||||
to decrease the number of new strings allocated, that's what. The why probably
|
||||
was that you have a large set of tests and found that this speeds them up.
|
||||
-->
|
||||
|
||||
|
103
.github/workflows/linux-other-builds.yml
vendored
Normal file
103
.github/workflows/linux-other-builds.yml
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
# The builds in this file are more complex (e.g. they need custom CMake
|
||||
# configuration) and thus are unsuitable to the simple build matrix
|
||||
# approach used in simple-builds
|
||||
name: Linux builds (complex)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.build_description}}, ${{matrix.cxx}}, C++${{matrix.std}} ${{matrix.build_type}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
# We add builds one by one in this case, because there are no
|
||||
# dimensions that are shared across the builds
|
||||
include:
|
||||
|
||||
# Single surrogate header build
|
||||
- cxx: clang++-10
|
||||
build_description: Surrogates build
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_BUILD_SURROGATES=ON
|
||||
|
||||
# Extras and examples with gcc-7
|
||||
- cxx: g++-7
|
||||
build_description: Extras + Examples
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: g++-7
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
- cxx: g++-7
|
||||
build_description: Extras + Examples
|
||||
build_type: Release
|
||||
std: 14
|
||||
other_pkgs: g++-7
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
|
||||
# Extras and examples with Clang-10
|
||||
- cxx: clang++-10
|
||||
build_description: Extras + Examples
|
||||
build_type: Debug
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
- cxx: clang++-10
|
||||
build_description: Extras + Examples
|
||||
build_type: Release
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
|
||||
# Configure tests with Clang-10
|
||||
- cxx: clang++-10
|
||||
build_description: CMake configuration tests
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_ENABLE_CONFIGURE_TESTS=ON
|
||||
|
||||
# Valgrind test Clang-10
|
||||
- cxx: clang++-10
|
||||
build_description: Valgrind tests
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: clang-10 valgrind
|
||||
cmake_configurations: -DMEMORYCHECK_COMMAND=`which valgrind` -DMEMORYCHECK_COMMAND_OPTIONS="-q --track-origins=yes --leak-check=full --num-callers=50 --show-leak-kinds=definite --error-exitcode=1"
|
||||
other_ctest_args: -T memcheck -LE uses-python
|
||||
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare environment
|
||||
run: sudo apt-get install -y ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure build
|
||||
working-directory: ${{runner.workspace}}
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
cmake -Bbuild -H$GITHUB_WORKSPACE \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCMAKE_CXX_EXTENSIONS=OFF \
|
||||
-DCATCH_DEVELOPMENT_BUILD=ON \
|
||||
${{matrix.cmake_configurations}} \
|
||||
-G Ninja
|
||||
|
||||
- name: Build tests + lib
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: ninja
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: 1
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
# Hardcode 2 cores we know are there
|
||||
run: ctest -C ${{matrix.build_type}} -j 2 ${{matrix.other_ctest_args}}
|
97
.github/workflows/linux-simple-builds.yml
vendored
Normal file
97
.github/workflows/linux-simple-builds.yml
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
name: Linux builds (basic)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx:
|
||||
# - g++-6
|
||||
- g++-7
|
||||
- g++-8
|
||||
- g++-9
|
||||
- g++-10
|
||||
- clang++-6.0
|
||||
- clang++-7
|
||||
- clang++-8
|
||||
- clang++-9
|
||||
- clang++-10
|
||||
build_type: [Debug, Release]
|
||||
std: [14]
|
||||
include:
|
||||
# cannot be installed on ubuntu-20.04 be default?
|
||||
# - cxx: g++-6
|
||||
# other_pkgs: g++-6
|
||||
- cxx: g++-7
|
||||
other_pkgs: g++-7
|
||||
- cxx: g++-8
|
||||
other_pkgs: g++-8
|
||||
- cxx: g++-9
|
||||
other_pkgs: g++-9
|
||||
- cxx: g++-10
|
||||
other_pkgs: g++-10
|
||||
- cxx: clang++-6.0
|
||||
other_pkgs: clang-6.0
|
||||
- cxx: clang++-7
|
||||
other_pkgs: clang-7
|
||||
- cxx: clang++-8
|
||||
other_pkgs: clang-8
|
||||
- cxx: clang++-9
|
||||
other_pkgs: clang-9
|
||||
- cxx: clang++-10
|
||||
other_pkgs: clang-10
|
||||
# Clang 6 + C++17
|
||||
# does not work with the default libstdc++ version thanks
|
||||
# to a disagreement on variant implementation.
|
||||
# - cxx: clang++-6.0
|
||||
# build_type: Debug
|
||||
# std: 17
|
||||
# other_pkgs: clang-6.0
|
||||
# - cxx: clang++-6.0
|
||||
# build_type: Release
|
||||
# std: 17
|
||||
# other_pkgs: clang-6.0
|
||||
# Clang 10 + C++17
|
||||
- cxx: clang++-10
|
||||
build_type: Debug
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
- cxx: clang++-10
|
||||
build_type: Release
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare environment
|
||||
run: sudo apt-get install -y ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure build
|
||||
working-directory: ${{runner.workspace}}
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
cmake -Bbuild -H$GITHUB_WORKSPACE \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCMAKE_CXX_EXTENSIONS=OFF \
|
||||
-DCATCH_DEVELOPMENT_BUILD=ON \
|
||||
-G Ninja
|
||||
|
||||
- name: Build tests + lib
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: ninja
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: 1
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
# Hardcode 2 cores we know are there
|
||||
run: ctest -C ${{matrix.build_type}} -j 2
|
45
.github/workflows/mac-builds.yml
vendored
Normal file
45
.github/workflows/mac-builds.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Mac builds
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-10.15
|
||||
strategy:
|
||||
matrix:
|
||||
cxx:
|
||||
- g++-9
|
||||
- clang++
|
||||
build_type: [Debug, Release]
|
||||
std: [14, 17]
|
||||
include:
|
||||
- build_type: Debug
|
||||
examples: ON
|
||||
extra_tests: ON
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Configure build
|
||||
working-directory: ${{runner.workspace}}
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
cmake -Bbuild -H$GITHUB_WORKSPACE \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCATCH_DEVELOPMENT_BUILD=ON -DCATCH_BUILD_EXAMPLES=${{matrix.examples}} \
|
||||
-DCATCH_BUILD_EXTRA_TESTS=${{matrix.examples}}
|
||||
|
||||
- name: Build tests + lib
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: make -j 2
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: 1
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
# Hardcode 2 cores we know are there
|
||||
run: ctest -C ${{matrix.build_type}} -j 2
|
36
.github/workflows/validate-header-guards.yml
vendored
Normal file
36
.github/workflows/validate-header-guards.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
name: Check header guards
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Set the type of machine to run on
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Dependencies
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.7'
|
||||
- name: Install checkguard
|
||||
run: pip install guardonce
|
||||
|
||||
- name: Check that include guards are properly named
|
||||
run: |
|
||||
wrong_files=$(checkguard -r src/catch2/ -p "name | append _INCLUDED | upper")
|
||||
if [[ $wrong_files ]]; then
|
||||
echo "Files with wrong header guard:"
|
||||
echo $wrong_files
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check that there are no duplicated filenames
|
||||
run: |
|
||||
./tools/scripts/checkDuplicateFilenames.py
|
||||
|
||||
- name: Check that all source files have the correct license header
|
||||
run: |
|
||||
./tools/scripts/checkLicense.py
|
23
.gitignore
vendored
23
.gitignore
vendored
@ -11,11 +11,6 @@ Release
|
||||
xcuserdata
|
||||
CatchSelfTest.xcscheme
|
||||
Breakpoints.xcbkptlist
|
||||
projects/VS2010/TestCatch/_UpgradeReport_Files/
|
||||
projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters
|
||||
projects/VisualStudio/TestCatch/UpgradeLog.XML
|
||||
projects/CMake/.idea
|
||||
projects/CMake/cmake-build-debug
|
||||
UpgradeLog.XML
|
||||
Resources/DWARF
|
||||
projects/Generated
|
||||
@ -24,6 +19,18 @@ DerivedData
|
||||
*.xccheckout
|
||||
Build
|
||||
.idea
|
||||
cmake-build-debug
|
||||
cmake-build-release
|
||||
.vs
|
||||
.vs
|
||||
.vscode
|
||||
cmake-build-*
|
||||
benchmark-dir
|
||||
.conan/test_package/build
|
||||
bazel-*
|
||||
build-fuzzers
|
||||
debug-build
|
||||
.vscode
|
||||
msvc-sln*
|
||||
# Currently we use Doxygen for dep graphs and the full docs are only slowly
|
||||
# being filled in, so we definitely do not want git to deal with the docs.
|
||||
docs/doxygen
|
||||
*.cache
|
||||
compile_commands.json
|
||||
|
227
.travis.yml
227
.travis.yml
@ -1,227 +0,0 @@
|
||||
language: cpp
|
||||
sudo: false
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
||||
# 1/ Linux Clang Builds
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: &clang35
|
||||
apt:
|
||||
sources: ['llvm-toolchain-precise-3.5', 'ubuntu-toolchain-r-test']
|
||||
packages: ['clang-3.5']
|
||||
env: COMPILER='clang++-3.5' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: *clang35
|
||||
env: COMPILER='clang++-3.5' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: &clang36
|
||||
apt:
|
||||
sources: ['llvm-toolchain-precise-3.6', 'ubuntu-toolchain-r-test']
|
||||
packages: ['clang-3.6']
|
||||
env: COMPILER='clang++-3.6' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: *clang36
|
||||
env: COMPILER='clang++-3.6' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: &clang37
|
||||
apt:
|
||||
sources: ['llvm-toolchain-precise-3.7', 'ubuntu-toolchain-r-test']
|
||||
packages: ['clang-3.7']
|
||||
env: COMPILER='clang++-3.7' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: *clang37
|
||||
env: COMPILER='clang++-3.7' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: &clang38
|
||||
apt:
|
||||
sources: ['llvm-toolchain-precise-3.8', 'ubuntu-toolchain-r-test']
|
||||
packages: ['clang-3.8']
|
||||
env: COMPILER='clang++-3.8' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: *clang38
|
||||
env: COMPILER='clang++-3.8' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
# 2/ Linux GCC Builds
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: &gcc48
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-4.8']
|
||||
env: COMPILER='g++-4.8' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc48
|
||||
env: COMPILER='g++-4.8' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: &gcc49
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-4.9']
|
||||
env: COMPILER='g++-4.9' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc49
|
||||
env: COMPILER='g++-4.9' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: &gcc5
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-5']
|
||||
env: COMPILER='g++-5' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc5
|
||||
env: COMPILER='g++-5' BUILD_TYPE='Debug'
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: &gcc6
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-6']
|
||||
env: COMPILER='g++-6' BUILD_TYPE='Release'
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc6
|
||||
env: COMPILER='g++-6' BUILD_TYPE='Debug'
|
||||
|
||||
# 3a/ Linux C++11 GCC builds
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc48
|
||||
env: COMPILER='g++-4.8' BUILD_TYPE='Release' CPP11=1
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc48
|
||||
env: COMPILER='g++-4.8' BUILD_TYPE='Debug' CPP11=1
|
||||
|
||||
# 3b/ Linux C++11 Clang builds
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: *clang38
|
||||
env: COMPILER='clang++-3.8' BUILD_TYPE='Release' CPP11=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons: *clang38
|
||||
env: COMPILER='clang++-3.8' BUILD_TYPE='Debug' CPP11=1
|
||||
|
||||
# 4a/ Linux C++14 GCC builds
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc6
|
||||
env: COMPILER='g++-6' BUILD_TYPE='Release' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons: *gcc6
|
||||
env: COMPILER='g++-6' BUILD_TYPE='Debug' CPP14=1
|
||||
|
||||
# # 4b/ Linux C++14 Clang builds
|
||||
# - os: linux
|
||||
# compiler: clang
|
||||
# addons: *clang38
|
||||
# env: COMPILER='clang++-3.8' BUILD_TYPE='Release' CPP14=1
|
||||
#
|
||||
# - os: linux
|
||||
# compiler: clang
|
||||
# addons: *clang38
|
||||
# env: COMPILER='clang++-3.8' BUILD_TYPE='Debug' CPP14=1
|
||||
|
||||
|
||||
# 5/ OSX Clang Builds
|
||||
- os: osx
|
||||
osx_image: xcode7.3
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Debug'
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode7.3
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Release'
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Debug'
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Release'
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Debug' USE_CPP11=1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Release' USE_CPP11=1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Debug' USE_CPP14=1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' BUILD_TYPE='Release' USE_CPP14=1
|
||||
|
||||
|
||||
install:
|
||||
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
|
||||
- mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR}
|
||||
- |
|
||||
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
|
||||
CMAKE_URL="http://www.cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz"
|
||||
mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake
|
||||
export PATH=${DEPS_DIR}/cmake/bin:${PATH}
|
||||
elif [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
|
||||
which cmake || brew install cmake
|
||||
fi
|
||||
|
||||
before_script:
|
||||
- export CXX=${COMPILER}
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
- cmake -H. -BBuild -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -Wdev -DUSE_CPP11=${CPP11} -DUSE_CPP14=${CPP14}
|
||||
- cd Build
|
||||
|
||||
script:
|
||||
- make -j 2
|
||||
- ctest -V -j 2
|
91
BUILD.bazel
Normal file
91
BUILD.bazel
Normal file
@ -0,0 +1,91 @@
|
||||
# Load the cc_library rule.
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
|
||||
|
||||
expand_template(
|
||||
name = "catch_user_config",
|
||||
out = "catch2/catch_user_config.hpp",
|
||||
substitutions = {
|
||||
"#cmakedefine CATCH_CONFIG_ANDROID_LOGWRITE": "",
|
||||
"#cmakedefine CATCH_CONFIG_BAZEL_SUPPORT": "#define CATCH_CONFIG_BAZEL_SUPPORT",
|
||||
"#cmakedefine CATCH_CONFIG_NO_COLOUR_WIN32": "",
|
||||
"#cmakedefine CATCH_CONFIG_COLOUR_WIN32": "",
|
||||
"#cmakedefine CATCH_CONFIG_COUNTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP11_TO_STRING": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_BYTE": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_OPTIONAL": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_STRING_VIEW": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_VARIANT": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE_STRINGIFICATION": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_REDIRECT": "",
|
||||
"#cmakedefine CATCH_CONFIG_FALLBACK_STRINGIFIER @CATCH_CONFIG_FALLBACK_STRINGIFIER@": "",
|
||||
"#cmakedefine CATCH_CONFIG_FAST_COMPILE": "",
|
||||
"#cmakedefine CATCH_CONFIG_GLOBAL_NEXTAFTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_COUNTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP11_TO_STRING": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_BYTE": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_OPTIONAL": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_STRING_VIEW": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_VARIANT": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_GLOBAL_NEXTAFTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_POSIX_SIGNALS": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_USE_ASYNC": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_WCHAR": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_WINDOWS_SEH": "",
|
||||
"#cmakedefine CATCH_CONFIG_NOSTDOUT": "",
|
||||
"#cmakedefine CATCH_CONFIG_POSIX_SIGNALS": "",
|
||||
"#cmakedefine CATCH_CONFIG_PREFIX_ALL": "",
|
||||
"#cmakedefine CATCH_CONFIG_USE_ASYNC": "",
|
||||
"#cmakedefine CATCH_CONFIG_WCHAR": "",
|
||||
"#cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG": "",
|
||||
"#cmakedefine CATCH_CONFIG_WINDOWS_SEH": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_ANDROID_LOGWRITE": "",
|
||||
"@CATCH_CONFIG_DEFAULT_REPORTER@": "console",
|
||||
"@CATCH_CONFIG_CONSOLE_WIDTH@": "80",
|
||||
},
|
||||
template = "src/catch2/catch_user_config.hpp.in",
|
||||
)
|
||||
|
||||
# Generated header library, modifies the include prefix to account for
|
||||
# generation path so that we can include <catch2/catch_user_config.hpp>
|
||||
# correctly.
|
||||
cc_library(
|
||||
name = "catch2_generated",
|
||||
hdrs = ["catch2/catch_user_config.hpp"],
|
||||
include_prefix = ".", # to manipulate -I of dependenices
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Static library, without main.
|
||||
cc_library(
|
||||
name = "catch2",
|
||||
srcs = glob(
|
||||
["src/catch2/**/*.cpp"],
|
||||
exclude = ["src/catch2/internal/catch_main.cpp"],
|
||||
),
|
||||
hdrs = glob(["src/catch2/**/*.hpp"]),
|
||||
includes = ["src/"],
|
||||
linkstatic = True,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":catch2_generated"],
|
||||
)
|
||||
|
||||
# Static library, with main.
|
||||
cc_library(
|
||||
name = "catch2_main",
|
||||
srcs = ["src/catch2/internal/catch_main.cpp"],
|
||||
includes = ["src/"],
|
||||
linkstatic = True,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":catch2"],
|
||||
)
|
10
CMake/Catch2Config.cmake.in
Normal file
10
CMake/Catch2Config.cmake.in
Normal file
@ -0,0 +1,10 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
|
||||
# Avoid repeatedly including the targets
|
||||
if(NOT TARGET Catch2::Catch2)
|
||||
# Provide path for scripts
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake)
|
||||
endif()
|
77
CMake/CatchConfigOptions.cmake
Normal file
77
CMake/CatchConfigOptions.cmake
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
# Copyright Catch2 Authors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
##
|
||||
# This file contains options that are materialized into the Catch2
|
||||
# compiled library. All of them default to OFF, as even the positive
|
||||
# forms correspond to the user _forcing_ them to ON, while being OFF
|
||||
# means that Catch2 can use its own autodetection.
|
||||
#
|
||||
# For detailed docs look into docs/configuration.md
|
||||
|
||||
|
||||
macro(AddOverridableConfigOption OptionBaseName)
|
||||
option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF)
|
||||
option(CATCH_CONFIG_NO_${OptionBaseName} "Read docs/configuration.md for details" OFF)
|
||||
endmacro()
|
||||
|
||||
macro(AddConfigOption OptionBaseName)
|
||||
option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF)
|
||||
endmacro()
|
||||
|
||||
set(_OverridableOptions
|
||||
"ANDROID_LOGWRITE"
|
||||
"BAZEL_SUPPORT"
|
||||
"COLOUR_WIN32"
|
||||
"COUNTER"
|
||||
"CPP11_TO_STRING"
|
||||
"CPP17_BYTE"
|
||||
"CPP17_OPTIONAL"
|
||||
"CPP17_STRING_VIEW"
|
||||
"CPP17_UNCAUGHT_EXCEPTIONS"
|
||||
"CPP17_VARIANT"
|
||||
"GLOBAL_NEXTAFTER"
|
||||
"POSIX_SIGNALS"
|
||||
"USE_ASYNC"
|
||||
"WCHAR"
|
||||
"WINDOWS_SEH"
|
||||
)
|
||||
|
||||
foreach(OptionName ${_OverridableOptions})
|
||||
AddOverridableConfigOption(${OptionName})
|
||||
endforeach()
|
||||
|
||||
set(_OtherConfigOptions
|
||||
"DISABLE_EXCEPTIONS"
|
||||
"DISABLE_EXCEPTIONS_CUSTOM_HANDLER"
|
||||
"DISABLE"
|
||||
"DISABLE_STRINGIFICATION"
|
||||
"ENABLE_ALL_STRINGMAKERS"
|
||||
"ENABLE_OPTIONAL_STRINGMAKER"
|
||||
"ENABLE_PAIR_STRINGMAKER"
|
||||
"ENABLE_TUPLE_STRINGMAKER"
|
||||
"ENABLE_VARIANT_STRINGMAKER"
|
||||
"EXPERIMENTAL_REDIRECT"
|
||||
"FAST_COMPILE"
|
||||
"NOSTDOUT"
|
||||
"PREFIX_ALL"
|
||||
"WINDOWS_CRTDBG"
|
||||
)
|
||||
|
||||
|
||||
foreach(OptionName ${_OtherConfigOptions})
|
||||
AddConfigOption(${OptionName})
|
||||
endforeach()
|
||||
|
||||
set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.")
|
||||
set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.")
|
||||
|
||||
# There is no good way to both turn this into a CMake cache variable,
|
||||
# and keep reasonable default semantics inside the project. Thus we do
|
||||
# not define it and users have to provide it as an outside variable.
|
||||
#set(CATCH_CONFIG_FALLBACK_STRINGIFIER "" CACHE STRING "Read docs/configuration.md for details.")
|
120
CMake/CatchMiscFunctions.cmake
Normal file
120
CMake/CatchMiscFunctions.cmake
Normal file
@ -0,0 +1,120 @@
|
||||
|
||||
# Copyright Catch2 Authors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
function(add_cxx_flag_if_supported_to_targets flagname targets)
|
||||
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
|
||||
|
||||
if (HAVE_FLAG_${flagname})
|
||||
foreach(target ${targets})
|
||||
target_compile_options(${target} PUBLIC ${flagname})
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Assumes that it is only called for development builds, where warnings
|
||||
# and Werror is desired, so it also enables Werror.
|
||||
function(add_warnings_to_targets targets)
|
||||
LIST(LENGTH targets TARGETS_LEN)
|
||||
# For now we just assume 2 possibilities: msvc and msvc-like compilers,
|
||||
# and other.
|
||||
if (MSVC)
|
||||
foreach(target ${targets})
|
||||
# Force MSVC to consider everything as encoded in utf-8
|
||||
target_compile_options( ${target} PRIVATE /utf-8 )
|
||||
# Enable Werror equivalent
|
||||
if (CATCH_ENABLE_WERROR)
|
||||
target_compile_options( ${target} PRIVATE /WX )
|
||||
endif()
|
||||
|
||||
# MSVC is currently handled specially
|
||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
||||
STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
|
||||
target_compile_options( ${target} PRIVATE /w44265 /w44061 /w44062 /w45038 )
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
|
||||
if (NOT MSVC)
|
||||
set(CHECKED_WARNING_FLAGS
|
||||
"-Wabsolute-value"
|
||||
"-Wall"
|
||||
"-Wc++20-compat"
|
||||
"-Wcall-to-pure-virtual-from-ctor-dtor"
|
||||
"-Wcast-align"
|
||||
"-Wcatch-value"
|
||||
"-Wdangling"
|
||||
"-Wdeprecated"
|
||||
"-Wdeprecated-register"
|
||||
"-Wexceptions"
|
||||
"-Wexit-time-destructors"
|
||||
"-Wextra"
|
||||
"-Wextra-semi"
|
||||
"-Wfloat-equal"
|
||||
"-Wglobal-constructors"
|
||||
"-Winit-self"
|
||||
"-Wmisleading-indentation"
|
||||
"-Wmismatched-new-delete"
|
||||
"-Wmismatched-return-types"
|
||||
"-Wmismatched-tags"
|
||||
"-Wmissing-braces"
|
||||
"-Wmissing-declarations"
|
||||
"-Wmissing-noreturn"
|
||||
"-Wmissing-prototypes"
|
||||
"-Wmissing-variable-declarations"
|
||||
"-Wnull-dereference"
|
||||
"-Wold-style-cast"
|
||||
"-Woverloaded-virtual"
|
||||
"-Wparentheses"
|
||||
"-Wpedantic"
|
||||
"-Wreorder"
|
||||
"-Wreturn-std-move"
|
||||
"-Wshadow"
|
||||
"-Wstrict-aliasing"
|
||||
"-Wsuggest-destructor-override"
|
||||
"-Wsuggest-override"
|
||||
"-Wundef"
|
||||
"-Wuninitialized"
|
||||
"-Wunneeded-internal-declaration"
|
||||
"-Wunreachable-code"
|
||||
"-Wunused"
|
||||
"-Wunused-function"
|
||||
"-Wunused-parameter"
|
||||
"-Wvla"
|
||||
"-Wweak-vtables"
|
||||
|
||||
# This is a useful warning, but our tests sometimes rely on
|
||||
# functions being present, but not picked (e.g. various checks
|
||||
# for stringification implementation ordering).
|
||||
# Ergo, we should use it every now and then, but we cannot
|
||||
# enable it by default.
|
||||
# "-Wunused-member-function"
|
||||
)
|
||||
foreach(warning ${CHECKED_WARNING_FLAGS})
|
||||
add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
|
||||
endforeach()
|
||||
|
||||
if (CATCH_ENABLE_WERROR)
|
||||
foreach(target ${targets})
|
||||
# Enable Werror equivalent
|
||||
target_compile_options( ${target} PRIVATE -Werror )
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Adds flags required for reproducible build to the target
|
||||
# Currently only supports GCC and Clang
|
||||
function(add_build_reproducibility_settings target)
|
||||
# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
|
||||
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8) OR
|
||||
("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 10))
|
||||
target_compile_options(${target} PRIVATE "-ffile-prefix-map=${CATCH_DIR}=.")
|
||||
endif()
|
||||
endfunction()
|
157
CMake/FindGcov.cmake
Normal file
157
CMake/FindGcov.cmake
Normal file
@ -0,0 +1,157 @@
|
||||
# This file is part of CMake-codecov.
|
||||
#
|
||||
# Copyright (c)
|
||||
# 2015-2017 RWTH Aachen University, Federal Republic of Germany
|
||||
#
|
||||
# See the LICENSE file in the package base directory for details
|
||||
#
|
||||
# Written by Alexander Haase, alexander.haase@rwth-aachen.de
|
||||
#
|
||||
|
||||
|
||||
# include required Modules
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
|
||||
# Search for gcov binary.
|
||||
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
|
||||
set(CMAKE_REQUIRED_QUIET ${codecov_FIND_QUIETLY})
|
||||
|
||||
get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
foreach (LANG ${ENABLED_LANGUAGES})
|
||||
# Gcov evaluation is dependent on the used compiler. Check gcov support for
|
||||
# each compiler that is used. If gcov binary was already found for this
|
||||
# compiler, do not try to find it again.
|
||||
if (NOT GCOV_${CMAKE_${LANG}_COMPILER_ID}_BIN)
|
||||
get_filename_component(COMPILER_PATH "${CMAKE_${LANG}_COMPILER}" PATH)
|
||||
|
||||
if ("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "GNU")
|
||||
# Some distributions like OSX (homebrew) ship gcov with the compiler
|
||||
# version appended as gcov-x. To find this binary we'll build the
|
||||
# suggested binary name with the compiler version.
|
||||
string(REGEX MATCH "^[0-9]+" GCC_VERSION
|
||||
"${CMAKE_${LANG}_COMPILER_VERSION}")
|
||||
|
||||
find_program(GCOV_BIN NAMES gcov-${GCC_VERSION} gcov
|
||||
HINTS ${COMPILER_PATH})
|
||||
|
||||
elseif ("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "Clang")
|
||||
# Some distributions like Debian ship llvm-cov with the compiler
|
||||
# version appended as llvm-cov-x.y. To find this binary we'll build
|
||||
# the suggested binary name with the compiler version.
|
||||
string(REGEX MATCH "^[0-9]+.[0-9]+" LLVM_VERSION
|
||||
"${CMAKE_${LANG}_COMPILER_VERSION}")
|
||||
|
||||
# llvm-cov prior version 3.5 seems to be not working with coverage
|
||||
# evaluation tools, but these versions are compatible with the gcc
|
||||
# gcov tool.
|
||||
if(LLVM_VERSION VERSION_GREATER 3.4)
|
||||
find_program(LLVM_COV_BIN NAMES "llvm-cov-${LLVM_VERSION}"
|
||||
"llvm-cov" HINTS ${COMPILER_PATH})
|
||||
mark_as_advanced(LLVM_COV_BIN)
|
||||
|
||||
if (LLVM_COV_BIN)
|
||||
find_program(LLVM_COV_WRAPPER "llvm-cov-wrapper" PATHS
|
||||
${CMAKE_MODULE_PATH})
|
||||
if (LLVM_COV_WRAPPER)
|
||||
set(GCOV_BIN "${LLVM_COV_WRAPPER}" CACHE FILEPATH "")
|
||||
|
||||
# set additional parameters
|
||||
set(GCOV_${CMAKE_${LANG}_COMPILER_ID}_ENV
|
||||
"LLVM_COV_BIN=${LLVM_COV_BIN}" CACHE STRING
|
||||
"Environment variables for llvm-cov-wrapper.")
|
||||
mark_as_advanced(GCOV_${CMAKE_${LANG}_COMPILER_ID}_ENV)
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT GCOV_BIN)
|
||||
# Fall back to gcov binary if llvm-cov was not found or is
|
||||
# incompatible. This is the default on OSX, but may crash on
|
||||
# recent Linux versions.
|
||||
find_program(GCOV_BIN gcov HINTS ${COMPILER_PATH})
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
||||
if (GCOV_BIN)
|
||||
set(GCOV_${CMAKE_${LANG}_COMPILER_ID}_BIN "${GCOV_BIN}" CACHE STRING
|
||||
"${LANG} gcov binary.")
|
||||
|
||||
if (NOT CMAKE_REQUIRED_QUIET)
|
||||
message("-- Found gcov evaluation for "
|
||||
"${CMAKE_${LANG}_COMPILER_ID}: ${GCOV_BIN}")
|
||||
endif()
|
||||
|
||||
unset(GCOV_BIN CACHE)
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
|
||||
|
||||
|
||||
# Add a new global target for all gcov targets. This target could be used to
|
||||
# generate the gcov files for the whole project instead of calling <TARGET>-gcov
|
||||
# for each target.
|
||||
if (NOT TARGET gcov)
|
||||
add_custom_target(gcov)
|
||||
endif (NOT TARGET gcov)
|
||||
|
||||
|
||||
|
||||
# This function will add gcov evaluation for target <TNAME>. Only sources of
|
||||
# this target will be evaluated and no dependencies will be added. It will call
|
||||
# Gcov on any source file of <TNAME> once and store the gcov file in the same
|
||||
# directory.
|
||||
function (add_gcov_target TNAME)
|
||||
set(TDIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TNAME}.dir)
|
||||
|
||||
# We don't have to check, if the target has support for coverage, thus this
|
||||
# will be checked by add_coverage_target in Findcoverage.cmake. Instead we
|
||||
# have to determine which gcov binary to use.
|
||||
get_target_property(TSOURCES ${TNAME} SOURCES)
|
||||
set(SOURCES "")
|
||||
set(TCOMPILER "")
|
||||
foreach (FILE ${TSOURCES})
|
||||
codecov_path_of_source(${FILE} FILE)
|
||||
if (NOT "${FILE}" STREQUAL "")
|
||||
codecov_lang_of_source(${FILE} LANG)
|
||||
if (NOT "${LANG}" STREQUAL "")
|
||||
list(APPEND SOURCES "${FILE}")
|
||||
set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID})
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# If no gcov binary was found, coverage data can't be evaluated.
|
||||
if (NOT GCOV_${TCOMPILER}_BIN)
|
||||
message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.")
|
||||
return()
|
||||
endif ()
|
||||
|
||||
set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}")
|
||||
set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}")
|
||||
|
||||
|
||||
set(BUFFER "")
|
||||
foreach(FILE ${SOURCES})
|
||||
get_filename_component(FILE_PATH "${TDIR}/${FILE}" PATH)
|
||||
|
||||
# call gcov
|
||||
add_custom_command(OUTPUT ${TDIR}/${FILE}.gcov
|
||||
COMMAND ${GCOV_ENV} ${GCOV_BIN} ${TDIR}/${FILE}.gcno > /dev/null
|
||||
DEPENDS ${TNAME} ${TDIR}/${FILE}.gcno
|
||||
WORKING_DIRECTORY ${FILE_PATH}
|
||||
)
|
||||
|
||||
list(APPEND BUFFER ${TDIR}/${FILE}.gcov)
|
||||
endforeach()
|
||||
|
||||
|
||||
# add target for gcov evaluation of <TNAME>
|
||||
add_custom_target(${TNAME}-gcov DEPENDS ${BUFFER})
|
||||
|
||||
# add evaluation target to the global gcov target.
|
||||
add_dependencies(gcov ${TNAME}-gcov)
|
||||
endfunction (add_gcov_target)
|
354
CMake/FindLcov.cmake
Normal file
354
CMake/FindLcov.cmake
Normal file
@ -0,0 +1,354 @@
|
||||
# This file is part of CMake-codecov.
|
||||
#
|
||||
# Copyright (c)
|
||||
# 2015-2017 RWTH Aachen University, Federal Republic of Germany
|
||||
#
|
||||
# See the LICENSE file in the package base directory for details
|
||||
#
|
||||
# Written by Alexander Haase, alexander.haase@rwth-aachen.de
|
||||
#
|
||||
|
||||
|
||||
# configuration
|
||||
set(LCOV_DATA_PATH "${CMAKE_BINARY_DIR}/lcov/data")
|
||||
set(LCOV_DATA_PATH_INIT "${LCOV_DATA_PATH}/init")
|
||||
set(LCOV_DATA_PATH_CAPTURE "${LCOV_DATA_PATH}/capture")
|
||||
set(LCOV_HTML_PATH "${CMAKE_BINARY_DIR}/lcov/html")
|
||||
|
||||
|
||||
|
||||
|
||||
# Search for Gcov which is used by Lcov.
|
||||
find_package(Gcov)
|
||||
|
||||
|
||||
|
||||
|
||||
# This function will add lcov evaluation for target <TNAME>. Only sources of
|
||||
# this target will be evaluated and no dependencies will be added. It will call
|
||||
# geninfo on any source file of <TNAME> once and store the info file in the same
|
||||
# directory.
|
||||
#
|
||||
# Note: This function is only a wrapper to define this function always, even if
|
||||
# coverage is not supported by the compiler or disabled. This function must
|
||||
# be defined here, because the module will be exited, if there is no coverage
|
||||
# support by the compiler or it is disabled by the user.
|
||||
function (add_lcov_target TNAME)
|
||||
if (LCOV_FOUND)
|
||||
# capture initial coverage data
|
||||
lcov_capture_initial_tgt(${TNAME})
|
||||
|
||||
# capture coverage data after execution
|
||||
lcov_capture_tgt(${TNAME})
|
||||
endif ()
|
||||
endfunction (add_lcov_target)
|
||||
|
||||
|
||||
|
||||
|
||||
# include required Modules
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Search for required lcov binaries.
|
||||
find_program(LCOV_BIN lcov)
|
||||
find_program(GENINFO_BIN geninfo)
|
||||
find_program(GENHTML_BIN genhtml)
|
||||
find_package_handle_standard_args(lcov
|
||||
REQUIRED_VARS LCOV_BIN GENINFO_BIN GENHTML_BIN
|
||||
)
|
||||
|
||||
# enable genhtml C++ demangeling, if c++filt is found.
|
||||
set(GENHTML_CPPFILT_FLAG "")
|
||||
find_program(CPPFILT_BIN c++filt)
|
||||
if (NOT CPPFILT_BIN STREQUAL "")
|
||||
set(GENHTML_CPPFILT_FLAG "--demangle-cpp")
|
||||
endif (NOT CPPFILT_BIN STREQUAL "")
|
||||
|
||||
# enable no-external flag for lcov, if available.
|
||||
if (GENINFO_BIN AND NOT DEFINED GENINFO_EXTERN_FLAG)
|
||||
set(FLAG "")
|
||||
execute_process(COMMAND ${GENINFO_BIN} --help OUTPUT_VARIABLE GENINFO_HELP)
|
||||
string(REGEX MATCH "external" GENINFO_RES "${GENINFO_HELP}")
|
||||
if (GENINFO_RES)
|
||||
set(FLAG "--no-external")
|
||||
endif ()
|
||||
|
||||
set(GENINFO_EXTERN_FLAG "${FLAG}"
|
||||
CACHE STRING "Geninfo flag to exclude system sources.")
|
||||
endif ()
|
||||
|
||||
# If Lcov was not found, exit module now.
|
||||
if (NOT LCOV_FOUND)
|
||||
return()
|
||||
endif (NOT LCOV_FOUND)
|
||||
|
||||
|
||||
|
||||
|
||||
# Create directories to be used.
|
||||
file(MAKE_DIRECTORY ${LCOV_DATA_PATH_INIT})
|
||||
file(MAKE_DIRECTORY ${LCOV_DATA_PATH_CAPTURE})
|
||||
|
||||
set(LCOV_REMOVE_PATTERNS "")
|
||||
|
||||
# This function will merge lcov files to a single target file. Additional lcov
|
||||
# flags may be set with setting LCOV_EXTRA_FLAGS before calling this function.
|
||||
function (lcov_merge_files OUTFILE ...)
|
||||
# Remove ${OUTFILE} from ${ARGV} and generate lcov parameters with files.
|
||||
list(REMOVE_AT ARGV 0)
|
||||
|
||||
# Generate merged file.
|
||||
string(REPLACE "${CMAKE_BINARY_DIR}/" "" FILE_REL "${OUTFILE}")
|
||||
add_custom_command(OUTPUT "${OUTFILE}.raw"
|
||||
COMMAND cat ${ARGV} > ${OUTFILE}.raw
|
||||
DEPENDS ${ARGV}
|
||||
COMMENT "Generating ${FILE_REL}"
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT "${OUTFILE}"
|
||||
COMMAND ${LCOV_BIN} --quiet -a ${OUTFILE}.raw --output-file ${OUTFILE}
|
||||
--base-directory ${PROJECT_SOURCE_DIR} ${LCOV_EXTRA_FLAGS}
|
||||
COMMAND ${LCOV_BIN} --quiet -r ${OUTFILE} ${LCOV_REMOVE_PATTERNS}
|
||||
--output-file ${OUTFILE} ${LCOV_EXTRA_FLAGS}
|
||||
DEPENDS ${OUTFILE}.raw
|
||||
COMMENT "Post-processing ${FILE_REL}"
|
||||
)
|
||||
endfunction ()
|
||||
|
||||
|
||||
|
||||
|
||||
# Add a new global target to generate initial coverage reports for all targets.
|
||||
# This target will be used to generate the global initial info file, which is
|
||||
# used to gather even empty report data.
|
||||
if (NOT TARGET lcov-capture-init)
|
||||
add_custom_target(lcov-capture-init)
|
||||
set(LCOV_CAPTURE_INIT_FILES "" CACHE INTERNAL "")
|
||||
endif (NOT TARGET lcov-capture-init)
|
||||
|
||||
|
||||
# This function will add initial capture of coverage data for target <TNAME>,
|
||||
# which is needed to get also data for objects, which were not loaded at
|
||||
# execution time. It will call geninfo for every source file of <TNAME> once and
|
||||
# store the info file in the same directory.
|
||||
function (lcov_capture_initial_tgt TNAME)
|
||||
# We don't have to check, if the target has support for coverage, thus this
|
||||
# will be checked by add_coverage_target in Findcoverage.cmake. Instead we
|
||||
# have to determine which gcov binary to use.
|
||||
get_target_property(TSOURCES ${TNAME} SOURCES)
|
||||
set(SOURCES "")
|
||||
set(TCOMPILER "")
|
||||
foreach (FILE ${TSOURCES})
|
||||
codecov_path_of_source(${FILE} FILE)
|
||||
if (NOT "${FILE}" STREQUAL "")
|
||||
codecov_lang_of_source(${FILE} LANG)
|
||||
if (NOT "${LANG}" STREQUAL "")
|
||||
list(APPEND SOURCES "${FILE}")
|
||||
set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID})
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# If no gcov binary was found, coverage data can't be evaluated.
|
||||
if (NOT GCOV_${TCOMPILER}_BIN)
|
||||
message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.")
|
||||
return()
|
||||
endif ()
|
||||
|
||||
set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}")
|
||||
set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}")
|
||||
|
||||
|
||||
set(TDIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TNAME}.dir)
|
||||
set(GENINFO_FILES "")
|
||||
foreach(FILE ${SOURCES})
|
||||
# generate empty coverage files
|
||||
set(OUTFILE "${TDIR}/${FILE}.info.init")
|
||||
list(APPEND GENINFO_FILES ${OUTFILE})
|
||||
|
||||
add_custom_command(OUTPUT ${OUTFILE} COMMAND ${GCOV_ENV} ${GENINFO_BIN}
|
||||
--quiet --base-directory ${PROJECT_SOURCE_DIR} --initial
|
||||
--gcov-tool ${GCOV_BIN} --output-filename ${OUTFILE}
|
||||
${GENINFO_EXTERN_FLAG} ${TDIR}/${FILE}.gcno
|
||||
DEPENDS ${TNAME}
|
||||
COMMENT "Capturing initial coverage data for ${FILE}"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# Concatenate all files generated by geninfo to a single file per target.
|
||||
set(OUTFILE "${LCOV_DATA_PATH_INIT}/${TNAME}.info")
|
||||
set(LCOV_EXTRA_FLAGS "--initial")
|
||||
lcov_merge_files("${OUTFILE}" ${GENINFO_FILES})
|
||||
add_custom_target(${TNAME}-capture-init ALL DEPENDS ${OUTFILE})
|
||||
|
||||
# add geninfo file generation to global lcov-geninfo target
|
||||
add_dependencies(lcov-capture-init ${TNAME}-capture-init)
|
||||
set(LCOV_CAPTURE_INIT_FILES "${LCOV_CAPTURE_INIT_FILES}"
|
||||
"${OUTFILE}" CACHE INTERNAL ""
|
||||
)
|
||||
endfunction (lcov_capture_initial_tgt)
|
||||
|
||||
|
||||
# This function will generate the global info file for all targets. It has to be
|
||||
# called after all other CMake functions in the root CMakeLists.txt file, to get
|
||||
# a full list of all targets that generate coverage data.
|
||||
function (lcov_capture_initial)
|
||||
# Skip this function (and do not create the following targets), if there are
|
||||
# no input files.
|
||||
if ("${LCOV_CAPTURE_INIT_FILES}" STREQUAL "")
|
||||
return()
|
||||
endif ()
|
||||
|
||||
# Add a new target to merge the files of all targets.
|
||||
set(OUTFILE "${LCOV_DATA_PATH_INIT}/all_targets.info")
|
||||
lcov_merge_files("${OUTFILE}" ${LCOV_CAPTURE_INIT_FILES})
|
||||
add_custom_target(lcov-geninfo-init ALL DEPENDS ${OUTFILE}
|
||||
lcov-capture-init
|
||||
)
|
||||
endfunction (lcov_capture_initial)
|
||||
|
||||
|
||||
|
||||
|
||||
# Add a new global target to generate coverage reports for all targets. This
|
||||
# target will be used to generate the global info file.
|
||||
if (NOT TARGET lcov-capture)
|
||||
add_custom_target(lcov-capture)
|
||||
set(LCOV_CAPTURE_FILES "" CACHE INTERNAL "")
|
||||
endif (NOT TARGET lcov-capture)
|
||||
|
||||
|
||||
# This function will add capture of coverage data for target <TNAME>, which is
|
||||
# needed to get also data for objects, which were not loaded at execution time.
|
||||
# It will call geninfo for every source file of <TNAME> once and store the info
|
||||
# file in the same directory.
|
||||
function (lcov_capture_tgt TNAME)
|
||||
# We don't have to check, if the target has support for coverage, thus this
|
||||
# will be checked by add_coverage_target in Findcoverage.cmake. Instead we
|
||||
# have to determine which gcov binary to use.
|
||||
get_target_property(TSOURCES ${TNAME} SOURCES)
|
||||
set(SOURCES "")
|
||||
set(TCOMPILER "")
|
||||
foreach (FILE ${TSOURCES})
|
||||
codecov_path_of_source(${FILE} FILE)
|
||||
if (NOT "${FILE}" STREQUAL "")
|
||||
codecov_lang_of_source(${FILE} LANG)
|
||||
if (NOT "${LANG}" STREQUAL "")
|
||||
list(APPEND SOURCES "${FILE}")
|
||||
set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID})
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# If no gcov binary was found, coverage data can't be evaluated.
|
||||
if (NOT GCOV_${TCOMPILER}_BIN)
|
||||
message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.")
|
||||
return()
|
||||
endif ()
|
||||
|
||||
set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}")
|
||||
set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}")
|
||||
|
||||
|
||||
set(TDIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TNAME}.dir)
|
||||
set(GENINFO_FILES "")
|
||||
foreach(FILE ${SOURCES})
|
||||
# Generate coverage files. If no .gcda file was generated during
|
||||
# execution, the empty coverage file will be used instead.
|
||||
set(OUTFILE "${TDIR}/${FILE}.info")
|
||||
list(APPEND GENINFO_FILES ${OUTFILE})
|
||||
|
||||
add_custom_command(OUTPUT ${OUTFILE}
|
||||
COMMAND test -f "${TDIR}/${FILE}.gcda"
|
||||
&& ${GCOV_ENV} ${GENINFO_BIN} --quiet --base-directory
|
||||
${PROJECT_SOURCE_DIR} --gcov-tool ${GCOV_BIN}
|
||||
--output-filename ${OUTFILE} ${GENINFO_EXTERN_FLAG}
|
||||
${TDIR}/${FILE}.gcda
|
||||
|| cp ${OUTFILE}.init ${OUTFILE}
|
||||
DEPENDS ${TNAME} ${TNAME}-capture-init
|
||||
COMMENT "Capturing coverage data for ${FILE}"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# Concatenate all files generated by geninfo to a single file per target.
|
||||
set(OUTFILE "${LCOV_DATA_PATH_CAPTURE}/${TNAME}.info")
|
||||
lcov_merge_files("${OUTFILE}" ${GENINFO_FILES})
|
||||
add_custom_target(${TNAME}-geninfo DEPENDS ${OUTFILE})
|
||||
|
||||
# add geninfo file generation to global lcov-capture target
|
||||
add_dependencies(lcov-capture ${TNAME}-geninfo)
|
||||
set(LCOV_CAPTURE_FILES "${LCOV_CAPTURE_FILES}" "${OUTFILE}" CACHE INTERNAL
|
||||
""
|
||||
)
|
||||
|
||||
# Add target for generating html output for this target only.
|
||||
file(MAKE_DIRECTORY ${LCOV_HTML_PATH}/${TNAME})
|
||||
add_custom_target(${TNAME}-genhtml
|
||||
COMMAND ${GENHTML_BIN} --quiet --sort --prefix ${PROJECT_SOURCE_DIR}
|
||||
--baseline-file ${LCOV_DATA_PATH_INIT}/${TNAME}.info
|
||||
--output-directory ${LCOV_HTML_PATH}/${TNAME}
|
||||
--title "${CMAKE_PROJECT_NAME} - target ${TNAME}"
|
||||
${GENHTML_CPPFILT_FLAG} ${OUTFILE}
|
||||
DEPENDS ${TNAME}-geninfo ${TNAME}-capture-init
|
||||
)
|
||||
endfunction (lcov_capture_tgt)
|
||||
|
||||
|
||||
# This function will generate the global info file for all targets. It has to be
|
||||
# called after all other CMake functions in the root CMakeLists.txt file, to get
|
||||
# a full list of all targets that generate coverage data.
|
||||
function (lcov_capture)
|
||||
# Skip this function (and do not create the following targets), if there are
|
||||
# no input files.
|
||||
if ("${LCOV_CAPTURE_FILES}" STREQUAL "")
|
||||
return()
|
||||
endif ()
|
||||
|
||||
# Add a new target to merge the files of all targets.
|
||||
set(OUTFILE "${LCOV_DATA_PATH_CAPTURE}/all_targets.info")
|
||||
lcov_merge_files("${OUTFILE}" ${LCOV_CAPTURE_FILES})
|
||||
add_custom_target(lcov-geninfo DEPENDS ${OUTFILE} lcov-capture)
|
||||
|
||||
# Add a new global target for all lcov targets. This target could be used to
|
||||
# generate the lcov html output for the whole project instead of calling
|
||||
# <TARGET>-geninfo and <TARGET>-genhtml for each target. It will also be
|
||||
# used to generate a html site for all project data together instead of one
|
||||
# for each target.
|
||||
if (NOT TARGET lcov)
|
||||
file(MAKE_DIRECTORY ${LCOV_HTML_PATH}/all_targets)
|
||||
add_custom_target(lcov
|
||||
COMMAND ${GENHTML_BIN} --quiet --sort
|
||||
--baseline-file ${LCOV_DATA_PATH_INIT}/all_targets.info
|
||||
--output-directory ${LCOV_HTML_PATH}/all_targets
|
||||
--title "${CMAKE_PROJECT_NAME}" --prefix "${PROJECT_SOURCE_DIR}"
|
||||
${GENHTML_CPPFILT_FLAG} ${OUTFILE}
|
||||
DEPENDS lcov-geninfo-init lcov-geninfo
|
||||
)
|
||||
endif ()
|
||||
endfunction (lcov_capture)
|
||||
|
||||
|
||||
|
||||
|
||||
# Add a new global target to generate the lcov html report for the whole project
|
||||
# instead of calling <TARGET>-genhtml for each target (to create an own report
|
||||
# for each target). Instead of the lcov target it does not require geninfo for
|
||||
# all targets, so you have to call <TARGET>-geninfo to generate the info files
|
||||
# the targets you'd like to have in your report or lcov-geninfo for generating
|
||||
# info files for all targets before calling lcov-genhtml.
|
||||
file(MAKE_DIRECTORY ${LCOV_HTML_PATH}/selected_targets)
|
||||
if (NOT TARGET lcov-genhtml)
|
||||
add_custom_target(lcov-genhtml
|
||||
COMMAND ${GENHTML_BIN}
|
||||
--quiet
|
||||
--output-directory ${LCOV_HTML_PATH}/selected_targets
|
||||
--title \"${CMAKE_PROJECT_NAME} - targets `find
|
||||
${LCOV_DATA_PATH_CAPTURE} -name \"*.info\" ! -name
|
||||
\"all_targets.info\" -exec basename {} .info \\\;`\"
|
||||
--prefix ${PROJECT_SOURCE_DIR}
|
||||
--sort
|
||||
${GENHTML_CPPFILT_FLAG}
|
||||
`find ${LCOV_DATA_PATH_CAPTURE} -name \"*.info\" ! -name
|
||||
\"all_targets.info\"`
|
||||
)
|
||||
endif (NOT TARGET lcov-genhtml)
|
258
CMake/Findcodecov.cmake
Normal file
258
CMake/Findcodecov.cmake
Normal file
@ -0,0 +1,258 @@
|
||||
# This file is part of CMake-codecov.
|
||||
#
|
||||
# Copyright (c)
|
||||
# 2015-2017 RWTH Aachen University, Federal Republic of Germany
|
||||
#
|
||||
# See the LICENSE file in the package base directory for details
|
||||
#
|
||||
# Written by Alexander Haase, alexander.haase@rwth-aachen.de
|
||||
#
|
||||
|
||||
|
||||
# Add an option to choose, if coverage should be enabled or not. If enabled
|
||||
# marked targets will be build with coverage support and appropriate targets
|
||||
# will be added. If disabled coverage will be ignored for *ALL* targets.
|
||||
option(ENABLE_COVERAGE "Enable coverage build." OFF)
|
||||
|
||||
set(COVERAGE_FLAG_CANDIDATES
|
||||
# gcc and clang
|
||||
"-O0 -g -fprofile-arcs -ftest-coverage"
|
||||
|
||||
# gcc and clang fallback
|
||||
"-O0 -g --coverage"
|
||||
)
|
||||
|
||||
|
||||
# Add coverage support for target ${TNAME} and register target for coverage
|
||||
# evaluation. If coverage is disabled or not supported, this function will
|
||||
# simply do nothing.
|
||||
#
|
||||
# Note: This function is only a wrapper to define this function always, even if
|
||||
# coverage is not supported by the compiler or disabled. This function must
|
||||
# be defined here, because the module will be exited, if there is no coverage
|
||||
# support by the compiler or it is disabled by the user.
|
||||
function (add_coverage TNAME)
|
||||
# only add coverage for target, if coverage is support and enabled.
|
||||
if (ENABLE_COVERAGE)
|
||||
foreach (TNAME ${ARGV})
|
||||
add_coverage_target(${TNAME})
|
||||
endforeach ()
|
||||
endif ()
|
||||
endfunction (add_coverage)
|
||||
|
||||
|
||||
# Add global target to gather coverage information after all targets have been
|
||||
# added. Other evaluation functions could be added here, after checks for the
|
||||
# specific module have been passed.
|
||||
#
|
||||
# Note: This function is only a wrapper to define this function always, even if
|
||||
# coverage is not supported by the compiler or disabled. This function must
|
||||
# be defined here, because the module will be exited, if there is no coverage
|
||||
# support by the compiler or it is disabled by the user.
|
||||
function (coverage_evaluate)
|
||||
# add lcov evaluation
|
||||
if (LCOV_FOUND)
|
||||
lcov_capture_initial()
|
||||
lcov_capture()
|
||||
endif (LCOV_FOUND)
|
||||
endfunction ()
|
||||
|
||||
|
||||
# Exit this module, if coverage is disabled. add_coverage is defined before this
|
||||
# return, so this module can be exited now safely without breaking any build-
|
||||
# scripts.
|
||||
if (NOT ENABLE_COVERAGE)
|
||||
return()
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
|
||||
# Find the reuired flags foreach language.
|
||||
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
|
||||
set(CMAKE_REQUIRED_QUIET ${codecov_FIND_QUIETLY})
|
||||
|
||||
get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
foreach (LANG ${ENABLED_LANGUAGES})
|
||||
# Coverage flags are not dependent on language, but the used compiler. So
|
||||
# instead of searching flags foreach language, search flags foreach compiler
|
||||
# used.
|
||||
set(COMPILER ${CMAKE_${LANG}_COMPILER_ID})
|
||||
if (NOT COVERAGE_${COMPILER}_FLAGS)
|
||||
foreach (FLAG ${COVERAGE_FLAG_CANDIDATES})
|
||||
if(NOT CMAKE_REQUIRED_QUIET)
|
||||
message(STATUS "Try ${COMPILER} code coverage flag = [${FLAG}]")
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
|
||||
unset(COVERAGE_FLAG_DETECTED CACHE)
|
||||
|
||||
if (${LANG} STREQUAL "C")
|
||||
include(CheckCCompilerFlag)
|
||||
check_c_compiler_flag("${FLAG}" COVERAGE_FLAG_DETECTED)
|
||||
|
||||
elseif (${LANG} STREQUAL "CXX")
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("${FLAG}" COVERAGE_FLAG_DETECTED)
|
||||
|
||||
elseif (${LANG} STREQUAL "Fortran")
|
||||
# CheckFortranCompilerFlag was introduced in CMake 3.x. To be
|
||||
# compatible with older Cmake versions, we will check if this
|
||||
# module is present before we use it. Otherwise we will define
|
||||
# Fortran coverage support as not available.
|
||||
include(CheckFortranCompilerFlag OPTIONAL
|
||||
RESULT_VARIABLE INCLUDED)
|
||||
if (INCLUDED)
|
||||
check_fortran_compiler_flag("${FLAG}"
|
||||
COVERAGE_FLAG_DETECTED)
|
||||
elseif (NOT CMAKE_REQUIRED_QUIET)
|
||||
message("-- Performing Test COVERAGE_FLAG_DETECTED")
|
||||
message("-- Performing Test COVERAGE_FLAG_DETECTED - Failed"
|
||||
" (Check not supported)")
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
if (COVERAGE_FLAG_DETECTED)
|
||||
set(COVERAGE_${COMPILER}_FLAGS "${FLAG}"
|
||||
CACHE STRING "${COMPILER} flags for code coverage.")
|
||||
mark_as_advanced(COVERAGE_${COMPILER}_FLAGS)
|
||||
break()
|
||||
else ()
|
||||
message(WARNING "Code coverage is not available for ${COMPILER}"
|
||||
" compiler. Targets using this compiler will be "
|
||||
"compiled without it.")
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
|
||||
|
||||
|
||||
|
||||
|
||||
# Helper function to get the language of a source file.
|
||||
function (codecov_lang_of_source FILE RETURN_VAR)
|
||||
get_filename_component(FILE_EXT "${FILE}" EXT)
|
||||
string(TOLOWER "${FILE_EXT}" FILE_EXT)
|
||||
string(SUBSTRING "${FILE_EXT}" 1 -1 FILE_EXT)
|
||||
|
||||
get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
foreach (LANG ${ENABLED_LANGUAGES})
|
||||
list(FIND CMAKE_${LANG}_SOURCE_FILE_EXTENSIONS "${FILE_EXT}" TEMP)
|
||||
if (NOT ${TEMP} EQUAL -1)
|
||||
set(${RETURN_VAR} "${LANG}" PARENT_SCOPE)
|
||||
return()
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
set(${RETURN_VAR} "" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
|
||||
# Helper function to get the relative path of the source file destination path.
|
||||
# This path is needed by FindGcov and FindLcov cmake files to locate the
|
||||
# captured data.
|
||||
function (codecov_path_of_source FILE RETURN_VAR)
|
||||
string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _source ${FILE})
|
||||
|
||||
# If expression was found, SOURCEFILE is a generator-expression for an
|
||||
# object library. Currently we found no way to call this function automatic
|
||||
# for the referenced target, so it must be called in the directoryso of the
|
||||
# object library definition.
|
||||
if (NOT "${_source}" STREQUAL "")
|
||||
set(${RETURN_VAR} "" PARENT_SCOPE)
|
||||
return()
|
||||
endif ()
|
||||
|
||||
|
||||
string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" FILE "${FILE}")
|
||||
if(IS_ABSOLUTE ${FILE})
|
||||
file(RELATIVE_PATH FILE ${CMAKE_CURRENT_SOURCE_DIR} ${FILE})
|
||||
endif()
|
||||
|
||||
# get the right path for file
|
||||
string(REPLACE ".." "__" PATH "${FILE}")
|
||||
|
||||
set(${RETURN_VAR} "${PATH}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
|
||||
|
||||
|
||||
# Add coverage support for target ${TNAME} and register target for coverage
|
||||
# evaluation.
|
||||
function(add_coverage_target TNAME)
|
||||
# Check if all sources for target use the same compiler. If a target uses
|
||||
# e.g. C and Fortran mixed and uses different compilers (e.g. clang and
|
||||
# gfortran) this can trigger huge problems, because different compilers may
|
||||
# use different implementations for code coverage.
|
||||
get_target_property(TSOURCES ${TNAME} SOURCES)
|
||||
set(TARGET_COMPILER "")
|
||||
set(ADDITIONAL_FILES "")
|
||||
foreach (FILE ${TSOURCES})
|
||||
# If expression was found, FILE is a generator-expression for an object
|
||||
# library. Object libraries will be ignored.
|
||||
string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _file ${FILE})
|
||||
if ("${_file}" STREQUAL "")
|
||||
codecov_lang_of_source(${FILE} LANG)
|
||||
if (LANG)
|
||||
list(APPEND TARGET_COMPILER ${CMAKE_${LANG}_COMPILER_ID})
|
||||
|
||||
list(APPEND ADDITIONAL_FILES "${FILE}.gcno")
|
||||
list(APPEND ADDITIONAL_FILES "${FILE}.gcda")
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
list(REMOVE_DUPLICATES TARGET_COMPILER)
|
||||
list(LENGTH TARGET_COMPILER NUM_COMPILERS)
|
||||
|
||||
if (NUM_COMPILERS GREATER 1)
|
||||
message(WARNING "Can't use code coverage for target ${TNAME}, because "
|
||||
"it will be compiled by incompatible compilers. Target will be "
|
||||
"compiled without code coverage.")
|
||||
return()
|
||||
|
||||
elseif (NUM_COMPILERS EQUAL 0)
|
||||
message(WARNING "Can't use code coverage for target ${TNAME}, because "
|
||||
"it uses an unknown compiler. Target will be compiled without "
|
||||
"code coverage.")
|
||||
return()
|
||||
|
||||
elseif (NOT DEFINED "COVERAGE_${TARGET_COMPILER}_FLAGS")
|
||||
# A warning has been printed before, so just return if flags for this
|
||||
# compiler aren't available.
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
||||
# enable coverage for target
|
||||
set_property(TARGET ${TNAME} APPEND_STRING
|
||||
PROPERTY COMPILE_FLAGS " ${COVERAGE_${TARGET_COMPILER}_FLAGS}")
|
||||
set_property(TARGET ${TNAME} APPEND_STRING
|
||||
PROPERTY LINK_FLAGS " ${COVERAGE_${TARGET_COMPILER}_FLAGS}")
|
||||
|
||||
|
||||
# Add gcov files generated by compiler to clean target.
|
||||
set(CLEAN_FILES "")
|
||||
foreach (FILE ${ADDITIONAL_FILES})
|
||||
codecov_path_of_source(${FILE} FILE)
|
||||
list(APPEND CLEAN_FILES "CMakeFiles/${TNAME}.dir/${FILE}")
|
||||
endforeach()
|
||||
|
||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
|
||||
"${CLEAN_FILES}")
|
||||
|
||||
|
||||
add_gcov_target(${TNAME})
|
||||
add_lcov_target(${TNAME})
|
||||
endfunction(add_coverage_target)
|
||||
|
||||
|
||||
|
||||
|
||||
# Include modules for parsing the collected data and output it in a readable
|
||||
# format (like gcov and lcov).
|
||||
find_package(Gcov)
|
||||
find_package(Lcov)
|
10
CMake/catch2-with-main.pc.in
Normal file
10
CMake/catch2-with-main.pc.in
Normal file
@ -0,0 +1,10 @@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
pkg_version=@Catch2_VERSION@
|
||||
|
||||
Name: Catch2-With-Main
|
||||
Description: A modern, C++-native test framework for C++14 and above (links in default main)
|
||||
Version: ${pkg_version}
|
||||
Requires: catch2 = ${pkg_version}
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lCatch2Main
|
11
CMake/catch2.pc.in
Normal file
11
CMake/catch2.pc.in
Normal file
@ -0,0 +1,11 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
|
||||
Name: Catch2
|
||||
Description: A modern, C++-native, test framework for C++14 and above
|
||||
URL: https://github.com/catchorg/Catch2
|
||||
Version: @Catch2_VERSION@
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lCatch2
|
56
CMake/llvm-cov-wrapper
Executable file
56
CMake/llvm-cov-wrapper
Executable file
@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This file is part of CMake-codecov.
|
||||
#
|
||||
# Copyright (c)
|
||||
# 2015-2017 RWTH Aachen University, Federal Republic of Germany
|
||||
#
|
||||
# See the LICENSE file in the package base directory for details
|
||||
#
|
||||
# Written by Alexander Haase, alexander.haase@rwth-aachen.de
|
||||
#
|
||||
|
||||
if [ -z "$LLVM_COV_BIN" ]
|
||||
then
|
||||
echo "LLVM_COV_BIN not set!" >& 2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Get LLVM version to find out.
|
||||
LLVM_VERSION=$($LLVM_COV_BIN -version | grep -i "LLVM version" \
|
||||
| sed "s/^\([A-Za-z ]*\)\([0-9]\).\([0-9]\).*$/\2.\3/g")
|
||||
|
||||
if [ "$1" = "-v" ]
|
||||
then
|
||||
echo "llvm-cov-wrapper $LLVM_VERSION"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [ -n "$LLVM_VERSION" ]
|
||||
then
|
||||
MAJOR=$(echo $LLVM_VERSION | cut -d'.' -f1)
|
||||
MINOR=$(echo $LLVM_VERSION | cut -d'.' -f2)
|
||||
|
||||
if [ $MAJOR -eq 3 ] && [ $MINOR -le 4 ]
|
||||
then
|
||||
if [ -f "$1" ]
|
||||
then
|
||||
filename=$(basename "$1")
|
||||
extension="${filename##*.}"
|
||||
|
||||
case "$extension" in
|
||||
"gcno") exec $LLVM_COV_BIN --gcno="$1" ;;
|
||||
"gcda") exec $LLVM_COV_BIN --gcda="$1" ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $MAJOR -eq 3 ] && [ $MINOR -le 5 ]
|
||||
then
|
||||
exec $LLVM_COV_BIN $@
|
||||
fi
|
||||
fi
|
||||
|
||||
exec $LLVM_COV_BIN gcov $@
|
502
CMakeLists.txt
502
CMakeLists.txt
@ -1,333 +1,205 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(CatchSelfTest)
|
||||
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# define some folders
|
||||
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
||||
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
|
||||
set(HEADER_DIR ${CATCH_DIR}/include)
|
||||
|
||||
if(USE_CPP14)
|
||||
message(STATUS "Enabling C++14")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
|
||||
# detect if Catch is being bundled,
|
||||
# disable testsuite in that case
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
set(NOT_SUBPROJECT ON)
|
||||
else()
|
||||
message(STATUS "Enabling C++11")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
set(NOT_SUBPROJECT OFF)
|
||||
endif()
|
||||
|
||||
if(USE_WMAIN)
|
||||
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
||||
option(CATCH_INSTALL_EXTRAS "Install extras (CMake scripts, debugger helpers) alongside library" ON)
|
||||
option(CATCH_DEVELOPMENT_BUILD "Build tests, enable warnings, enable Werror, etc" OFF)
|
||||
|
||||
include(CMakeDependentOption)
|
||||
cmake_dependent_option(CATCH_BUILD_TESTING "Build the SelfTest project" ON "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_BUILD_EXAMPLES "Build code examples" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_BUILD_FUZZERS "Build fuzzers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_WERROR "Enables Werror during build" ON "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building surrogate TUs for the main headers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_CONFIGURE_TESTS "Enable CMake configuration tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
|
||||
|
||||
# Catch2's build breaks if done in-tree. You probably should not build
|
||||
# things in tree anyway, but we can allow projects that include Catch2
|
||||
# as a subproject to build in-tree as long as it is not in our tree.
|
||||
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.8)
|
||||
# Enable IPO for CMake versions that support it
|
||||
cmake_policy(SET CMP0069 NEW)
|
||||
endif()
|
||||
|
||||
|
||||
project(Catch2
|
||||
VERSION 3.1.0 # CML version placeholder, don't delete
|
||||
LANGUAGES CXX
|
||||
# HOMEPAGE_URL is not supported until CMake version 3.12, which
|
||||
# we do not target yet.
|
||||
# HOMEPAGE_URL "https://github.com/catchorg/Catch2"
|
||||
DESCRIPTION "A modern, C++-native, unit test framework."
|
||||
)
|
||||
|
||||
|
||||
# Provide path for scripts. We first add path to the scripts we don't use,
|
||||
# but projects including us might, and set the path up to parent scope.
|
||||
# Then we also add path that we use to configure the project, but is of
|
||||
# no use to top level projects.
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extras")
|
||||
if (NOT NOT_SUBPROJECT)
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
|
||||
endif()
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(CatchConfigOptions)
|
||||
if(CATCH_DEVELOPMENT_BUILD)
|
||||
include(CTest)
|
||||
endif()
|
||||
|
||||
# This variable is used in some subdirectories, so we need it here, rather
|
||||
# than later in the install block
|
||||
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
||||
|
||||
# We have some Windows builds that test `wmain` entry point,
|
||||
# and we need this change to be present in all binaries that
|
||||
# are built during these tests, so this is required here, before
|
||||
# the subdirectories are added.
|
||||
if(CATCH_TEST_USE_WMAIN)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
||||
endif()
|
||||
|
||||
#checks that the given hard-coded list contains all headers + sources in the given folder
|
||||
function(CheckFileList LIST_VAR FOLDER)
|
||||
set(MESSAGE " should be added to the variable ${LIST_VAR}")
|
||||
set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
|
||||
file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp"
|
||||
"${FOLDER}/*.hpp"
|
||||
"${FOLDER}/*.h")
|
||||
list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
|
||||
foreach(EXTRA_ITEM ${GLOBBED_LIST})
|
||||
string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
|
||||
message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(CheckFileListRec LIST_VAR FOLDER)
|
||||
set(MESSAGE " should be added to the variable ${LIST_VAR}")
|
||||
set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
|
||||
file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp"
|
||||
"${FOLDER}/*.hpp"
|
||||
"${FOLDER}/*.h")
|
||||
list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
|
||||
foreach(EXTRA_ITEM ${GLOBBED_LIST})
|
||||
string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
|
||||
message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
# Basic paths
|
||||
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(SOURCES_DIR ${CATCH_DIR}/src/catch2)
|
||||
set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
|
||||
set(BENCHMARK_DIR ${CATCH_DIR}/tests/Benchmark)
|
||||
set(EXAMPLES_DIR ${CATCH_DIR}/examples)
|
||||
|
||||
# define the sources of the self test
|
||||
# Please keep these ordered alphabetically
|
||||
set(TEST_SOURCES
|
||||
${SELF_TEST_DIR}/ApproxTests.cpp
|
||||
${SELF_TEST_DIR}/BDDTests.cpp
|
||||
${SELF_TEST_DIR}/Benchmark.tests.cpp
|
||||
${SELF_TEST_DIR}/ClassTests.cpp
|
||||
${SELF_TEST_DIR}/CmdLineTests.cpp
|
||||
${SELF_TEST_DIR}/CompilationTests.cpp
|
||||
${SELF_TEST_DIR}/ConditionTests.cpp
|
||||
${SELF_TEST_DIR}/DecompositionTests.cpp
|
||||
${SELF_TEST_DIR}/EnumToString.cpp
|
||||
${SELF_TEST_DIR}/ExceptionTests.cpp
|
||||
${SELF_TEST_DIR}/MessageTests.cpp
|
||||
${SELF_TEST_DIR}/MiscTests.cpp
|
||||
${SELF_TEST_DIR}/PartTrackerTests.cpp
|
||||
${SELF_TEST_DIR}/TagAliasTests.cpp
|
||||
${SELF_TEST_DIR}/TestMain.cpp
|
||||
${SELF_TEST_DIR}/ToStringChrono.cpp
|
||||
${SELF_TEST_DIR}/ToStringGeneralTests.cpp
|
||||
${SELF_TEST_DIR}/ToStringPair.cpp
|
||||
${SELF_TEST_DIR}/ToStringTuple.cpp
|
||||
${SELF_TEST_DIR}/ToStringVector.cpp
|
||||
${SELF_TEST_DIR}/ToStringWhich.cpp
|
||||
${SELF_TEST_DIR}/TrickyTests.cpp
|
||||
${SELF_TEST_DIR}/VariadicMacrosTests.cpp
|
||||
${SELF_TEST_DIR}/MatchersTests.cpp
|
||||
${SELF_TEST_DIR}/StringRef.tests.cpp
|
||||
)
|
||||
CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
|
||||
# We need to bring-in the variables defined there to this scope
|
||||
add_subdirectory(src)
|
||||
|
||||
# A set of impl files that just #include a single header
|
||||
# Please keep these ordered alphabetically
|
||||
set(SURROGATE_SOURCES
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
|
||||
${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
|
||||
)
|
||||
CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
|
||||
|
||||
|
||||
# Please keep these ordered alphabetically
|
||||
set(TOP_LEVEL_HEADERS
|
||||
${HEADER_DIR}/catch.hpp
|
||||
${HEADER_DIR}/catch_with_main.hpp
|
||||
)
|
||||
CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
|
||||
|
||||
# Please keep these ordered alphabetically
|
||||
set(EXTERNAL_HEADERS
|
||||
${HEADER_DIR}/external/clara.hpp
|
||||
)
|
||||
CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
|
||||
|
||||
|
||||
# Please keep these ordered alphabetically
|
||||
set(INTERNAL_HEADERS
|
||||
${HEADER_DIR}/internal/catch_approx.h
|
||||
${HEADER_DIR}/internal/catch_assertionhandler.h
|
||||
${HEADER_DIR}/internal/catch_assertioninfo.h
|
||||
${HEADER_DIR}/internal/catch_assertionresult.h
|
||||
${HEADER_DIR}/internal/catch_capture.hpp
|
||||
${HEADER_DIR}/internal/catch_capture_matchers.h
|
||||
${HEADER_DIR}/internal/catch_clara.h
|
||||
${HEADER_DIR}/internal/catch_commandline.h
|
||||
${HEADER_DIR}/internal/catch_common.h
|
||||
${HEADER_DIR}/internal/catch_compiler_capabilities.h
|
||||
${HEADER_DIR}/internal/catch_config.hpp
|
||||
${HEADER_DIR}/internal/catch_console_colour.h
|
||||
${HEADER_DIR}/internal/catch_context.h
|
||||
${HEADER_DIR}/internal/catch_debug_console.h
|
||||
${HEADER_DIR}/internal/catch_debugger.h
|
||||
${HEADER_DIR}/internal/catch_decomposer.h
|
||||
${HEADER_DIR}/internal/catch_default_main.hpp
|
||||
${HEADER_DIR}/internal/catch_enforce.h
|
||||
${HEADER_DIR}/internal/catch_errno_guard.h
|
||||
${HEADER_DIR}/internal/catch_exception_translator_registry.h
|
||||
${HEADER_DIR}/internal/catch_external_interfaces.h
|
||||
${HEADER_DIR}/internal/catch_fatal_condition.h
|
||||
${HEADER_DIR}/internal/catch_impl.hpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_capture.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_config.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_exception.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_reporter.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_runner.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
|
||||
${HEADER_DIR}/internal/catch_interfaces_testcase.h
|
||||
${HEADER_DIR}/internal/catch_leak_detector.h
|
||||
${HEADER_DIR}/internal/catch_list.h
|
||||
${HEADER_DIR}/internal/catch_matchers.h
|
||||
${HEADER_DIR}/internal/catch_matchers_string.h
|
||||
${HEADER_DIR}/internal/catch_matchers_vector.h
|
||||
${HEADER_DIR}/internal/catch_message.h
|
||||
${HEADER_DIR}/internal/catch_objc.hpp
|
||||
${HEADER_DIR}/internal/catch_objc_arc.hpp
|
||||
${HEADER_DIR}/internal/catch_option.hpp
|
||||
${HEADER_DIR}/internal/catch_platform.h
|
||||
${HEADER_DIR}/internal/catch_random_number_generator.h
|
||||
${HEADER_DIR}/internal/catch_reenable_warnings.h
|
||||
${HEADER_DIR}/internal/catch_reporter_registrars.hpp
|
||||
${HEADER_DIR}/internal/catch_reporter_registry.h
|
||||
${HEADER_DIR}/internal/catch_result_type.h
|
||||
${HEADER_DIR}/internal/catch_run_context.h
|
||||
${HEADER_DIR}/internal/catch_benchmark.h
|
||||
${HEADER_DIR}/internal/catch_section.h
|
||||
${HEADER_DIR}/internal/catch_section_info.h
|
||||
${HEADER_DIR}/internal/catch_session.h
|
||||
${HEADER_DIR}/internal/catch_startup_exception_registry.h
|
||||
${HEADER_DIR}/internal/catch_stream.h
|
||||
${HEADER_DIR}/internal/catch_streambuf.h
|
||||
${HEADER_DIR}/internal/catch_stringref.h
|
||||
${HEADER_DIR}/internal/catch_string_manip.h
|
||||
${HEADER_DIR}/internal/catch_suppress_warnings.h
|
||||
${HEADER_DIR}/internal/catch_tag_alias.h
|
||||
${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.h
|
||||
${HEADER_DIR}/internal/catch_tag_alias_registry.h
|
||||
${HEADER_DIR}/internal/catch_test_case_info.h
|
||||
${HEADER_DIR}/internal/catch_test_case_registry_impl.h
|
||||
${HEADER_DIR}/internal/catch_test_case_tracker.h
|
||||
${HEADER_DIR}/internal/catch_test_registry.h
|
||||
${HEADER_DIR}/internal/catch_test_spec.h
|
||||
${HEADER_DIR}/internal/catch_test_spec_parser.h
|
||||
${HEADER_DIR}/internal/catch_text.h
|
||||
${HEADER_DIR}/internal/catch_timer.h
|
||||
${HEADER_DIR}/internal/catch_tostring.h
|
||||
${HEADER_DIR}/internal/catch_totals.h
|
||||
${HEADER_DIR}/internal/catch_version.h
|
||||
${HEADER_DIR}/internal/catch_wildcard_pattern.h
|
||||
${HEADER_DIR}/internal/catch_windows_h_proxy.h
|
||||
${HEADER_DIR}/internal/catch_xmlwriter.h
|
||||
)
|
||||
set(IMPL_SOURCES
|
||||
${HEADER_DIR}/internal/catch_approx.cpp
|
||||
${HEADER_DIR}/internal/catch_assertionhandler.cpp
|
||||
${HEADER_DIR}/internal/catch_assertionresult.cpp
|
||||
${HEADER_DIR}/internal/catch_benchmark.cpp
|
||||
${HEADER_DIR}/internal/catch_capture_matchers.cpp
|
||||
${HEADER_DIR}/internal/catch_commandline.cpp
|
||||
${HEADER_DIR}/internal/catch_common.cpp
|
||||
${HEADER_DIR}/internal/catch_config.cpp
|
||||
${HEADER_DIR}/internal/catch_console_colour.cpp
|
||||
${HEADER_DIR}/internal/catch_context.cpp
|
||||
${HEADER_DIR}/internal/catch_debug_console.cpp
|
||||
${HEADER_DIR}/internal/catch_debugger.cpp
|
||||
${HEADER_DIR}/internal/catch_decomposer.cpp
|
||||
${HEADER_DIR}/internal/catch_errno_guard.cpp
|
||||
${HEADER_DIR}/internal/catch_exception_translator_registry.cpp
|
||||
${HEADER_DIR}/internal/catch_fatal_condition.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_capture.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_config.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_exception.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_runner.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_testcase.cpp
|
||||
${HEADER_DIR}/internal/catch_list.cpp
|
||||
${HEADER_DIR}/internal/catch_leak_detector.cpp
|
||||
${HEADER_DIR}/internal/catch_matchers.cpp
|
||||
${HEADER_DIR}/internal/catch_matchers_string.cpp
|
||||
${HEADER_DIR}/internal/catch_message.cpp
|
||||
${HEADER_DIR}/internal/catch_registry_hub.cpp
|
||||
${HEADER_DIR}/internal/catch_interfaces_reporter.cpp
|
||||
${HEADER_DIR}/internal/catch_random_number_generator.cpp
|
||||
${HEADER_DIR}/internal/catch_reporter_registry.cpp
|
||||
${HEADER_DIR}/internal/catch_result_type.cpp
|
||||
${HEADER_DIR}/internal/catch_run_context.cpp
|
||||
${HEADER_DIR}/internal/catch_section.cpp
|
||||
${HEADER_DIR}/internal/catch_section_info.cpp
|
||||
${HEADER_DIR}/internal/catch_session.cpp
|
||||
${HEADER_DIR}/internal/catch_startup_exception_registry.cpp
|
||||
${HEADER_DIR}/internal/catch_stream.cpp
|
||||
${HEADER_DIR}/internal/catch_streambuf.cpp
|
||||
${HEADER_DIR}/internal/catch_stringref.cpp
|
||||
${HEADER_DIR}/internal/catch_string_manip.cpp
|
||||
${HEADER_DIR}/internal/catch_tag_alias.cpp
|
||||
${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.cpp
|
||||
${HEADER_DIR}/internal/catch_tag_alias_registry.cpp
|
||||
${HEADER_DIR}/internal/catch_test_case_info.cpp
|
||||
${HEADER_DIR}/internal/catch_test_case_registry_impl.cpp
|
||||
${HEADER_DIR}/internal/catch_test_case_tracker.cpp
|
||||
${HEADER_DIR}/internal/catch_test_registry.cpp
|
||||
${HEADER_DIR}/internal/catch_test_spec.cpp
|
||||
${HEADER_DIR}/internal/catch_test_spec_parser.cpp
|
||||
${HEADER_DIR}/internal/catch_timer.cpp
|
||||
${HEADER_DIR}/internal/catch_tostring.cpp
|
||||
${HEADER_DIR}/internal/catch_totals.cpp
|
||||
${HEADER_DIR}/internal/catch_version.cpp
|
||||
${HEADER_DIR}/internal/catch_wildcard_pattern.cpp
|
||||
${HEADER_DIR}/internal/catch_xmlwriter.cpp
|
||||
)
|
||||
set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS})
|
||||
CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal)
|
||||
|
||||
# Please keep these ordered alphabetically
|
||||
set(REPORTER_HEADERS
|
||||
${HEADER_DIR}/reporters/catch_reporter_automake.hpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_bases.hpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_multi.h
|
||||
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
|
||||
)
|
||||
set(REPORTER_SOURCES
|
||||
${HEADER_DIR}/reporters/catch_reporter_bases.cpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_compact.cpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_console.cpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_junit.cpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_multi.cpp
|
||||
${HEADER_DIR}/reporters/catch_reporter_xml.cpp
|
||||
)
|
||||
set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES})
|
||||
CheckFileList(REPORTER_FILES ${HEADER_DIR}/reporters)
|
||||
|
||||
# Specify the headers, too, so CLion recognises them as project files
|
||||
set(HEADERS
|
||||
${TOP_LEVEL_HEADERS}
|
||||
${EXTERNAL_HEADERS}
|
||||
${INTERNAL_HEADERS}
|
||||
${REPORTER_HEADERS}
|
||||
)
|
||||
|
||||
|
||||
set(BENCH_SOURCES
|
||||
${BENCHMARK_DIR}/BenchMain.cpp
|
||||
${BENCHMARK_DIR}/StringificationBench.cpp
|
||||
)
|
||||
CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
|
||||
|
||||
# Provide some groupings for IDEs
|
||||
SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
|
||||
SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES})
|
||||
SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
|
||||
|
||||
# configure the executable
|
||||
include_directories(${HEADER_DIR})
|
||||
|
||||
add_definitions( -DCATCH_CONFIG_FULL_PROJECT )
|
||||
|
||||
# Projects consuming Catch via ExternalProject_Add might want to use install step
|
||||
# without building all of our selftests.
|
||||
if (NOT NO_SELFTEST)
|
||||
add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS})
|
||||
add_executable(Benchmark ${BENCH_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${HEADERS})
|
||||
|
||||
# Add desired warnings
|
||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
|
||||
target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code )
|
||||
target_compile_options( Benchmark PRIVATE -Wall -Wextra -Wunreachable-code )
|
||||
# Build tests only if requested
|
||||
if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
|
||||
find_package(PythonInterp 3 REQUIRED)
|
||||
if (NOT PYTHONINTERP_FOUND)
|
||||
message(FATAL_ERROR "Python not found, but required for tests")
|
||||
endif()
|
||||
# Clang specific warning go here
|
||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
||||
# Actually keep these
|
||||
target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
|
||||
endif()
|
||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
||||
target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )
|
||||
target_compile_options( Benchmark PRIVATE /W4 )
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
if(CATCH_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
if(CATCH_BUILD_EXTRA_TESTS)
|
||||
add_subdirectory(tests/ExtraTests)
|
||||
endif()
|
||||
|
||||
if(CATCH_BUILD_FUZZERS)
|
||||
add_subdirectory(fuzzing)
|
||||
endif()
|
||||
|
||||
if (CATCH_DEVELOPMENT_BUILD)
|
||||
add_warnings_to_targets("${CATCH_WARNING_TARGETS}")
|
||||
endif()
|
||||
|
||||
# Only perform the installation steps when Catch is not being used as
|
||||
# a subproject via `add_subdirectory`, or the destinations will break,
|
||||
# see https://github.com/catchorg/Catch2/issues/1373
|
||||
if (NOT_SUBPROJECT)
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
||||
INSTALL_DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
||||
DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
|
||||
# Install documentation
|
||||
if(CATCH_INSTALL_DOCS)
|
||||
install(
|
||||
DIRECTORY
|
||||
docs/
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_DOCDIR}"
|
||||
PATTERN "doxygen" EXCLUDE
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CATCH_INSTALL_EXTRAS)
|
||||
# Install CMake scripts
|
||||
install(
|
||||
FILES
|
||||
"extras/ParseAndAddCatchTests.cmake"
|
||||
"extras/Catch.cmake"
|
||||
"extras/CatchAddTests.cmake"
|
||||
DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
|
||||
# Install debugger helpers
|
||||
install(
|
||||
FILES
|
||||
"extras/gdbinit"
|
||||
"extras/lldbinit"
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_DATAROOTDIR}/Catch2
|
||||
)
|
||||
endif()
|
||||
|
||||
# configure unit tests via CTest
|
||||
enable_testing()
|
||||
add_test(NAME RunTests COMMAND SelfTest)
|
||||
## Provide some pkg-config integration
|
||||
set(PKGCONFIG_INSTALL_DIR
|
||||
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
|
||||
CACHE PATH "Path where catch2.pc is installed"
|
||||
)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
|
||||
@ONLY
|
||||
)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc
|
||||
@ONLY
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc"
|
||||
DESTINATION
|
||||
${PKGCONFIG_INSTALL_DIR}
|
||||
)
|
||||
|
||||
add_test(NAME ListTests COMMAND SelfTest --list-tests)
|
||||
set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
|
||||
# CPack/CMake started taking the package version from project version 3.12
|
||||
# So we need to set the version manually for older CMake versions
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
endif()
|
||||
|
||||
add_test(NAME ListTags COMMAND SelfTest --list-tags)
|
||||
set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
|
||||
|
||||
# AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable
|
||||
add_test(NAME ApprovalTests COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
|
||||
set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
|
||||
endif() # !NO_SELFTEST
|
||||
set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
|
||||
|
||||
|
||||
install(DIRECTORY "single_include/" DESTINATION "include/catch")
|
||||
include( CPack )
|
||||
|
||||
endif(NOT_SUBPROJECT)
|
||||
|
25
CMakePresets.json
Normal file
25
CMakePresets.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "basic-tests",
|
||||
"displayName": "Basic development build",
|
||||
"description": "Enables development build with basic tests that are cheap to build and run",
|
||||
"cacheVariables": {
|
||||
"CATCH_DEVELOPMENT_BUILD": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "all-tests",
|
||||
"inherits": "basic-tests",
|
||||
"displayName": "Full development build",
|
||||
"description": "Enables development build with examples and ALL tests",
|
||||
"cacheVariables": {
|
||||
"CATCH_BUILD_EXAMPLES": "ON",
|
||||
"CATCH_BUILD_EXTRA_TESTS": "ON",
|
||||
"CATCH_BUILD_SURROGATES": "ON",
|
||||
"CATCH_ENABLE_CONFIGURE_TESTS": "ON"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
52
README.md
52
README.md
@ -1,19 +1,41 @@
|
||||
<a id="top"></a>
|
||||

|
||||

|
||||
|
||||
[](https://github.com/philsquared/catch/releases)
|
||||
[](https://travis-ci.org/philsquared/Catch?branch=catch2)
|
||||
[](https://ci.appveyor.com/project/philsquared/catch/branch/catch2)
|
||||
[](https://github.com/catchorg/catch2/releases)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/linux-other-builds.yml)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/mac-builds.yml)
|
||||
[](https://ci.appveyor.com/project/catchorg/catch2)
|
||||
[](https://codecov.io/gh/catchorg/Catch2)
|
||||
[](https://godbolt.org/z/EdoY15q9G)
|
||||
[](https://discord.gg/4CWS9zD)
|
||||
|
||||
<a href="https://github.com/philsquared/Catch/releases/download/v2.0.0-develop.4/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
|
||||
|
||||
## What's the Catch?
|
||||
## What's the Catch2?
|
||||
|
||||
Catch2 is mainly a unit testing framework for C++, but it also
|
||||
provides basic micro-benchmarking features, and simple BDD macros.
|
||||
|
||||
Catch2's main advantage is that using it is both simple and natural.
|
||||
Tests autoregister themselves and do not have to be named with valid
|
||||
identifiers, assertions look like normal C++ code, and sections provide
|
||||
a nice way to share set-up and tear-down code in tests.
|
||||
|
||||
|
||||
## Catch2 v3 is being developed!
|
||||
|
||||
You are on the `devel` branch, where the next major version, v3, of
|
||||
Catch2 is being developed. As it is a significant rework, you will
|
||||
find that parts of this documentation are likely still stuck on v2.
|
||||
|
||||
For stable (and documentation-matching) version of Catch2, [go to the
|
||||
`v2.x` branch](https://github.com/catchorg/Catch2/tree/v2.x).
|
||||
|
||||
For migrating from the v2 releases to v3, you should look at [our
|
||||
documentation](docs/migrate-v2-to-v3.md#top). It provides a simple
|
||||
guidelines on getting started, and collects most common migration
|
||||
problems.
|
||||
|
||||
Catch stands for C++ Automated Test Cases in Headers and is a
|
||||
multi-paradigm test framework for C++. which also supports Objective-C
|
||||
and, maybe, C.
|
||||
It is primarily distributed as a single header file, although certain
|
||||
extensions may require additional headers.
|
||||
|
||||
## How to use it
|
||||
This documentation comprises these three parts:
|
||||
@ -22,7 +44,9 @@ This documentation comprises these three parts:
|
||||
* [Tutorial](docs/tutorial.md#top) - getting started
|
||||
* [Reference section](docs/Readme.md#top) - all the details
|
||||
|
||||
|
||||
## More
|
||||
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/philsquared/Catch/issues)
|
||||
* For discussion or questions please use [the dedicated Google Groups forum](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)
|
||||
* See [who else is using Catch](docs/opensource-users.md#top)
|
||||
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/catchorg/Catch2/issues)
|
||||
* For discussion or questions please use [our Discord](https://discord.gg/4CWS9zD)
|
||||
* See who else is using Catch2 in [Open Source Software](docs/opensource-users.md#top)
|
||||
or [commercially](docs/commercial-users.md#top).
|
||||
|
19
SECURITY.md
Normal file
19
SECURITY.md
Normal file
@ -0,0 +1,19 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
* Versions 1.x (branch Catch1.x) are no longer supported.
|
||||
* Versions 2.x (branch v2.x) are currently supported.
|
||||
* `devel` branch serves for stable-ish development and is supported,
|
||||
but branches `devel-*` are considered short lived and are not supported separately.
|
||||
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Due to its nature as a _unit_ test framework, Catch2 shouldn't interact
|
||||
with untrusted inputs and there shouldn't be many security vulnerabilities
|
||||
in it.
|
||||
|
||||
However, if you find one you send email to martin <dot> horenovsky <at>
|
||||
gmail <dot> com. If you want to encrypt the email, my pgp key is
|
||||
`E29C 46F3 B8A7 5028 6079 3B7D ECC9 C20E 314B 2360`.
|
14
WORKSPACE
Normal file
14
WORKSPACE
Normal file
@ -0,0 +1,14 @@
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "bazel_skylib",
|
||||
strip_prefix = "bazel-skylib-2a87d4a62af886fb320883aba102255aba87275e",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel-skylib/archive/2a87d4a62af886fb320883aba102255aba87275e.tar.gz",
|
||||
],
|
||||
sha256 = "d847b08d6702d2779e9eb399b54ff8920fa7521dc45e3e53572d1d8907767de7",
|
||||
)
|
||||
|
||||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
|
||||
|
||||
bazel_skylib_workspace()
|
153
appveyor.yml
153
appveyor.yml
@ -1,60 +1,129 @@
|
||||
# version string format -- This will be overwritten later anyway
|
||||
version: "{build}"
|
||||
version: "{build}-{branch}"
|
||||
|
||||
os:
|
||||
- Visual Studio 2017
|
||||
- Visual Studio 2015
|
||||
# If we ever get a backlog larger than clone_depth, builds will fail
|
||||
# spuriously. I do not think we will ever get 20 deep commits deep though.
|
||||
clone_depth: 20
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- additional_flags: "/permissive- /std:c++latest"
|
||||
wmain: 0
|
||||
# We want to build everything, except for branches that are explicitly
|
||||
# for messing around with travis.
|
||||
branches:
|
||||
except:
|
||||
- /dev-travis.+/
|
||||
|
||||
- additional_flags: ""
|
||||
wmain: 0
|
||||
|
||||
- additional_flags: "/D_UNICODE /DUNICODE"
|
||||
wmain: 1
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
-
|
||||
additional_flags: "/permissive- /std:c++latest"
|
||||
os: Visual Studio 2015
|
||||
-
|
||||
additional_flags: "/permissive- /std:c++latest"
|
||||
os: Visual Studio 2013
|
||||
|
||||
# We need a more up to date pip because Python 2.7 is EOL soon
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
# Set build version to git commit-hash
|
||||
- ps: Update-AppveyorBuild -Version "$($env:APPVEYOR_REPO_BRANCH) - $($env:APPVEYOR_REPO_COMMIT)"
|
||||
- set PATH=C:\Python35;C:\Python35\Scripts;%PATH%
|
||||
|
||||
# fetch repository as zip archive
|
||||
shallow_clone: true
|
||||
|
||||
# Win32 and x64 are CMake-compatible solution platform names.
|
||||
# This allows us to pass %PLATFORM% to CMake -A.
|
||||
platform:
|
||||
- Win32
|
||||
- x64
|
||||
install:
|
||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { pip --disable-pip-version-check install codecov }
|
||||
# This removes our changes to PATH. Keep this step last!
|
||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\tools\misc\installOpenCppCoverage.ps1 }
|
||||
|
||||
# build Configurations, i.e. Debug, Release, etc.
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
|
||||
#Cmake will autodetect the compiler, but we set the arch
|
||||
before_build:
|
||||
# We need to modify PATH again, because it was reset since the "init" step
|
||||
- set PATH=C:\Python35;C:\Python35\Scripts;%PATH%
|
||||
- set CXXFLAGS=%additional_flags%
|
||||
- cmake -H. -BBuild -A%PLATFORM% -DUSE_WMAIN=%wmain%
|
||||
# If we are building examples/extra-tests, we need to regenerate the amalgamated files
|
||||
- cmd: if "%examples%"=="1" ( python .\tools\scripts\generateAmalgamatedFiles.py )
|
||||
# Indirection because appveyor doesn't handle multiline batch scripts properly
|
||||
# https://stackoverflow.com/questions/37627248/how-to-split-a-command-over-multiple-lines-in-appveyor-yml/37647169#37647169
|
||||
# https://help.appveyor.com/discussions/questions/3888-multi-line-cmd-or-powershell-warning-ignore
|
||||
- cmd: .\tools\misc\appveyorBuildConfigurationScript.bat
|
||||
|
||||
|
||||
# build with MSBuild
|
||||
build:
|
||||
project: Build\CatchSelfTest.sln # path to Visual Studio solution or project
|
||||
project: Build\Catch2.sln # path to Visual Studio solution or project
|
||||
parallel: true # enable MSBuild parallel builds
|
||||
verbosity: normal # MSBuild verbosity level {quiet|minimal|normal|detailed}
|
||||
|
||||
test_script:
|
||||
- cd Build
|
||||
- ctest -V -j 2 -C %CONFIGURATION%
|
||||
- set CTEST_OUTPUT_ON_FAILURE=1
|
||||
- cmd: .\tools\misc\appveyorTestRunScript.bat
|
||||
|
||||
|
||||
# Sadly we cannot use the standard "dimensions" based approach towards
|
||||
# specifying the different builds, as there is no way to add one-offs
|
||||
# builds afterwards. This means that we will painfully specify each
|
||||
# build explicitly.
|
||||
environment:
|
||||
matrix:
|
||||
- FLAVOR: VS 2019 x64 Debug Surrogates Configure Tests
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
surrogates: 1
|
||||
configure_tests: 1
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2019 x64 Release
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
platform: x64
|
||||
configuration: Release
|
||||
|
||||
- FLAVOR: VS 2019 x64 Debug Coverage Examples
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
examples: 1
|
||||
coverage: 1
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2019 x64 Debug WMain
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
wmain: 1
|
||||
additional_flags: "/D_UNICODE /DUNICODE"
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2019 Win32 Debug
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
platform: Win32
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2019 x64 Debug Latest Strict
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
additional_flags: "/permissive- /std:c++latest"
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2017 x64 Debug
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2017 x64 Release
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
platform: x64
|
||||
configuration: Release
|
||||
|
||||
- FLAVOR: VS 2017 x64 Release Coverage
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
coverage: 1
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2017 Win32 Debug
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
platform: Win32
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2017 Win32 Debug Examples
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
examples: 1
|
||||
platform: Win32
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2017 Win32 Debug WMain
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
wmain: 1
|
||||
additional_flags: "/D_UNICODE /DUNICODE"
|
||||
platform: Win32
|
||||
configuration: Debug
|
||||
|
||||
- FLAVOR: VS 2017 x64 Debug Latest Strict
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
additional_flags: "/permissive- /std:c++latest"
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 52 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
22
codecov.yml
Normal file
22
codecov.yml
Normal file
@ -0,0 +1,22 @@
|
||||
coverage:
|
||||
precision: 2
|
||||
round: nearest
|
||||
range: "60...90"
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
threshold: 2%
|
||||
patch:
|
||||
default:
|
||||
target: 80%
|
||||
ignore:
|
||||
- "**/external/clara.hpp"
|
||||
- "tests"
|
||||
|
||||
|
||||
codecov:
|
||||
branch: devel
|
||||
max_report_age: off
|
||||
|
||||
comment:
|
||||
layout: "diff"
|
64
conanfile.py
64
conanfile.py
@ -1,16 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
from conans import ConanFile
|
||||
|
||||
from conans import ConanFile, CMake, tools
|
||||
|
||||
class CatchConan(ConanFile):
|
||||
name = "Catch"
|
||||
version = "2.0.0-develop.5"
|
||||
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
|
||||
author = "philsquared"
|
||||
name = "catch2"
|
||||
description = "A modern, C++-native, framework for unit-tests, TDD and BDD"
|
||||
topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
|
||||
url = "https://github.com/catchorg/Catch2"
|
||||
homepage = url
|
||||
license = "BSL-1.0"
|
||||
|
||||
exports = "LICENSE.txt"
|
||||
exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*")
|
||||
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
|
||||
generators = "cmake"
|
||||
exports_sources = "single_include/*"
|
||||
url = "https://github.com/philsquared/Catch"
|
||||
license = "Boost Software License - Version 1.0. http://www.boost.org/LICENSE_1_0.txt"
|
||||
|
||||
def _configure_cmake(self):
|
||||
cmake = CMake(self)
|
||||
cmake.definitions["BUILD_TESTING"] = "OFF"
|
||||
cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
|
||||
cmake.definitions["CATCH_INSTALL_EXTRAS"] = "ON"
|
||||
cmake.configure(build_folder="build")
|
||||
return cmake
|
||||
|
||||
def build(self):
|
||||
# We need this workaround until the toolchains feature
|
||||
# to inject stuff like MD/MT
|
||||
line_to_replace = 'list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")'
|
||||
tools.replace_in_file("CMakeLists.txt", line_to_replace,
|
||||
'''{}
|
||||
include("{}/conanbuildinfo.cmake")
|
||||
conan_basic_setup()'''.format(line_to_replace, self.install_folder.replace("\\", "/")))
|
||||
|
||||
cmake = self._configure_cmake()
|
||||
cmake.build()
|
||||
|
||||
def package(self):
|
||||
self.copy(pattern="catch.hpp", src="single_include", dst="include")
|
||||
self.copy(pattern="LICENSE.txt", dst="licenses")
|
||||
cmake = self._configure_cmake()
|
||||
cmake.install()
|
||||
|
||||
def package_info(self):
|
||||
lib_suffix = "d" if self.settings.build_type == "Debug" else ""
|
||||
|
||||
self.cpp_info.names["cmake_find_package"] = "Catch2"
|
||||
self.cpp_info.names["cmake_find_package_multi"] = "Catch2"
|
||||
# Catch2
|
||||
self.cpp_info.components["catch2base"].names["cmake_find_package"] = "Catch2"
|
||||
self.cpp_info.components["catch2base"].names["cmake_find_package_multi"] = "Catch2"
|
||||
self.cpp_info.components["catch2base"].names["pkg_config"] = "Catch2"
|
||||
self.cpp_info.components["catch2base"].libs = ["Catch2" + lib_suffix]
|
||||
self.cpp_info.components["catch2base"].builddirs.append("lib/cmake/Catch2")
|
||||
# Catch2WithMain
|
||||
self.cpp_info.components["catch2main"].names["cmake_find_package"] = "Catch2WithMain"
|
||||
self.cpp_info.components["catch2main"].names["cmake_find_package_multi"] = "Catch2WithMain"
|
||||
self.cpp_info.components["catch2main"].names["pkg_config"] = "Catch2WithMain"
|
||||
self.cpp_info.components["catch2main"].libs = ["Catch2Main" + lib_suffix]
|
||||
self.cpp_info.components["catch2main"].requires = ["catch2base"]
|
||||
|
BIN
data/artwork/catch2-c-logo.png
Normal file
BIN
data/artwork/catch2-c-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
data/artwork/catch2-hand-logo.png
Normal file
BIN
data/artwork/catch2-hand-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
data/artwork/catch2-logo-small.png
Normal file
BIN
data/artwork/catch2-logo-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@ -1,7 +1,7 @@
|
||||
<a id="top"></a>
|
||||
# Reference
|
||||
|
||||
To get the most out of Catch, start with the [tutorial](tutorial.md#top).
|
||||
To get the most out of Catch2, start with the [tutorial](tutorial.md#top).
|
||||
Once you're up and running consider the following reference material.
|
||||
|
||||
Writing tests:
|
||||
@ -12,6 +12,9 @@ Writing tests:
|
||||
* [Test fixtures](test-fixtures.md#top)
|
||||
* [Reporters](reporters.md#top)
|
||||
* [Event Listeners](event-listeners.md#top)
|
||||
* [Data Generators](generators.md#top)
|
||||
* [Other macros](other-macros.md#top)
|
||||
* [Micro benchmarking](benchmarks.md#top)
|
||||
|
||||
Fine tuning:
|
||||
* [Supplying your own main()](own-main.md#top)
|
||||
@ -20,14 +23,19 @@ Fine tuning:
|
||||
|
||||
Running:
|
||||
* [Command line](command-line.md#top)
|
||||
* [CI and Build system integration](build-systems.md#top)
|
||||
|
||||
FAQ:
|
||||
* [Why are my tests slow to compile?](slow-compiles.md#top)
|
||||
Odds and ends:
|
||||
* [Frequently Asked Questions (FAQ)](faq.md#top)
|
||||
* [Best practices and other tips](usage-tips.md#top)
|
||||
* [CMake integration](cmake-integration.md#top)
|
||||
* [CI and other miscellaneous pieces](ci-and-misc.md#top)
|
||||
* [Known limitations](limitations.md#top)
|
||||
|
||||
Other:
|
||||
* [Why Catch?](why-catch.md#top)
|
||||
* [Open Source Projects using Catch](opensource-users.md#top)
|
||||
* [Why Catch2?](why-catch.md#top)
|
||||
* [Migrating from v2 to v3](migrate-v2-to-v3.md#top)
|
||||
* [Open Source Projects using Catch2](opensource-users.md#top)
|
||||
* [Commercial Projects using Catch2](commercial-users.md#top)
|
||||
* [Contributing](contributing.md#top)
|
||||
* [Release Notes](release-notes.md#top)
|
||||
* [Deprecations and incoming changes](deprecations.md#top)
|
||||
|
@ -1,15 +1,16 @@
|
||||
<a id="top"></a>
|
||||
# Assertion Macros
|
||||
|
||||
**Contents**
|
||||
[Natural Expressions](#natural-expressions)
|
||||
[Exceptions](#exceptions)
|
||||
[Matcher expressions](#matcher-expressions)
|
||||
[Thread Safety](#thread-safety)
|
||||
**Contents**<br>
|
||||
[Natural Expressions](#natural-expressions)<br>
|
||||
[Exceptions](#exceptions)<br>
|
||||
[Matcher expressions](#matcher-expressions)<br>
|
||||
[Thread Safety](#thread-safety)<br>
|
||||
[Expressions with commas](#expressions-with-commas)<br>
|
||||
|
||||
Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (```_EQUALS```, ```_NOTEQUALS```, ```_GREATER_THAN``` etc).
|
||||
|
||||
Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there are a rich set of auxilliary macros as well. We'll describe all of these here.
|
||||
Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there is a rich set of auxiliary macros as well. We'll describe all of these here.
|
||||
|
||||
Most of these macros come in two forms:
|
||||
|
||||
@ -21,7 +22,7 @@ The ```CHECK``` family are equivalent but execution continues in the same test c
|
||||
* **REQUIRE(** _expression_ **)** and
|
||||
* **CHECK(** _expression_ **)**
|
||||
|
||||
Evaluates the expression and records the result. If an exception is thrown it is caught, reported, and counted as a failure. These are the macros you will use most of the time
|
||||
Evaluates the expression and records the result. If an exception is thrown, it is caught, reported, and counted as a failure. These are the macros you will use most of the time.
|
||||
|
||||
Examples:
|
||||
```
|
||||
@ -54,37 +55,54 @@ This expression is too complex because of the `||` operator. If you want to chec
|
||||
|
||||
When comparing floating point numbers - especially if at least one of them has been computed - great care must be taken to allow for rounding errors and inexact representations.
|
||||
|
||||
Catch provides a way to perform tolerant comparisons of floating point values through use of a wrapper class called ```Approx```. ```Approx``` can be used on either side of a comparison expression. It overloads the comparisons operators to take a tolerance into account. Here's a simple example:
|
||||
Catch provides a way to perform tolerant comparisons of floating point values through use of a wrapper class called `Approx`. `Approx` can be used on either side of a comparison expression. It overloads the comparisons operators to take a tolerance into account. Here's a simple example:
|
||||
|
||||
```
|
||||
```cpp
|
||||
REQUIRE( performComputation() == Approx( 2.1 ) );
|
||||
```
|
||||
|
||||
This way `Approx` is constructed with reasonable defaults, covering most simple cases of rounding errors. If these are insufficient, each `Approx` instance has 3 tuning knobs, that can be used to customize it for your computation.
|
||||
Catch also provides a user-defined literal for `Approx`; `_a`. It resides in
|
||||
the `Catch::literals` namespace and can be used like so:
|
||||
```cpp
|
||||
using namespace Catch::literals;
|
||||
REQUIRE( performComputation() == 2.1_a );
|
||||
```
|
||||
|
||||
* __epsilon__ - epsilon serves to set the percentage by which a result can be erroneous, before it is rejected. By default set to `std::numeric_limits<float>::epsilon()*100`.
|
||||
* __margin__ - margin serves to set the the absolute value by which a result can be erroneous before it is rejected. By default set to `0.0`.
|
||||
* __scale__ - scale serves to adjust the base for comparison used by epsilon, can be used when By default set to `1.0`.
|
||||
`Approx` is constructed with defaults that should cover most simple cases.
|
||||
For the more complex cases, `Approx` provides 3 customization points:
|
||||
|
||||
* __epsilon__ - epsilon serves to set the coefficient by which a result
|
||||
can differ from `Approx`'s value before it is rejected.
|
||||
_By default set to `std::numeric_limits<float>::epsilon()*100`._
|
||||
* __margin__ - margin serves to set the the absolute value by which
|
||||
a result can differ from `Approx`'s value before it is rejected.
|
||||
_By default set to `0.0`._
|
||||
* __scale__ - scale is used to change the magnitude of `Approx` for relative check.
|
||||
_By default set to `0.0`._
|
||||
|
||||
#### epsilon example
|
||||
```cpp
|
||||
Approx target = Approx(100).epsilon(0.01);
|
||||
100.0 == target; // Obviously true
|
||||
200.0 == target; // Obviously still false
|
||||
100.5 == target; // True, because we set target to allow up to 1% error
|
||||
100.5 == target; // True, because we set target to allow up to 1% difference
|
||||
```
|
||||
|
||||
#### margin example
|
||||
_Margin check is used only if the relative (epsilon and scale based) check fails._
|
||||
```cpp
|
||||
Approx target = Approx(100).margin(5);
|
||||
100.0 == target; // Obviously true
|
||||
200.0 == target; // Obviously still false
|
||||
104.0 == target; // True, because we set target to allow absolute error up to 5
|
||||
104.0 == target; // True, because we set target to allow absolute difference of at most 5
|
||||
```
|
||||
|
||||
#### scale
|
||||
Scale can be useful if the computation leading to the result worked on different scale, than is used by the results (and thus expected errors are on a different scale than would be expected based on the results alone).
|
||||
Scale can be useful if the computation leading to the result worked
|
||||
on different scale than is used by the results. Since allowed difference
|
||||
between Approx's value and compared value is based primarily on Approx's value
|
||||
(the allowed difference is computed as
|
||||
`(Approx::scale + Approx::value) * epsilon`), the resulting comparison could
|
||||
need rescaling to be correct.
|
||||
|
||||
|
||||
## Exceptions
|
||||
@ -118,7 +136,7 @@ REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
|
||||
* **REQUIRE_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)** and
|
||||
* **CHECK_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)**
|
||||
|
||||
Expects that exception of _exception type_ is thrown and it matches provided matcher (see next section for Matchers).
|
||||
Expects that exception of _exception type_ is thrown and it matches provided matcher (see the [documentation for Matchers](matchers.md#top)).
|
||||
|
||||
|
||||
_Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function._
|
||||
@ -150,6 +168,34 @@ Matchers can be composed using `&&`, `||` and `!` operators.
|
||||
Currently assertions in Catch are not thread safe.
|
||||
For more details, along with workarounds, see the section on [the limitations page](limitations.md#thread-safe-assertions).
|
||||
|
||||
## Expressions with commas
|
||||
|
||||
Because the preprocessor parses code using different rules than the
|
||||
compiler, multiple-argument assertions (e.g. `REQUIRE_THROWS_AS`) have
|
||||
problems with commas inside the provided expressions. As an example
|
||||
`REQUIRE_THROWS_AS(std::pair<int, int>(1, 2), std::invalid_argument);`
|
||||
will fail to compile, because the preprocessor sees 3 arguments provided,
|
||||
but the macro accepts only 2. There are two possible workarounds.
|
||||
|
||||
1) Use typedef:
|
||||
```cpp
|
||||
using int_pair = std::pair<int, int>;
|
||||
REQUIRE_THROWS_AS(int_pair(1, 2), std::invalid_argument);
|
||||
```
|
||||
|
||||
This solution is always applicable, but makes the meaning of the code
|
||||
less clear.
|
||||
|
||||
2) Parenthesize the expression:
|
||||
```cpp
|
||||
TEST_CASE_METHOD((Fixture<int, int>), "foo", "[bar]") {
|
||||
SUCCEED();
|
||||
}
|
||||
```
|
||||
|
||||
This solution is not always applicable, because it might require extra
|
||||
changes on the Catch's side to work.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
251
docs/benchmarks.md
Normal file
251
docs/benchmarks.md
Normal file
@ -0,0 +1,251 @@
|
||||
<a id="top"></a>
|
||||
# Authoring benchmarks
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
Writing benchmarks is not easy. Catch simplifies certain aspects but you'll
|
||||
always need to take care about various aspects. Understanding a few things about
|
||||
the way Catch runs your code will be very helpful when writing your benchmarks.
|
||||
|
||||
First off, let's go over some terminology that will be used throughout this
|
||||
guide.
|
||||
|
||||
- *User code*: user code is the code that the user provides to be measured.
|
||||
- *Run*: one run is one execution of the user code. Sometimes also referred
|
||||
to as an _iteration_.
|
||||
- *Sample*: one sample is one data point obtained by measuring the time it takes
|
||||
to perform a certain number of runs. One sample can consist of more than one
|
||||
run if the clock available does not have enough resolution to accurately
|
||||
measure a single run. All samples for a given benchmark execution are obtained
|
||||
with the same number of runs.
|
||||
|
||||
## Execution procedure
|
||||
|
||||
Now I can explain how a benchmark is executed in Catch. There are three main
|
||||
steps, though the first does not need to be repeated for every benchmark.
|
||||
|
||||
1. *Environmental probe*: before any benchmarks can be executed, the clock's
|
||||
resolution is estimated. A few other environmental artifacts are also estimated
|
||||
at this point, like the cost of calling the clock function, but they almost
|
||||
never have any impact in the results.
|
||||
|
||||
2. *Estimation*: the user code is executed a few times to obtain an estimate of
|
||||
the amount of runs that should be in each sample. This also has the potential
|
||||
effect of bringing relevant code and data into the caches before the actual
|
||||
measurement starts.
|
||||
|
||||
3. *Measurement*: all the samples are collected sequentially by performing the
|
||||
number of runs estimated in the previous step for each sample.
|
||||
|
||||
This already gives us one important rule for writing benchmarks for Catch: the
|
||||
benchmarks must be repeatable. The user code will be executed several times, and
|
||||
the number of times it will be executed during the estimation step cannot be
|
||||
known beforehand since it depends on the time it takes to execute the code.
|
||||
User code that cannot be executed repeatedly will lead to bogus results or
|
||||
crashes.
|
||||
|
||||
## Benchmark specification
|
||||
|
||||
Benchmarks can be specified anywhere inside a Catch test case.
|
||||
There is a simple and a slightly more advanced version of the `BENCHMARK` macro.
|
||||
|
||||
Let's have a look how a naive Fibonacci implementation could be benchmarked:
|
||||
```c++
|
||||
std::uint64_t Fibonacci(std::uint64_t number) {
|
||||
return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2);
|
||||
}
|
||||
```
|
||||
Now the most straight forward way to benchmark this function, is just adding a `BENCHMARK` macro to our test case:
|
||||
```c++
|
||||
TEST_CASE("Fibonacci") {
|
||||
CHECK(Fibonacci(0) == 1);
|
||||
// some more asserts..
|
||||
CHECK(Fibonacci(5) == 8);
|
||||
// some more asserts..
|
||||
|
||||
// now let's benchmark:
|
||||
BENCHMARK("Fibonacci 20") {
|
||||
return Fibonacci(20);
|
||||
};
|
||||
|
||||
BENCHMARK("Fibonacci 25") {
|
||||
return Fibonacci(25);
|
||||
};
|
||||
|
||||
BENCHMARK("Fibonacci 30") {
|
||||
return Fibonacci(30);
|
||||
};
|
||||
|
||||
BENCHMARK("Fibonacci 35") {
|
||||
return Fibonacci(35);
|
||||
};
|
||||
}
|
||||
```
|
||||
There's a few things to note:
|
||||
- As `BENCHMARK` expands to a lambda expression it is necessary to add a semicolon after
|
||||
the closing brace (as opposed to the first experimental version).
|
||||
- The `return` is a handy way to avoid the compiler optimizing away the benchmark code.
|
||||
|
||||
Running this already runs the benchmarks and outputs something similar to:
|
||||
```
|
||||
-------------------------------------------------------------------------------
|
||||
Fibonacci
|
||||
-------------------------------------------------------------------------------
|
||||
C:\path\to\Catch2\Benchmark.tests.cpp(10)
|
||||
...............................................................................
|
||||
benchmark name samples iterations estimated
|
||||
mean low mean high mean
|
||||
std dev low std dev high std dev
|
||||
-------------------------------------------------------------------------------
|
||||
Fibonacci 20 100 416439 83.2878 ms
|
||||
2 ns 2 ns 2 ns
|
||||
0 ns 0 ns 0 ns
|
||||
|
||||
Fibonacci 25 100 400776 80.1552 ms
|
||||
3 ns 3 ns 3 ns
|
||||
0 ns 0 ns 0 ns
|
||||
|
||||
Fibonacci 30 100 396873 79.3746 ms
|
||||
17 ns 17 ns 17 ns
|
||||
0 ns 0 ns 0 ns
|
||||
|
||||
Fibonacci 35 100 145169 87.1014 ms
|
||||
468 ns 464 ns 473 ns
|
||||
21 ns 15 ns 34 ns
|
||||
```
|
||||
|
||||
### Advanced benchmarking
|
||||
The simplest use case shown above, takes no arguments and just runs the user code that needs to be measured.
|
||||
However, if using the `BENCHMARK_ADVANCED` macro and adding a `Catch::Benchmark::Chronometer` argument after
|
||||
the macro, some advanced features are available. The contents of the simple benchmarks are invoked once per run,
|
||||
while the blocks of the advanced benchmarks are invoked exactly twice:
|
||||
once during the estimation phase, and another time during the execution phase.
|
||||
|
||||
```c++
|
||||
BENCHMARK("simple"){ return long_computation(); };
|
||||
|
||||
BENCHMARK_ADVANCED("advanced")(Catch::Benchmark::Chronometer meter) {
|
||||
set_up();
|
||||
meter.measure([] { return long_computation(); });
|
||||
};
|
||||
```
|
||||
|
||||
These advanced benchmarks no longer consist entirely of user code to be measured.
|
||||
In these cases, the code to be measured is provided via the
|
||||
`Catch::Benchmark::Chronometer::measure` member function. This allows you to set up any
|
||||
kind of state that might be required for the benchmark but is not to be included
|
||||
in the measurements, like making a vector of random integers to feed to a
|
||||
sorting algorithm.
|
||||
|
||||
A single call to `Catch::Benchmark::Chronometer::measure` performs the actual measurements
|
||||
by invoking the callable object passed in as many times as necessary. Anything
|
||||
that needs to be done outside the measurement can be done outside the call to
|
||||
`measure`.
|
||||
|
||||
The callable object passed in to `measure` can optionally accept an `int`
|
||||
parameter.
|
||||
|
||||
```c++
|
||||
meter.measure([](int i) { return long_computation(i); });
|
||||
```
|
||||
|
||||
If it accepts an `int` parameter, the sequence number of each run will be passed
|
||||
in, starting with 0. This is useful if you want to measure some mutating code,
|
||||
for example. The number of runs can be known beforehand by calling
|
||||
`Catch::Benchmark::Chronometer::runs`; with this one can set up a different instance to be
|
||||
mutated by each run.
|
||||
|
||||
```c++
|
||||
std::vector<std::string> v(meter.runs());
|
||||
std::fill(v.begin(), v.end(), test_string());
|
||||
meter.measure([&v](int i) { in_place_escape(v[i]); });
|
||||
```
|
||||
|
||||
Note that it is not possible to simply use the same instance for different runs
|
||||
and resetting it between each run since that would pollute the measurements with
|
||||
the resetting code.
|
||||
|
||||
It is also possible to just provide an argument name to the simple `BENCHMARK` macro to get
|
||||
the same semantics as providing a callable to `meter.measure` with `int` argument:
|
||||
|
||||
```c++
|
||||
BENCHMARK("indexed", i){ return long_computation(i); };
|
||||
```
|
||||
|
||||
### Constructors and destructors
|
||||
|
||||
All of these tools give you a lot mileage, but there are two things that still
|
||||
need special handling: constructors and destructors. The problem is that if you
|
||||
use automatic objects they get destroyed by the end of the scope, so you end up
|
||||
measuring the time for construction and destruction together. And if you use
|
||||
dynamic allocation instead, you end up including the time to allocate memory in
|
||||
the measurements.
|
||||
|
||||
To solve this conundrum, Catch provides class templates that let you manually
|
||||
construct and destroy objects without dynamic allocation and in a way that lets
|
||||
you measure construction and destruction separately.
|
||||
|
||||
```c++
|
||||
BENCHMARK_ADVANCED("construct")(Catch::Benchmark::Chronometer meter) {
|
||||
std::vector<Catch::Benchmark::storage_for<std::string>> storage(meter.runs());
|
||||
meter.measure([&](int i) { storage[i].construct("thing"); });
|
||||
};
|
||||
|
||||
BENCHMARK_ADVANCED("destroy")(Catch::Benchmark::Chronometer meter) {
|
||||
std::vector<Catch::Benchmark::destructable_object<std::string>> storage(meter.runs());
|
||||
for(auto&& o : storage)
|
||||
o.construct("thing");
|
||||
meter.measure([&](int i) { storage[i].destruct(); });
|
||||
};
|
||||
```
|
||||
|
||||
`Catch::Benchmark::storage_for<T>` objects are just pieces of raw storage suitable for `T`
|
||||
objects. You can use the `Catch::Benchmark::storage_for::construct` member function to call a constructor and
|
||||
create an object in that storage. So if you want to measure the time it takes
|
||||
for a certain constructor to run, you can just measure the time it takes to run
|
||||
this function.
|
||||
|
||||
When the lifetime of a `Catch::Benchmark::storage_for<T>` object ends, if an actual object was
|
||||
constructed there it will be automatically destroyed, so nothing leaks.
|
||||
|
||||
If you want to measure a destructor, though, we need to use
|
||||
`Catch::Benchmark::destructable_object<T>`. These objects are similar to
|
||||
`Catch::Benchmark::storage_for<T>` in that construction of the `T` object is manual, but
|
||||
it does not destroy anything automatically. Instead, you are required to call
|
||||
the `Catch::Benchmark::destructable_object::destruct` member function, which is what you
|
||||
can use to measure the destruction time.
|
||||
|
||||
### The optimizer
|
||||
|
||||
Sometimes the optimizer will optimize away the very code that you want to
|
||||
measure. There are several ways to use results that will prevent the optimiser
|
||||
from removing them. You can use the `volatile` keyword, or you can output the
|
||||
value to standard output or to a file, both of which force the program to
|
||||
actually generate the value somehow.
|
||||
|
||||
Catch adds a third option. The values returned by any function provided as user
|
||||
code are guaranteed to be evaluated and not optimised out. This means that if
|
||||
your user code consists of computing a certain value, you don't need to bother
|
||||
with using `volatile` or forcing output. Just `return` it from the function.
|
||||
That helps with keeping the code in a natural fashion.
|
||||
|
||||
Here's an example:
|
||||
|
||||
```c++
|
||||
// may measure nothing at all by skipping the long calculation since its
|
||||
// result is not used
|
||||
BENCHMARK("no return"){ long_calculation(); };
|
||||
|
||||
// the result of long_calculation() is guaranteed to be computed somehow
|
||||
BENCHMARK("with return"){ return long_calculation(); };
|
||||
```
|
||||
|
||||
However, there's no other form of control over the optimizer whatsoever. It is
|
||||
up to you to write a benchmark that actually measures what you want and doesn't
|
||||
just measure the time to do a whole bunch of nothing.
|
||||
|
||||
To sum up, there are two simple rules: whatever you would do in handwritten code
|
||||
to control optimization still works in Catch; and Catch makes return values
|
||||
from user code into observable effects that can't be optimized away.
|
||||
|
||||
<i>Adapted from nonius' documentation.</i>
|
@ -1,11 +1,18 @@
|
||||
<a id="top"></a>
|
||||
# CI and build system integration
|
||||
# CI and other odd pieces
|
||||
|
||||
**Contents**<br>
|
||||
[Continuous Integration systems](#continuous-integration-systems)<br>
|
||||
[Other reporters](#other-reporters)<br>
|
||||
[Low-level tools](#low-level-tools)<br>
|
||||
[CMake](#cmake)<br>
|
||||
|
||||
This page talks about how Catch integrates with Continuous Integration
|
||||
Build Systems may refer to low-level tools, like CMake, or larger systems that run on servers, like Jenkins or TeamCity. This page will talk about both.
|
||||
|
||||
## Continuous Integration systems
|
||||
|
||||
Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP and Automake reporters).
|
||||
Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP, Automake and SonarQube reporters).
|
||||
|
||||
Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them.
|
||||
|
||||
@ -16,7 +23,7 @@ The XML Reporter writes in an XML format that is specific to Catch.
|
||||
|
||||
The advantage of this format is that it corresponds well to the way Catch works (especially the more unusual features, such as nested sections) and is a fully streaming format - that is it writes output as it goes, without having to store up all its results before it can start writing.
|
||||
|
||||
The disadvantage is that, being specific to Catch, no existing build servers understand the format natively. It can be used as input to an XSLT transformation that could covert it to, say, HTML - although this loses the streaming advantage, of course.
|
||||
The disadvantage is that, being specific to Catch, no existing build servers understand the format natively. It can be used as input to an XSLT transformation that could convert it to, say, HTML - although this loses the streaming advantage, of course.
|
||||
|
||||
### JUnit Reporter
|
||||
```-r junit```
|
||||
@ -28,9 +35,14 @@ The advantage of this format is that the JUnit Ant schema is widely understood b
|
||||
The disadvantage is that this schema was designed to correspond to how JUnit works - and there is a significant mismatch with how Catch works. Additionally the format is not streamable (because opening elements hold counts of failed and passing tests as attributes) - so the whole test run must complete before it can be written.
|
||||
|
||||
## Other reporters
|
||||
Other reporters are not part of the single-header distribution and need to be downloaded and included separately. All reporters are stored in `include/reporters` directory in the git repository, and are named `catch_reporter_*.hpp`. For example, to use the TeamCity reporter you need to download `include/reporters/catch_reporter_teamcity.hpp` and include it after Catch itself.
|
||||
Other reporters are not part of the single-header distribution and need
|
||||
to be downloaded and included separately. All reporters are stored in
|
||||
`single_include` directory in the git repository, and are named
|
||||
`catch_reporter_*.hpp`. For example, to use the TeamCity reporter you
|
||||
need to download `single_include/catch_reporter_teamcity.hpp` and include
|
||||
it after Catch itself.
|
||||
|
||||
```
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include "catch_reporter_teamcity.hpp"
|
||||
@ -53,92 +65,48 @@ The Automake Reporter writes out the [meta tags](https://www.gnu.org/software/au
|
||||
|
||||
Because of the incremental nature of Catch's test suites and ability to run specific tests, our implementation of TAP reporter writes out the number of tests in a suite last.
|
||||
|
||||
### SonarQube Reporter
|
||||
```-r sonarqube```
|
||||
[SonarQube Generic Test Data](https://docs.sonarqube.org/latest/analysis/generic-test/) XML format for tests metrics.
|
||||
|
||||
## Low-level tools
|
||||
|
||||
### CMake
|
||||
### Precompiled headers (PCHs)
|
||||
|
||||
In general we recommend "vendoring" Catch's single-include releases inside your own repository. If you do this, the following example shows a minimal CMake project:
|
||||
```CMake
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
Catch offers prototypal support for being included in precompiled headers, but because of its single-header nature it does need some actions by the user:
|
||||
* The precompiled header needs to define `CATCH_CONFIG_ALL_PARTS`
|
||||
* The implementation file needs to
|
||||
* undefine `TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED`
|
||||
* define `CATCH_CONFIG_IMPL_ONLY`
|
||||
* define `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`
|
||||
* include "catch.hpp" again
|
||||
|
||||
project(cmake_test)
|
||||
|
||||
# Prepare "Catch" library for other executables
|
||||
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch)
|
||||
add_library(Catch INTERFACE)
|
||||
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
|
||||
|
||||
# Make test executable
|
||||
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
|
||||
add_executable(tests ${TEST_SOURCES})
|
||||
target_link_libraries(tests Catch)
|
||||
```
|
||||
Note that it assumes that the path to the Catch's header is `catch/catch.hpp` from the `CMakeLists.txt` file.
|
||||
|
||||
|
||||
You can also use the following CMake snippet to automatically fetch the entire Catch repository from github and configure it as an external project:
|
||||
```CMake
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
project(catch_builder CXX)
|
||||
include(ExternalProject)
|
||||
find_package(Git REQUIRED)
|
||||
|
||||
ExternalProject_Add(
|
||||
catch
|
||||
PREFIX ${CMAKE_BINARY_DIR}/catch
|
||||
GIT_REPOSITORY https://github.com/philsquared/Catch.git
|
||||
TIMEOUT 10
|
||||
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
LOG_DOWNLOAD ON
|
||||
)
|
||||
|
||||
# Expose required variable (CATCH_INCLUDE_DIR) to parent scope
|
||||
ExternalProject_Get_Property(catch source_dir)
|
||||
set(CATCH_INCLUDE_DIR ${source_dir}/single_include CACHE INTERNAL "Path to include folder for Catch")
|
||||
```
|
||||
|
||||
If you put it in, e.g., `${PROJECT_SRC_DIR}/${EXT_PROJECTS_DIR}/catch/`, you can use it in your project by adding the following to your root CMake file:
|
||||
|
||||
```CMake
|
||||
# Includes Catch in the project:
|
||||
add_subdirectory(${EXT_PROJECTS_DIR}/catch)
|
||||
include_directories(${CATCH_INCLUDE_DIR} ${COMMON_INCLUDES})
|
||||
enable_testing(true) # Enables unit-testing.
|
||||
```
|
||||
|
||||
The advantage of this approach is that you can always automatically update Catch to the latest release. The disadvantage is that it means bringing in lot more than you need.
|
||||
|
||||
|
||||
### Automatic test registration
|
||||
If you are also using ctest, `contrib/ParseAndAddCatchTests.cmake` is a CMake script that attempts to parse your test files and automatically register all test cases, using tags as labels. This means that these
|
||||
```cpp
|
||||
TEST_CASE("Test1", "[unit]") {
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
REQUIRE(a == b);
|
||||
}
|
||||
|
||||
TEST_CASE("Test2") {
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
REQUIRE(a == b);
|
||||
}
|
||||
|
||||
TEST_CASE("Test3", "[a][b][c]") {
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
REQUIRE(a == b);
|
||||
}
|
||||
```
|
||||
would be registered as 3 tests, `Test1`, `Test2` and `Test3`, and ctest 4 labels would be created, `a`, `b`, `c` and `unit`.
|
||||
|
||||
### CodeCoverage module (GCOV, LCOV...)
|
||||
|
||||
If you are using GCOV tool to get testing coverage of your code, and are not sure how to integrate it with CMake and Catch, there should be an external example over at https://github.com/fkromer/catch_cmake_coverage
|
||||
|
||||
|
||||
### pkg-config
|
||||
|
||||
Catch2 provides a rudimentary pkg-config integration, by registering itself
|
||||
under the name `catch2`. This means that after Catch2 is installed, you
|
||||
can use `pkg-config` to get its include path: `pkg-config --cflags catch2`.
|
||||
|
||||
### gdb and lldb scripts
|
||||
|
||||
Catch2's `extras` folder also contains two simple debugger scripts,
|
||||
`gdbinit` for `gdb` and `lldbinit` for `lldb`. If loaded into their
|
||||
respective debugger, these will tell it to step over Catch2's internals
|
||||
when stepping through code.
|
||||
|
||||
|
||||
## CMake
|
||||
|
||||
[As it has been getting kinda long, the documentation of Catch2's
|
||||
integration with CMake has been moved to its own page.](cmake-integration.md#top)
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
402
docs/cmake-integration.md
Normal file
402
docs/cmake-integration.md
Normal file
@ -0,0 +1,402 @@
|
||||
<a id="top"></a>
|
||||
# CMake integration
|
||||
|
||||
**Contents**<br>
|
||||
[CMake targets](#cmake-targets)<br>
|
||||
[Automatic test registration](#automatic-test-registration)<br>
|
||||
[CMake project options](#cmake-project-options)<br>
|
||||
[`CATCH_CONFIG_*` customization options in CMake](#catch_config_-customization-options-in-cmake)<br>
|
||||
[Installing Catch2 from git repository](#installing-catch2-from-git-repository)<br>
|
||||
[Installing Catch2 from vcpkg](#installing-catch2-from-vcpkg)<br>
|
||||
|
||||
Because we use CMake to build Catch2, we also provide a couple of
|
||||
integration points for our users.
|
||||
|
||||
1) Catch2 exports a (namespaced) CMake target
|
||||
2) Catch2's repository contains CMake scripts for automatic registration
|
||||
of `TEST_CASE`s in CTest
|
||||
|
||||
## CMake targets
|
||||
|
||||
Catch2's CMake build exports two targets, `Catch2::Catch2`, and
|
||||
`Catch2::Catch2WithMain`. If you do not need custom `main` function,
|
||||
you should be using the latter (and only the latter). Linking against
|
||||
it will add the proper include paths and link your target together with
|
||||
2 static libraries that implement Catch2 and its main respectively.
|
||||
If you need custom `main`, you should link only against `Catch2::Catch2`.
|
||||
|
||||
This means that if Catch2 has been installed on the system, it should
|
||||
be enough to do
|
||||
```cmake
|
||||
find_package(Catch2 3 REQUIRED)
|
||||
# These tests can use the Catch2-provided main
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
|
||||
# These tests need their own main
|
||||
add_executable(custom-main-tests test.cpp test-main.cpp)
|
||||
target_link_libraries(custom-main-tests PRIVATE Catch2::Catch2)
|
||||
```
|
||||
|
||||
These targets are also provided when Catch2 is used as a subdirectory.
|
||||
Assuming Catch2 has been cloned to `lib/Catch2`, you only need to replace
|
||||
the `find_package` call with `add_subdirectory(lib/Catch2)` and the snippet
|
||||
above still works.
|
||||
|
||||
|
||||
Another possibility is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
|
||||
```cmake
|
||||
Include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.0.1 # or a later release
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
```
|
||||
|
||||
|
||||
## Automatic test registration
|
||||
|
||||
Catch2's repository also contains three CMake scripts that help users
|
||||
with automatically registering their `TEST_CASE`s with CTest. They
|
||||
can be found in the `extras` folder, and are
|
||||
|
||||
1) `Catch.cmake` (and its dependency `CatchAddTests.cmake`)
|
||||
2) `ParseAndAddCatchTests.cmake` (deprecated)
|
||||
3) `CatchShardTests.cmake` (and its dependency `CatchShardTestsImpl.cmake`)
|
||||
|
||||
If Catch2 has been installed in system, both of these can be used after
|
||||
doing `find_package(Catch2 REQUIRED)`. Otherwise you need to add them
|
||||
to your CMake module path.
|
||||
|
||||
<a id="catch_discover_tests"></a>
|
||||
### `Catch.cmake` and `CatchAddTests.cmake`
|
||||
|
||||
`Catch.cmake` provides function `catch_discover_tests` to get tests from
|
||||
a target. This function works by running the resulting executable with
|
||||
`--list-test-names-only` flag, and then parsing the output to find all
|
||||
existing tests.
|
||||
|
||||
#### Usage
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(baz LANGUAGES CXX VERSION 0.0.1)
|
||||
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(foo test.cpp)
|
||||
target_link_libraries(foo PRIVATE Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests(foo)
|
||||
```
|
||||
|
||||
When using `FetchContent`, `include(Catch)` will fail unless
|
||||
`CMAKE_MODULE_PATH` is explicitly updated to include the extras
|
||||
directory.
|
||||
|
||||
```cmake
|
||||
# ... FetchContent ...
|
||||
#
|
||||
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests()
|
||||
```
|
||||
|
||||
#### Customization
|
||||
`catch_discover_tests` can be given several extra argumets:
|
||||
```cmake
|
||||
catch_discover_tests(target
|
||||
[TEST_SPEC arg1...]
|
||||
[EXTRA_ARGS arg1...]
|
||||
[WORKING_DIRECTORY dir]
|
||||
[TEST_PREFIX prefix]
|
||||
[TEST_SUFFIX suffix]
|
||||
[PROPERTIES name1 value1...]
|
||||
[TEST_LIST var]
|
||||
[REPORTER reporter]
|
||||
[OUTPUT_DIR dir]
|
||||
[OUTPUT_PREFIX prefix]
|
||||
[OUTPUT_SUFFIX suffix]
|
||||
)
|
||||
```
|
||||
|
||||
* `TEST_SPEC arg1...`
|
||||
|
||||
Specifies test cases, wildcarded test cases, tags and tag expressions to
|
||||
pass to the Catch executable alongside the `--list-test-names-only` flag.
|
||||
|
||||
|
||||
* `EXTRA_ARGS arg1...`
|
||||
|
||||
Any extra arguments to pass on the command line to each test case.
|
||||
|
||||
|
||||
* `WORKING_DIRECTORY dir`
|
||||
|
||||
Specifies the directory in which to run the discovered test cases. If this
|
||||
option is not provided, the current binary directory is used.
|
||||
|
||||
|
||||
* `TEST_PREFIX prefix`
|
||||
|
||||
Specifies a _prefix_ to be added to the name of each discovered test case.
|
||||
This can be useful when the same test executable is being used in multiple
|
||||
calls to `catch_discover_tests()`, with different `TEST_SPEC` or `EXTRA_ARGS`.
|
||||
|
||||
|
||||
* `TEST_SUFFIX suffix`
|
||||
|
||||
Same as `TEST_PREFIX`, except it specific the _suffix_ for the test names.
|
||||
Both `TEST_PREFIX` and `TEST_SUFFIX` can be specified at the same time.
|
||||
|
||||
|
||||
* `PROPERTIES name1 value1...`
|
||||
|
||||
Specifies additional properties to be set on all tests discovered by this
|
||||
invocation of `catch_discover_tests`.
|
||||
|
||||
|
||||
* `TEST_LIST var`
|
||||
|
||||
Make the list of tests available in the variable `var`, rather than the
|
||||
default `<target>_TESTS`. This can be useful when the same test
|
||||
executable is being used in multiple calls to `catch_discover_tests()`.
|
||||
Note that this variable is only available in CTest.
|
||||
|
||||
* `REPORTER reporter`
|
||||
|
||||
Use the specified reporter when running the test case. The reporter will
|
||||
be passed to the test runner as `--reporter reporter`.
|
||||
|
||||
* `OUTPUT_DIR dir`
|
||||
|
||||
If specified, the parameter is passed along as
|
||||
`--out dir/<test_name>` to test executable. The actual file name is the
|
||||
same as the test name. This should be used instead of
|
||||
`EXTRA_ARGS --out foo` to avoid race conditions writing the result output
|
||||
when using parallel test execution.
|
||||
|
||||
* `OUTPUT_PREFIX prefix`
|
||||
|
||||
May be used in conjunction with `OUTPUT_DIR`.
|
||||
If specified, `prefix` is added to each output file name, like so
|
||||
`--out dir/prefix<test_name>`.
|
||||
|
||||
* `OUTPUT_SUFFIX suffix`
|
||||
|
||||
May be used in conjunction with `OUTPUT_DIR`.
|
||||
If specified, `suffix` is added to each output file name, like so
|
||||
`--out dir/<test_name>suffix`. This can be used to add a file extension to
|
||||
the output file name e.g. ".xml".
|
||||
|
||||
|
||||
### `ParseAndAddCatchTests.cmake`
|
||||
|
||||
⚠ This script is [deprecated](https://github.com/catchorg/Catch2/pull/2120)
|
||||
in Catch2 2.13.4 and superseded by the above approach using `catch_discover_tests`.
|
||||
See [#2092](https://github.com/catchorg/Catch2/issues/2092) for details.
|
||||
|
||||
`ParseAndAddCatchTests` works by parsing all implementation files
|
||||
associated with the provided target, and registering them via CTest's
|
||||
`add_test`. This approach has some limitations, such as the fact that
|
||||
commented-out tests will be registered anyway. More serious, only a
|
||||
subset of the assertion macros currently available in Catch can be
|
||||
detected by this script and tests with any macros that cannot be
|
||||
parsed are *silently ignored*.
|
||||
|
||||
|
||||
#### Usage
|
||||
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(baz LANGUAGES CXX VERSION 0.0.1)
|
||||
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(foo test.cpp)
|
||||
target_link_libraries(foo PRIVATE Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
include(ParseAndAddCatchTests)
|
||||
ParseAndAddCatchTests(foo)
|
||||
```
|
||||
|
||||
|
||||
#### Customization
|
||||
|
||||
`ParseAndAddCatchTests` provides some customization points:
|
||||
* `PARSE_CATCH_TESTS_VERBOSE` -- When `ON`, the script prints debug
|
||||
messages. Defaults to `OFF`.
|
||||
* `PARSE_CATCH_TESTS_NO_HIDDEN_TESTS` -- When `ON`, hidden tests (tests
|
||||
tagged with either of `[.]` or `[.foo]`) will not be registered.
|
||||
Defaults to `OFF`.
|
||||
* `PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME` -- When `ON`, adds fixture
|
||||
class name to the test name in CTest. Defaults to `ON`.
|
||||
* `PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME` -- When `ON`, adds target
|
||||
name to the test name in CTest. Defaults to `ON`.
|
||||
* `PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS` -- When `ON`, adds test
|
||||
file to `CMAKE_CONFIGURE_DEPENDS`. This means that the CMake configuration
|
||||
step will be re-ran when the test files change, letting new tests be
|
||||
automatically discovered. Defaults to `OFF`.
|
||||
|
||||
|
||||
Optionally, one can specify a launching command to run tests by setting the
|
||||
variable `OptionalCatchTestLauncher` before calling `ParseAndAddCatchTests`. For
|
||||
instance to run some tests using `MPI` and other sequentially, one can write
|
||||
```cmake
|
||||
set(OptionalCatchTestLauncher ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${NUMPROC})
|
||||
ParseAndAddCatchTests(mpi_foo)
|
||||
unset(OptionalCatchTestLauncher)
|
||||
ParseAndAddCatchTests(bar)
|
||||
```
|
||||
|
||||
|
||||
### `CatchShardTests.cmake`
|
||||
|
||||
> `CatchShardTests.cmake` was introduced in Catch2 3.1.0.
|
||||
|
||||
`CatchShardTests.cmake` provides a function
|
||||
`catch_add_sharded_tests(TEST_BINARY)` that splits tests from `TEST_BINARY`
|
||||
into multiple shards. The tests in each shard and their order is randomized,
|
||||
and the seed changes every invocation of CTest.
|
||||
|
||||
Currently there are 3 customization points for this script:
|
||||
|
||||
* SHARD_COUNT - number of shards to split target's tests into
|
||||
* REPORTER - reporter spec to use for tests
|
||||
* TEST_SPEC - test spec used for filtering tests
|
||||
|
||||
Example usage:
|
||||
|
||||
```
|
||||
include(CatchShardTests)
|
||||
|
||||
catch_add_sharded_tests(foo-tests
|
||||
SHARD_COUNT 4
|
||||
REPORTER "xml::out=-"
|
||||
TEST_SPEC "A"
|
||||
)
|
||||
|
||||
catch_add_sharded_tests(tests
|
||||
SHARD_COUNT 8
|
||||
REPORTER "xml::out=-"
|
||||
TEST_SPEC "B"
|
||||
)
|
||||
```
|
||||
|
||||
This registers total of 12 CTest tests (4 + 8 shards) to run shards
|
||||
from `foo-tests` test binary, filtered by a test spec.
|
||||
|
||||
_Note that this script is currently a proof-of-concept for reseeding
|
||||
shards per CTest run, and thus does not support (nor does it currently
|
||||
aim to support) all customization points from
|
||||
[`catch_discover_tests`](#catch_discover_tests)._
|
||||
|
||||
|
||||
## CMake project options
|
||||
|
||||
Catch2's CMake project also provides some options for other projects
|
||||
that consume it. These are:
|
||||
|
||||
* `BUILD_TESTING` -- When `ON` and the project is not used as a subproject,
|
||||
Catch2's test binary will be built. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_DOCS` -- When `ON`, Catch2's documentation will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_EXTRAS` -- When `ON`, Catch2's extras folder (the CMake
|
||||
scripts mentioned above, debugger helpers) will be included in the
|
||||
installation. Defaults to `ON`.
|
||||
* `CATCH_DEVELOPMENT_BUILD` -- When `ON`, configures the build for development
|
||||
of Catch2. This means enabling test projects, warnings and so on.
|
||||
Defaults to `OFF`.
|
||||
|
||||
|
||||
Enabling `CATCH_DEVELOPMENT_BUILD` also enables further configuration
|
||||
customization options:
|
||||
|
||||
* `CATCH_BUILD_TESTING` -- When `ON`, Catch2's SelfTest project will be
|
||||
built. Defaults to `ON`. Note that Catch2 also obeys `BUILD_TESTING` CMake
|
||||
variable, so _both_ of them need to be `ON` for the SelfTest to be built,
|
||||
and either of them can be set to `OFF` to disable building SelfTest.
|
||||
* `CATCH_BUILD_EXAMPLES` -- When `ON`, Catch2's usage examples will be
|
||||
built. Defaults to `OFF`.
|
||||
* `CATCH_BUILD_EXTRA_TESTS` -- When `ON`, Catch2's extra tests will be
|
||||
built. Defaults to `OFF`.
|
||||
* `CATCH_BUILD_FUZZERS` -- When `ON`, Catch2 fuzzing entry points will
|
||||
be built. Defaults to `OFF`.
|
||||
* `CATCH_ENABLE_WERROR` -- When `ON`, adds `-Werror` or equivalent flag
|
||||
to the compilation. Defaults to `ON`.
|
||||
* `CATCH_BUILD_SURROGATES` -- When `ON`, each header in Catch2 will be
|
||||
compiled separately to ensure that they are self-sufficient.
|
||||
Defaults to `OFF`.
|
||||
|
||||
|
||||
## `CATCH_CONFIG_*` customization options in CMake
|
||||
|
||||
> CMake support for `CATCH_CONFIG_*` options was introduced in Catch2 3.0.1
|
||||
|
||||
Due to the new separate compilation model, all the options from the
|
||||
[Compile-time configuration docs](configuration.md#top) can also be set
|
||||
through Catch2's CMake. To set them, define the option you want as `ON`,
|
||||
e.g. `-DCATCH_CONFIG_NOSTDOUT=ON`.
|
||||
|
||||
Note that setting the option to `OFF` doesn't disable it. To force disable
|
||||
an option, you need to set the `_NO_` form of it to `ON`, e.g.
|
||||
`-DCATCH_CONFIG_NO_COLOUR_WIN32=ON`.
|
||||
|
||||
|
||||
To summarize the configuration option behaviour with an example:
|
||||
|
||||
| `-DCATCH_CONFIG_COLOUR_WIN32` | `-DCATCH_CONFIG_NO_COLOUR_WIN32` | Result |
|
||||
|-------------------------------|----------------------------------|-------------|
|
||||
| `ON` | `ON` | error |
|
||||
| `ON` | `OFF` | force-on |
|
||||
| `OFF` | `ON` | force-off |
|
||||
| `OFF` | `OFF` | auto-detect |
|
||||
|
||||
|
||||
|
||||
## Installing Catch2 from git repository
|
||||
|
||||
If you cannot install Catch2 from a package manager (e.g. Ubuntu 16.04
|
||||
provides catch only in version 1.2.0) you might want to install it from
|
||||
the repository instead. Assuming you have enough rights, you can just
|
||||
install it to the default location, like so:
|
||||
```
|
||||
$ git clone https://github.com/catchorg/Catch2.git
|
||||
$ cd Catch2
|
||||
$ cmake -Bbuild -H. -DBUILD_TESTING=OFF
|
||||
$ sudo cmake --build build/ --target install
|
||||
```
|
||||
|
||||
If you do not have superuser rights, you will also need to specify
|
||||
[CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html)
|
||||
when configuring the build, and then modify your calls to
|
||||
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html)
|
||||
accordingly.
|
||||
|
||||
## Installing Catch2 from vcpkg
|
||||
|
||||
Alternatively, you can build and install Catch2 using [vcpkg](https://github.com/microsoft/vcpkg/) dependency manager:
|
||||
```
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install catch2
|
||||
```
|
||||
|
||||
The catch2 port in vcpkg is kept up to date by microsoft team members and community contributors.
|
||||
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@ -1,37 +1,43 @@
|
||||
<a id="top"></a>
|
||||
# Command line
|
||||
|
||||
**Contents**
|
||||
[Specifying which tests to run](#specifying-which-tests-to-run)
|
||||
[Choosing a reporter to use](#choosing-a-reporter-to-use)
|
||||
[Breaking into the debugger](#breaking-into-the-debugger)
|
||||
[Showing results for successful tests](#showing-results-for-successful-tests)
|
||||
[Aborting after a certain number of failures](#aborting-after-a-certain-number-of-failures)
|
||||
[Listing available tests, tags or reporters](#listing-available-tests-tags-or-reporters)
|
||||
[Sending output to a file](#sending-output-to-a-file)
|
||||
[Naming a test run](#naming-a-test-run)
|
||||
[Eliding assertions expected to throw](#eliding-assertions-expected-to-throw)
|
||||
[Make whitespace visible](#make-whitespace-visible)
|
||||
[Warnings](#warnings)
|
||||
[Reporting timings](#reporting-timings)
|
||||
[Load test names to run from a file](#load-test-names-to-run-from-a-file)
|
||||
[Just test names](#just-test-names)
|
||||
[Specify the order test cases are run](#specify-the-order-test-cases-are-run)
|
||||
[Specify a seed for the Random Number Generator](#specify-a-seed-for-the-random-number-generator)
|
||||
[Identify framework and version according to the libIdentify standard](#identify-framework-and-version-according-to-the-libidentify-standard)
|
||||
[Wait for key before continuing](#wait-for-key-before-continuing)
|
||||
[Specify multiples of clock resolution to run benchmarks for](#specify-multiples-of-clock-resolution-to-run-benchmarks-for)
|
||||
[Usage](#usage)
|
||||
[Specify the section to run](#specify-the-section-to-run)
|
||||
[Filenames as tags](#filenames-as-tags)
|
||||
**Contents**<br>
|
||||
[Specifying which tests to run](#specifying-which-tests-to-run)<br>
|
||||
[Choosing a reporter to use](#choosing-a-reporter-to-use)<br>
|
||||
[Breaking into the debugger](#breaking-into-the-debugger)<br>
|
||||
[Showing results for successful tests](#showing-results-for-successful-tests)<br>
|
||||
[Aborting after a certain number of failures](#aborting-after-a-certain-number-of-failures)<br>
|
||||
[Listing available tests, tags or reporters](#listing-available-tests-tags-or-reporters)<br>
|
||||
[Sending output to a file](#sending-output-to-a-file)<br>
|
||||
[Naming a test run](#naming-a-test-run)<br>
|
||||
[Eliding assertions expected to throw](#eliding-assertions-expected-to-throw)<br>
|
||||
[Make whitespace visible](#make-whitespace-visible)<br>
|
||||
[Warnings](#warnings)<br>
|
||||
[Reporting timings](#reporting-timings)<br>
|
||||
[Load test names to run from a file](#load-test-names-to-run-from-a-file)<br>
|
||||
[Specify the order test cases are run](#specify-the-order-test-cases-are-run)<br>
|
||||
[Specify a seed for the Random Number Generator](#specify-a-seed-for-the-random-number-generator)<br>
|
||||
[Identify framework and version according to the libIdentify standard](#identify-framework-and-version-according-to-the-libidentify-standard)<br>
|
||||
[Wait for key before continuing](#wait-for-key-before-continuing)<br>
|
||||
[Skip all benchmarks](#skip-all-benchmarks)<br>
|
||||
[Specify the number of benchmark samples to collect](#specify-the-number-of-benchmark-samples-to-collect)<br>
|
||||
[Specify the number of resamples for bootstrapping](#specify-the-number-of-resamples-for-bootstrapping)<br>
|
||||
[Specify the confidence-interval for bootstrapping](#specify-the-confidence-interval-for-bootstrapping)<br>
|
||||
[Disable statistical analysis of collected benchmark samples](#disable-statistical-analysis-of-collected-benchmark-samples)<br>
|
||||
[Specify the amount of time in milliseconds spent on warming up each test](#specify-the-amount-of-time-in-milliseconds-spent-on-warming-up-each-test)<br>
|
||||
[Usage](#usage)<br>
|
||||
[Specify the section to run](#specify-the-section-to-run)<br>
|
||||
[Filenames as tags](#filenames-as-tags)<br>
|
||||
[Override output colouring](#override-output-colouring)<br>
|
||||
[Test Sharding](#test-sharding)<br>
|
||||
[Allow running the binary without tests](#allow-running-the-binary-without-tests)<br>
|
||||
[Output verbosity](#output-verbosity)<br>
|
||||
|
||||
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
|
||||
Click one of the followings links to take you straight to that option - or scroll on to browse the available options.
|
||||
Click one of the following links to take you straight to that option - or scroll on to browse the available options.
|
||||
|
||||
<a href="#specifying-which-tests-to-run"> ` <test-spec> ...`</a><br />
|
||||
<a href="#usage"> ` -h, -?, --help`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` -l, --list-tests`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` -t, --list-tags`</a><br />
|
||||
<a href="#showing-results-for-successful-tests"> ` -s, --success`</a><br />
|
||||
<a href="#breaking-into-the-debugger"> ` -b, --break`</a><br />
|
||||
<a href="#eliding-assertions-expected-to-throw"> ` -e, --nothrow`</a><br />
|
||||
@ -50,13 +56,25 @@ Click one of the followings links to take you straight to that option - or scrol
|
||||
|
||||
</br>
|
||||
|
||||
<a href="#list-test-names-only"> ` --list-test-names-only`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-tests`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-tags`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-reporters`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-listeners`</a><br />
|
||||
<a href="#order"> ` --order`</a><br />
|
||||
<a href="#rng-seed"> ` --rng-seed`</a><br />
|
||||
<a href="#libidentify"> ` --libidentify`</a><br />
|
||||
<a href="#wait-for-keypress"> ` --wait-for-keypress`</a><br />
|
||||
<a href="#benchmark-resolution-multiple"> ` --benchmark-resolution-multiple`</a><br />
|
||||
<a href="#skip-benchmarks"> ` --skip-benchmarks`</a><br />
|
||||
<a href="#benchmark-samples"> ` --benchmark-samples`</a><br />
|
||||
<a href="#benchmark-resamples"> ` --benchmark-resamples`</a><br />
|
||||
<a href="#benchmark-confidence-interval"> ` --benchmark-confidence-interval`</a><br />
|
||||
<a href="#benchmark-no-analysis"> ` --benchmark-no-analysis`</a><br />
|
||||
<a href="#benchmark-warmup-time"> ` --benchmark-warmup-time`</a><br />
|
||||
<a href="#colour-mode"> ` --colour-mode`</a><br />
|
||||
<a href="#test-sharding"> ` --shard-count`</a><br />
|
||||
<a href="#test-sharding"> ` --shard-index`</a><br />
|
||||
<a href=#no-tests-override> ` --allow-running-no-tests`</a><br />
|
||||
<a href=#output-verbosity> ` --verbosity`</a><br />
|
||||
|
||||
</br>
|
||||
|
||||
@ -78,12 +96,13 @@ Wildcards consist of the `*` character at the beginning and/or end of test case
|
||||
|
||||
Test specs are case insensitive.
|
||||
|
||||
If a spec is prefixed with `exclude:` or the `~` character then the pattern matches an exclusion. This means that tests matching the pattern are excluded from the set - even if a prior inclusion spec included them. Subsequent inclusion specs will take precendence, however.
|
||||
If a spec is prefixed with `exclude:` or the `~` character then the pattern matches an exclusion. This means that tests matching the pattern are excluded from the set - even if a prior inclusion spec included them. Subsequent inclusion specs will take precedence, however.
|
||||
Inclusions and exclusions are evaluated in left-to-right order.
|
||||
|
||||
Test case examples:
|
||||
|
||||
<pre>thisTestOnly Matches the test case called, 'thisTestOnly'
|
||||
```
|
||||
thisTestOnly Matches the test case called, 'thisTestOnly'
|
||||
"this test only" Matches the test case called, 'this test only'
|
||||
these* Matches all cases starting with 'these'
|
||||
exclude:notThis Matches all tests except, 'notThis'
|
||||
@ -91,10 +110,12 @@ exclude:notThis Matches all tests except, 'notThis'
|
||||
~*private* Matches all tests except those that contain 'private'
|
||||
a* ~ab* abc Matches all tests that start with 'a', except those that
|
||||
start with 'ab', except 'abc', which is included
|
||||
</pre>
|
||||
~[tag1] Matches all tests except those tagged with '[tag1]'
|
||||
-# [#somefile] Matches all tests from the file 'somefile.cpp'
|
||||
```
|
||||
|
||||
Names within square brackets are interpreted as tags.
|
||||
A series of tags form an AND expression wheras a comma-separated sequence forms an OR expression. e.g.:
|
||||
A series of tags form an AND expression whereas a comma-separated sequence forms an OR expression. e.g.:
|
||||
|
||||
<pre>[one][two],[three]</pre>
|
||||
This matches all tests tagged `[one]` and `[two]`, as well as all tests tagged `[three]`
|
||||
@ -105,24 +126,56 @@ Test names containing special characters, such as `,` or `[` can specify them on
|
||||
<a id="choosing-a-reporter-to-use"></a>
|
||||
## Choosing a reporter to use
|
||||
|
||||
<pre>-r, --reporter <reporter></pre>
|
||||
<pre>-r, --reporter <reporter[::key=value]*></pre>
|
||||
|
||||
A reporter is an object that formats and structures the output of running tests, and potentially summarises the results. By default a console reporter is used that writes, IDE friendly, textual output. Catch comes bundled with some alternative reporters, but more can be added in client code.<br />
|
||||
The bundled reporters are:
|
||||
Reporters are how the output from Catch2 (results of assertions, tests,
|
||||
benchmarks and so on) is formatted and written out. The default reporter
|
||||
is called the "Console" reporter and is intended to provide relatively
|
||||
verbose and human-friendly output.
|
||||
|
||||
<pre>-r console
|
||||
-r compact
|
||||
-r xml
|
||||
-r junit
|
||||
</pre>
|
||||
Reporters are also individually configurable. To pass configuration options
|
||||
to the reporter, you append `::key=value` to the reporter specification
|
||||
as many times as you want, e.g. `--reporter xml::out=someFile.xml`.
|
||||
|
||||
The keys must either be prefixed by "X", in which case they are not parsed
|
||||
by Catch2 and are only passed down to the reporter, or one of options
|
||||
hardcoded into Catch2. Currently there are only 2,
|
||||
["out"](#sending-output-to-a-file), and ["colour-mode"](#colour-mode).
|
||||
|
||||
_Note that the reporter might still check the X-prefixed options for
|
||||
validity, and throw an error if they are wrong._
|
||||
|
||||
> Support for passing arguments to reporters through the `-r`, `--reporter` flag was introduced in Catch2 3.0.1
|
||||
|
||||
There are multiple built-in reporters, you can see what they do by using the
|
||||
[`--list-reporter`](command-line.md#listing-available-tests-tags-or-reporters)
|
||||
flag. If you need a reporter providing custom format outside of the already
|
||||
provided ones, look at the ["write your own reporter" part of the reporter
|
||||
documentation](reporters.md#writing-your-own-reporter).
|
||||
|
||||
This option may be passed multiple times to use multiple (different)
|
||||
reporters at the same time. See the [reporter documentation](reporters.md#multiple-reporters)
|
||||
for details on what the resulting behaviour is. Also note that at most one
|
||||
reporter can be provided without the output-file part of reporter spec.
|
||||
This reporter will use the "default" output destination, based on
|
||||
the [`-o`, `--out`](#sending-output-to-a-file) option.
|
||||
|
||||
> Support for using multiple different reporters at the same time was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 3.0.1
|
||||
|
||||
|
||||
_Note: There is currently no way to escape `::` in the reporter spec,
|
||||
and thus the reporter names, or configuration keys and values, cannot
|
||||
contain `::`. As `::` in paths is relatively obscure (unlike ':'), we do
|
||||
not consider this an issue._
|
||||
|
||||
The JUnit reporter is an xml format that follows the structure of the JUnit XML Report ANT task, as consumed by a number of third-party tools, including Continuous Integration servers such as Hudson. If not otherwise needed, the standard XML reporter is preferred as this is a streaming reporter, whereas the Junit reporter needs to hold all its results until the end so it can write the overall results into attributes of the root node.
|
||||
|
||||
<a id="breaking-into-the-debugger"></a>
|
||||
## Breaking into the debugger
|
||||
<pre>-b, --break</pre>
|
||||
|
||||
In some IDEs (currently XCode and Visual Studio) it is possible for Catch to break into the debugger on a test failure. This can be very helpful during debug sessions - especially when there is more than one path through a particular test.
|
||||
Under most debuggers Catch2 is capable of automatically breaking on a test
|
||||
failure. This allows the user to see the current state of the test during
|
||||
failure.
|
||||
|
||||
<a id="showing-results-for-successful-tests"></a>
|
||||
## Showing results for successful tests
|
||||
@ -144,24 +197,62 @@ Sometimes this results in a flood of failure messages and you'd rather just see
|
||||
|
||||
<a id="listing-available-tests-tags-or-reporters"></a>
|
||||
## Listing available tests, tags or reporters
|
||||
<pre>-l, --list-tests
|
||||
-t, --list-tags
|
||||
```
|
||||
--list-tests
|
||||
--list-tags
|
||||
--list-reporters
|
||||
</pre>
|
||||
--list-listeners
|
||||
```
|
||||
|
||||
```-l``` or ```--list-tests``` will list all registered tests, along with any tags.
|
||||
If one or more test-specs have been supplied too then only the matching tests will be listed.
|
||||
> The `--list*` options became customizable through reporters in Catch2 3.0.1
|
||||
|
||||
```-t``` or ```--list-tags``` lists all available tags, along with the number of test cases they match. Again, supplying test specs limits the tags that match.
|
||||
> The `--list-listeners` option was added in Catch2 3.0.1
|
||||
|
||||
```--list-reporters``` lists the available reporters.
|
||||
`--list-tests` lists all registered tests matching specified test spec.
|
||||
Usually this listing also includes tags, and potentially also other
|
||||
information, like source location, based on verbosity and reporter's design.
|
||||
|
||||
`--list-tags` lists all tags from registered tests matching specified test
|
||||
spec. Usually this also includes number of tests cases they match and
|
||||
similar information.
|
||||
|
||||
`--list-reporters` lists all available reporters and their descriptions.
|
||||
|
||||
`--list-listeners` lists all registered listeners and their descriptions.
|
||||
|
||||
The [`--verbosity` argument](#output-verbosity) modifies the level of detail provided by the default `--list*` options
|
||||
as follows:
|
||||
|
||||
| Option | `normal` (default) | `quiet` | `high` |
|
||||
|--------------------|---------------------------------|---------------------|-----------------------------------------|
|
||||
| `--list-tests` | Test names and tags | Test names only | Same as `normal`, plus source code line |
|
||||
| `--list-tags` | Tags and counts | Same as `normal` | Same as `normal` |
|
||||
| `--list-reporters` | Reporter names and descriptions | Reporter names only | Same as `normal` |
|
||||
| `--list-listeners` | Listener names and descriptions | Same as `normal` | Same as `normal` |
|
||||
|
||||
<a id="sending-output-to-a-file"></a>
|
||||
## Sending output to a file
|
||||
<pre>-o, --out <filename>
|
||||
<pre>-o, --out <filename>
|
||||
</pre>
|
||||
|
||||
Use this option to send all output to a file. By default output is sent to stdout (note that uses of stdout and stderr *from within test cases* are redirected and included in the report - so even stderr will effectively end up on stdout).
|
||||
Use this option to send all output to a file, instead of stdout. You can
|
||||
use `-` as the filename to explicitly send the output to stdout (this is
|
||||
useful e.g. when using multiple reporters).
|
||||
|
||||
> Support for `-` as the filename was introduced in Catch2 3.0.1
|
||||
|
||||
Filenames starting with "%" (percent symbol) are reserved by Catch2 for
|
||||
meta purposes, e.g. using `%debug` as the filename opens stream that
|
||||
writes to platform specific debugging/logging mechanism.
|
||||
|
||||
Catch2 currently recognizes 3 meta streams:
|
||||
|
||||
* `%debug` - writes to platform specific debugging/logging output
|
||||
* `%stdout` - writes to stdout
|
||||
* `%stderr` - writes to stderr
|
||||
|
||||
> Support for `%stdout` and `%stderr` was introduced in Catch2 3.0.1
|
||||
|
||||
|
||||
<a id="naming-a-test-run"></a>
|
||||
## Naming a test run
|
||||
@ -192,9 +283,24 @@ This option transforms tabs and newline characters into ```\t``` and ```\n``` re
|
||||
## Warnings
|
||||
<pre>-w, --warn <warning name></pre>
|
||||
|
||||
Enables reporting of warnings (only one, at time of this writing). If a warning is issued it fails the test.
|
||||
You can think of Catch2's warnings as the equivalent of `-Werror` (`/WX`)
|
||||
flag for C++ compilers. It turns some suspicious occurences, like a section
|
||||
without assertions, into errors. Because these might be intended, warnings
|
||||
are not enabled by default, but user can opt in.
|
||||
|
||||
You can enable multiple warnings at the same time.
|
||||
|
||||
There are currently two warnings implemented:
|
||||
|
||||
```
|
||||
NoAssertions // Fail test case / leaf section if no assertions
|
||||
// (e.g. `REQUIRE`) is encountered.
|
||||
UnmatchedTestSpec // Fail test run if any of the CLI test specs did
|
||||
// not match any tests.
|
||||
```
|
||||
|
||||
> `UnmatchedTestSpec` was introduced in Catch2 3.0.1.
|
||||
|
||||
The ony available warning, presently, is ```NoAssertions```. This warning fails a test case, or (leaf) section if no assertions (```REQUIRE```/ ```CHECK``` etc) are encountered.
|
||||
|
||||
<a id="reporting-timings"></a>
|
||||
## Reporting timings
|
||||
@ -202,19 +308,27 @@ The ony available warning, presently, is ```NoAssertions```. This warning fails
|
||||
|
||||
When set to ```yes``` Catch will report the duration of each test case, in milliseconds. Note that it does this regardless of whether a test case passes or fails. Note, also, the certain reporters (e.g. Junit) always report test case durations regardless of this option being set or not.
|
||||
|
||||
<pre>-D, --min-duration <value></pre>
|
||||
|
||||
> `--min-duration` was [introduced](https://github.com/catchorg/Catch2/pull/1910) in Catch2 2.13.0
|
||||
|
||||
When set, Catch will report the duration of each test case that took more
|
||||
than <value> seconds, in milliseconds. This option is overriden by both
|
||||
`-d yes` and `-d no`, so that either all durations are reported, or none
|
||||
are.
|
||||
|
||||
|
||||
<a id="input-file"></a>
|
||||
## Load test names to run from a file
|
||||
<pre>-f, --input-file <filename></pre>
|
||||
|
||||
Provide the name of a file that contains a list of test case names - one per line. Blank lines are skipped and anything after the comment character, ```#```, is ignored.
|
||||
Provide the name of a file that contains a list of test case names,
|
||||
one per line. Blank lines are skipped.
|
||||
|
||||
A useful way to generate an initial instance of this file is to use the <a href="#list-test-names-only">list-test-names-only</a> option. This can then be manually curated to specify a specific subset of tests - or in a specific order.
|
||||
|
||||
<a id="list-test-names-only"></a>
|
||||
## Just test names
|
||||
<pre>--list-test-names-only</pre>
|
||||
|
||||
This option lists all available tests in a non-indented form, one on each line. This makes it ideal for saving to a file and feeding back into the <a href="#input-file">```-f``` or ```--input-file```</a> option.
|
||||
A useful way to generate an initial instance of this file is to combine
|
||||
the [`--list-tests`](#listing-available-tests-tags-or-reporters) flag with
|
||||
the [`--verbosity quiet`](#output-verbosity) option. You can also
|
||||
use test specs to filter this list down to what you want first.
|
||||
|
||||
|
||||
<a id="order"></a>
|
||||
@ -223,25 +337,48 @@ This option lists all available tests in a non-indented form, one on each line.
|
||||
|
||||
Test cases are ordered one of three ways:
|
||||
|
||||
|
||||
### decl
|
||||
Declaration order. The order the tests were originally declared in. Note that ordering between files is not guaranteed and is implementation dependent.
|
||||
Declaration order (this is the default order if no --order argument is provided).
|
||||
Tests in the same TU are sorted using their declaration orders, different
|
||||
TUs are in an implementation (linking) dependent order.
|
||||
|
||||
|
||||
### lex
|
||||
Lexicographically sorted. Tests are sorted, alpha-numerically, by name.
|
||||
Lexicographic order. Tests are sorted by their name, their tags are ignored.
|
||||
|
||||
|
||||
### rand
|
||||
Randomly sorted. Test names are sorted using ```std::random_shuffle()```. By default the random number generator is seeded with 0 - and so the order is repeatable. To control the random seed see <a href="#rng-seed">rng-seed</a>.
|
||||
|
||||
Randomly ordered. The order is dependent on Catch2's random seed (see
|
||||
[`--rng-seed`](#rng-seed)), and is subset invariant. What this means
|
||||
is that as long as the random seed is fixed, running only some tests
|
||||
(e.g. via tag) does not change their relative order.
|
||||
|
||||
> The subset stability was introduced in Catch2 v2.12.0
|
||||
|
||||
Since the random order was made subset stable, we promise that given
|
||||
the same random seed, the order of test cases will be the same across
|
||||
different platforms, as long as the tests were compiled against identical
|
||||
version of Catch2. We reserve the right to change the relative order
|
||||
of tests cases between Catch2 versions, but it is unlikely to happen often.
|
||||
|
||||
|
||||
<a id="rng-seed"></a>
|
||||
## Specify a seed for the Random Number Generator
|
||||
<pre>--rng-seed <'time'|number></pre>
|
||||
<pre>--rng-seed <'time'|'random-device'|number></pre>
|
||||
|
||||
Sets a seed for the random number generator using ```std::srand()```.
|
||||
If a number is provided this is used directly as the seed so the random pattern is repeatable.
|
||||
Alternatively if the keyword ```time``` is provided then the result of calling ```std::time(0)``` is used and so the pattern becomes unpredictable.
|
||||
Sets the seed for random number generators used by Catch2. These are used
|
||||
e.g. to shuffle tests when user asks for tests to be in random order.
|
||||
|
||||
Using `time` as the argument asks Catch2 generate the seed through call
|
||||
to `std::time(nullptr)`. This provides very weak randomness and multiple
|
||||
runs of the binary can generate the same seed if they are started close
|
||||
to each other.
|
||||
|
||||
Using `random-device` asks for `std::random_device` to be used instead.
|
||||
If your implementation provides working `std::random_device`, it should
|
||||
be preferred to using `time`. Catch2 uses `std::random_device` by default.
|
||||
|
||||
In either case the actual value for the seed is printed as part of Catch's output so if an issue is discovered that is sensitive to test ordering the ordering can be reproduced - even if it was originally seeded from ```std::time(0)```.
|
||||
|
||||
<a id="libidentify"></a>
|
||||
## Identify framework and version according to the libIdentify standard
|
||||
@ -251,18 +388,71 @@ See [The LibIdentify repo for more information and examples](https://github.com/
|
||||
|
||||
<a id="wait-for-keypress"></a>
|
||||
## Wait for key before continuing
|
||||
<pre>--wait-for-keypress <start|exit|both></pre>
|
||||
<pre>--wait-for-keypress <never|start|exit|both></pre>
|
||||
|
||||
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing -
|
||||
either before running any tests, after running all tests - or both, depending on the argument.
|
||||
|
||||
<a id="benchmark-resolution-multiple"></a>
|
||||
## Specify multiples of clock resolution to run benchmarks for
|
||||
<pre>--benchmark-resolution-multiple <multiplier></pre>
|
||||
<a id="skip-benchmarks"></a>
|
||||
## Skip all benchmarks
|
||||
<pre>--skip-benchmarks</pre>
|
||||
|
||||
When running benchmarks the clock resolution is estimated. Benchmarks are then run for exponentially increasing
|
||||
numbers of iterations until some multiple of the estimated resolution is exceed. By default that multiple is 100, but
|
||||
it can be overriden here.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/2408) in Catch2 3.0.1.
|
||||
|
||||
This flag tells Catch2 to skip running all benchmarks. Benchmarks in this
|
||||
case mean code blocks in `BENCHMARK` and `BENCHMARK_ADVANCED` macros, not
|
||||
test cases with the `[!benchmark]` tag.
|
||||
|
||||
<a id="benchmark-samples"></a>
|
||||
## Specify the number of benchmark samples to collect
|
||||
<pre>--benchmark-samples <# of samples></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
When running benchmarks a number of "samples" is collected. This is the base data for later statistical analysis.
|
||||
Per sample a clock resolution dependent number of iterations of the user code is run, which is independent of the number of samples. Defaults to 100.
|
||||
|
||||
<a id="benchmark-resamples"></a>
|
||||
## Specify the number of resamples for bootstrapping
|
||||
<pre>--benchmark-resamples <# of resamples></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
After the measurements are performed, statistical [bootstrapping] is performed
|
||||
on the samples. The number of resamples for that bootstrapping is configurable
|
||||
but defaults to 100000. Due to the bootstrapping it is possible to give
|
||||
estimates for the mean and standard deviation. The estimates come with a lower
|
||||
bound and an upper bound, and the confidence interval (which is configurable but
|
||||
defaults to 95%).
|
||||
|
||||
[bootstrapping]: http://en.wikipedia.org/wiki/Bootstrapping_%28statistics%29
|
||||
|
||||
<a id="benchmark-confidence-interval"></a>
|
||||
## Specify the confidence-interval for bootstrapping
|
||||
<pre>--benchmark-confidence-interval <confidence-interval></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
The confidence-interval is used for statistical bootstrapping on the samples to
|
||||
calculate the upper and lower bounds of mean and standard deviation.
|
||||
Must be between 0 and 1 and defaults to 0.95.
|
||||
|
||||
<a id="benchmark-no-analysis"></a>
|
||||
## Disable statistical analysis of collected benchmark samples
|
||||
<pre>--benchmark-no-analysis</pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
When this flag is specified no bootstrapping or any other statistical analysis is performed.
|
||||
Instead the user code is only measured and the plain mean from the samples is reported.
|
||||
|
||||
<a id="benchmark-warmup-time"></a>
|
||||
## Specify the amount of time in milliseconds spent on warming up each test
|
||||
<pre>--benchmark-warmup-time</pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1844) in Catch2 2.11.2.
|
||||
|
||||
Configure the amount of time spent warming up each test.
|
||||
|
||||
<a id="usage"></a>
|
||||
## Usage
|
||||
@ -309,7 +499,7 @@ There are some limitations of this feature to be aware of:
|
||||
- Code outside of sections being skipped will still be executed - e.g. any set-up code in the TEST_CASE before the
|
||||
start of the first section.</br>
|
||||
- At time of writing, wildcards are not supported in section names.
|
||||
- If you specify a section without narrowing to a test case first then all test cases will be executed
|
||||
- If you specify a section without narrowing to a test case first then all test cases will be executed
|
||||
(but only matching sections within them).
|
||||
|
||||
|
||||
@ -317,11 +507,77 @@ start of the first section.</br>
|
||||
## Filenames as tags
|
||||
<pre>-#, --filenames-as-tags</pre>
|
||||
|
||||
When this option is used then every test is given an additional tag which is formed of the unqualified
|
||||
When this option is used then every test is given an additional tag which is formed of the unqualified
|
||||
filename it is found in, with any extension stripped, prefixed with the `#` character.
|
||||
|
||||
So, for example, tests within the file `~\Dev\MyProject\Ferrets.cpp` would be tagged `[#Ferrets]`.
|
||||
|
||||
<a id="colour-mode"></a>
|
||||
## Override output colouring
|
||||
<pre>--colour-mode <ansi|win32|none|default></pre>
|
||||
|
||||
> The `--colour-mode` option replaced the old `--colour` option in Catch2 3.0.1
|
||||
|
||||
|
||||
Catch2 support two different ways of colouring terminal output, and by
|
||||
default it attempts to make a good guess on which implementation to use
|
||||
(and whether to even use it, e.g. Catch2 tries to avoid writing colour
|
||||
codes when writing the results into a file).
|
||||
|
||||
`--colour-mode` allows the user to explicitly select what happens.
|
||||
|
||||
* `--colour-mode ansi` tells Catch2 to always use ANSI colour codes, even
|
||||
when writing to a file
|
||||
* `--colour-mode win32` tells Catch2 to use colour implementation based
|
||||
on Win32 terminal API
|
||||
* `--colour-mode none` tells Catch2 to disable colours completely
|
||||
* `--colour-mode default` lets Catch2 decide
|
||||
|
||||
`--colour-mode default` is the default setting.
|
||||
|
||||
|
||||
<a id="test-sharding"></a>
|
||||
## Test Sharding
|
||||
<pre>--shard-count <#number of shards>, --shard-index <#shard index to run></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/2257) in Catch2 3.0.1.
|
||||
|
||||
When `--shard-count <#number of shards>` is used, the tests to execute
|
||||
will be split evenly in to the given number of sets, identified by indices
|
||||
starting at 0. The tests in the set given by
|
||||
`--shard-index <#shard index to run>` will be executed. The default shard
|
||||
count is `1`, and the default index to run is `0`.
|
||||
|
||||
_It is an error to specify a shard index greater than the number of shards._
|
||||
|
||||
Sharding is useful when you want to split test execution across multiple
|
||||
processes, as is done with the [Bazel test sharding](https://docs.bazel.build/versions/main/test-encyclopedia.html#test-sharding).
|
||||
|
||||
|
||||
<a id="no-tests-override"></a>
|
||||
## Allow running the binary without tests
|
||||
<pre>--allow-running-no-tests</pre>
|
||||
|
||||
> Introduced in Catch2 3.0.1.
|
||||
|
||||
By default, Catch2 test binaries return non-0 exit code if no tests were
|
||||
run, e.g. if the binary was compiled with no tests, or the provided test
|
||||
spec matched no tests. This flag overrides that, so a test run with no
|
||||
tests still returns 0.
|
||||
|
||||
## Output verbosity
|
||||
```
|
||||
-v, --verbosity <quiet|normal|high>
|
||||
```
|
||||
|
||||
Changing verbosity might change how much details Catch2's reporters output.
|
||||
However, you should consider changing the verbosity level as a _suggestion_.
|
||||
Not all reporters support all verbosity levels, e.g. because the reporter's
|
||||
format cannot meaningfully change. In that case, the verbosity level is
|
||||
ignored.
|
||||
|
||||
Verbosity defaults to _normal_.
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,17 +1,23 @@
|
||||
<a id="top"></a>
|
||||
# Commercial users of Catch
|
||||
# Commercial users of Catch2
|
||||
|
||||
As well as [Open Source](opensource-users.md#top) users Catch is widely used within proprietary code bases too.
|
||||
Many organisations like to keep this information internal, and that's fine,
|
||||
but if you're more open it would be great if we could list the names of as
|
||||
many organisations as possible that use Catch somewhere in their codebase.
|
||||
Enterprise environments often tend to be far more conservative in their tool adoption -
|
||||
and being aware that other companies are using Catch can ease the path in.
|
||||
Catch2 is also widely used in proprietary code bases. This page contains
|
||||
some of them that are willing to share this information.
|
||||
|
||||
So if you are aware of Catch usage in your organisation, and are fairly confident there is no issue with sharing this
|
||||
fact then please let us know - either directly, via a PR or
|
||||
[issue](https://github.com/philsquared/Catch/issues), or on the [forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum).
|
||||
If you want to add your organisation, please check that there is no issue
|
||||
with you sharing this fact.
|
||||
|
||||
- Bloomberg
|
||||
- NASA
|
||||
- [Bloomlife](https://bloomlife.com)
|
||||
- [Inscopix Inc.](https://www.inscopix.com/)
|
||||
- Locksley.CZ
|
||||
- [Makimo](https://makimo.pl/)
|
||||
- NASA
|
||||
- [Nexus Software Systems](https://nexwebsites.com)
|
||||
- [UX3D](https://ux3d.io)
|
||||
- [King](https://king.com)
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@ -1,112 +1,185 @@
|
||||
<a id="top"></a>
|
||||
# Compile-time configuration
|
||||
|
||||
**Contents**
|
||||
[main()/ implementation](#main-implementation)
|
||||
[Prefixing Catch macros](#prefixing-catch-macros)
|
||||
[Terminal colour](#terminal-colour)
|
||||
[Console width](#console-width)
|
||||
[stdout](#stdout)
|
||||
[Other toggles](#other-toggles)
|
||||
[Windows header clutter](#windows-header-clutter)
|
||||
[Enabling stringification](#enabling-stringification)
|
||||
**Contents**<br>
|
||||
[Prefixing Catch macros](#prefixing-catch-macros)<br>
|
||||
[Terminal colour](#terminal-colour)<br>
|
||||
[Console width](#console-width)<br>
|
||||
[stdout](#stdout)<br>
|
||||
[Fallback stringifier](#fallback-stringifier)<br>
|
||||
[Default reporter](#default-reporter)<br>
|
||||
[Bazel support](#bazel-support)<br>
|
||||
[C++11 toggles](#c11-toggles)<br>
|
||||
[C++17 toggles](#c17-toggles)<br>
|
||||
[Other toggles](#other-toggles)<br>
|
||||
[Enabling stringification](#enabling-stringification)<br>
|
||||
[Disabling exceptions](#disabling-exceptions)<br>
|
||||
[Overriding Catch's debug break (`-b`)](#overriding-catchs-debug-break--b)<br>
|
||||
|
||||
Catch is designed to "just work" as much as possible. For most people the only configuration needed is telling Catch which source file should host all the implementation code (```CATCH_CONFIG_MAIN```).
|
||||
Catch2 is designed to "just work" as much as possible, and most of the
|
||||
configuration options below are changed automatically during compilation,
|
||||
according to the detected environment. However, this detection can also
|
||||
be overriden by users, using macros documented below, and/or CMake options
|
||||
with the same name.
|
||||
|
||||
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
|
||||
|
||||
## main()/ implementation
|
||||
|
||||
CATCH_CONFIG_MAIN // Designates this as implementation file and defines main()
|
||||
CATCH_CONFIG_RUNNER // Designates this as implementation file
|
||||
|
||||
Although Catch is header only it still, internally, maintains a distinction between interface headers and headers that contain implementation. Only one source file in your test project should compile the implementation headers and this is controlled through the use of one of these macros - one of these identifiers should be defined before including Catch in *exactly one implementation file in your project*.
|
||||
|
||||
# Reporter / Listener interfaces
|
||||
|
||||
CATCH_CONFIG_EXTERNAL_INTERFACES // Brings in neccessary headers for Reporter/Listener implementation
|
||||
|
||||
Brings in various parts of Catch that are required for user defined Reporters and Listeners. This means that new Reporters and Listeners can be defined in this file as well as in the main file.
|
||||
|
||||
Implied by both `CATCH_CONFIG_MAIN` and `CATCH_CONFIG_RUNNER`.
|
||||
|
||||
## Prefixing Catch macros
|
||||
|
||||
CATCH_CONFIG_PREFIX_ALL
|
||||
CATCH_CONFIG_PREFIX_ALL
|
||||
|
||||
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
|
||||
|
||||
|
||||
## Terminal colour
|
||||
|
||||
CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
|
||||
CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
|
||||
CATCH_CONFIG_COLOUR_ANSI // forces ANSI colour codes to be used
|
||||
CATCH_CONFIG_COLOUR_WIN32 // Force enables compiling colouring impl based on Win32 console API
|
||||
CATCH_CONFIG_NO_COLOUR_WIN32 // Force disables ...
|
||||
|
||||
Yes, I am English, so I will continue to spell "colour" with a 'u'.
|
||||
Yes, Catch2 uses the british spelling of colour.
|
||||
|
||||
When sending output to the terminal, if it detects that it can, Catch will use colourised text. On Windows the Win32 API, ```SetConsoleTextAttribute```, is used. On POSIX systems ANSI colour escape codes are inserted into the stream.
|
||||
Catch2 attempts to autodetect whether the Win32 console colouring API,
|
||||
`SetConsoleTextAttribute`, is available, and if it is available it compiles
|
||||
in a console colouring implementation that uses it.
|
||||
|
||||
For finer control you can define one of the above identifiers (these are mutually exclusive - but that is not checked so may behave unexpectedly if you mix them):
|
||||
This option can be used to override Catch2's autodetection and force the
|
||||
compilation either ON or OFF.
|
||||
|
||||
Note that when ANSI colour codes are used "unistd.h" must be includable - along with a definition of ```isatty()```
|
||||
|
||||
Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
|
||||
|
||||
## Console width
|
||||
|
||||
CATCH_CONFIG_CONSOLE_WIDTH = x // where x is a number
|
||||
CATCH_CONFIG_CONSOLE_WIDTH = x // where x is a number
|
||||
|
||||
Catch formats output intended for the console to fit within a fixed number of characters. This is especially important as indentation is used extensively and uncontrolled line wraps break this.
|
||||
By default a console width of 80 is assumed but this can be controlled by defining the above identifier to be a different value.
|
||||
|
||||
## stdout
|
||||
|
||||
CATCH_CONFIG_NOSTDOUT
|
||||
CATCH_CONFIG_NOSTDOUT
|
||||
|
||||
Catch does not use ```std::cout```, ```std::cerr``` and ```std::clog``` directly but gets them from ```Catch::cout()```, ```Catch::cerr()``` and ```Catch::clog``` respectively. If the above identifier is defined these functions are left unimplemented and you must implement them yourself. Their signatures are:
|
||||
To support platforms that do not provide `std::cout`, `std::cerr` and
|
||||
`std::clog`, Catch does not use them directly, but rather calls
|
||||
`Catch::cout`, `Catch::cerr` and `Catch::clog`. You can replace their
|
||||
implementation by defining `CATCH_CONFIG_NOSTDOUT` and implementing
|
||||
them yourself, their signatures are:
|
||||
|
||||
std::ostream& cout();
|
||||
std::ostream& cerr();
|
||||
std::ostream& clog();
|
||||
|
||||
This can be useful on certain platforms that do not provide the standard iostreams, such as certain embedded systems.
|
||||
[You can see an example of replacing these functions here.](
|
||||
../examples/231-Cfg-OutputStreams.cpp)
|
||||
|
||||
|
||||
## Fallback stringifier
|
||||
|
||||
By default, when Catch's stringification machinery has to stringify
|
||||
a type that does not specialize `StringMaker`, does not overload `operator<<`,
|
||||
is not an enumeration and is not a range, it uses `"{?}"`. This can be
|
||||
overridden by defining `CATCH_CONFIG_FALLBACK_STRINGIFIER` to name of a
|
||||
function that should perform the stringification instead.
|
||||
|
||||
All types that do not provide `StringMaker` specialization or `operator<<`
|
||||
overload will be sent to this function (this includes enums and ranges).
|
||||
The provided function must return `std::string` and must accept any type,
|
||||
e.g. via overloading.
|
||||
|
||||
_Note that if the provided function does not handle a type and this type
|
||||
requires to be stringified, the compilation will fail._
|
||||
|
||||
|
||||
## Default reporter
|
||||
|
||||
Catch's default reporter can be changed by defining macro
|
||||
`CATCH_CONFIG_DEFAULT_REPORTER` to string literal naming the desired
|
||||
default reporter.
|
||||
|
||||
This means that defining `CATCH_CONFIG_DEFAULT_REPORTER` to `"console"`
|
||||
is equivalent with the out-of-the-box experience.
|
||||
|
||||
|
||||
## Bazel support
|
||||
When `CATCH_CONFIG_BAZEL_SUPPORT` is defined or when `BAZEL_TEST=1` (which is set by the Bazel inside of a test environment),
|
||||
Catch2 will register a `JUnit` reporter writing to a path pointed by `XML_OUTPUT_FILE` provided by Bazel.
|
||||
|
||||
> `CATCH_CONFIG_BAZEL_SUPPORT` was [introduced](https://github.com/catchorg/Catch2/pull/2399) in Catch2 3.0.1.
|
||||
|
||||
> `CATCH_CONFIG_BAZEL_SUPPORT` was [deprecated](https://github.com/catchorg/Catch2/pull/2459) in Catch2 3.1.0.
|
||||
|
||||
## C++11 toggles
|
||||
|
||||
CATCH_CONFIG_CPP11_TO_STRING // Use `std::to_string`
|
||||
|
||||
Because we support platforms whose standard library does not contain
|
||||
`std::to_string`, it is possible to force Catch to use a workaround
|
||||
based on `std::stringstream`. On platforms other than Android,
|
||||
the default is to use `std::to_string`. On Android, the default is to
|
||||
use the `stringstream` workaround. As always, it is possible to override
|
||||
Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
|
||||
`CATCH_CONFIG_NO_CPP11_TO_STRING`.
|
||||
|
||||
|
||||
## C++17 toggles
|
||||
|
||||
CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS // Override std::uncaught_exceptions (instead of std::uncaught_exception) support detection
|
||||
CATCH_CONFIG_CPP17_STRING_VIEW // Override std::string_view support detection (Catch provides a StringMaker specialization by default)
|
||||
CATCH_CONFIG_CPP17_VARIANT // Override std::variant support detection (checked by CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
|
||||
CATCH_CONFIG_CPP17_OPTIONAL // Override std::optional support detection (checked by CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER)
|
||||
CATCH_CONFIG_CPP17_BYTE // Override std::byte support detection (Catch provides a StringMaker specialization by default)
|
||||
|
||||
> `CATCH_CONFIG_CPP17_STRING_VIEW` was [introduced](https://github.com/catchorg/Catch2/issues/1376) in Catch2 2.4.1.
|
||||
|
||||
Catch contains basic compiler/standard detection and attempts to use
|
||||
some C++17 features whenever appropriate. This automatic detection
|
||||
can be manually overridden in both directions, that is, a feature
|
||||
can be enabled by defining the macro in the table above, and disabled
|
||||
by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
|
||||
|
||||
|
||||
## Other toggles
|
||||
|
||||
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
|
||||
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
|
||||
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
|
||||
CATCH_CONFIG_DISABLE_MATCHERS // Do not compile Matchers in this compilation unit
|
||||
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
||||
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
||||
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
||||
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||
CATCH_CONFIG_WCHAR // Enables use of wchart_t
|
||||
CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
|
||||
CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking
|
||||
CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output
|
||||
CATCH_CONFIG_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter
|
||||
|
||||
> [`CATCH_CONFIG_ANDROID_LOGWRITE`](https://github.com/catchorg/Catch2/issues/1743) and [`CATCH_CONFIG_GLOBAL_NEXTAFTER`](https://github.com/catchorg/Catch2/pull/1739) were introduced in Catch2 2.10.0
|
||||
|
||||
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
|
||||
|
||||
`CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`).
|
||||
|
||||
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running.
|
||||
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's
|
||||
CRT is used to check for memory leaks, and displays them after the tests
|
||||
finish running. This option only works when linking against the default
|
||||
main, and must be defined for the whole library build.
|
||||
|
||||
These toggles can be disabled by using `_NO_` form of the toggle, e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
||||
`CATCH_CONFIG_WCHAR` is on by default, but can be disabled. Currently
|
||||
it is only used in support for DJGPP cross-compiler.
|
||||
|
||||
With the exception of `CATCH_CONFIG_EXPERIMENTAL_REDIRECT`,
|
||||
these toggles can be disabled by using `_NO_` form of the toggle,
|
||||
e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
||||
|
||||
### `CATCH_CONFIG_FAST_COMPILE`
|
||||
Defining this flag speeds up compilation of test files by ~20%, by making 2 changes:
|
||||
* The `-b` (`--break`) flag no longer makes Catch break into debugger in the same stack frame as the failed test, but rather in a stack frame *below*.
|
||||
* Non-exception family of macros ({`REQUIRE`,`CHECK`}{`_`,`_FALSE`, `_FALSE`}, no longer use local try-cache block. This disables exception translation, but should not lead to false negatives.
|
||||
This compile-time flag speeds up compilation of assertion macros by ~20%,
|
||||
by disabling the generation of assertion-local try-catch blocks for
|
||||
non-exception family of assertion macros ({`REQUIRE`,`CHECK`}{``,`_FALSE`, `_THAT`}).
|
||||
This disables translation of exceptions thrown under these assertions, but
|
||||
should not lead to false negatives.
|
||||
|
||||
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined, in all translation units that are linked into single test binary, or the behaviour of setting `-b` flag and throwing unexpected exceptions will be unpredictable.
|
||||
|
||||
### `CATCH_CONFIG_DISABLE_MATCHERS`
|
||||
When `CATCH_CONFIG_DISABLE_MATCHERS` is defined, all mentions of Catch's Matchers are ifdef-ed away from the translation unit. Doing so will speed up compilation of that TU.
|
||||
|
||||
_Note: If you define `CATCH_CONFIG_DISABLE_MATCHERS` in the same file as Catch's main is implemented, your test executable will fail to link if you use Matchers anywhere._
|
||||
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined,
|
||||
in all translation units that are linked into single test binary.
|
||||
|
||||
### `CATCH_CONFIG_DISABLE_STRINGIFICATION`
|
||||
This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#Visual Studio 2017 -- raw string literal in assert fails to compile)
|
||||
This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#visual-studio-2017----raw-string-literal-in-assert-fails-to-compile).
|
||||
|
||||
### `CATCH_CONFIG_DISABLE`
|
||||
This toggle removes most of Catch from given file. This means that `TEST_CASE`s are not registered and assertions are turned into no-ops. Useful for keeping tests within implementation files (ie for functions with internal linkage), instead of in external files.
|
||||
@ -115,22 +188,67 @@ This feature is considered experimental and might change at any point.
|
||||
|
||||
_Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`_
|
||||
|
||||
## Windows header clutter
|
||||
|
||||
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
|
||||
|
||||
CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro
|
||||
CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro
|
||||
|
||||
|
||||
## Enabling stringification
|
||||
|
||||
By default, Catch does not stringify some types from the standard library. This is done to avoid dragging in various standard library headers by default. However, Catch does contain these and can be configured to provide them, using these macros:
|
||||
|
||||
CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair
|
||||
CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple
|
||||
CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER // Provide StringMaker specialization for std::chrono::duration, std::chrono::timepoint
|
||||
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above
|
||||
CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair
|
||||
CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple
|
||||
CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER // Provide StringMaker specialization for std::variant, std::monostate (on C++17)
|
||||
CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional (on C++17)
|
||||
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above
|
||||
|
||||
> `CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1380) in Catch2 2.4.1.
|
||||
|
||||
> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch2 2.6.0.
|
||||
|
||||
## Disabling exceptions
|
||||
|
||||
> Introduced in Catch2 2.4.0.
|
||||
|
||||
By default, Catch2 uses exceptions to signal errors and to abort tests
|
||||
when an assertion from the `REQUIRE` family of assertions fails. We also
|
||||
provide an experimental support for disabling exceptions. Catch2 should
|
||||
automatically detect when it is compiled with exceptions disabled, but
|
||||
it can be forced to compile without exceptions by defining
|
||||
|
||||
CATCH_CONFIG_DISABLE_EXCEPTIONS
|
||||
|
||||
Note that when using Catch2 without exceptions, there are 2 major
|
||||
limitations:
|
||||
|
||||
1) If there is an error that would normally be signalled by an exception,
|
||||
the exception's message will instead be written to `Catch::cerr` and
|
||||
`std::terminate` will be called.
|
||||
2) If an assertion from the `REQUIRE` family of macros fails,
|
||||
`std::terminate` will be called after the active reporter returns.
|
||||
|
||||
|
||||
There is also a customization point for the exact behaviour of what
|
||||
happens instead of exception being thrown. To use it, define
|
||||
|
||||
CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER
|
||||
|
||||
and provide a definition for this function:
|
||||
|
||||
```cpp
|
||||
namespace Catch {
|
||||
[[noreturn]]
|
||||
void throw_exception(std::exception const&);
|
||||
}
|
||||
```
|
||||
|
||||
## Overriding Catch's debug break (`-b`)
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1846) in Catch2 2.11.2.
|
||||
|
||||
You can override Catch2's break-into-debugger code by defining the
|
||||
`CATCH_BREAK_INTO_DEBUGGER()` macro. This can be used if e.g. Catch2 does
|
||||
not know your platform, or your platform is misdetected.
|
||||
|
||||
The macro will be used as is, that is, `CATCH_BREAK_INTO_DEBUGGER();`
|
||||
must compile and must break into debugger.
|
||||
|
||||
|
||||
---
|
||||
|
@ -1,60 +1,317 @@
|
||||
<a id="top"></a>
|
||||
# Contributing to Catch
|
||||
# Contributing to Catch2
|
||||
|
||||
So you want to contribute something to Catch? That's great! Whether it's a bug fix, a new feature, support for
|
||||
additional compilers - or just a fix to the documentation - all contributions are very welcome and very much appreciated.
|
||||
Of course so are bug reports and other comments and questions.
|
||||
**Contents**<br>
|
||||
[Using Git(Hub)](#using-github)<br>
|
||||
[Testing your changes](#testing-your-changes)<br>
|
||||
[Writing documentation](#writing-documentation)<br>
|
||||
[Writing code](#writing-code)<br>
|
||||
[CoC](#coc)<br>
|
||||
|
||||
If you are contributing to the code base there are a few simple guidelines to keep in mind. This also includes notes to
|
||||
help you find your way around. As this is liable to drift out of date please raise an issue or, better still, a pull
|
||||
request for this file, if you notice that.
|
||||
So you want to contribute something to Catch2? That's great! Whether it's
|
||||
a bug fix, a new feature, support for additional compilers - or just
|
||||
a fix to the documentation - all contributions are very welcome and very
|
||||
much appreciated. Of course so are bug reports, other comments, and
|
||||
questions, but generally it is a better idea to ask questions in our
|
||||
[Discord](https://discord.gg/4CWS9zD), than in the issue tracker.
|
||||
|
||||
## Branches
|
||||
|
||||
Ongoing development is currently on _master_. At some point an integration branch will be set-up and PRs should target
|
||||
that - but for now it's all against master. You may see feature branches come and go from time to time, too.
|
||||
This page covers some guidelines and helpful tips for contributing
|
||||
to the codebase itself.
|
||||
|
||||
## Directory structure
|
||||
## Using Git(Hub)
|
||||
|
||||
_Users_ of Catch primarily use the single header version. _Maintainers_ should work with the full source (which is still,
|
||||
primarily, in headers). This can be found in the `include` folder. There are a set of test files, currently under
|
||||
`projects/SelfTest`. The test app can be built via CMake from the `CMakeLists.txt` file in the root, or you can generate
|
||||
project files for Visual Studio, XCode, and others (instructions in the `projects` folder). If you have access to CLion,
|
||||
it can work with the CMake file directly.
|
||||
Ongoing development happens in the `devel` branch for Catch2 v3, and in
|
||||
`v2.x` for maintenance updates to the v2 versions.
|
||||
|
||||
As well as the runtime test files you'll also see a `SurrogateCpps` directory under `projects/SelfTest`.
|
||||
This contains a set of .cpp files that each `#include` a single header.
|
||||
While these files are not essential to compilation they help to keep the implementation headers self-contained.
|
||||
At time of writing this set is not complete but has reasonable coverage.
|
||||
If you add additional headers please try to remember to add a surrogate cpp for it.
|
||||
Commits should be small and atomic. A commit is atomic when, after it is
|
||||
applied, the codebase, tests and all, still works as expected. Small
|
||||
commits are also preferred, as they make later operations with git history,
|
||||
whether it is bisecting, reverting, or something else, easier.
|
||||
|
||||
The other directories are `scripts` which contains a set of python scripts to help in testing Catch as well as
|
||||
generating the single include, and `docs`, which contains the documentation as a set of markdown files.
|
||||
_When submitting a pull request please do not include changes to the
|
||||
amalgamated distribution files. This means do not include them in your
|
||||
git commits!_
|
||||
|
||||
When addressing review comments in a MR, please do not rebase/squash the
|
||||
commits immediately. Doing so makes it harder to review the new changes,
|
||||
slowing down the process of merging a MR. Instead, when addressing review
|
||||
comments, you should append new commits to the branch and only squash
|
||||
them into other commits when the MR is ready to be merged. We recommend
|
||||
creating new commits with `git commit --fixup` (or `--squash`) and then
|
||||
later squashing them with `git rebase --autosquash` to make things easier.
|
||||
|
||||
__When submitting a pull request please do not include changes to the single include, or to the version number file
|
||||
as these are managed by the scripts!__
|
||||
|
||||
|
||||
## Testing your changes
|
||||
|
||||
Obviously all changes to Catch's code should be tested. If you added new functionality, you should add tests covering and
|
||||
showcasing it. Even if you have only made changes to Catch internals (ie you implemented some performance improvements),
|
||||
you should still test your changes.
|
||||
|
||||
This means 3 things
|
||||
|
||||
* Compiling Catch's SelfTest project -- code that does not compile is evidently incorrect. Obviously, you are not expected to
|
||||
have access to all compilers and platforms Catch supports, Catch's CI pipeline will compile your code using supported compilers
|
||||
once you open a PR.
|
||||
* Running the SelfTest binary. There should be no unexpected failures on simple run.
|
||||
* Running Catch's approval tests. Approval tests compare current output of the SelfTest binary in various configurations against
|
||||
known good output. Catch's repository provides utility scripts `approvalTests.py` to help you with this. It needs to be passed
|
||||
the SelfTest binary compiled with your changes, like so: `$ ./scripts/approvalTests.py clang-build/SelfTest`. The output should
|
||||
be fairly self-explanatory.
|
||||
_Note: Running Catch2's tests requires Python3_
|
||||
|
||||
|
||||
Catch2 has multiple layers of tests that are then run as part of our CI.
|
||||
The most obvious one are the unit tests compiled into the `SelfTest`
|
||||
binary. These are then used in "Approval tests", which run (almost) all
|
||||
tests from `SelfTest` through a specific reporter and then compare the
|
||||
generated output with a known good output ("Baseline"). By default, new
|
||||
tests should be placed here.
|
||||
|
||||
However, not all tests can be written as plain unit tests. For example,
|
||||
checking that Catch2 orders tests randomly when asked to, and that this
|
||||
random ordering is subset-invariant, is better done as an integration
|
||||
test using an external check script. Catch2 integration tests are written
|
||||
using CTest, either as a direct command invocation + pass/fail regex,
|
||||
or by delegating the check to a Python script.
|
||||
|
||||
Catch2 is slowly gaining more and more types of tests, currently Catch2
|
||||
project also has buildable examples, "ExtraTests", and CMake config tests.
|
||||
Examples present a small and self-contained snippets of code that
|
||||
use Catch2's facilities for specific purpose. Currently they are assumed
|
||||
passing if they compile.
|
||||
|
||||
ExtraTests then are expensive tests, that we do not want to run all the
|
||||
time. This can be either because they take a long time to run, or because
|
||||
they take a long time to compile, e.g. because they test compile time
|
||||
configuration and require separate compilation.
|
||||
|
||||
Finally, CMake config tests test that you set Catch2's compile-time
|
||||
configuration options through CMake, using CMake options of the same name.
|
||||
|
||||
None of these tests are enabled by default. To enable them, add
|
||||
`-DCATCH_BUILD_EXAMPLES=ON`, `-DCATCH_BUILD_EXTRA_TESTS=ON`, and
|
||||
`-DCATCH_ENABLE_CONFIGURE_TESTS=ON` when configuration the CMake build.
|
||||
|
||||
Bringing this all together, the steps below should configure, build,
|
||||
and run all tests in the `Debug` compilation.
|
||||
|
||||
<!-- snippet: catch2-build-and-test -->
|
||||
<a id='snippet-catch2-build-and-test'></a>
|
||||
```sh
|
||||
# 1. Regenerate the amalgamated distribution
|
||||
./tools/scripts/generateAmalgamatedFiles.py
|
||||
|
||||
# 2. Configure the full test build
|
||||
cmake -Bdebug-build -H. -DCMAKE_BUILD_TYPE=Debug -DCATCH_DEVELOPMENT_BUILD=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_BUILD_EXTRA_TESTS=ON
|
||||
|
||||
# 3. Run the actual build
|
||||
cmake --build debug-build
|
||||
|
||||
# 4. Run the tests using CTest
|
||||
cd debug-build
|
||||
ctest -j 4 --output-on-failure -C Debug
|
||||
```
|
||||
<sup><a href='/tools/scripts/buildAndTest.sh#L6-L19' title='File snippet `catch2-build-and-test` was extracted from'>snippet source</a> | <a href='#snippet-catch2-build-and-test' title='Navigate to start of snippet `catch2-build-and-test`'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
For convenience, the above commands are in the script `tools/scripts/buildAndTest.sh`, and can be run like this:
|
||||
|
||||
```bash
|
||||
cd Catch2
|
||||
./tools/scripts/buildAndTest.sh
|
||||
```
|
||||
|
||||
A Windows version of the script is available at `tools\scripts\buildAndTest.cmd`.
|
||||
|
||||
If you added new tests, you will likely see `ApprovalTests` failure.
|
||||
After you check that the output difference is expected, you should
|
||||
run `tools/scripts/approve.py` to confirm them, and include these changes
|
||||
in your commit.
|
||||
|
||||
|
||||
## Writing documentation
|
||||
|
||||
If you have added new feature to Catch2, it needs documentation, so that
|
||||
other people can use it as well. This section collects some technical
|
||||
information that you will need for updating Catch2's documentation, and
|
||||
possibly some generic advise as well.
|
||||
|
||||
|
||||
### Technicalities
|
||||
|
||||
First, the technicalities:
|
||||
|
||||
* If you have introduced a new document, there is a simple template you
|
||||
should use. It provides you with the top anchor mentioned to link to
|
||||
(more below), and also with a backlink to the top of the documentation:
|
||||
```markdown
|
||||
<a id="top"></a>
|
||||
# Cool feature
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/123456) in Catch2 X.Y.Z
|
||||
|
||||
Text that explains how to use the cool feature.
|
||||
|
||||
*this document is still in-progress...*
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
```
|
||||
|
||||
* Crosslinks to different pages should target the `top` anchor, like this
|
||||
`[link to contributing](contributing.md#top)`.
|
||||
|
||||
* We introduced version tags to the documentation, which show users in
|
||||
which version a specific feature was introduced. This means that newly
|
||||
written documentation should be tagged with a placeholder, that will
|
||||
be replaced with the actual version upon release. There are 2 styles
|
||||
of placeholders used through the documentation, you should pick one that
|
||||
fits your text better (if in doubt, take a look at the existing version
|
||||
tags for other features).
|
||||
* `> [Introduced](link-to-issue-or-PR) in Catch2 X.Y.Z` - this
|
||||
placeholder is usually used after a section heading
|
||||
* `> X (Y and Z) was [introduced](link-to-issue-or-PR) in Catch2 X.Y.Z`
|
||||
- this placeholder is used when you need to tag a subpart of something,
|
||||
e.g. a list
|
||||
|
||||
* For pages with more than 4 subheadings, we provide a table of contents
|
||||
(ToC) at the top of the page. Because GitHub markdown does not support
|
||||
automatic generation of ToC, it has to be handled semi-manually. Thus,
|
||||
if you've added a new subheading to some page, you should add it to the
|
||||
ToC. This can be done either manually, or by running the
|
||||
`updateDocumentToC.py` script in the `scripts/` folder.
|
||||
|
||||
### Contents
|
||||
|
||||
Now, for some content tips:
|
||||
|
||||
* Usage examples are good. However, having large code snippets inline
|
||||
can make the documentation less readable, and so the inline snippets
|
||||
should be kept reasonably short. To provide more complex compilable
|
||||
examples, consider adding new .cpp file to `examples/`.
|
||||
|
||||
* Don't be afraid to introduce new pages. The current documentation
|
||||
tends towards long pages, but a lot of that is caused by legacy, and
|
||||
we know that some of the pages are overly big and unfocused.
|
||||
|
||||
* When adding information to an existing page, please try to keep your
|
||||
formatting, style and changes consistent with the rest of the page.
|
||||
|
||||
* Any documentation has multiple different audiences, that desire
|
||||
different information from the text. The 3 basic user-types to try and
|
||||
cover are:
|
||||
* A beginner to Catch2, who requires closer guidance for the usage of Catch2.
|
||||
* Advanced user of Catch2, who want to customize their usage.
|
||||
* Experts, looking for full reference of Catch2's capabilities.
|
||||
|
||||
|
||||
## Writing code
|
||||
|
||||
If want to contribute code, this section contains some simple rules
|
||||
and tips on things like code formatting, code constructions to avoid,
|
||||
and so on.
|
||||
|
||||
### C++ standard version
|
||||
|
||||
Catch2 currently targets C++14 as the minimum supported C++ version.
|
||||
Features from higher language versions should be used only sparingly,
|
||||
when the benefits from using them outweight the maintenance overhead.
|
||||
|
||||
Example of good use of polyfilling features is our use of `conjunction`,
|
||||
where if available we use `std::conjunction` and otherwise provide our
|
||||
own implementation. The reason it is good is that the surface area for
|
||||
maintenance is quite small, and `std::conjunction` can directly use
|
||||
compiler built-ins, thus providing significant compilation benefits.
|
||||
|
||||
Example of bad use of polyfilling features would be to keep around two
|
||||
sets of metaprogramming in the stringification implementation, once
|
||||
using C++14 compliant TMP and once using C++17's `if constexpr`. While
|
||||
the C++17 would provide significant compilation speedups, the maintenance
|
||||
cost would be too high.
|
||||
|
||||
|
||||
### Formatting
|
||||
|
||||
To make code formatting simpler for the contributors, Catch2 provides
|
||||
its own config for `clang-format`. However, because it is currently
|
||||
impossible to replicate existing Catch2's formatting in clang-format,
|
||||
using it to reformat a whole file would cause massive diffs. To keep
|
||||
the size of your diffs reasonable, you should only use clang-format
|
||||
on the newly changed code.
|
||||
|
||||
|
||||
### Code constructs to watch out for
|
||||
|
||||
This section is a (sadly incomplete) listing of various constructs that
|
||||
are problematic and are not always caught by our CI infrastructure.
|
||||
|
||||
|
||||
#### Naked exceptions and exceptions-related function
|
||||
|
||||
If you are throwing an exception, it should be done via `CATCH_ERROR`
|
||||
or `CATCH_RUNTIME_ERROR` in `internal/catch_enforce.hpp`. These macros will handle
|
||||
the differences between compilation with or without exceptions for you.
|
||||
However, some platforms (IAR) also have problems with exceptions-related
|
||||
functions, such as `std::current_exceptions`. We do not have IAR in our
|
||||
CI, but luckily there should not be too many reasons to use these.
|
||||
However, if you do, they should be kept behind a
|
||||
`CATCH_CONFIG_DISABLE_EXCEPTIONS` macro.
|
||||
|
||||
|
||||
#### Avoid `std::move` and `std::forward`
|
||||
|
||||
`std::move` and `std::forward` provide nice semantic name for a specific
|
||||
`static_cast`. However, being function templates they have surprisingly
|
||||
high cost during compilation, and can also have a negative performance
|
||||
impact for low-optimization builds.
|
||||
|
||||
You should be using `CATCH_MOVE` and `CATCH_FORWARD` macros from
|
||||
`internal/catch_move_and_forward.hpp` instead. They expand into the proper
|
||||
`static_cast`, and avoid the overhead of `std::move` and `std::forward`.
|
||||
|
||||
|
||||
#### Unqualified usage of functions from C's stdlib
|
||||
|
||||
If you are using a function from C's stdlib, please include the header
|
||||
as `<cfoo>` and call the function qualified. The common knowledge that
|
||||
there is no difference is wrong, QNX and VxWorks won't compile if you
|
||||
include the header as `<cfoo>` and call the function unqualified.
|
||||
|
||||
|
||||
#### User-Defined Literals (UDL) for Catch2' types
|
||||
|
||||
Due to messy standardese and ... not great ... implementation of
|
||||
`-Wreserved-identifier` in Clang, avoid declaring UDLs as
|
||||
```cpp
|
||||
Approx operator "" _a(long double);
|
||||
```
|
||||
and instead declare them as
|
||||
```cpp
|
||||
Approx operator ""_a(long double);
|
||||
```
|
||||
|
||||
Notice that the second version does not have a space between the `""` and
|
||||
the literal suffix.
|
||||
|
||||
|
||||
|
||||
### New source file template
|
||||
|
||||
If you are adding new source file, there is a template you should use.
|
||||
Specifically, every source file should start with the licence header:
|
||||
```cpp
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
```
|
||||
|
||||
The include guards for header files should follow the pattern `{FILENAME}_INCLUDED`.
|
||||
This means that for file `catch_matchers_foo.hpp`, the include guard should
|
||||
be `CATCH_MATCHERS_FOO_HPP_INCLUDED`, for `catch_generators_bar.hpp`, the include
|
||||
guard should be `CATCH_GENERATORS_BAR_HPP_INCLUDED`, and so on.
|
||||
|
||||
|
||||
## CoC
|
||||
|
||||
This project has a [CoC](../CODE_OF_CONDUCT.md). Please adhere to it
|
||||
while contributing to Catch2.
|
||||
|
||||
-----------
|
||||
|
||||
_This documentation will always be in-progress as new information comes
|
||||
up, but we are trying to keep it as up to date as possible._
|
||||
|
||||
---
|
||||
|
||||
|
31
docs/deprecations.md
Normal file
31
docs/deprecations.md
Normal file
@ -0,0 +1,31 @@
|
||||
<a id="top"></a>
|
||||
# Deprecations and incoming changes
|
||||
|
||||
This page documents current deprecations and upcoming planned changes
|
||||
inside Catch2. The difference between these is that a deprecated feature
|
||||
will be removed, while a planned change to a feature means that the
|
||||
feature will behave differently, but will still be present. Obviously,
|
||||
either of these is a breaking change, and thus will not happen until
|
||||
at least the next major release.
|
||||
|
||||
|
||||
### `ParseAndAddCatchTests.cmake`
|
||||
|
||||
The CMake/CTest integration using `ParseAndAddCatchTests.cmake` is deprecated,
|
||||
as it can be replaced by `Catch.cmake` that provides the function
|
||||
`catch_discover_tests` to get tests directly from a CMake target via the
|
||||
command line interface instead of parsing C++ code with regular expressions.
|
||||
|
||||
|
||||
### `CATCH_CONFIG_BAZEL_SUPPORT`
|
||||
|
||||
Catch2 supports writing the Bazel JUnit XML output file when it is aware
|
||||
that is within a bazel testing environment. Originally there was no way
|
||||
to accurately probe the environment for this information so the flag
|
||||
`CATCH_CONFIG_BAZEL_SUPPORT` was added. This now deprecated. Bazel has now had a change
|
||||
where it will export `BAZEL_TEST=1` for purposes like the above. Catch2
|
||||
will now instead inspect the environment instead of relying on build configuration.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@ -1,74 +1,43 @@
|
||||
<a id="top"></a>
|
||||
# Event Listeners
|
||||
|
||||
A `Listener` is a class you can register with Catch that will then be passed events,
|
||||
such as a test case starting or ending, as they happen during a test run.
|
||||
`Listeners` are actually types of `Reporters`, with a few small differences:
|
||||
|
||||
1. Once registered in code they are automatically used - you don't need to specify them on the command line
|
||||
2. They are called in addition to (just before) any reporters, and you can register multiple listeners.
|
||||
3. They derive from `Catch::TestEventListenerBase`, which has default stubs for all the events,
|
||||
so you are not forced to implement events you're not interested in.
|
||||
4. You register a listener with `CATCH_REGISTER_LISTENER`
|
||||
An event listener is a bit like a reporter, in that it responds to various
|
||||
reporter events in Catch2, but it is not expected to write any output.
|
||||
Instead, an event listener performs actions within the test process, such
|
||||
as performing global initialization (e.g. of a C library), or cleaning out
|
||||
in-memory logs if they are not needed (the test case passed).
|
||||
|
||||
Unlike reporters, each registered event listener is always active. Event
|
||||
listeners are always notified before reporter(s).
|
||||
|
||||
## Implementing a Listener
|
||||
Simply derive a class from `Catch::TestEventListenerBase` and implement the methods you are interested in, either in
|
||||
the main source file (i.e. the one that defines `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`), or in a
|
||||
file that defines `CATCH_CONFIG_EXTERNAL_INTERFACES`.
|
||||
To write your own event listener, you should derive from `Catch::TestEventListenerBase`,
|
||||
as it provides empty stubs for all reporter events, allowing you to
|
||||
only override events you care for. Afterwards you have to register it
|
||||
with Catch2 using `CATCH_REGISTER_LISTENER` macro, so that Catch2 knows
|
||||
about it and instantiates it before running tests.
|
||||
|
||||
Then register it using `CATCH_REGISTER_LISTENER`.
|
||||
Example event listener:
|
||||
```cpp
|
||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
|
||||
For example:
|
||||
class testRunListener : public Catch::EventListenerBase {
|
||||
public:
|
||||
using Catch::EventListenerBase::EventListenerBase;
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
struct MyListener : Catch::TestEventListenerBase {
|
||||
|
||||
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
|
||||
|
||||
virtual void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override {
|
||||
// Perform some setup before a test case is run
|
||||
void testRunStarting(Catch::TestRunInfo const&) override {
|
||||
lib_foo_init();
|
||||
}
|
||||
|
||||
virtual void testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override {
|
||||
// Tear-down after a test case is run
|
||||
}
|
||||
};
|
||||
CATCH_REGISTER_LISTENER( MyListener )
|
||||
|
||||
CATCH_REGISTER_LISTENER(testRunListener)
|
||||
```
|
||||
|
||||
_Note that you should not use any assertion macros within a Listener!_
|
||||
|
||||
## Events that can be hooked
|
||||
[You can find the list of events that the listeners can react to on its
|
||||
own page](reporter-events.md#top).
|
||||
|
||||
The following are the methods that can be overriden in the Listener:
|
||||
|
||||
```c++
|
||||
// The whole test run, starting and ending
|
||||
virtual void testRunStarting( TestRunInfo const& testRunInfo );
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats );
|
||||
|
||||
// Test cases starting and ending
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo );
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats );
|
||||
|
||||
// Sections starting and ending
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo );
|
||||
virtual void sectionEnded( SectionStats const& sectionStats );
|
||||
|
||||
// Assertions before/ after
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo );
|
||||
virtual bool assertionEnded( AssertionStats const& assertionStats );
|
||||
|
||||
// A test is being skipped (because it is "hidden")
|
||||
virtual void skipTest( TestCaseInfo const& testInfo );
|
||||
```
|
||||
|
||||
More information about the events (e.g. name of the test case) is contained in the structs passed as arguments -
|
||||
just look in the source code to see what fields are available.
|
||||
|
||||
---
|
||||
|
||||
|
62
docs/faq.md
Normal file
62
docs/faq.md
Normal file
@ -0,0 +1,62 @@
|
||||
<a id="top"></a>
|
||||
# Frequently Asked Questions (FAQ)
|
||||
|
||||
**Contents**<br>
|
||||
[How do I run global setup/teardown only if tests will be run?](#how-do-i-run-global-setupteardown-only-if-tests-will-be-run)<br>
|
||||
[How do I clean up global state between running different tests?](#how-do-i-clean-up-global-state-between-running-different-tests)<br>
|
||||
[Why cannot I derive from the built-in reporters?](#why-cannot-i-derive-from-the-built-in-reporters)<br>
|
||||
[What is Catch2's ABI stability policy?](#what-is-catch2s-abi-stability-policy)<br>
|
||||
[What is Catch2's API stability policy?](#what-is-catch2s-api-stability-policy)<br>
|
||||
|
||||
## How do I run global setup/teardown only if tests will be run?
|
||||
|
||||
Write a custom [event listener](event-listeners.md#top) and place the
|
||||
global setup/teardown code into the `testRun*` events.
|
||||
|
||||
|
||||
## How do I clean up global state between running different tests?
|
||||
|
||||
Write a custom [event listener](event-listeners.md#top) and place the
|
||||
cleanup code into either `testCase*` or `testCasePartial*` events,
|
||||
depending on how often the cleanup needs to happen.
|
||||
|
||||
|
||||
## Why cannot I derive from the built-in reporters?
|
||||
|
||||
They are not made to be overriden, in that we do not attempt to maintain
|
||||
a consistent internal state if a member function is overriden, and by
|
||||
forbidding users from using them as a base class, we can refactor them
|
||||
as needed later.
|
||||
|
||||
|
||||
## What is Catch2's ABI stability policy?
|
||||
|
||||
Catch2 provides no ABI stability guarantees whatsoever. Catch2 provides
|
||||
rich C++ interface, and trying to freeze its ABI would take a lot of
|
||||
pointless work.
|
||||
|
||||
Catch2 is not designed to be distributed as dynamic library, and you
|
||||
should really be able to compile everything with the same compiler binary.
|
||||
|
||||
|
||||
## What is Catch2's API stability policy?
|
||||
|
||||
Catch2 follows [semver](https://semver.org/) to the best of our ability.
|
||||
This means that we will not knowingly make backwards-incompatible changes
|
||||
without incrementing the major version number.
|
||||
|
||||
|
||||
## Does Catch2 support running tests in parallel?
|
||||
|
||||
Not natively, no. We see running tests in parallel as the job of an
|
||||
external test runner, that can also run them in separate processes,
|
||||
support test execution timeouts and so on.
|
||||
|
||||
However, Catch2 provides some tools that make the job of external test
|
||||
runners easier. [See the relevant section in our page on best
|
||||
practices](usage-tips.md#parallel-tests).
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
219
docs/generators.md
Normal file
219
docs/generators.md
Normal file
@ -0,0 +1,219 @@
|
||||
<a id="top"></a>
|
||||
# Data Generators
|
||||
|
||||
> Introduced in Catch2 2.6.0.
|
||||
|
||||
Data generators (also known as _data driven/parametrized test cases_)
|
||||
let you reuse the same set of assertions across different input values.
|
||||
In Catch2, this means that they respect the ordering and nesting
|
||||
of the `TEST_CASE` and `SECTION` macros, and their nested sections
|
||||
are run once per each value in a generator.
|
||||
|
||||
This is best explained with an example:
|
||||
```cpp
|
||||
TEST_CASE("Generators") {
|
||||
auto i = GENERATE(1, 3, 5);
|
||||
REQUIRE(is_odd(i));
|
||||
}
|
||||
```
|
||||
|
||||
The "Generators" `TEST_CASE` will be entered 3 times, and the value of
|
||||
`i` will be 1, 3, and 5 in turn. `GENERATE`s can also be used multiple
|
||||
times at the same scope, in which case the result will be a cartesian
|
||||
product of all elements in the generators. This means that in the snippet
|
||||
below, the test case will be run 6 (2\*3) times.
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Generators") {
|
||||
auto i = GENERATE(1, 2);
|
||||
auto j = GENERATE(3, 4, 5);
|
||||
}
|
||||
```
|
||||
|
||||
There are 2 parts to generators in Catch2, the `GENERATE` macro together
|
||||
with the already provided generators, and the `IGenerator<T>` interface
|
||||
that allows users to implement their own generators.
|
||||
|
||||
|
||||
## Combining `GENERATE` and `SECTION`.
|
||||
|
||||
`GENERATE` can be seen as an implicit `SECTION`, that goes from the place
|
||||
`GENERATE` is used, to the end of the scope. This can be used for various
|
||||
effects. The simplest usage is shown below, where the `SECTION` "one"
|
||||
runs 4 (2\*2) times, and `SECTION` "two" is run 6 times (2\*3).
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Generators") {
|
||||
auto i = GENERATE(1, 2);
|
||||
SECTION("one") {
|
||||
auto j = GENERATE(-3, -2);
|
||||
REQUIRE(j < i);
|
||||
}
|
||||
SECTION("two") {
|
||||
auto k = GENERATE(4, 5, 6);
|
||||
REQUIRE(i != k);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The specific order of the `SECTION`s will be "one", "one", "two", "two",
|
||||
"two", "one"...
|
||||
|
||||
|
||||
The fact that `GENERATE` introduces a virtual `SECTION` can also be used
|
||||
to make a generator replay only some `SECTION`s, without having to
|
||||
explicitly add a `SECTION`. As an example, the code below reports 3
|
||||
assertions, because the "first" section is run once, but the "second"
|
||||
section is run twice.
|
||||
|
||||
```cpp
|
||||
TEST_CASE("GENERATE between SECTIONs") {
|
||||
SECTION("first") { REQUIRE(true); }
|
||||
auto _ = GENERATE(1, 2);
|
||||
SECTION("second") { REQUIRE(true); }
|
||||
}
|
||||
```
|
||||
|
||||
This can lead to surprisingly complex test flows. As an example, the test
|
||||
below will report 14 assertions:
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Complex mix of sections and generates") {
|
||||
auto i = GENERATE(1, 2);
|
||||
SECTION("A") {
|
||||
SUCCEED("A");
|
||||
}
|
||||
auto j = GENERATE(3, 4);
|
||||
SECTION("B") {
|
||||
SUCCEED("B");
|
||||
}
|
||||
auto k = GENERATE(5, 6);
|
||||
SUCCEED();
|
||||
}
|
||||
```
|
||||
|
||||
> The ability to place `GENERATE` between two `SECTION`s was [introduced](https://github.com/catchorg/Catch2/issues/1938) in Catch2 2.13.0.
|
||||
|
||||
## Provided generators
|
||||
|
||||
Catch2's provided generator functionality consists of three parts,
|
||||
|
||||
* `GENERATE` macro, that serves to integrate generator expression with
|
||||
a test case,
|
||||
* 2 fundamental generators
|
||||
* `SingleValueGenerator<T>` -- contains only single element
|
||||
* `FixedValuesGenerator<T>` -- contains multiple elements
|
||||
* 5 generic generators that modify other generators
|
||||
* `FilterGenerator<T, Predicate>` -- filters out elements from a generator
|
||||
for which the predicate returns "false"
|
||||
* `TakeGenerator<T>` -- takes first `n` elements from a generator
|
||||
* `RepeatGenerator<T>` -- repeats output from a generator `n` times
|
||||
* `MapGenerator<T, U, Func>` -- returns the result of applying `Func`
|
||||
on elements from a different generator
|
||||
* `ChunkGenerator<T>` -- returns chunks (inside `std::vector`) of n elements from a generator
|
||||
* 4 specific purpose generators
|
||||
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
|
||||
* `RandomFloatGenerator<Float>` -- generates random Floats from range
|
||||
* `RangeGenerator<T>(first, last)` -- generates all values inside a `[first, last)` arithmetic range
|
||||
* `IteratorGenerator<T>` -- copies and returns values from an iterator range
|
||||
|
||||
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch2 2.7.0.
|
||||
|
||||
> `IteratorGenerator<T>` was introduced in Catch2 2.10.0.
|
||||
|
||||
The generators also have associated helper functions that infer their
|
||||
type, making their usage much nicer. These are
|
||||
|
||||
* `value(T&&)` for `SingleValueGenerator<T>`
|
||||
* `values(std::initializer_list<T>)` for `FixedValuesGenerator<T>`
|
||||
* `table<Ts...>(std::initializer_list<std::tuple<Ts...>>)` for `FixedValuesGenerator<std::tuple<Ts...>>`
|
||||
* `filter(predicate, GeneratorWrapper<T>&&)` for `FilterGenerator<T, Predicate>`
|
||||
* `take(count, GeneratorWrapper<T>&&)` for `TakeGenerator<T>`
|
||||
* `repeat(repeats, GeneratorWrapper<T>&&)` for `RepeatGenerator<T>`
|
||||
* `map(func, GeneratorWrapper<T>&&)` for `MapGenerator<T, U, Func>` (map `U` to `T`, deduced from `Func`)
|
||||
* `map<T>(func, GeneratorWrapper<U>&&)` for `MapGenerator<T, U, Func>` (map `U` to `T`)
|
||||
* `chunk(chunk-size, GeneratorWrapper<T>&&)` for `ChunkGenerator<T>`
|
||||
* `random(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator`
|
||||
* `range(Arithemtic start, Arithmetic end)` for `RangeGenerator<Arithmetic>` with a step size of `1`
|
||||
* `range(Arithmetic start, Arithmetic end, Arithmetic step)` for `RangeGenerator<Arithmetic>` with a custom step size
|
||||
* `from_range(InputIterator from, InputIterator to)` for `IteratorGenerator<T>`
|
||||
* `from_range(Container const&)` for `IteratorGenerator<T>`
|
||||
|
||||
> `chunk()`, `random()` and both `range()` functions were introduced in Catch2 2.7.0.
|
||||
|
||||
> `from_range` has been introduced in Catch2 2.10.0
|
||||
|
||||
> `range()` for floating point numbers has been introduced in Catch2 2.11.0
|
||||
|
||||
And can be used as shown in the example below to create a generator
|
||||
that returns 100 odd random number:
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Generating random ints", "[example][generator]") {
|
||||
SECTION("Deducing functions") {
|
||||
auto i = GENERATE(take(100, filter([](int i) { return i % 2 == 1; }, random(-100, 100))));
|
||||
REQUIRE(i > -100);
|
||||
REQUIRE(i < 100);
|
||||
REQUIRE(i % 2 == 1);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Apart from registering generators with Catch2, the `GENERATE` macro has
|
||||
one more purpose, and that is to provide simple way of generating trivial
|
||||
generators, as seen in the first example on this page, where we used it
|
||||
as `auto i = GENERATE(1, 2, 3);`. This usage converted each of the three
|
||||
literals into a single `SingleValueGenerator<int>` and then placed them all in
|
||||
a special generator that concatenates other generators. It can also be
|
||||
used with other generators as arguments, such as `auto i = GENERATE(0, 2,
|
||||
take(100, random(300, 3000)));`. This is useful e.g. if you know that
|
||||
specific inputs are problematic and want to test them separately/first.
|
||||
|
||||
**For safety reasons, you cannot use variables inside the `GENERATE` macro.
|
||||
This is done because the generator expression _will_ outlive the outside
|
||||
scope and thus capturing references is dangerous. If you need to use
|
||||
variables inside the generator expression, make sure you thought through
|
||||
the lifetime implications and use `GENERATE_COPY` or `GENERATE_REF`.**
|
||||
|
||||
> `GENERATE_COPY` and `GENERATE_REF` were introduced in Catch2 2.7.1.
|
||||
|
||||
You can also override the inferred type by using `as<type>` as the first
|
||||
argument to the macro. This can be useful when dealing with string literals,
|
||||
if you want them to come out as `std::string`:
|
||||
|
||||
```cpp
|
||||
TEST_CASE("type conversion", "[generators]") {
|
||||
auto str = GENERATE(as<std::string>{}, "a", "bb", "ccc");
|
||||
REQUIRE(str.size() > 0);
|
||||
}
|
||||
```
|
||||
|
||||
## Generator interface
|
||||
|
||||
You can also implement your own generators, by deriving from the
|
||||
`IGenerator<T>` interface:
|
||||
|
||||
```cpp
|
||||
template<typename T>
|
||||
struct IGenerator : GeneratorUntypedBase {
|
||||
// via GeneratorUntypedBase:
|
||||
// Attempts to move the generator to the next element.
|
||||
// Returns true if successful (and thus has another element that can be read)
|
||||
virtual bool next() = 0;
|
||||
|
||||
// Precondition:
|
||||
// The generator is either freshly constructed or the last call to next() returned true
|
||||
virtual T const& get() const = 0;
|
||||
};
|
||||
```
|
||||
|
||||
However, to be able to use your custom generator inside `GENERATE`, it
|
||||
will need to be wrapped inside a `GeneratorWrapper<T>`.
|
||||
`GeneratorWrapper<T>` is a value wrapper around a
|
||||
`std::unique_ptr<IGenerator<T>>`.
|
||||
|
||||
For full example of implementing your own generator, look into Catch2's
|
||||
examples, specifically
|
||||
[Generators: Create your own generator](../examples/300-Gen-OwnGenerator.cpp).
|
||||
|
@ -1,12 +1,19 @@
|
||||
<a id="top"></a>
|
||||
# Known limitations
|
||||
|
||||
Catch has some known limitations, that we are not planning to change. Some of these are caused by our desire to support C++98 compilers, some of these are caused by our desire to keep Catch crossplatform, some exist because their priority is seen as low compared to the development effort they would need and some other yet are compiler/runtime bugs.
|
||||
Over time, some limitations of Catch2 emerged. Some of these are due
|
||||
to implementation details that cannot be easily changed, some of these
|
||||
are due to lack of development resources on our part, and some of these
|
||||
are due to plain old 3rd party bugs.
|
||||
|
||||
|
||||
## Implementation limits
|
||||
### Sections nested in loops
|
||||
|
||||
If you are using `SECTION`s inside loops, you have to create them with different name per loop's iteration. The recommended way to do so is to incorporate the loop's counter into section's name, like so
|
||||
If you are using `SECTION`s inside loops, you have to create them with
|
||||
different name per loop's iteration. The recommended way to do so is to
|
||||
incorporate the loop's counter into section's name, like so:
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "Looped section" ) {
|
||||
for (char i = '0'; i < '5'; ++i) {
|
||||
@ -17,11 +24,43 @@ TEST_CASE( "Looped section" ) {
|
||||
}
|
||||
```
|
||||
|
||||
or with a `DYNAMIC_SECTION` macro (that was made for exactly this purpose):
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "Looped section" ) {
|
||||
for (char i = '0'; i < '5'; ++i) {
|
||||
DYNAMIC_SECTION( "Looped section " << i) {
|
||||
SUCCEED( "Everything is OK" );
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Tests might be run again if last section fails
|
||||
|
||||
If the last section in a test fails, it might be run again. This is because
|
||||
Catch2 discovers `SECTION`s dynamically, as they are about to run, and
|
||||
if the last section in test case is aborted during execution (e.g. via
|
||||
the `REQUIRE` family of macros), Catch2 does not know that there are no
|
||||
more sections in that test case and must run the test case again.
|
||||
|
||||
|
||||
### MinGW/CygWin compilation (linking) is extremely slow
|
||||
|
||||
Compiling Catch2 with MinGW can be exceedingly slow, especially during
|
||||
the linking step. As far as we can tell, this is caused by deficiencies
|
||||
in its default linker. If you can tell MinGW to instead use lld, via
|
||||
`-fuse-ld=lld`, the link time should drop down to reasonable length
|
||||
again.
|
||||
|
||||
|
||||
## Features
|
||||
This section outlines some missing features, what is their status and their possible workarounds.
|
||||
|
||||
### Thread safe assertions
|
||||
Because threading support in standard C++98 is limited (well, non-existent), assertion macros in Catch are not thread safe. This does not mean that you cannot use threads inside Catch's test, but that only single thread can interact with Catch's assertions and other macros.
|
||||
Catch2's assertion macros are not thread safe. This does not mean that
|
||||
you cannot use threads inside Catch's test, but that only single thread
|
||||
can interact with Catch's assertions and other macros.
|
||||
|
||||
This means that this is ok
|
||||
```cpp
|
||||
@ -49,45 +88,63 @@ because only one thread passes the `REQUIRE` macro and this is not
|
||||
REQUIRE(cnt == 16);
|
||||
```
|
||||
|
||||
|
||||
_This limitation is highly unlikely to be lifted before Catch 2 is released._
|
||||
Because C++11 provides the necessary tools to do this, we are planning
|
||||
to remove this limitation in the future.
|
||||
|
||||
### Process isolation in a test
|
||||
Catch does not support running tests in isolated (forked) processes. While this might in the future, the fact that Windows does not support forking and only allows full-on process creation and the desire to keep code as similar as possible across platforms, mean that this is likely to take significant development time, that is not currently available.
|
||||
|
||||
### Running multiple tests in parallel
|
||||
Catch's test execution is strictly serial. If you find yourself with a test suite that takes too long to run and you want to make it parallel, there are 2 feasible solutions
|
||||
* You can split your tests into multiple binaries and then run these binaries in parallel.
|
||||
* You can have Catch list contained test cases and then run the same test binary multiple times in parallel, passing each instance list of test cases it should run.
|
||||
|
||||
Both of these solutions have their problems, but should let you wring parallelism out of your test suite.
|
||||
### Running multiple tests in parallel
|
||||
|
||||
Catch2 keeps test execution in one process strictly serial, and there
|
||||
are no plans to change this. If you find yourself with a test suite
|
||||
that takes too long to run and yo uwant to make it parallel, you have
|
||||
to run multiple processes side by side.
|
||||
|
||||
There are 2 basic ways to do that,
|
||||
* you can split your tests into multiple binaries, and run those binaries
|
||||
in parallel
|
||||
* you can run the same test binary multiple times, but run a different
|
||||
subset of the tests in each process
|
||||
|
||||
There are multiple ways to achieve the latter, the easiest way is to use
|
||||
[test sharding](command-line.md#test-sharding).
|
||||
|
||||
|
||||
## 3rd party bugs
|
||||
|
||||
This section outlines known bugs in 3rd party components (this means compilers, standard libraries, standard runtimes).
|
||||
|
||||
|
||||
### Visual Studio 2017 -- raw string literal in assert fails to compile
|
||||
There is a known bug in Visual Studio 2017 (VC 15), that causes compilation error when preprocessor attempts to stringize a raw string literal (`#` preprocessor is applied to it). This snippet is sufficient to trigger the compilation error:
|
||||
|
||||
There is a known bug in Visual Studio 2017 (VC 15), that causes compilation
|
||||
error when preprocessor attempts to stringize a raw string literal
|
||||
(`#` preprocessor directive is applied to it). This snippet is sufficient
|
||||
to trigger the compilation error:
|
||||
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("test") {
|
||||
CHECK(std::string(R"("\)") == "\"\\");
|
||||
}
|
||||
```
|
||||
|
||||
Catch provides a workaround, it is possible to disable stringification of original expressions by defining `CATCH_CONFIG_DISABLE_STRINGIFICATION`:
|
||||
Catch2 provides a workaround, by letting the user disable stringification
|
||||
of the original expression by defining `CATCH_CONFIG_DISABLE_STRINGIFICATION`,
|
||||
like so:
|
||||
```cpp
|
||||
#define CATCH_CONFIG_FAST_COMPILE
|
||||
#define CATCH_CONFIG_DISABLE_STRINGIFICATION
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("test") {
|
||||
CHECK(std::string(R"("\)") == "\"\\");
|
||||
}
|
||||
```
|
||||
|
||||
_Do note that this changes the output somewhat_
|
||||
_Do note that this changes the output:_
|
||||
```
|
||||
catchwork\test1.cpp(6):
|
||||
PASSED:
|
||||
@ -97,39 +154,10 @@ with expansion:
|
||||
```
|
||||
|
||||
|
||||
### Visual Studio 2013 -- do-while loop withing range based for fails to compile (C2059)
|
||||
There is a known bug in Visual Studio 2013 (VC 12), that causes compilation error if range based for is followed by an assertion macro, without enclosing the block in braces. This snippet is sufficient to trigger the error
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE("Syntax error with VC12") {
|
||||
for ( auto x : { 1 , 2, 3 } )
|
||||
REQUIRE( x < 3.14 );
|
||||
}
|
||||
```
|
||||
An easy workaround is possible, use braces:
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE("No longer a syntax error with VC12") {
|
||||
for ( auto x : { 1 , 2, 3 } ) {
|
||||
REQUIRE( x < 3.14 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Visual Studio 2003 -- Syntax error caused by improperly expanded `__LINE__` macro
|
||||
Older version of Visual Studio can have trouble compiling Catch, not expanding the `__LINE__` macro properly when recompiling the test binary. This is caused by Edit and Continue being on.
|
||||
|
||||
A workaround is to turn off Edit and Continue when compiling the test binary.
|
||||
|
||||
### Clang/G++ -- skipping leaf sections after an exception
|
||||
Some versions of `libc++` and `libstdc++` (or their runtimes) have a bug with `std::uncaught_exception()` getting stuck returning `true` after rethrow, even if there are no active exceptions. One such case is this snippet, which skipped the sections "a" and "b", when compiled against `libcxxrt` from master
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("a") {
|
||||
CHECK_THROWS(throw 3);
|
||||
@ -144,3 +172,14 @@ TEST_CASE("b") {
|
||||
```
|
||||
|
||||
If you are seeing a problem like this, i.e. a weird test paths that trigger only under Clang with `libc++`, or only under very specific version of `libstdc++`, it is very likely you are seeing this. The only known workaround is to use a fixed version of your standard library.
|
||||
|
||||
|
||||
### libstdc++, `_GLIBCXX_DEBUG` macro and random ordering of tests
|
||||
|
||||
Running a Catch2 binary compiled against libstdc++ with `_GLIBCXX_DEBUG`
|
||||
macro defined with `--order rand` will cause a debug check to trigger and
|
||||
abort the run due to self-assignment.
|
||||
[This is a known bug inside libstdc++](https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-stdshuffle/23691322)
|
||||
|
||||
Workaround: Don't use `--order rand` when compiling against debug-enabled
|
||||
libstdc++.
|
||||
|
46
docs/list-of-examples.md
Normal file
46
docs/list-of-examples.md
Normal file
@ -0,0 +1,46 @@
|
||||
<a id="top"></a>
|
||||
# List of examples
|
||||
|
||||
## Already available
|
||||
|
||||
- Test Case: [Single-file](../examples/010-TestCase.cpp)
|
||||
- Test Case: [Multiple-file 1](../examples/020-TestCase-1.cpp), [2](../examples/020-TestCase-2.cpp)
|
||||
- Assertion: [REQUIRE, CHECK](../examples/030-Asn-Require-Check.cpp)
|
||||
- Fixture: [Sections](../examples/100-Fix-Section.cpp)
|
||||
- Fixture: [Class-based fixtures](../examples/110-Fix-ClassFixture.cpp)
|
||||
- BDD: [SCENARIO, GIVEN, WHEN, THEN](../examples/120-Bdd-ScenarioGivenWhenThen.cpp)
|
||||
- Listener: [Listeners](../examples/210-Evt-EventListeners.cpp)
|
||||
- Configuration: [Provide your own output streams](../examples/231-Cfg-OutputStreams.cpp)
|
||||
- Generators: [Create your own generator](../examples/300-Gen-OwnGenerator.cpp)
|
||||
- Generators: [Use map to convert types in GENERATE expression](../examples/301-Gen-MapTypeConversion.cpp)
|
||||
- Generators: [Run test with a table of input values](../examples/302-Gen-Table.cpp)
|
||||
- Generators: [Use variables in generator expressions](../examples/310-Gen-VariablesInGenerators.cpp)
|
||||
- Generators: [Use custom variable capture in generator expressions](../examples/311-Gen-CustomCapture.cpp)
|
||||
|
||||
|
||||
## Planned
|
||||
|
||||
- Assertion: [REQUIRE_THAT and Matchers](../examples/040-Asn-RequireThat.cpp)
|
||||
- Assertion: [REQUIRE_NO_THROW](../examples/050-Asn-RequireNoThrow.cpp)
|
||||
- Assertion: [REQUIRE_THROWS](../examples/050-Asn-RequireThrows.cpp)
|
||||
- Assertion: [REQUIRE_THROWS_AS](../examples/070-Asn-RequireThrowsAs.cpp)
|
||||
- Assertion: [REQUIRE_THROWS_WITH](../examples/080-Asn-RequireThrowsWith.cpp)
|
||||
- Assertion: [REQUIRE_THROWS_MATCHES](../examples/090-Asn-RequireThrowsMatches.cpp)
|
||||
- Floating point: [Approx - Comparisons](../examples/130-Fpt-Approx.cpp)
|
||||
- Logging: [CAPTURE - Capture expression](../examples/140-Log-Capture.cpp)
|
||||
- Logging: [INFO - Provide information with failure](../examples/150-Log-Info.cpp)
|
||||
- Logging: [WARN - Issue warning](../examples/160-Log-Warn.cpp)
|
||||
- Logging: [FAIL, FAIL_CHECK - Issue message and force failure/continue](../examples/170-Log-Fail.cpp)
|
||||
- Logging: [SUCCEED - Issue message and continue](../examples/180-Log-Succeed.cpp)
|
||||
- Report: [User-defined type](../examples/190-Rpt-ReportUserDefinedType.cpp)
|
||||
- Report: [User-defined reporter](../examples/202-Rpt-UserDefinedReporter.cpp)
|
||||
- Report: [Automake reporter](../examples/205-Rpt-AutomakeReporter.cpp)
|
||||
- Report: [TAP reporter](../examples/206-Rpt-TapReporter.cpp)
|
||||
- Report: [Multiple reporter](../examples/208-Rpt-MultipleReporters.cpp)
|
||||
- Configuration: [Provide your own main()](../examples/220-Cfg-OwnMain.cpp)
|
||||
- Configuration: [Compile-time configuration](../examples/230-Cfg-CompileTimeConfiguration.cpp)
|
||||
- Configuration: [Run-time configuration](../examples/240-Cfg-RunTimeConfiguration.cpp)
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
110
docs/logging.md
110
docs/logging.md
@ -1,7 +1,7 @@
|
||||
<a id="top"></a>
|
||||
# Logging macros
|
||||
|
||||
Additional messages can be logged during a test case. Note that the messages are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
|
||||
Additional messages can be logged during a test case. Note that the messages logged with `INFO` are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Foo") {
|
||||
@ -28,10 +28,66 @@ The number is 1
|
||||
```
|
||||
When the last `CHECK` fails in the "Bar" test case, then only one message will be printed: `Test case start`.
|
||||
|
||||
## Logging without local scope
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
|
||||
|
||||
`UNSCOPED_INFO` is similar to `INFO` with two key differences:
|
||||
|
||||
- Lifetime of an unscoped message is not tied to its own scope.
|
||||
- An unscoped message can be reported by the first following assertion only, regardless of the result of that assertion.
|
||||
|
||||
In other words, lifetime of `UNSCOPED_INFO` is limited by the following assertion (or by the end of test case/section, whichever comes first) whereas lifetime of `INFO` is limited by its own scope.
|
||||
|
||||
These differences make this macro useful for reporting information from helper functions or inner scopes. An example:
|
||||
|
||||
```cpp
|
||||
void print_some_info() {
|
||||
UNSCOPED_INFO("Info from helper");
|
||||
}
|
||||
|
||||
TEST_CASE("Baz") {
|
||||
print_some_info();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
UNSCOPED_INFO("The number is " << i);
|
||||
}
|
||||
CHECK(false);
|
||||
}
|
||||
|
||||
TEST_CASE("Qux") {
|
||||
INFO("First info");
|
||||
UNSCOPED_INFO("First unscoped info");
|
||||
CHECK(false);
|
||||
|
||||
INFO("Second info");
|
||||
UNSCOPED_INFO("Second unscoped info");
|
||||
CHECK(false);
|
||||
}
|
||||
```
|
||||
|
||||
"Baz" test case prints:
|
||||
```
|
||||
Info from helper
|
||||
The number is 0
|
||||
The number is 1
|
||||
```
|
||||
|
||||
With "Qux" test case, two messages will be printed when the first `CHECK` fails:
|
||||
```
|
||||
First info
|
||||
First unscoped info
|
||||
```
|
||||
|
||||
"First unscoped info" message will be cleared after the first `CHECK`, while "First info" message will persist until the end of the test case. Therefore, when the second `CHECK` fails, three messages will be printed:
|
||||
```
|
||||
First info
|
||||
Second info
|
||||
Second unscoped info
|
||||
```
|
||||
|
||||
## Streaming macros
|
||||
|
||||
All these macros allow heterogenous sequences of values to be streaming using the insertion operator (```<<```) in the same way that std::ostream, std::cout, etc support it.
|
||||
All these macros allow heterogeneous sequences of values to be streaming using the insertion operator (```<<```) in the same way that std::ostream, std::cout, etc support it.
|
||||
|
||||
E.g.:
|
||||
```c++
|
||||
@ -43,7 +99,16 @@ These macros come in three forms:
|
||||
|
||||
**INFO(** _message expression_ **)**
|
||||
|
||||
The message is logged to a buffer, but only reported with the next assertion that is logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.
|
||||
The message is logged to a buffer, but only reported with next assertions that are logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.
|
||||
|
||||
_Note that in Catch2 2.x.x `INFO` can be used without a trailing semicolon as there is a trailing semicolon inside macro.
|
||||
This semicolon will be removed with next major version. It is highly advised to use a trailing semicolon after `INFO` macro._
|
||||
|
||||
**UNSCOPED_INFO(** _message expression_ **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
|
||||
|
||||
Similar to `INFO`, but messages are not limited to their own scope: They are removed from the buffer after each assertion, section or test case, whichever comes first.
|
||||
|
||||
**WARN(** _message expression_ **)**
|
||||
|
||||
@ -57,26 +122,37 @@ The message is reported and the test case fails.
|
||||
|
||||
AS `FAIL`, but does not abort the test
|
||||
|
||||
## Quickly capture a variable value
|
||||
## Quickly capture value of variables or expressions
|
||||
|
||||
**CAPTURE(** _expression_ **)**
|
||||
**CAPTURE(** _expression1_, _expression2_, ... **)**
|
||||
|
||||
Sometimes you just want to log the name and value of a variable. While you can easily do this with the INFO macro, above, as a convenience the CAPTURE macro handles the stringising of the variable name for you (actually it works with any expression, not just variables).
|
||||
Sometimes you just want to log a value of variable, or expression. For
|
||||
convenience, we provide the `CAPTURE` macro, that can take a variable,
|
||||
or an expression, and prints out that variable/expression and its value
|
||||
at the time of capture.
|
||||
|
||||
E.g.
|
||||
```c++
|
||||
CAPTURE( theAnswer );
|
||||
e.g. `CAPTURE( theAnswer );` will log message "theAnswer := 42", while
|
||||
```cpp
|
||||
int a = 1, b = 2, c = 3;
|
||||
CAPTURE( a, b, c, a + b, c > b, a == 1);
|
||||
```
|
||||
will log a total of 6 messages:
|
||||
```
|
||||
a := 1
|
||||
b := 2
|
||||
c := 3
|
||||
a + b := 3
|
||||
c > b := true
|
||||
a == 1 := true
|
||||
```
|
||||
|
||||
This would log something like:
|
||||
You can also capture expressions that use commas inside parentheses
|
||||
(e.g. function calls), brackets, or braces (e.g. initializers). To
|
||||
properly capture expression that contains template parameters list
|
||||
(in other words, it contains commas between angle brackets), you need
|
||||
to enclose the expression inside parentheses:
|
||||
`CAPTURE( (std::pair<int, int>{1, 2}) );`
|
||||
|
||||
<pre>"theAnswer := 42"</pre>
|
||||
|
||||
## Deprecated macros
|
||||
|
||||
**SCOPED_INFO and SCOPED_CAPTURE**
|
||||
|
||||
These macros are now deprecated and are just aliases for INFO and CAPTURE (which were not previously scoped).
|
||||
|
||||
---
|
||||
|
||||
|
462
docs/matchers.md
462
docs/matchers.md
@ -1,105 +1,435 @@
|
||||
<a id="top"></a>
|
||||
# Matchers
|
||||
|
||||
Matchers are an alternative way to do assertions which are easily extensible and composable.
|
||||
This makes them well suited to use with more complex types (such as collections) or your own custom types.
|
||||
Matchers were first popularised by the [Hamcrest](https://en.wikipedia.org/wiki/Hamcrest) family of frameworks.
|
||||
**Contents**<br>
|
||||
[Using Matchers](#using-matchers)<br>
|
||||
[Built-in matchers](#built-in-matchers)<br>
|
||||
[Writing custom matchers (old style)](#writing-custom-matchers-old-style)<br>
|
||||
[Writing custom matchers (new style)](#writing-custom-matchers-new-style)<br>
|
||||
|
||||
## In use
|
||||
Matchers, as popularized by the [Hamcrest](https://en.wikipedia.org/wiki/Hamcrest)
|
||||
framework are an alternative way to write assertions, useful for tests
|
||||
where you work with complex types or need to assert more complex
|
||||
properties. Matchers are easily composable and users can write their
|
||||
own and combine them with the Catch2-provided matchers seamlessly.
|
||||
|
||||
Matchers are introduced with the `REQUIRE_THAT` or `CHECK_THAT` macros, which take two arguments.
|
||||
The first argument is the thing (object or value) under test. The second part is a match _expression_,
|
||||
which consists of either a single matcher or one or more matchers combined using `&&`, `||` or `!` operators.
|
||||
|
||||
For example, to assert that a string ends with a certain substring:
|
||||
|
||||
```c++
|
||||
using Catch::Matchers::EndsWith; // or Catch::EndsWith
|
||||
std::string str = getStringFromSomewhere();
|
||||
REQUIRE_THAT( str, EndsWith( "as a service" ) );
|
||||
```
|
||||
## Using Matchers
|
||||
|
||||
The matcher objects can take multiple arguments, allowing more fine tuning.
|
||||
The built-in string matchers, for example, take a second argument specifying whether the comparison is
|
||||
case sensitive or not:
|
||||
Matchers are most commonly used in tandem with the `REQUIRE_THAT` or
|
||||
`CHECK_THAT` macros. The `REQUIRE_THAT` macro takes two arguments,
|
||||
the first one is the input (object/value) to test, the second argument
|
||||
is the matcher itself.
|
||||
|
||||
```c++
|
||||
REQUIRE_THAT( str, EndsWith( "as a service", Catch::CaseSensitive::No ) );
|
||||
```
|
||||
For example, to assert that a string ends with the "as a service"
|
||||
substring, you can write the following assertion
|
||||
|
||||
And matchers can be combined:
|
||||
```cpp
|
||||
using Catch::Matchers::EndsWith;
|
||||
|
||||
```c++
|
||||
REQUIRE_THAT( str,
|
||||
EndsWith( "as a service" ) ||
|
||||
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
|
||||
REQUIRE_THAT( getSomeString(), EndsWith("as a service") );
|
||||
```
|
||||
|
||||
## Built in matchers
|
||||
Currently Catch has some string matchers and some vector matchers. They are in the `Catch::Matchers` and `Catch` namespaces.
|
||||
The string matchers are `StartsWith`, `EndsWith`, `Contains` and `Equals`. Each of them also takes an optional second argument, that decides case sensitivity (by-default, they are case sensitive).
|
||||
The vector matchers are `Contains`, `VectorContains` and `Equals`. `VectorContains` looks for a single element in the matched vector, `Contains` looks for a set (vector) of elements inside the matched vector.
|
||||
Individual matchers can also be combined using the C++ logical
|
||||
operators, that is `&&`, `||`, and `!`, like so:
|
||||
|
||||
```cpp
|
||||
using Catch::Matchers::EndsWith;
|
||||
using Catch::Matchers::ContainsSubstring;
|
||||
|
||||
REQUIRE_THAT( getSomeString(),
|
||||
EndsWith("as a service") && ContainsSubstring("web scale"));
|
||||
```
|
||||
|
||||
The example above asserts that the string returned from `getSomeString`
|
||||
_both_ ends with the suffix "as a service" _and_ contains the string
|
||||
"web scale" somewhere.
|
||||
|
||||
|
||||
## Custom matchers
|
||||
It's easy to provide your own matchers to extend Catch or just to work with your own types.
|
||||
Both of the string matchers used in the examples above live in the
|
||||
`catch_matchers_string.hpp` header, so to compile the code above also
|
||||
requires `#include <catch2/matchers/catch_matchers_string.hpp>`.
|
||||
|
||||
You need to provide two things:
|
||||
1. A matcher class, derived from `Catch::MatcherBase<T>` - where `T` is the type being tested.
|
||||
The constructor takes and stores any arguments needed (e.g. something to compare against) and you must
|
||||
override two methods: `match()` and `describe()`.
|
||||
2. A simple builder function. This is what is actually called from the test code and allows overloading.
|
||||
**IMPORTANT**: The combining operators do not take ownership of the
|
||||
matcher objects being combined. This means that if you store combined
|
||||
matcher object, you have to ensure that the matchers being combined
|
||||
outlive its last use. What this means is that the following code leads
|
||||
to a use-after-free (UAF):
|
||||
|
||||
Here's an example for asserting that an integer falls within a given range
|
||||
(note that it is all inline for the sake of keeping the example short):
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
|
||||
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
|
||||
std::string str = "Bugs as a service";
|
||||
|
||||
auto match_expression = Catch::Matchers::EndsWith( "as a service" ) ||
|
||||
(Catch::Matchers::StartsWith( "Big data" ) && !Catch::Matchers::ContainsSubstring( "web scale" ) );
|
||||
REQUIRE_THAT(str, match_expression);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Built-in matchers
|
||||
|
||||
Every matcher provided by Catch2 is split into 2 parts, a factory
|
||||
function that lives in the `Catch::Matchers` namespace, and the actual
|
||||
matcher type that is in some deeper namespace and should not be used by
|
||||
the user. In the examples above, we used `Catch::Matchers::Contains`.
|
||||
This is the factory function for the
|
||||
`Catch::Matchers::StdString::ContainsMatcher` type that does the actual
|
||||
matching.
|
||||
|
||||
Out of the box, Catch2 provides the following matchers:
|
||||
|
||||
|
||||
### `std::string` matchers
|
||||
|
||||
Catch2 provides 5 different matchers that work with `std::string`,
|
||||
* `StartsWith(std::string str, CaseSensitive)`,
|
||||
* `EndsWith(std::string str, CaseSensitive)`,
|
||||
* `ContainsSubstring(std::string str, CaseSensitive)`,
|
||||
* `Equals(std::string str, CaseSensitive)`, and
|
||||
* `Matches(std::string str, CaseSensitive)`.
|
||||
|
||||
The first three should be fairly self-explanatory, they succeed if
|
||||
the argument starts with `str`, ends with `str`, or contains `str`
|
||||
somewhere inside it.
|
||||
|
||||
The `Equals` matcher matches a string if (and only if) the argument
|
||||
string is equal to `str`.
|
||||
|
||||
Finally, the `Matches` matcher performs an ECMAScript regex match using
|
||||
`str` against the argument string. It is important to know that
|
||||
the match is performed against the string as a whole, meaning that
|
||||
the regex `"abc"` will not match input string `"abcd"`. To match
|
||||
`"abcd"`, you need to use e.g. `"abc.*"` as your regex.
|
||||
|
||||
The second argument sets whether the matching should be case-sensitive
|
||||
or not. By default, it is case-sensitive.
|
||||
|
||||
> `std::string` matchers live in `catch2/matchers/catch_matchers_string.hpp`
|
||||
|
||||
|
||||
### Vector matchers
|
||||
|
||||
_Vector matchers have been deprecated in favour of the generic
|
||||
range matchers with the same functionality._
|
||||
|
||||
Catch2 provides 5 built-in matchers that work on `std::vector`.
|
||||
|
||||
These are
|
||||
|
||||
* `Contains` which checks whether a specified vector is present in the result
|
||||
* `VectorContains` which checks whether a specified element is present in the result
|
||||
* `Equals` which checks whether the result is exactly equal (order matters) to a specific vector
|
||||
* `UnorderedEquals` which checks whether the result is equal to a specific vector under a permutation
|
||||
* `Approx` which checks whether the result is "approx-equal" (order matters, but comparison is done via `Approx`) to a specific vector
|
||||
> Approx matcher was [introduced](https://github.com/catchorg/Catch2/issues/1499) in Catch2 2.7.2.
|
||||
|
||||
An example usage:
|
||||
```cpp
|
||||
std::vector<int> some_vec{ 1, 2, 3 };
|
||||
REQUIRE_THAT(some_vec, Catch::Matchers::UnorderedEquals(std::vector<int>{ 3, 2, 1 }));
|
||||
```
|
||||
|
||||
This assertions will pass, because the elements given to the matchers
|
||||
are a permutation of the ones in `some_vec`.
|
||||
|
||||
> vector matchers live in `catch2/matchers/catch_matchers_vector.hpp`
|
||||
|
||||
|
||||
### Floating point matchers
|
||||
|
||||
Catch2 provides 3 matchers that target floating point numbers. These
|
||||
are:
|
||||
|
||||
* `WithinAbs(double target, double margin)`,
|
||||
* `WithinULP(FloatingPoint target, uint64_t maxUlpDiff)`, and
|
||||
* `WithinRel(FloatingPoint target, FloatingPoint eps)`.
|
||||
|
||||
> `WithinRel` matcher was introduced in Catch2 2.10.0
|
||||
|
||||
|
||||
`WithinAbs` creates a matcher that accepts floating point numbers whose
|
||||
difference with `target` is less than the `margin`.
|
||||
|
||||
`WithinULP` creates a matcher that accepts floating point numbers that
|
||||
are no more than `maxUlpDiff`
|
||||
[ULPs](https://en.wikipedia.org/wiki/Unit_in_the_last_place)
|
||||
away from the `target` value. The short version of what this means
|
||||
is that there is no more than `maxUlpDiff - 1` representeable floating
|
||||
point numbers between the argument for matching and the `target` value.
|
||||
|
||||
**Important**: The WithinULP matcher requires the platform to use the
|
||||
[IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) representation for
|
||||
floating point numbers.
|
||||
|
||||
|
||||
`WithinRel` creates a matcher that accepts floating point numbers that
|
||||
are _approximately equal_ with the `target` with tolerance of `eps.`
|
||||
Specifically, it matches if
|
||||
`|arg - target| <= eps * max(|arg|, |target|)` holds. If you do not
|
||||
specify `eps`, `std::numeric_limits<FloatingPoint>::epsilon * 100`
|
||||
is used as the default.
|
||||
|
||||
|
||||
In practice, you will often want to combine multiple of these matchers,
|
||||
together for an assertion, because all 3 options have edge cases where
|
||||
they behave differently than you would expect. As an example, under
|
||||
the `WithinRel` matcher, a `0.` only ever matches a `0.` (or `-0.`),
|
||||
regardless of the relative tolerance specified. Thus, if you want to
|
||||
handle numbers that are "close enough to 0 to be 0", you have to combine
|
||||
it with the `WithinAbs` matcher.
|
||||
|
||||
For example, to check that our computation matches known good value
|
||||
within 0.1%, or is close enough (no different to 5 decimal places)
|
||||
to zero, we would write this assertion:
|
||||
```cpp
|
||||
REQUIRE_THAT( computation(input),
|
||||
Catch::Matchers::WithinRel(expected, 0.001)
|
||||
|| Catch::Matchers::WithinAbs(0, 0.000001) );
|
||||
```
|
||||
|
||||
|
||||
> floating point matchers live in `catch2/matchers/catch_matchers_floating.hpp`
|
||||
|
||||
|
||||
### Miscellaneous matchers
|
||||
|
||||
Catch2 also provides some matchers and matcher utilities that do not
|
||||
quite fit into other categories.
|
||||
|
||||
The first one of them is the `Predicate(Callable pred, std::string description)`
|
||||
matcher. It creates a matcher object that calls `pred` for the provided
|
||||
argument. The `description` argument allows users to set what the
|
||||
resulting matcher should self-describe as if required.
|
||||
|
||||
Do note that you will need to explicitly specify the type of the
|
||||
argument, like in this example:
|
||||
|
||||
```cpp
|
||||
REQUIRE_THAT("Hello olleH",
|
||||
Predicate<std::string>(
|
||||
[] (std::string const& str) -> bool { return str.front() == str.back(); },
|
||||
"First and last character should be equal")
|
||||
);
|
||||
```
|
||||
|
||||
> the predicate matcher lives in `catch2/matchers/catch_matchers_predicate.hpp`
|
||||
|
||||
|
||||
The other miscellaneous matcher utility is exception matching.
|
||||
|
||||
|
||||
#### Matching exceptions
|
||||
|
||||
Catch2 provides an utility macro for asserting that an expression
|
||||
throws exception of specific type, and that the exception has desired
|
||||
properties. The macro is `REQUIRE_THROWS_MATCHES(expr, ExceptionType, Matcher)`.
|
||||
|
||||
> `REQUIRE_THROWS_MATCHES` macro lives in `catch2/matchers/catch_matchers.hpp`
|
||||
|
||||
|
||||
Catch2 currently provides only one matcher for exceptions,
|
||||
`Message(std::string message)`. `Message` checks that the exception's
|
||||
message, as returned from `what` is exactly equal to `message`.
|
||||
|
||||
Example use:
|
||||
```cpp
|
||||
REQUIRE_THROWS_MATCHES(throwsDerivedException(), DerivedException, Message("DerivedException::what"));
|
||||
```
|
||||
|
||||
Note that `DerivedException` in the example above has to derive from
|
||||
`std::exception` for the example to work.
|
||||
|
||||
> the exception message matcher lives in `catch2/matchers/catch_matchers_exception.hpp`
|
||||
|
||||
|
||||
### Generic range Matchers
|
||||
|
||||
> Generic range matchers were introduced in Catch2 3.0.1
|
||||
|
||||
Catch2 also provides some matchers that use the new style matchers
|
||||
definitions to handle generic range-like types. These are:
|
||||
|
||||
* `IsEmpty()`
|
||||
* `SizeIs(size_t target_size)`
|
||||
* `SizeIs(Matcher size_matcher)`
|
||||
* `Contains(T&& target_element, Comparator = std::equal_to<>{})`
|
||||
* `Contains(Matcher element_matcher)`
|
||||
* `AllMatch(Matcher element_matcher)`
|
||||
* `NoneMatch(Matcher element_matcher)`
|
||||
* `AnyMatch(Matcher element_matcher)`
|
||||
* `AllTrue()`
|
||||
* `NoneTrue()`
|
||||
* `AnyTrue()`
|
||||
|
||||
`IsEmpty` should be self-explanatory. It successfully matches objects
|
||||
that are empty according to either `std::empty`, or ADL-found `empty`
|
||||
free function.
|
||||
|
||||
`SizeIs` checks range's size. If constructed with `size_t` arg, the
|
||||
matchers accepts ranges whose size is exactly equal to the arg. If
|
||||
constructed from another matcher, then the resulting matcher accepts
|
||||
ranges whose size is accepted by the provided matcher.
|
||||
|
||||
`Contains` accepts ranges that contain specific element. There are
|
||||
again two variants, one that accepts the desired element directly,
|
||||
in which case a range is accepted if any of its elements is equal to
|
||||
the target element. The other variant is constructed from a matcher,
|
||||
in which case a range is accepted if any of its elements is accepted
|
||||
by the provided matcher.
|
||||
|
||||
`AllMatch`, `NoneMatch`, and `AnyMatch` match ranges for which either
|
||||
all, none, or any of the contained elements matches the given matcher,
|
||||
respectively.
|
||||
|
||||
`AllTrue`, `NoneTrue`, and `AnyTrue` match ranges for which either
|
||||
all, none, or any of the contained elements are `true`, respectively.
|
||||
It works for ranges of `bool`s and ranges of elements (explicitly)
|
||||
convertible to `bool`.
|
||||
|
||||
## Writing custom matchers (old style)
|
||||
|
||||
The old style of writing matchers has been introduced back in Catch
|
||||
Classic. To create an old-style matcher, you have to create your own
|
||||
type that derives from `Catch::Matchers::MatcherBase<ArgT>`, where
|
||||
`ArgT` is the type your matcher works for. Your type has to override
|
||||
two methods, `bool match(ArgT const&) const`,
|
||||
and `std::string describe() const`.
|
||||
|
||||
As the name suggests, `match` decides whether the provided argument
|
||||
is matched (accepted) by the matcher. `describe` then provides a
|
||||
human-oriented description of what the matcher does.
|
||||
|
||||
We also recommend that you create factory function, just like Catch2
|
||||
does, but that is mostly useful for template argument deduction for
|
||||
templated matchers (assuming you do not have CTAD available).
|
||||
|
||||
To combine these into an example, let's say that you want to write
|
||||
a matcher that decides whether the provided argument is a number
|
||||
within certain range. We will call it `IsBetweenMatcher<T>`:
|
||||
|
||||
```c++
|
||||
// The matcher class
|
||||
class IntRange : public Catch::MatcherBase<int> {
|
||||
int m_begin, m_end;
|
||||
public:
|
||||
IntRange( int begin, int end ) : m_begin( begin ), m_end( end ) {}
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
// ...
|
||||
|
||||
// Performs the test for this matcher
|
||||
virtual bool match( int const& i ) const override {
|
||||
return i >= m_begin && i <= m_end;
|
||||
|
||||
template <typename T>
|
||||
class IsBetweenMatcher : public Catch::Matchers::MatcherBase<T> {
|
||||
T m_begin, m_end;
|
||||
public:
|
||||
IsBetweenMatcher(T begin, T end) : m_begin(begin), m_end(end) {}
|
||||
|
||||
bool match(T const& in) const override {
|
||||
return in >= m_begin && in <= m_end;
|
||||
}
|
||||
|
||||
// Produces a string describing what this matcher does. It should
|
||||
// include any provided data (the begin/ end in this case) and
|
||||
// be written as if it were stating a fact (in the output it will be
|
||||
// preceded by the value under test).
|
||||
virtual std::string describe() const {
|
||||
std::string describe() const override {
|
||||
std::ostringstream ss;
|
||||
ss << "is between " << m_begin << " and " << m_end;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
// The builder function
|
||||
inline IntRange IsBetween( int begin, int end ) {
|
||||
return IntRange( begin, end );
|
||||
template <typename T>
|
||||
IsBetweenMatcher<T> IsBetween(T begin, T end) {
|
||||
return { begin, end };
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
// Usage
|
||||
TEST_CASE("Integers are within a range")
|
||||
{
|
||||
CHECK_THAT( 3, IsBetween( 1, 10 ) );
|
||||
CHECK_THAT( 100, IsBetween( 1, 10 ) );
|
||||
TEST_CASE("Numbers are within range") {
|
||||
// infers `double` for the argument type of the matcher
|
||||
CHECK_THAT(3., IsBetween(1., 10.));
|
||||
// infers `int` for the argument type of the matcher
|
||||
CHECK_THAT(100, IsBetween(1, 10));
|
||||
}
|
||||
```
|
||||
|
||||
Running this test gives the following in the console:
|
||||
|
||||
```
|
||||
/**/TestFile.cpp:123: FAILED:
|
||||
CHECK_THAT( 100, IsBetween( 1, 10 ) )
|
||||
with expansion:
|
||||
100 is between 1 and 10
|
||||
Obviously, the code above can be improved somewhat, for example you
|
||||
might want to `static_assert` over the fact that `T` is an arithmetic
|
||||
type... or generalize the matcher to cover any type for which the user
|
||||
can provide a comparison function object.
|
||||
|
||||
Note that while any matcher written using the old style can also be
|
||||
written using the new style, combining old style matchers should
|
||||
generally compile faster. Also note that you can combine old and new
|
||||
style matchers arbitrarily.
|
||||
|
||||
> `MatcherBase` lives in `catch2/matchers/catch_matchers.hpp`
|
||||
|
||||
|
||||
## Writing custom matchers (new style)
|
||||
|
||||
> New style matchers were introduced in Catch2 3.0.1
|
||||
|
||||
To create a new-style matcher, you have to create your own type that
|
||||
derives from `Catch::Matchers::MatcherGenericBase`. Your type has to
|
||||
also provide two methods, `bool match( ... ) const` and overriden
|
||||
`std::string describe() const`.
|
||||
|
||||
Unlike with old-style matchers, there are no requirements on how
|
||||
the `match` member function takes its argument. This means that the
|
||||
argument can be taken by value or by mutating reference, but also that
|
||||
the matcher's `match` member function can be templated.
|
||||
|
||||
This allows you to write more complex matcher, such as a matcher that
|
||||
can compare one range-like (something that responds to `begin` and
|
||||
`end`) object to another, like in the following example:
|
||||
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers_templated.hpp>
|
||||
// ...
|
||||
|
||||
template<typename Range>
|
||||
struct EqualsRangeMatcher : Catch::Matchers::MatcherGenericBase {
|
||||
EqualsRangeMatcher(Range const& range):
|
||||
range{ range }
|
||||
{}
|
||||
|
||||
template<typename OtherRange>
|
||||
bool match(OtherRange const& other) const {
|
||||
using std::begin; using std::end;
|
||||
|
||||
return std::equal(begin(range), end(range), begin(other), end(other));
|
||||
}
|
||||
|
||||
std::string describe() const override {
|
||||
return "Equals: " + Catch::rangeToString(range);
|
||||
}
|
||||
|
||||
private:
|
||||
Range const& range;
|
||||
};
|
||||
|
||||
template<typename Range>
|
||||
auto EqualsRange(const Range& range) -> EqualsRangeMatcher<Range> {
|
||||
return EqualsRangeMatcher<Range>{range};
|
||||
}
|
||||
|
||||
TEST_CASE("Combining templated matchers", "[matchers][templated]") {
|
||||
std::array<int, 3> container{{ 1,2,3 }};
|
||||
|
||||
std::array<int, 3> a{{ 1,2,3 }};
|
||||
std::vector<int> b{ 0,1,2 };
|
||||
std::list<int> c{ 4,5,6 };
|
||||
|
||||
REQUIRE_THAT(container, EqualsRange(a) || EqualsRange(b) || EqualsRange(c));
|
||||
}
|
||||
```
|
||||
|
||||
Do note that while you can rewrite any matcher from the old style to
|
||||
a new style matcher, combining new style matchers is more expensive
|
||||
in terms of compilation time. Also note that you can combine old style
|
||||
and new style matchers arbitrarily.
|
||||
|
||||
> `MatcherGenericBase` lives in `catch2/matchers/catch_matchers_templated.hpp`
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
85
docs/migrate-v2-to-v3.md
Normal file
85
docs/migrate-v2-to-v3.md
Normal file
@ -0,0 +1,85 @@
|
||||
<a id="top"></a>
|
||||
# Migrating from v2 to v3
|
||||
|
||||
v3 is the next major version of Catch2 and brings three significant changes:
|
||||
* Catch2 is now split into multiple headers
|
||||
* Catch2 is now compiled as a static library
|
||||
* C++14 is the minimum required C++ version
|
||||
|
||||
There are many reasons why we decided to go from the old single-header
|
||||
distribution model to a more standard library distribution model. The
|
||||
big one is compile-time performance, but moving over to a split header
|
||||
distribution model also improves the future maintainability and
|
||||
extendability of the codebase. For example v3 adds a new kind of matchers
|
||||
without impacting the compilation times of users that do not use matchers
|
||||
in their tests. The new model is also more friendly towards package
|
||||
managers, such as vcpkg and Conan.
|
||||
|
||||
The result of this move is a significant improvement in compilation
|
||||
times, e.g. the inclusion overhead of Catch2 in the common case has been
|
||||
reduced by roughly 80%. The improved ease of maintenance also led to
|
||||
various runtime performance improvements and the introduction of new features.
|
||||
For details, look at [the release notes of 3.0.1](release-notes.md#301).
|
||||
|
||||
_Note that we still provide one header + one TU distribution but do
|
||||
not consider it the primarily supported option. You should also expect
|
||||
that the compilation times will be worse if you use this option._
|
||||
|
||||
|
||||
## How to migrate projects from v2 to v3
|
||||
|
||||
To migrate to v3, there are two basic approaches to do so.
|
||||
|
||||
1. Use `catch_amalgamated.hpp` and `catch_amalgamated.cpp`.
|
||||
2. Build Catch2 as a proper (static) library, and move to piecewise headers
|
||||
|
||||
Doing 1 means downloading the [amalgamated header](/extras/catch_amalgamated.hpp)
|
||||
and the [amalgamated sources](/extras/catch_amalgamated.cpp) from `extras`,
|
||||
dropping them into your test project, and rewriting your includes from
|
||||
`<catch2/catch.hpp>` to `"catch_amalgamated.hpp"` (or something similar,
|
||||
based on how you set up your paths).
|
||||
|
||||
The disadvantage of using this approach are increased compilation times,
|
||||
at least compared to the second approach, but it does let you avoid
|
||||
dealing with consuming libraries in your build system of choice.
|
||||
|
||||
|
||||
However, we recommend doing 2, and taking extra time to migrate to v3
|
||||
properly. This lets you reap the benefits of significantly improved
|
||||
compilation times in the v3 version. The basic steps to do so are:
|
||||
|
||||
1. Change your CMakeLists.txt to link against `Catch2WithMain` target if
|
||||
you use Catch2's default main. (If you do not, keep linking against
|
||||
the `Catch2` target.). If you use pkg-config, change `pkg-config catch2` to
|
||||
`pkg-config catch2-with-main`.
|
||||
2. Delete TU with `CATCH_CONFIG_RUNNER` or `CATCH_CONFIG_MAIN` defined,
|
||||
as it is no longer needed.
|
||||
3. Change `#include <catch2/catch.hpp>` to `#include <catch2/catch_all.hpp>`
|
||||
4. Check that everything compiles. You might have to modify namespaces,
|
||||
or perform some other changes (see the
|
||||
[Things that can break during porting](#things-that-can-break-during-porting)
|
||||
section for the most common things).
|
||||
5. Start migrating your test TUs from including `<catch2/catch_all.hpp>`
|
||||
to piecemeal includes. You will likely want to start by including
|
||||
`<catch2/catch_test_macros.hpp>`, and then go from there. (see
|
||||
[other notes](#other-notes) for further ideas)
|
||||
|
||||
## Other notes
|
||||
* The main test include is now `<catch2/catch_test_macros.hpp>`
|
||||
* Big "subparts" like Matchers, or Generators, have their own folder, and
|
||||
also their own "big header", so if you just want to include all matchers,
|
||||
you can include `<catch2/matchers/catch_matchers_all.hpp>`,
|
||||
or `<catch2/generators/catch_generators_all.hpp>`
|
||||
|
||||
|
||||
## Things that can break during porting
|
||||
* The namespace on Matchers were cleaned up, they are no longer first declared
|
||||
deep within an internal namespace and then brought up. All Matchers now live
|
||||
in `Catch::Matchers`.
|
||||
* The reporter interfaces changed in a breaking manner. If you wrote custom
|
||||
reporter or listener, you might need to modify them a bit.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@ -1,42 +1,81 @@
|
||||
<a id="top"></a>
|
||||
# Open Source projects using Catch
|
||||
# Open Source projects using Catch2
|
||||
|
||||
Catch is great for open source. With it's [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
|
||||
it's easy to just drop the header into your project and start writing tests - what's not to like?
|
||||
Catch2 is great for open source. It is licensed under the [Boost Software
|
||||
License (BSL)](../LICENSE.txt), has no further dependencies and supports
|
||||
two file distribution.
|
||||
|
||||
As a result, Catch2 is used for testing in many different Open Source
|
||||
projects. This page lists at least some of them, even though it will
|
||||
obviously never be complete (and does not have the ambition to be
|
||||
complete). Note that the list below is intended to be in alphabetical
|
||||
order, to avoid implications of relative importance of the projects.
|
||||
|
||||
_Please only add projects here if you are their maintainer, or have the
|
||||
maintainer's explicit consent._
|
||||
|
||||
As a result Catch is now being used in many Open Source projects, including some quite well known ones.
|
||||
This page is an attempt to track those projects. Obviously it can never be complete.
|
||||
This effort largely relies on the maintainers of the projects themselves updating this page and submitting a PR
|
||||
(or, if you prefer contact one of the maintainers of Catch directly, use the
|
||||
[forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)), or raise an [issue](https://github.com/philsquared/Catch/issues) to let us know).
|
||||
Of course users of those projects might want to update this page too. That's fine - as long you're confident the project maintainers won't mind.
|
||||
If you're an Open Source project maintainer and see your project listed here but would rather it wasn't -
|
||||
just let us know via any of the previously mentioned means - although I'm sure there won't be many who feel that way.
|
||||
|
||||
Listing a project here does not imply endorsement and the plan is to keep these ordered alphabetically to avoid an implication of relative importance.
|
||||
|
||||
## Libraries & Frameworks
|
||||
|
||||
### [Azmq](https://github.com/zeromq/azmq)
|
||||
Boost Asio style bindings for ZeroMQ
|
||||
### [accessorpp](https://github.com/wqking/accessorpp)
|
||||
C++ library for implementing property and data binding.
|
||||
|
||||
### [ChakraCore](https://github.com/Microsoft/ChakraCore)
|
||||
The core part of the Chakra Javascript engine that powers Microsoft Edge
|
||||
### [alpaka](https://github.com/alpaka-group/alpaka)
|
||||
A header-only C++14 abstraction library for accelerator development.
|
||||
|
||||
### [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp)
|
||||
C++11 implementation of Approval Tests, for quick, convenient testing of legacy code.
|
||||
|
||||
### [args](https://github.com/Taywee/args)
|
||||
A simple header-only C++ argument parser library.
|
||||
|
||||
### [Azmq](https://github.com/zeromq/azmq)
|
||||
Boost Asio style bindings for ZeroMQ.
|
||||
|
||||
### [Cataclysm: Dark Days Ahead](https://github.com/CleverRaven/Cataclysm-DDA)
|
||||
Post-apocalyptic survival RPG.
|
||||
|
||||
### [ChaiScript](https://github.com/ChaiScript/ChaiScript)
|
||||
A, header-only, embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques
|
||||
A, header-only, embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques.
|
||||
|
||||
### [ChakraCore](https://github.com/Microsoft/ChakraCore)
|
||||
The core part of the Chakra JavaScript engine that powers Microsoft Edge.
|
||||
|
||||
### [Clara](https://github.com/philsquared/Clara)
|
||||
A, single-header-only, type-safe, command line parser - which also prints formatted usage strings.
|
||||
|
||||
### [Couchbase-lite-core](https://github.com/couchbase/couchbase-lite-core)
|
||||
The next-generation core storage and query engine for Couchbase Lite/
|
||||
The next-generation core storage and query engine for Couchbase Lite.
|
||||
|
||||
### [JSON for Modern C++](https://github.com/nlohmann/json)
|
||||
A, single-header, JSON parsing library that takes advantage of what C++ has to offer.
|
||||
### [cppcodec](https://github.com/tplgy/cppcodec)
|
||||
Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockford's base32.
|
||||
|
||||
### [DtCraft](https://github.com/twhuang-uiuc/DtCraft)
|
||||
A High-performance Cluster Computing Engine.
|
||||
|
||||
### [eventpp](https://github.com/wqking/eventpp)
|
||||
C++ event library for callbacks, event dispatcher, and event queue. With eventpp you can easily implement signal and slot mechanism, publisher and subscriber pattern, or observer pattern.
|
||||
|
||||
### [forest](https://github.com/xorz57/forest)
|
||||
Template Library of Tree Data Structures.
|
||||
|
||||
### [Fuxedo](https://github.com/fuxedo/fuxedo)
|
||||
Open source Oracle Tuxedo-like XATMI middleware for C and C++.
|
||||
|
||||
### [HIP CPU Runtime](https://github.com/ROCm-Developer-Tools/HIP-CPU)
|
||||
A header-only library that allows CPUs to execute unmodified HIP code. It is generic and does not assume a particular CPU vendor or architecture.
|
||||
|
||||
### [Inja](https://github.com/pantor/inja)
|
||||
A header-only template engine for modern C++.
|
||||
|
||||
### [LLAMA](https://github.com/alpaka-group/llama)
|
||||
A C++17 template header-only library for the abstraction of memory access patterns.
|
||||
|
||||
### [libcluon](https://github.com/chrberger/libcluon)
|
||||
A single-header-only library written in C++14 to glue distributed software components (UDP, TCP, shared memory) supporting natively Protobuf, LCM/ZCM, MsgPack, and JSON for dynamic message transformations in-between.
|
||||
|
||||
### [MNMLSTC Core](https://github.com/mnmlstc/core)
|
||||
a small and easy to use C++11 library that adds a functionality set that will be available in C++14 and later, as well as some useful additions
|
||||
A small and easy to use C++11 library that adds a functionality set that will be available in C++14 and later, as well as some useful additions.
|
||||
|
||||
### [nanodbc](https://github.com/lexicalunit/nanodbc/)
|
||||
A small C++ library wrapper for the native C ODBC API.
|
||||
@ -44,43 +83,67 @@ A small C++ library wrapper for the native C ODBC API.
|
||||
### [Nonius](https://github.com/libnonius/nonius)
|
||||
A header-only framework for benchmarking small snippets of C++ code.
|
||||
|
||||
### [SOCI](https://github.com/SOCI/soci)
|
||||
The C++ Database Access Library
|
||||
### [OpenALpp](https://github.com/Laguna1989/OpenALpp)
|
||||
A modern OOP C++14 audio library built on OpenAL for Windows, Linux and web (emscripten).
|
||||
|
||||
### [polymorphic_value](https://github.com/jbcoe/polymorphic_value)
|
||||
A polymorphic value-type for C++
|
||||
A polymorphic value-type for C++.
|
||||
|
||||
### [Ppconsul](https://github.com/oliora/ppconsul)
|
||||
A C++ client library for Consul. Consul is a distributed tool for discovering and configuring services in your infrastructure
|
||||
A C++ client library for Consul. Consul is a distributed tool for discovering and configuring services in your infrastructure.
|
||||
|
||||
### [Reactive-Extensions/ RxCpp](https://github.com/Reactive-Extensions/RxCpp)
|
||||
A library of algorithms for values-distributed-in-time
|
||||
A library of algorithms for values-distributed-in-time.
|
||||
|
||||
### [SOCI](https://github.com/SOCI/soci)
|
||||
The C++ Database Access Library.
|
||||
|
||||
### [TextFlowCpp](https://github.com/philsquared/textflowcpp)
|
||||
A small, single-header-only, library for wrapping and composing columns of text
|
||||
A small, single-header-only, library for wrapping and composing columns of text.
|
||||
|
||||
### [thor](https://github.com/xorz57/thor)
|
||||
Wrapper Library for CUDA.
|
||||
|
||||
### [toml++](https://github.com/marzer/tomlplusplus)
|
||||
A header-only TOML parser and serializer for modern C++.
|
||||
|
||||
### [Trompeloeil](https://github.com/rollbear/trompeloeil)
|
||||
A thread safe header only mocking framework for C++14
|
||||
|
||||
### [args](https://github.com/Taywee/args)
|
||||
A simple header-only C++ argument parser library.
|
||||
A thread-safe header-only mocking framework for C++14.
|
||||
|
||||
## Applications & Tools
|
||||
|
||||
### [App Mesh](https://github.com/laoshanxi/app-mesh)
|
||||
A high available cloud native micro-service application management platform implemented by modern C++.
|
||||
|
||||
### [ArangoDB](https://github.com/arangodb/arangodb)
|
||||
ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values.
|
||||
|
||||
### [Cytopia](https://github.com/CytopiaTeam/Cytopia)
|
||||
Cytopia is a free, open source retro pixel-art city building game with a big focus on mods. It utilizes a custom isometric rendering engine based on SDL2.
|
||||
|
||||
### [d-SEAMS](https://github.com/d-SEAMS/seams-core)
|
||||
Open source molecular dynamics simulation structure analysis suite of tools in modern C++.
|
||||
|
||||
### [Giada - Your Hardcore Loop Machine](https://github.com/monocasual/giada)
|
||||
Minimal, open-source and cross-platform audio tool for live music production.
|
||||
|
||||
### [MAME](https://github.com/mamedev/mame)
|
||||
MAME originally stood for Multiple Arcade Machine Emulator
|
||||
MAME originally stood for Multiple Arcade Machine Emulator.
|
||||
|
||||
### [Newsbeuter](https://github.com/akrennmair/newsbeuter)
|
||||
Newsbeuter is an open-source RSS/Atom feed reader for text terminals.
|
||||
|
||||
### [PopHead](https://github.com/SPC-Some-Polish-Coders/PopHead)
|
||||
A 2D, Zombie, RPG game which is being made on our own engine.
|
||||
|
||||
### [raspigcd](https://github.com/pantadeusz/raspigcd)
|
||||
Low level CLI app and library for execution of GCODE on Raspberry Pi without any additional microcontrolers (just RPi + Stepsticks).
|
||||
|
||||
### [SpECTRE](https://github.com/sxs-collaboration/spectre)
|
||||
SpECTRE is a code for multi-scale, multi-physics problems in astrophysics and gravitational physics.
|
||||
|
||||
### [Standardese](https://github.com/foonathan/standardese)
|
||||
Standardese aims to be a nextgen Doxygen
|
||||
Standardese aims to be a nextgen Doxygen.
|
||||
|
||||
---
|
||||
|
||||
|
155
docs/other-macros.md
Normal file
155
docs/other-macros.md
Normal file
@ -0,0 +1,155 @@
|
||||
<a id="top"></a>
|
||||
# Other macros
|
||||
|
||||
This page serves as a reference for macros that are not documented
|
||||
elsewhere. For now, these macros are separated into 2 rough categories,
|
||||
"assertion related macros" and "test case related macros".
|
||||
|
||||
## Assertion related macros
|
||||
|
||||
* `CHECKED_IF` and `CHECKED_ELSE`
|
||||
|
||||
`CHECKED_IF( expr )` is an `if` replacement, that also applies Catch2's
|
||||
stringification machinery to the _expr_ and records the result. As with
|
||||
`if`, the block after a `CHECKED_IF` is entered only if the expression
|
||||
evaluates to `true`. `CHECKED_ELSE( expr )` work similarly, but the block
|
||||
is entered only if the _expr_ evaluated to `false`.
|
||||
|
||||
> `CHECKED_X` macros were changed to not count as failure in Catch2 3.0.1.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
int a = ...;
|
||||
int b = ...;
|
||||
CHECKED_IF( a == b ) {
|
||||
// This block is entered when a == b
|
||||
} CHECKED_ELSE ( a == b ) {
|
||||
// This block is entered when a != b
|
||||
}
|
||||
```
|
||||
|
||||
* `CHECK_NOFAIL`
|
||||
|
||||
`CHECK_NOFAIL( expr )` is a variant of `CHECK` that does not fail the test
|
||||
case if _expr_ evaluates to `false`. This can be useful for checking some
|
||||
assumption, that might be violated without the test necessarily failing.
|
||||
|
||||
Example output:
|
||||
```
|
||||
main.cpp:6:
|
||||
FAILED - but was ok:
|
||||
CHECK_NOFAIL( 1 == 2 )
|
||||
|
||||
main.cpp:7:
|
||||
PASSED:
|
||||
CHECK( 2 == 2 )
|
||||
```
|
||||
|
||||
* `SUCCEED`
|
||||
|
||||
`SUCCEED( msg )` is mostly equivalent with `INFO( msg ); REQUIRE( true );`.
|
||||
In other words, `SUCCEED` is for cases where just reaching a certain line
|
||||
means that the test has been a success.
|
||||
|
||||
Example usage:
|
||||
```cpp
|
||||
TEST_CASE( "SUCCEED showcase" ) {
|
||||
int I = 1;
|
||||
SUCCEED( "I is " << I );
|
||||
}
|
||||
```
|
||||
|
||||
* `STATIC_REQUIRE` and `STATIC_CHECK`
|
||||
|
||||
> `STATIC_REQUIRE` was [introduced](https://github.com/catchorg/Catch2/issues/1362) in Catch2 2.4.2.
|
||||
|
||||
`STATIC_REQUIRE( expr )` is a macro that can be used the same way as a
|
||||
`static_assert`, but also registers the success with Catch2, so it is
|
||||
reported as a success at runtime. The whole check can also be deferred
|
||||
to the runtime, by defining `CATCH_CONFIG_RUNTIME_STATIC_REQUIRE` before
|
||||
including the Catch2 header.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
TEST_CASE("STATIC_REQUIRE showcase", "[traits]") {
|
||||
STATIC_REQUIRE( std::is_void<void>::value );
|
||||
STATIC_REQUIRE_FALSE( std::is_void<int>::value );
|
||||
}
|
||||
```
|
||||
|
||||
> `STATIC_CHECK` was [introduced](https://github.com/catchorg/Catch2/pull/2318) in Catch2 3.0.1.
|
||||
|
||||
`STATIC_CHECK( expr )` is equivalent to `STATIC_REQUIRE( expr )`, with the
|
||||
difference that when `CATCH_CONFIG_RUNTIME_STATIC_REQUIRE` is defined, it
|
||||
becomes equivalent to `CHECK` instead of `REQUIRE`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
TEST_CASE("STATIC_CHECK showcase", "[traits]") {
|
||||
STATIC_CHECK( std::is_void<void>::value );
|
||||
STATIC_CHECK_FALSE( std::is_void<int>::value );
|
||||
}
|
||||
```
|
||||
|
||||
## Test case related macros
|
||||
|
||||
* `METHOD_AS_TEST_CASE`
|
||||
|
||||
`METHOD_AS_TEST_CASE( member-function-pointer, description )` lets you
|
||||
register a member function of a class as a Catch2 test case. The class
|
||||
will be separately instantiated for each method registered in this way.
|
||||
|
||||
```cpp
|
||||
class TestClass {
|
||||
std::string s;
|
||||
|
||||
public:
|
||||
TestClass()
|
||||
:s( "hello" )
|
||||
{}
|
||||
|
||||
void testCase() {
|
||||
REQUIRE( s == "hello" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
METHOD_AS_TEST_CASE( TestClass::testCase, "Use class's method as a test case", "[class]" )
|
||||
```
|
||||
|
||||
* `REGISTER_TEST_CASE`
|
||||
|
||||
`REGISTER_TEST_CASE( function, description )` let's you register
|
||||
a `function` as a test case. The function has to have `void()` signature,
|
||||
the description can contain both name and tags.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
REGISTER_TEST_CASE( someFunction, "ManuallyRegistered", "[tags]" );
|
||||
```
|
||||
|
||||
_Note that the registration still has to happen before Catch2's session
|
||||
is initiated. This means that it either needs to be done in a global
|
||||
constructor, or before Catch2's session is created in user's own main._
|
||||
|
||||
|
||||
* `DYNAMIC_SECTION`
|
||||
|
||||
> Introduced in Catch2 2.3.0.
|
||||
|
||||
`DYNAMIC_SECTION` is a `SECTION` where the user can use `operator<<` to
|
||||
create the final name for that section. This can be useful with e.g.
|
||||
generators, or when creating a `SECTION` dynamically, within a loop.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
TEST_CASE( "looped SECTION tests" ) {
|
||||
int a = 1;
|
||||
|
||||
for( int b = 0; b < 10; ++b ) {
|
||||
DYNAMIC_SECTION( "b is currently: " << b ) {
|
||||
CHECK( b > a );
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
123
docs/own-main.md
123
docs/own-main.md
@ -1,72 +1,70 @@
|
||||
<a id="top"></a>
|
||||
# Supplying main() yourself
|
||||
|
||||
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
|
||||
**Contents**<br>
|
||||
[Let Catch2 take full control of args and config](#let-catch2-take-full-control-of-args-and-config)<br>
|
||||
[Amending the Catch2 config](#amending-the-catch2-config)<br>
|
||||
[Adding your own command line options](#adding-your-own-command-line-options)<br>
|
||||
[Version detection](#version-detection)<br>
|
||||
|
||||
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
|
||||
The easiest way to use Catch2 is to use its own `main` function, and let
|
||||
it handle the command line arguments. This is done by linking against
|
||||
Catch2Main library, e.g. through the [CMake target](cmake-integration.md#cmake-targets),
|
||||
or pkg-config files.
|
||||
|
||||
Sometimes, though, you need to write your own version of main(). You can do this by writing ```#define CATCH_CONFIG_RUNNER``` instead. Now you are free to write ```main()``` as normal and call into Catch yourself manually.
|
||||
If you want to provide your own `main`, then you should link against
|
||||
the static library (target) only, without the main part. You will then
|
||||
have to write your own `main` and call into Catch2 test runner manually.
|
||||
|
||||
You now have a lot of flexibility - but here are three recipes to get your started:
|
||||
Below are some basic recipes on what you can do supplying your own main.
|
||||
|
||||
## Let Catch take full control of args and config
|
||||
|
||||
If you just need to have code that executes before and/ or after Catch this is the simplest option.
|
||||
## Let Catch2 take full control of args and config
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
This is useful if you just need to have code that executes before/after
|
||||
Catch2 runs tests.
|
||||
|
||||
```cpp
|
||||
#include <catch2/catch_session.hpp>
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
// global setup...
|
||||
// your setup ...
|
||||
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
|
||||
// global clean-up...
|
||||
// your clean-up...
|
||||
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
## Amending the config
|
||||
_Note that if you only want to run some set up before tests are run, it
|
||||
might be simpler to use [event listeners](event-listeners.md#top) instead._
|
||||
|
||||
If you still want Catch to process the command line, but you want to programatically tweak the config, you can do so in one of two ways:
|
||||
|
||||
## Amending the Catch2 config
|
||||
|
||||
If you want Catch2 to process command line arguments, but also want to
|
||||
programmatically change the resulting configuration of Catch2 run,
|
||||
you can do it in two ways:
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
int main( int argc, char* argv[] ) {
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
// writing to session.configData() here sets defaults
|
||||
// this is the preferred way to set them
|
||||
|
||||
// Verify that all tests, aliases, etc registered properly
|
||||
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
|
||||
if ( !exceptions.empty() ) {
|
||||
// iterate over all exceptions and notify user
|
||||
for ( const auto& ex_ptr : exceptions ) {
|
||||
try {
|
||||
std::rethrow_exception(ex_ptr);
|
||||
} catch (std::exception const& ex) {
|
||||
Catch::cerr() << ex.what();
|
||||
}
|
||||
}
|
||||
// Indicate that an error occured before main
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
return returnCode;
|
||||
|
||||
// writing to session.configData() or session.Config() here
|
||||
// writing to session.configData() or session.Config() here
|
||||
// overrides command line args
|
||||
// only do this if you know you need to
|
||||
|
||||
int numFailed = session.run();
|
||||
|
||||
// numFailed is clamped to 255 as some unices only use the lower 8 bits.
|
||||
// This clamping has already been applied, so just return it here
|
||||
// You can also do any post run clean-up here
|
||||
@ -74,13 +72,60 @@ int main( int argc, char* argv[] )
|
||||
}
|
||||
```
|
||||
|
||||
Take a look at the definitions of Config and ConfigData to see what you can do with them.
|
||||
If you want full control of the configuration, don't call `applyCommandLine`.
|
||||
|
||||
To take full control of the config simply omit the call to ```applyCommandLine()```.
|
||||
|
||||
## Adding your own command line options
|
||||
|
||||
Catch embeds a powerful command line parser which you can also use to parse your own options out. This capability is still in active development but will be documented here when it is ready.
|
||||
You can add new command line options to Catch2, by composing the premade
|
||||
CLI parser (called Clara), and add your own options.
|
||||
|
||||
```cpp
|
||||
int main( int argc, char* argv[] ) {
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
int height = 0; // Some user variable you want to be able to set
|
||||
|
||||
// Build a new parser on top of Catch2's
|
||||
using namespace Catch::Clara;
|
||||
auto cli
|
||||
= session.cli() // Get Catch2's command line parser
|
||||
| Opt( height, "height" ) // bind variable to a new option, with a hint string
|
||||
["-g"]["--height"] // the option names it will respond to
|
||||
("how high?"); // description string for the help output
|
||||
|
||||
// Now pass the new composite back to Catch2 so it uses that
|
||||
session.cli( cli );
|
||||
|
||||
// Let Catch2 (using Clara) parse the command line
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
|
||||
// if set on the command line then 'height' is now set at this point
|
||||
if( height > 0 )
|
||||
std::cout << "height: " << height << std::endl;
|
||||
|
||||
return session.run();
|
||||
}
|
||||
```
|
||||
|
||||
See the [Clara documentation](https://github.com/catchorg/Clara/blob/master/README.md)
|
||||
for more details on how to use the Clara parser.
|
||||
|
||||
|
||||
## Version detection
|
||||
|
||||
Catch2 provides a triplet of macros providing the header's version,
|
||||
|
||||
* `CATCH_VERSION_MAJOR`
|
||||
* `CATCH_VERSION_MINOR`
|
||||
* `CATCH_VERSION_PATCH`
|
||||
|
||||
these macros expand into a single number, that corresponds to the appropriate
|
||||
part of the version. As an example, given single header version v2.3.4,
|
||||
the macros would expand into `2`, `3`, and `4` respectively.
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,18 @@
|
||||
<a id="top"></a>
|
||||
# How to release
|
||||
|
||||
When enough changes have accumulated, it is time to release new version of Catch. This document describes the proces in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `scripts/` directory.
|
||||
When enough changes have accumulated, it is time to release new version of Catch. This document describes the process in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `tools/scripts/` directory.
|
||||
|
||||
## Neccessary steps
|
||||
## Necessary steps
|
||||
|
||||
These steps are neccessary and have to be performed before each new release. They serve to make sure that the new release is correct and linked-to from the standard places.
|
||||
These steps are necessary and have to be performed before each new release. They serve to make sure that the new release is correct and linked-to from the standard places.
|
||||
|
||||
|
||||
### Approval testing
|
||||
### Testing
|
||||
|
||||
Catch's releases are primarily validated against output from previous release, stored in `projects/SelfTest/Baselines`. To validate current sources, build the SelfTest binary and pass it to the `approvalTests.py` script: `approvalTests.py <path/to/SelfTest>`.
|
||||
|
||||
There should be no differences, as Approval tests should be updated when changes to Catch are made, but if there are, then they need to be manually reviewed and either approved (using `approve.py`) or Catch requires other fixes.
|
||||
All of the tests are currently run in our CI setup based on TravisCI and
|
||||
AppVeyor. As long as the last commit tested green, the release can
|
||||
proceed.
|
||||
|
||||
|
||||
### Incrementing version number
|
||||
@ -21,44 +21,46 @@ Catch uses a variant of [semantic versioning](http://semver.org/), with breaking
|
||||
|
||||
After deciding which part of version number should be incremented, you can use one of the `*Release.py` scripts to perform the required changes to Catch.
|
||||
|
||||
|
||||
### Generate updated single-include header
|
||||
|
||||
After updating version number, regenerate single-include header using `generateSingleHeader.py`.
|
||||
This will take care of generating the single include header, updating
|
||||
version numbers everywhere and pushing the new version to Wandbox.
|
||||
|
||||
|
||||
### Release notes
|
||||
|
||||
Once a release is ready, release notes need to be written. They should summarize changes done since last release. For rough idea of expected notes see previous releases. Once written, release notes should be placed in `docs/release-notes.md`.
|
||||
Once a release is ready, release notes need to be written. They should summarize changes done since last release. For rough idea of expected notes see previous releases. Once written, release notes should be added to `docs/release-notes.md`.
|
||||
|
||||
|
||||
### Commit and push update to GitHub
|
||||
|
||||
After version number is incremented, single-include header is regenerated and release notes are updated, changes should be commited and pushed to GitHub.
|
||||
After version number is incremented, single-include header is regenerated and release notes are updated, changes should be committed and pushed to GitHub.
|
||||
|
||||
|
||||
### Release on GitHub
|
||||
|
||||
After pushing changes to GitHub, GitHub release *needs* to be created. Tag version and release title should be same as the new version, description should contain the release notes for the current release. Single header version of `catch.hpp` *needs* to be attached as a binary, as that is where the official download link links to. Preferably it should use linux line endings.
|
||||
After pushing changes to GitHub, GitHub release *needs* to be created.
|
||||
Tag version and release title should be same as the new version,
|
||||
description should contain the release notes for the current release.
|
||||
We also attach the two amalgamated files as "binaries".
|
||||
|
||||
## Optional steps
|
||||
Since 2.5.0, the release tag and the "binaries" (amalgamated files) should
|
||||
be PGP signed.
|
||||
|
||||
The following steps are optional, and do not have to be performed when releasing new version of Catch. However, they are *should* happen, but they can happen the next day without losing anything significant.
|
||||
#### Signing a tag
|
||||
|
||||
To create a signed tag, use `git tag -s <VERSION>`, where `<VERSION>`
|
||||
is the version being released, e.g. `git tag -s v2.6.0`.
|
||||
|
||||
### vcpkg update
|
||||
Use the version name as the short message and the release notes as
|
||||
the body (long) message.
|
||||
|
||||
Catch is maintaining its own port in Microsoft's package manager [vcpkg](https://github.com/Microsoft/vcpkg). This means that when new version of Catch is released, it should be posted there as well. `updateVcpkgPackage.py` can do a lot of neccessary work for you, it creates a branch and commits neccessary changes. You should review these changes, push and open a PR against vcpkg's upstream.
|
||||
#### Signing the amalgamated files
|
||||
|
||||
This will create ASCII-armored signatures for the two amalgamated files
|
||||
that are uploaded to the GitHub release:
|
||||
|
||||
Note that the script assumes you have your fork of vcpkg checked out in a directory next to the directory where you have checked out Catch, like so:
|
||||
```
|
||||
GitHub
|
||||
Catch
|
||||
vcpkg
|
||||
gpg --armor --output extras/catch_amalgamated.hpp.asc --detach-sig extras/catch_amalgamated.hpp
|
||||
gpg --armor --output extras/catch_amalgamated.cpp.asc --detach-sig extras/catch_amalgamated.cpp
|
||||
```
|
||||
|
||||
|
||||
### Wandbox update
|
||||
|
||||
Recently we also included a link to wandbox with preloaded Catch on the main page. Strictly speaking it is unneccessary to update this after every release, Catch usually does not change that much between versions, but it should be kept up to date anyway.
|
||||
|
||||
_GPG does not support signing multiple files in single invocation._
|
||||
|
175
docs/reporter-events.md
Normal file
175
docs/reporter-events.md
Normal file
@ -0,0 +1,175 @@
|
||||
<a id="top"></a>
|
||||
# Reporter events
|
||||
|
||||
**Contents**<br>
|
||||
[Test running events](#test-running-events)<br>
|
||||
[Benchmarking events](#benchmarking-events)<br>
|
||||
[Listings events](#listings-events)<br>
|
||||
[Miscellaneous events](#miscellaneous-events)<br>
|
||||
|
||||
Reporter events are one of the customization points for user code. They
|
||||
are used by [reporters](reporters.md#top) to customize Catch2's output,
|
||||
and by [event listeners](event-listeners.md#top) to perform in-process
|
||||
actions under some conditions.
|
||||
|
||||
There are currently 21 reporter events in Catch2, split between 4 distinct
|
||||
event groups:
|
||||
* test running events (10 events)
|
||||
* benchmarking (4 events)
|
||||
* listings (3 events)
|
||||
* miscellaneous (4 events)
|
||||
|
||||
## Test running events
|
||||
|
||||
Test running events are always paired so that for each `fooStarting` event,
|
||||
there is a `fooEnded` event. This means that the 10 test running events
|
||||
consist of 5 pairs of events:
|
||||
|
||||
* `testRunStarting` and `testRunEnded`,
|
||||
* `testCaseStarting` and `testCaseEnded`,
|
||||
* `testCasePartialStarting` and `testCasePartialEnded`,
|
||||
* `sectionStarting` and `sectionEnded`,
|
||||
* `assertionStarting` and `assertionEnded`
|
||||
|
||||
### `testRun` events
|
||||
|
||||
```cpp
|
||||
void testRunStarting( TestRunInfo const& testRunInfo );
|
||||
void testRunEnded( TestRunStats const& testRunStats );
|
||||
```
|
||||
|
||||
The `testRun` events bookend the entire test run. `testRunStarting` is
|
||||
emitted before the first test case is executed, and `testRunEnded` is
|
||||
emitted after all the test cases have been executed.
|
||||
|
||||
### `testCase` events
|
||||
|
||||
```cpp
|
||||
void testCaseStarting( TestCaseInfo const& testInfo );
|
||||
void testCaseEnded( TestCaseStats const& testCaseStats );
|
||||
```
|
||||
|
||||
The `testCase` events bookend one _full_ run of a specific test case.
|
||||
Individual runs through a test case, e.g. due to `SECTION`s or `GENERATE`s,
|
||||
are handled by a different event.
|
||||
|
||||
|
||||
### `testCasePartial` events
|
||||
|
||||
> Introduced in Catch2 3.0.1
|
||||
|
||||
```cpp
|
||||
void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber );
|
||||
void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber );
|
||||
```
|
||||
|
||||
`testCasePartial` events bookend one _partial_ run of a specific test case.
|
||||
This means that for any given test case, these events can be emitted
|
||||
multiple times, e.g. due to multiple leaf sections.
|
||||
|
||||
In regards to nesting with `testCase` events, `testCasePartialStarting`
|
||||
will never be emitted before the corresponding `testCaseStarting`, and
|
||||
`testCasePartialEnded` will always be emitted before the corresponding
|
||||
`testCaseEnded`.
|
||||
|
||||
|
||||
### `section` events
|
||||
|
||||
```cpp
|
||||
void sectionStarting( SectionInfo const& sectionInfo );
|
||||
void sectionEnded( SectionStats const& sectionStats );
|
||||
```
|
||||
|
||||
`section` events are emitted only for active `SECTION`s, that is, sections
|
||||
that are entered. Sections that are skipped in this test case run-through
|
||||
do not cause events to be emitted.
|
||||
|
||||
_Note that test cases always contain one implicit section. The event for
|
||||
this section is emitted after the corresponding `testCasePartialStarting`
|
||||
event._
|
||||
|
||||
|
||||
### `assertion` events
|
||||
|
||||
```cpp
|
||||
void assertionStarting( AssertionInfo const& assertionInfo );
|
||||
void assertionEnded( AssertionStats const& assertionStats );
|
||||
```
|
||||
|
||||
`assertionStarting` is called after the expression is captured, but before
|
||||
the assertion expression is evaluated. This might seem like a minor
|
||||
distinction, but what it means is that if you have assertion like
|
||||
`REQUIRE( a + b == c + d )`, then what happens is that `a + b` and `c + d`
|
||||
are evaluated before `assertionStarting` is emitted, while the `==` is
|
||||
evaluated after the event.
|
||||
|
||||
|
||||
## Benchmarking events
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
```cpp
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
|
||||
void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
```
|
||||
|
||||
Due to the benchmark lifecycle being bit more complicated, the benchmarking
|
||||
events have their own category, even though they could be seen as parallel
|
||||
to the `assertion*` events. You should expect running a benchmark to
|
||||
generate at least 2 of the events above.
|
||||
|
||||
To understand the explanation below, you should read the [benchmarking
|
||||
documentation](benchmarks.md#top) first.
|
||||
|
||||
* `benchmarkPreparing` event is sent after the environmental probe
|
||||
finishes, but before the user code is first estimated.
|
||||
* `benchmarkStarting` event is sent after the user code is estimated,
|
||||
but has not been benchmarked yet.
|
||||
* `benchmarkEnded` event is sent after the user code has been benchmarked,
|
||||
and contains the benchmarking results.
|
||||
* `benchmarkFailed` event is sent if either the estimation or the
|
||||
benchmarking itself fails.
|
||||
|
||||
|
||||
## Listings events
|
||||
|
||||
> Introduced in Catch2 3.0.1.
|
||||
|
||||
Listings events are events that correspond to the test binary being
|
||||
invoked with `--list-foo` flag.
|
||||
|
||||
There are currently 3 listing events, one for reporters, one for tests,
|
||||
and one for tags. Note that they are not exclusive to each other.
|
||||
|
||||
```cpp
|
||||
void listReporters( std::vector<ReporterDescription> const& descriptions );
|
||||
void listTests( std::vector<TestCaseHandle> const& tests );
|
||||
void listTags( std::vector<TagInfo> const& tagInfos );
|
||||
```
|
||||
|
||||
|
||||
## Miscellaneous events
|
||||
|
||||
```cpp
|
||||
void reportInvalidTestSpec( StringRef unmatchedSpec );
|
||||
void fatalErrorEncountered( StringRef error );
|
||||
void noMatchingTestCases( StringRef unmatchedSpec );
|
||||
```
|
||||
|
||||
These are one-off events that do not neatly fit into other categories.
|
||||
|
||||
`reportInvalidTestSpec` is sent for each [test specification command line
|
||||
argument](command-line.md#specifying-which-tests-to-run) that wasn't
|
||||
parsed into a valid spec.
|
||||
|
||||
`fatalErrorEncountered` is sent when Catch2's POSIX signal handling
|
||||
or Windows SE handler is called into with a fatal signal/exception.
|
||||
|
||||
`noMatchingTestCases` is sent for each user provided test specification
|
||||
that did not match any registered tests.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@ -1,45 +1,212 @@
|
||||
<a id="top"></a>
|
||||
# Reporters
|
||||
|
||||
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
|
||||
You can also write your own reporters.
|
||||
Reporters are a customization point for most of Catch2's output, e.g.
|
||||
formatting and writing out [assertions (whether passing or failing),
|
||||
sections, test cases, benchmarks, and so on](reporter-events.md#top).
|
||||
|
||||
Catch2 comes with a bunch of reporters by default (currently 8), and
|
||||
you can also write your own reporter. Because multiple reporters can
|
||||
be active at the same time, your own reporters do not even have to handle
|
||||
all reporter event, just the ones you are interested in, e.g. benchmarks.
|
||||
|
||||
|
||||
## Using different reporters
|
||||
|
||||
The reporter to use can easily be controlled from the command line.
|
||||
To specify a reporter use [`-r` or `--reporter`](command-line.md#choosing-a-reporter-to-use), followed by the name of the reporter, e.g.:
|
||||
You can see which reporters are available by running the test binary
|
||||
with `--list-reporters`. You can then pick one of them with the [`-r`,
|
||||
`--reporter` option](command-line.md#choosing-a-reporter-to-use), followed
|
||||
by the name of the desired reporter, like so:
|
||||
|
||||
```
|
||||
-r xml
|
||||
--reporter xml
|
||||
```
|
||||
|
||||
If you don't specify a reporter then the console reporter is used by default.
|
||||
There are four reporters built in to the single include:
|
||||
You can also select multiple reporters to be used at the same time.
|
||||
In that case you should read the [section on using multiple
|
||||
reporters](#multiple-reporters) to avoid any surprises from doing so.
|
||||
|
||||
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
|
||||
* `compact` similar to `console` but optimised for minimal output - each entry on one line
|
||||
* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit.
|
||||
Because of the way the junit format is structured the run must complete before anything is written.
|
||||
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
|
||||
|
||||
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
|
||||
Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
|
||||
<a id="multiple-reporters"></a>
|
||||
## Using multiple reporters
|
||||
|
||||
* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
|
||||
Use this when building as part of a TeamCity build to see results as they happen.
|
||||
* `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format.
|
||||
* `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files
|
||||
> Support for having multiple parallel reporters was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 3.0.1
|
||||
|
||||
Catch2 supports using multiple reporters at the same time while having
|
||||
them write into different destinations. The two main uses of this are
|
||||
|
||||
* having both human-friendly and machine-parseable (e.g. in JUnit format)
|
||||
output from one run of binary
|
||||
* having "partial" reporters that are highly specialized, e.g. having one
|
||||
reporter that writes out benchmark results as markdown tables and does
|
||||
nothing else, while also having standard testing output separately
|
||||
|
||||
Specifying multiple reporter looks like this:
|
||||
```
|
||||
--reporter JUnit::out=result-junit.xml --reporter console::out=-::colour-mode=ansi
|
||||
```
|
||||
|
||||
This tells Catch2 to use two reporters, `JUnit` reporter that writes
|
||||
its machine-readable XML output to file `result-junit.xml`, and the
|
||||
`console` reporter that writes its user-friendly output to stdout and
|
||||
uses ANSI colour codes for colouring the output.
|
||||
|
||||
Using multiple reporters (or one reporter and one-or-more [event
|
||||
listeners](event-listener.md#top)) can have surprisingly complex semantics
|
||||
when using customization points provided to reporters by Catch2, namely
|
||||
capturing stdout/stderr from test cases.
|
||||
|
||||
As long as at least one reporter (or listener) asks Catch2 to capture
|
||||
stdout/stderr, captured stdout and stderr will be available to all
|
||||
reporters and listeners.
|
||||
|
||||
Because this might be surprising to the users, if at least one active
|
||||
_reporter_ is non-capturing, then Catch2 tries to roughly emulate
|
||||
non-capturing behaviour by printing out the captured stdout/stderr
|
||||
just before `testCasePartialEnded` event is sent out to the active
|
||||
reporters and listeners. This means that stdout/stderr is no longer
|
||||
printed out from tests as it is being written, but instead it is written
|
||||
out in batch after each runthrough of a test case is finished.
|
||||
|
||||
You see what reporters are available from the command line by running with `--list-reporters`.
|
||||
|
||||
By default all these reports are written to stdout, but can be redirected to a file with [`-o` or `--out`](command-line.md#sending-output-to-a-file)
|
||||
|
||||
## Writing your own reporter
|
||||
|
||||
You can write your own custom reporter and register it with Catch.
|
||||
At time of writing the interface is subject to some changes so is not, yet, documented here.
|
||||
If you are determined you shouldn't have too much trouble working it out from the existing implementations -
|
||||
but do keep in mind upcoming changes (these will be minor, simplifying, changes such as not needing to forward calls to the base class).
|
||||
You can also write your own custom reporter and tell Catch2 to use it.
|
||||
When writing your reporter, you have two options:
|
||||
|
||||
* Derive from `Catch::ReporterBase`. When doing this, you will have
|
||||
to provide handling for all [reporter events](reporter-events.md#top).
|
||||
* Derive from one of the provided [utility reporter bases in
|
||||
Catch2](#utility-reporter-bases).
|
||||
|
||||
Generally we recommend doing the latter, as it is less work.
|
||||
|
||||
Apart from overriding handling of the individual reporter events, reporters
|
||||
have access to some extra customization points, described below.
|
||||
|
||||
|
||||
### Utility reporter bases
|
||||
|
||||
Catch2 currently provides two utility reporter bases:
|
||||
|
||||
* `Catch::StreamingReporterBase`
|
||||
* `Catch::CumulativeReporterBase`
|
||||
|
||||
`StreamingReporterBase` is useful for reporters that can format and write
|
||||
out the events as they come in. It provides (usually empty) implementation
|
||||
for all reporter events, and if you let it handle the relevant events,
|
||||
it also handles storing information about active test run and test case.
|
||||
|
||||
`CumulativeReporterBase` is a base for reporters that need to see the whole
|
||||
test run, before they can start writing the output, such as the JUnit
|
||||
and SonarQube reporters. This post-facto approach requires the assertions
|
||||
to be stringified when it is finished, so that the assertion can be written
|
||||
out later. Because the stringification can be expensive, and not all
|
||||
cumulative reporters need the assertions, this base provides customization
|
||||
point to change whether the assertions are saved or not, separate for
|
||||
passing and failing assertions.
|
||||
|
||||
|
||||
_Generally we recommend that if you override a member function from either
|
||||
of the bases, you call into the base's implementation first. This is not
|
||||
necessarily in all cases, but it is safer and easier._
|
||||
|
||||
|
||||
Writing your own reporter then looks like this:
|
||||
|
||||
```cpp
|
||||
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class PartialReporter : public Catch::StreamingReporterBase {
|
||||
public:
|
||||
using StreamingReporterBase::StreamingReporterBase;
|
||||
|
||||
static std::string getDescription() {
|
||||
return "Reporter for testing TestCasePartialStarting/Ended events";
|
||||
}
|
||||
|
||||
void testCasePartialStarting(Catch::TestCaseInfo const& testInfo,
|
||||
uint64_t partNumber) override {
|
||||
std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n';
|
||||
}
|
||||
|
||||
void testCasePartialEnded(Catch::TestCaseStats const& testCaseStats,
|
||||
uint64_t partNumber) override {
|
||||
std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
CATCH_REGISTER_REPORTER("partial", PartialReporter)
|
||||
```
|
||||
|
||||
This create a simple reporter that responds to `testCasePartial*` events,
|
||||
and calls itself "partial" reporter, so it can be invoked with
|
||||
`--reporter partial` command line flag.
|
||||
|
||||
|
||||
### `ReporterPreferences`
|
||||
|
||||
Each reporter instance contains instance of `ReporterPreferences`, a type
|
||||
that holds flags for the behaviour of Catch2 when this reporter run.
|
||||
Currently there are two customization options:
|
||||
|
||||
* `shouldRedirectStdOut` - whether the reporter wants to handle
|
||||
writes to stdout/stderr from user code, or not. This is useful for
|
||||
reporters that output machine-parseable output, e.g. the JUnit
|
||||
reporter, or the XML reporter.
|
||||
* `shouldReportAllAssertions` - whether the reporter wants to handle
|
||||
`assertionEnded` events for passing assertions as well as failing
|
||||
assertions. Usually reporters do not report successful assertions
|
||||
and don't need them for their output, but sometimes the desired output
|
||||
format includes passing assertions even without the `-s` flag.
|
||||
|
||||
|
||||
### Per-reporter configuration
|
||||
|
||||
> Per-reporter configuration was introduced in Catch2 3.0.1
|
||||
|
||||
Catch2 supports some configuration to happen per reporter. The configuration
|
||||
options fall into one of two categories:
|
||||
|
||||
* Catch2-recognized options
|
||||
* Reporter-specific options
|
||||
|
||||
The former is a small set of universal options that Catch2 handles for
|
||||
the reporters, e.g. output file or console colour mode. The latter are
|
||||
options that the reporters have to handle themselves, but the keys and
|
||||
values can be arbitrary strings, as long as they don't contain `::`. This
|
||||
allows writing reporters that can be significantly customized at runtime.
|
||||
|
||||
Reporter-specific options always have to be prefixed with "X" (large
|
||||
letter X).
|
||||
|
||||
|
||||
### Other expected functionality of a reporter
|
||||
|
||||
When writing a custom reporter, there are few more things that you should
|
||||
keep in mind. These are not important for correctness, but they are
|
||||
important for the reporter to work _nicely_.
|
||||
|
||||
* Catch2 provides a simple verbosity option for users. There are three
|
||||
verbosity levels, "quiet", "normal", and "high", and if it makes sense
|
||||
for reporter's output format, it should respond to these by changing
|
||||
what, and how much, it writes out.
|
||||
|
||||
* Catch2 operates with an rng-seed. Knowing what seed a test run had
|
||||
is important if you want to replicate it, so your reporter should
|
||||
report the rng-seed, if at all possible given the target output format.
|
||||
|
||||
* Catch2 also operates with test filters, or test specs. If a filter
|
||||
is present, you should also report the filter, if at all possible given
|
||||
the target output format.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,71 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Why do my tests take so long to compile?
|
||||
|
||||
**Contents**
|
||||
[Short answer](#short-answer)
|
||||
[Long answer](#long-answer)
|
||||
[Practical example](#practical-example)
|
||||
[Other possible solutions](#other-possible-solutions)
|
||||
|
||||
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
|
||||
|
||||
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
|
||||
|
||||
## Short answer
|
||||
Exactly one source file must ```#define``` either ```CATCH_CONFIG_MAIN``` or ```CATCH_CONFIG_RUNNER``` before ```#include```-ing Catch. In this file *do not write any test cases*! In most cases that means this file will just contain two lines (the ```#define``` and the ```#include```).
|
||||
|
||||
## Long answer
|
||||
|
||||
Usually C++ code is split between a header file, containing declarations and prototypes, and an implementation file (.cpp) containing the definition, or implementation, code. Each implementation file, along with all the headers that it includes (and which those headers include, etc), is expanded into a single entity called a translation unit - which is then passed to the compiler and compiled down to an object file.
|
||||
|
||||
But functions and methods can also be written inline in header files. The downside to this is that these definitions will then be compiled in *every* translation unit that includes the header.
|
||||
|
||||
Because Catch is implemented *entirely* in headers you might think that the whole of Catch must be compiled into every translation unit that uses it! Actually it's not quite as bad as that. Catch mitigates this situation by effectively maintaining the traditional separation between the implementation code and declarations. Internally the implementation code is protected by ```#ifdef```s and is conditionally compiled into only one translation unit. This translation unit is that one that ```#define```s ```CATCH_CONFIG_MAIN``` or ```CATCH_CONFIG_RUNNER```. Let's call this the main source file.
|
||||
|
||||
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch
|
||||
|
||||
## Practical example
|
||||
Assume you have the `Factorial` function from the [tutorial](tutorial.md#top) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
|
||||
|
||||
```cpp
|
||||
// tests-main.cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
```
|
||||
|
||||
```cpp
|
||||
// tests-factorial.cpp
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "factorial.h"
|
||||
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
||||
```
|
||||
|
||||
After compiling `tests-main.cpp` once, it is enough to link it with separately compiled `tests-factorial.cpp`. This means that adding more tests to `tests-factorial.cpp`, will not result in recompiling Catch's main and the resulting compilation times will decrease substantially.
|
||||
|
||||
```
|
||||
$ g++ tests-main.cpp -c
|
||||
$ g++ tests-main.o tests-factorial.cpp -o tests && ./tests -r compact
|
||||
Passed 1 test case with 4 assertions.
|
||||
```
|
||||
|
||||
Now, the next time we change the file `tests-factorial.cpp` (say we add `REQUIRE( Factorial(0) == 1)`), it is enough to recompile the tests instead of recompiling main as well:
|
||||
|
||||
```
|
||||
$ g++ tests-main.o tests-factorial.cpp -o tests && ./tests -r compact
|
||||
tests-factorial.cpp:11: failed: Factorial(0) == 1 for: 0 == 1
|
||||
Failed 1 test case, failed 1 assertion.
|
||||
```
|
||||
|
||||
## Other possible solutions
|
||||
You can also opt to sacrifice some features in order to speed-up Catch's compilation times. For details see the [documentation on Catch's compile-time configuration](configuration.md#other-toggles).
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@ -1,6 +1,13 @@
|
||||
<a id="top"></a>
|
||||
# Test cases and sections
|
||||
|
||||
**Contents**<br>
|
||||
[Tags](#tags)<br>
|
||||
[Tag aliases](#tag-aliases)<br>
|
||||
[BDD-style test cases](#bdd-style-test-cases)<br>
|
||||
[Type parametrised test cases](#type-parametrised-test-cases)<br>
|
||||
[Signature based parametrised test cases](#signature-based-parametrised-test-cases)<br>
|
||||
|
||||
While Catch fully supports the traditional, xUnit, style of class-based fixtures containing test case methods this is not the preferred style.
|
||||
|
||||
Instead Catch provides a powerful mechanism for nesting test case sections within a test case. For a more detailed discussion see the [tutorial](tutorial.md#test-cases-and-sections).
|
||||
@ -8,9 +15,17 @@ Instead Catch provides a powerful mechanism for nesting test case sections withi
|
||||
Test cases and sections are very easy to use in practice:
|
||||
|
||||
* **TEST_CASE(** _test name_ \[, _tags_ \] **)**
|
||||
* **SECTION(** _section name_ **)**
|
||||
* **SECTION(** _section name_, \[, _section description_ \] **)**
|
||||
|
||||
_test name_ and _section name_ are free form, quoted, strings. The optional _tags_ argument is a quoted string containing one or more tags enclosed in square brackets. Tags are discussed below. Test names must be unique within the Catch executable.
|
||||
|
||||
_test name_ and _section name_ are free form, quoted, strings.
|
||||
The optional _tags_ argument is a quoted string containing one or more
|
||||
tags enclosed in square brackets, and are discussed below.
|
||||
_section description_ can be used to provide long form description
|
||||
of a section while keeping the _section name_ short for use with the
|
||||
[`-c` command line parameter](command-line.md#specify-the-section-to-run).
|
||||
|
||||
**Test names must be unique within the Catch executable.**
|
||||
|
||||
For examples see the [Tutorial](tutorial.md#top)
|
||||
|
||||
@ -20,46 +35,55 @@ Tags allow an arbitrary number of additional strings to be associated with a tes
|
||||
|
||||
As an example - given the following test cases:
|
||||
|
||||
TEST_CASE( "A", "[widget]" ) { /* ... */ }
|
||||
TEST_CASE( "B", "[widget]" ) { /* ... */ }
|
||||
TEST_CASE( "C", "[gadget]" ) { /* ... */ }
|
||||
TEST_CASE( "D", "[widget][gadget]" ) { /* ... */ }
|
||||
TEST_CASE( "A", "[widget]" ) { /* ... */ }
|
||||
TEST_CASE( "B", "[widget]" ) { /* ... */ }
|
||||
TEST_CASE( "C", "[gadget]" ) { /* ... */ }
|
||||
TEST_CASE( "D", "[widget][gadget]" ) { /* ... */ }
|
||||
|
||||
The tag expression, ```"[widget]"``` selects A, B & D. ```"[gadget]"``` selects C & D. ```"[widget][gadget]"``` selects just D and ```"[widget],[gadget]"``` selects all four test cases.
|
||||
|
||||
For more detail on command line selection see [the command line docs](command-line.md#specifying-which-tests-to-run)
|
||||
|
||||
Tag names are not case sensitive and can contain any ASCII characters. This means that tags `[tag with spaces]` and `[I said "good day"]` are both allowed tags and can be filtered on. Escapes are not supported however and `[\]]` is not a valid tag.
|
||||
Tag names are not case sensitive and can contain any ASCII characters.
|
||||
This means that tags `[tag with spaces]` and `[I said "good day"]`
|
||||
are both allowed tags and can be filtered on. However, escapes are not
|
||||
supported however and `[\]]` is not a valid tag.
|
||||
|
||||
The same tag can be specified multiple times for a single test case,
|
||||
but only one of the instances of identical tags will be kept. Which one
|
||||
is kept is functionally random.
|
||||
|
||||
|
||||
### Special Tags
|
||||
|
||||
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
|
||||
|
||||
* `[!hide]` or `[.]` - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`. Because the hide tag has evolved to have several forms, all forms are added as tags if you use one of them.
|
||||
* `[.]` - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`.
|
||||
|
||||
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
|
||||
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
|
||||
|
||||
* `[!mayfail]` - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in the your tests.
|
||||
* `[!mayfail]` - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in your tests.
|
||||
|
||||
* `[!shouldfail]` - like `[!mayfail]` but *fails* the test if it *passes*. This can be useful if you want to be notified of accidental, or third-party, fixes.
|
||||
|
||||
* `[!nonportable]` - Indicates that behaviour may vary between platforms or compilers.
|
||||
|
||||
* `[#<filename>]` - running with `-#` or `--filenames-as-tags` causes Catch to add the filename, prefixed with `#` (and with any extension stripped) as a tag. e.g. tests in testfile.cpp would all be tagged `[#testfile]`.
|
||||
* `[#<filename>]` - running with `-#` or `--filenames-as-tags` causes Catch to add the filename, prefixed with `#` (and with any extension stripped), as a tag to all contained tests, e.g. tests in testfile.cpp would all be tagged `[#testfile]`.
|
||||
|
||||
* `[@<alias>]` - tag aliases all begin with `@` (see below).
|
||||
|
||||
* `[!benchmark]` - this test case is actually a benchmark. This is an experimental feature, and currently has no documentation. If you want to try it out, look at `projects/SelfTest/Benchmark.tests.cpp` for details.
|
||||
* `[!benchmark]` - this test case is actually a benchmark. Currently this only serves to hide the test case by default, to avoid the execution time costs.
|
||||
|
||||
|
||||
## Tag aliases
|
||||
|
||||
Between tag expressions and wildcarded test names (as well as combinations of the two) quite complex patterns can be constructed to direct which test cases are run. If a complex pattern is used often it is convenient to be able to create an alias for the expression. this can be done, in code, using the following form:
|
||||
Between tag expressions and wildcarded test names (as well as combinations of the two) quite complex patterns can be constructed to direct which test cases are run. If a complex pattern is used often it is convenient to be able to create an alias for the expression. This can be done, in code, using the following form:
|
||||
|
||||
CATCH_REGISTER_TAG_ALIAS( <alias string>, <tag expression> )
|
||||
CATCH_REGISTER_TAG_ALIAS( <alias string>, <tag expression> )
|
||||
|
||||
Aliases must begin with the `@` character. An example of a tag alias is:
|
||||
|
||||
CATCH_REGISTER_TAG_ALIAS( "[@nhf]", "[failing]~[.]" )
|
||||
CATCH_REGISTER_TAG_ALIAS( "[@nhf]", "[failing]~[.]" )
|
||||
|
||||
Now when `[@nhf]` is used on the command line this matches all tests that are tagged `[failing]`, but which are not also hidden.
|
||||
|
||||
@ -75,17 +99,240 @@ This macro maps onto ```TEST_CASE``` and works in the same way, except that the
|
||||
* **WHEN(** _something_ **)**
|
||||
* **THEN(** _something_ **)**
|
||||
|
||||
These macros map onto ```SECTION```s except that the section names are the _something_s prefixed by "given: ", "when: " or "then: " respectively.
|
||||
These macros map onto ```SECTION```s except that the section names are the _something_ texts prefixed by
|
||||
"given: ", "when: " or "then: " respectively. These macros also map onto the AAA or A<sup>3</sup> test pattern
|
||||
(standing either for [Assemble-Activate-Assert](http://wiki.c2.com/?AssembleActivateAssert) or
|
||||
[Arrange-Act-Assert](http://wiki.c2.com/?ArrangeActAssert)), and in this context, the macros provide both code
|
||||
documentation and reporting of these parts of a test case without the need for extra comments or code to do so.
|
||||
|
||||
Semantically, a `GIVEN` clause may have multiple _independent_ `WHEN` clauses within it. This allows a test
|
||||
to have, e.g., one set of "given" objects and multiple subtests using those objects in various ways in each
|
||||
of the `WHEN` clauses without repeating the initialisation from the `GIVEN` clause. When there are _dependent_
|
||||
clauses -- such as a second `WHEN` clause that should only happen _after_ the previous `WHEN` clause has been
|
||||
executed and validated -- there are additional macros starting with `AND_`:
|
||||
|
||||
* **AND_GIVEN(** _something_ **)**
|
||||
* **AND_WHEN(** _something_ **)**
|
||||
* **AND_THEN(** _something_ **)**
|
||||
|
||||
Similar to ```WHEN``` and ```THEN``` except that the prefixes start with "and ". These are used to chain ```WHEN```s and ```THEN```s together.
|
||||
These are used to chain ```GIVEN```s, ```WHEN```s and ```THEN```s together. The `AND_*` clause is placed
|
||||
_inside_ the clause on which it depends. There can be multiple _independent_ clauses that are all _dependent_
|
||||
on a single outer clause.
|
||||
```cpp
|
||||
SCENARIO( "vector can be sized and resized" ) {
|
||||
GIVEN( "An empty vector" ) {
|
||||
auto v = std::vector<std::string>{};
|
||||
|
||||
// Validate assumption of the GIVEN clause
|
||||
THEN( "The size and capacity start at 0" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() == 0 );
|
||||
}
|
||||
|
||||
// Validate one use case for the GIVEN object
|
||||
WHEN( "push_back() is called" ) {
|
||||
v.push_back("hullo");
|
||||
|
||||
THEN( "The size changes" ) {
|
||||
REQUIRE( v.size() == 1 );
|
||||
REQUIRE( v.capacity() >= 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This code will result in two runs through the scenario:
|
||||
```
|
||||
Scenario : vector can be sized and resized
|
||||
Given : An empty vector
|
||||
Then : The size and capacity start at 0
|
||||
|
||||
Scenario : vector can be sized and resized
|
||||
Given : An empty vector
|
||||
When : push_back() is called
|
||||
Then : The size changes
|
||||
```
|
||||
|
||||
See also [runnable example on godbolt](https://godbolt.org/z/eY5a64r99),
|
||||
with a more complicated (and failing) example.
|
||||
|
||||
> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch2 2.4.0.
|
||||
|
||||
When any of these macros are used the console reporter recognises them and formats the test case header such that the Givens, Whens and Thens are aligned to aid readability.
|
||||
|
||||
Other than the additional prefixes and the formatting in the console reporter these macros behave exactly as ```TEST_CASE```s and ```SECTION```s. As such there is nothing enforcing the correct sequencing of these macros - that's up to the programmer!
|
||||
|
||||
## Type parametrised test cases
|
||||
|
||||
In addition to `TEST_CASE`s, Catch2 also supports test cases parametrised
|
||||
by types, in the form of `TEMPLATE_TEST_CASE`,
|
||||
`TEMPLATE_PRODUCT_TEST_CASE` and `TEMPLATE_LIST_TEST_CASE`.
|
||||
|
||||
* **TEMPLATE_TEST_CASE(** _test name_ , _tags_, _type1_, _type2_, ..., _typen_ **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1437) in Catch2 2.5.0.
|
||||
|
||||
_test name_ and _tag_ are exactly the same as they are in `TEST_CASE`,
|
||||
with the difference that the tag string must be provided (however, it
|
||||
can be empty). _type1_ through _typen_ is the list of types for which
|
||||
this test case should run, and, inside the test code, the current type
|
||||
is available as the `TestType` type.
|
||||
|
||||
Because of limitations of the C++ preprocessor, if you want to specify
|
||||
a type with multiple template parameters, you need to enclose it in
|
||||
parentheses, e.g. `std::map<int, std::string>` needs to be passed as
|
||||
`(std::map<int, std::string>)`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
TEMPLATE_TEST_CASE( "vectors can be sized and resized", "[vector][template]", int, std::string, (std::tuple<int,float>) ) {
|
||||
|
||||
std::vector<TestType> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
SECTION( "resizing bigger changes size and capacity" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
SECTION( "resizing smaller changes size but not capacity" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
SECTION( "We can use the 'swap trick' to reset the capacity" ) {
|
||||
std::vector<TestType> empty;
|
||||
empty.swap( v );
|
||||
|
||||
REQUIRE( v.capacity() == 0 );
|
||||
}
|
||||
}
|
||||
SECTION( "reserving smaller does not change size or capacity" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* **TEMPLATE_PRODUCT_TEST_CASE(** _test name_ , _tags_, (_template-type1_, _template-type2_, ..., _template-typen_), (_template-arg1_, _template-arg2_, ..., _template-argm_) **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1468) in Catch2 2.6.0.
|
||||
|
||||
_template-type1_ through _template-typen_ is list of template template
|
||||
types which should be combined with each of _template-arg1_ through
|
||||
_template-argm_, resulting in _n * m_ test cases. Inside the test case,
|
||||
the resulting type is available under the name of `TestType`.
|
||||
|
||||
To specify more than 1 type as a single _template-type_ or _template-arg_,
|
||||
you must enclose the types in an additional set of parentheses, e.g.
|
||||
`((int, float), (char, double))` specifies 2 template-args, each
|
||||
consisting of 2 concrete types (`int`, `float` and `char`, `double`
|
||||
respectively). You can also omit the outer set of parentheses if you
|
||||
specify only one type as the full set of either the _template-types_,
|
||||
or the _template-args_.
|
||||
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
template< typename T>
|
||||
struct Foo {
|
||||
size_t size() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
TEMPLATE_PRODUCT_TEST_CASE("A Template product test case", "[template][product]", (std::vector, Foo), (int, float)) {
|
||||
TestType x;
|
||||
REQUIRE(x.size() == 0);
|
||||
}
|
||||
```
|
||||
|
||||
You can also have different arities in the _template-arg_ packs:
|
||||
```cpp
|
||||
TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", "[template][product]", std::tuple, (int, (int, double), (int, double, float))) {
|
||||
TestType x;
|
||||
REQUIRE(std::tuple_size<TestType>::value >= 1);
|
||||
}
|
||||
```
|
||||
|
||||
* **TEMPLATE_LIST_TEST_CASE(** _test name_, _tags_, _type list_ **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1627) in Catch2 2.9.0.
|
||||
|
||||
_type list_ is a generic list of types on which test case should be instantiated.
|
||||
List can be `std::tuple`, `boost::mpl::list`, `boost::mp11::mp_list` or anything with
|
||||
`template <typename...>` signature.
|
||||
|
||||
This allows you to reuse the _type list_ in multiple test cases.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
using MyTypes = std::tuple<int, char, float>;
|
||||
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std::tuple", "[template][list]", MyTypes)
|
||||
{
|
||||
REQUIRE(sizeof(TestType) > 0);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Signature based parametrised test cases
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 2.8.0.
|
||||
|
||||
In addition to [type parametrised test cases](#type-parametrised-test-cases) Catch2 also supports
|
||||
signature base parametrised test cases, in form of `TEMPLATE_TEST_CASE_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_SIG`.
|
||||
These test cases have similar syntax like [type parametrised test cases](#type-parametrised-test-cases), with one
|
||||
additional positional argument which specifies the signature.
|
||||
|
||||
### Signature
|
||||
Signature has some strict rules for these tests cases to work properly:
|
||||
* signature with multiple template parameters e.g. `typename T, size_t S` must have this format in test case declaration
|
||||
`((typename T, size_t S), T, S)`
|
||||
* signature with variadic template arguments e.g. `typename T, size_t S, typename...Ts` must have this format in test case declaration
|
||||
`((typename T, size_t S, typename...Ts), T, S, Ts...)`
|
||||
* signature with single non type template parameter e.g. `int V` must have this format in test case declaration `((int V), V)`
|
||||
* signature with single type template parameter e.g. `typename T` should not be used as it is in fact `TEMPLATE_TEST_CASE`
|
||||
|
||||
Currently Catch2 support up to 11 template parameters in signature
|
||||
|
||||
### Examples
|
||||
|
||||
* **TEMPLATE_TEST_CASE_SIG(** _test name_ , _tags_, _signature_, _type1_, _type2_, ..., _typen_ **)**
|
||||
|
||||
Inside `TEMPLATE_TEST_CASE_SIG` test case you can use the names of template parameters as defined in _signature_.
|
||||
|
||||
```cpp
|
||||
TEMPLATE_TEST_CASE_SIG("TemplateTestSig: arrays can be created from NTTP arguments", "[vector][template][nttp]",
|
||||
((typename T, int V), T, V), (int,5), (float,4), (std::string,15), ((std::tuple<int, float>), 6)) {
|
||||
|
||||
std::array<T, V> v;
|
||||
REQUIRE(v.size() > 1);
|
||||
}
|
||||
```
|
||||
|
||||
* **TEMPLATE_PRODUCT_TEST_CASE_SIG(** _test name_ , _tags_, _signature_, (_template-type1_, _template-type2_, ..., _template-typen_), (_template-arg1_, _template-arg2_, ..., _template-argm_) **)**
|
||||
|
||||
```cpp
|
||||
|
||||
template<typename T, size_t S>
|
||||
struct Bar {
|
||||
size_t size() { return S; }
|
||||
};
|
||||
|
||||
TEMPLATE_PRODUCT_TEST_CASE_SIG("A Template product test case with array signature", "[template][product][nttp]", ((typename T, size_t S), T, S), (std::array, Bar), ((int, 9), (float, 42))) {
|
||||
TestType x;
|
||||
REQUIRE(x.size() > 0);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@ -1,6 +1,8 @@
|
||||
<a id="top"></a>
|
||||
# Test fixtures
|
||||
|
||||
## Defining test fixtures
|
||||
|
||||
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
|
||||
|
||||
```c++
|
||||
@ -30,6 +32,131 @@ class UniqueTestsFixture {
|
||||
|
||||
The two test cases here will create uniquely-named derived classes of UniqueTestsFixture and thus can access the `getID()` protected method and `conn` member variables. This ensures that both the test cases are able to create a DBConnection using the same method (DRY principle) and that any ID's created are unique such that the order that tests are executed does not matter.
|
||||
|
||||
|
||||
Catch2 also provides `TEMPLATE_TEST_CASE_METHOD` and
|
||||
`TEMPLATE_PRODUCT_TEST_CASE_METHOD` that can be used together
|
||||
with templated fixtures and templated template fixtures to perform
|
||||
tests for multiple different types. Unlike `TEST_CASE_METHOD`,
|
||||
`TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD` do
|
||||
require the tag specification to be non-empty, as it is followed by
|
||||
further macro arguments.
|
||||
|
||||
Also note that, because of limitations of the C++ preprocessor, if you
|
||||
want to specify a type with multiple template parameters, you need to
|
||||
enclose it in parentheses, e.g. `std::map<int, std::string>` needs to be
|
||||
passed as `(std::map<int, std::string>)`.
|
||||
In the case of `TEMPLATE_PRODUCT_TEST_CASE_METHOD`, if a member of the
|
||||
type list should consist of more than single type, it needs to be enclosed
|
||||
in another pair of parentheses, e.g. `(std::map, std::pair)` and
|
||||
`((int, float), (char, double))`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
template< typename T >
|
||||
struct Template_Fixture {
|
||||
Template_Fixture(): m_a(1) {}
|
||||
|
||||
T m_a;
|
||||
};
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD(Template_Fixture,
|
||||
"A TEMPLATE_TEST_CASE_METHOD based test run that succeeds",
|
||||
"[class][template]",
|
||||
int, float, double) {
|
||||
REQUIRE( Template_Fixture<TestType>::m_a == 1 );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct Template_Template_Fixture {
|
||||
Template_Template_Fixture() {}
|
||||
|
||||
T m_a;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Foo_class {
|
||||
size_t size() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
TEMPLATE_PRODUCT_TEST_CASE_METHOD(Template_Template_Fixture,
|
||||
"A TEMPLATE_PRODUCT_TEST_CASE_METHOD based test succeeds",
|
||||
"[class][template]",
|
||||
(Foo_class, std::vector),
|
||||
int) {
|
||||
REQUIRE( Template_Template_Fixture<TestType>::m_a.size() == 0 );
|
||||
}
|
||||
```
|
||||
|
||||
_While there is an upper limit on the number of types you can specify
|
||||
in single `TEMPLATE_TEST_CASE_METHOD` or `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
|
||||
the limit is very high and should not be encountered in practice._
|
||||
|
||||
## Signature-based parametrised test fixtures
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 2.8.0.
|
||||
|
||||
Catch2 also provides `TEMPLATE_TEST_CASE_METHOD_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG` to support
|
||||
fixtures using non-type template parameters. These test cases work similar to `TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
|
||||
with additional positional argument for [signature](test-cases-and-sections.md#signature-based-parametrised-test-cases).
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
template <int V>
|
||||
struct Nttp_Fixture{
|
||||
int value = V;
|
||||
};
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD_SIG(
|
||||
Nttp_Fixture,
|
||||
"A TEMPLATE_TEST_CASE_METHOD_SIG based test run that succeeds",
|
||||
"[class][template][nttp]",
|
||||
((int V), V),
|
||||
1, 3, 6) {
|
||||
REQUIRE(Nttp_Fixture<V>::value > 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct Template_Fixture_2 {
|
||||
Template_Fixture_2() {}
|
||||
|
||||
T m_a;
|
||||
};
|
||||
|
||||
template< typename T, size_t V>
|
||||
struct Template_Foo_2 {
|
||||
size_t size() { return V; }
|
||||
};
|
||||
|
||||
TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG(
|
||||
Template_Fixture_2,
|
||||
"A TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG based test run that succeeds",
|
||||
"[class][template][product][nttp]",
|
||||
((typename T, size_t S), T, S),
|
||||
(std::array, Template_Foo_2),
|
||||
((int,2), (float,6))) {
|
||||
REQUIRE(Template_Fixture_2<TestType>{}.m_a.size() >= 2);
|
||||
}
|
||||
```
|
||||
|
||||
## Template fixtures with types specified in template type lists
|
||||
|
||||
Catch2 also provides `TEMPLATE_LIST_TEST_CASE_METHOD` to support template fixtures with types specified in
|
||||
template type lists like `std::tuple`, `boost::mpl::list` or `boost::mp11::mp_list`. This test case works the same as `TEMPLATE_TEST_CASE_METHOD`,
|
||||
only difference is the source of types. This allows you to reuse the template type list in multiple test cases.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
using MyTypes = std::tuple<int, char, double>;
|
||||
TEMPLATE_LIST_TEST_CASE_METHOD(Template_Fixture,
|
||||
"Template test case method with test types specified inside std::tuple",
|
||||
"[class][template][list]",
|
||||
MyTypes) {
|
||||
REQUIRE( Template_Fixture<TestType>::m_a == 1 );
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
108
docs/tostring.md
108
docs/tostring.md
@ -1,6 +1,15 @@
|
||||
<a id="top"></a>
|
||||
# String conversions
|
||||
|
||||
**Contents**<br>
|
||||
[operator << overload for std::ostream](#operator--overload-for-stdostream)<br>
|
||||
[Catch::StringMaker specialisation](#catchstringmaker-specialisation)<br>
|
||||
[Catch::is_range specialisation](#catchis_range-specialisation)<br>
|
||||
[Exceptions](#exceptions)<br>
|
||||
[Enums](#enums)<br>
|
||||
[Floating point precision](#floating-point-precision)<br>
|
||||
|
||||
|
||||
Catch needs to be able to convert types you use in assertions and logging expressions into strings (for logging and reporting purposes).
|
||||
Most built-in or std types are supported out of the box but there are two ways that you can tell Catch how to convert your own types (or other, third-party types) into strings.
|
||||
|
||||
@ -8,41 +17,116 @@ Most built-in or std types are supported out of the box but there are two ways t
|
||||
|
||||
This is the standard way of providing string conversions in C++ - and the chances are you may already provide this for your own purposes. If you're not familiar with this idiom it involves writing a free function of the form:
|
||||
|
||||
```
|
||||
```cpp
|
||||
std::ostream& operator << ( std::ostream& os, T const& value ) {
|
||||
os << convertMyTypeToString( value );
|
||||
return os;
|
||||
os << convertMyTypeToString( value );
|
||||
return os;
|
||||
}
|
||||
```
|
||||
|
||||
(where ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable - it doesn't have to be in another function).
|
||||
|
||||
You should put this function in the same namespace as your type and have it declared before including Catch's header.
|
||||
You should put this function in the same namespace as your type, or the global namespace, and have it declared before including Catch's header.
|
||||
|
||||
## Catch::StringMaker<T> specialisation
|
||||
## Catch::StringMaker specialisation
|
||||
If you don't want to provide an ```operator <<``` overload, or you want to convert your type differently for testing purposes, you can provide a specialization for `Catch::StringMaker<T>`:
|
||||
|
||||
```
|
||||
```cpp
|
||||
namespace Catch {
|
||||
template<>
|
||||
template<>
|
||||
struct StringMaker<T> {
|
||||
static std::string convert( T const& value ) {
|
||||
return convertMyTypeToString( value );
|
||||
static std::string convert( T const& value ) {
|
||||
return convertMyTypeToString( value );
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## Catch::is_range specialisation
|
||||
As a fallback, Catch attempts to detect if the type can be iterated
|
||||
(`begin(T)` and `end(T)` are valid) and if it can be, it is stringified
|
||||
as a range. For certain types this can lead to infinite recursion, so
|
||||
it can be disabled by specializing `Catch::is_range` like so:
|
||||
|
||||
```cpp
|
||||
namespace Catch {
|
||||
template<>
|
||||
struct is_range<T> {
|
||||
static const bool value = false;
|
||||
};
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Exceptions
|
||||
|
||||
By default all exceptions deriving from `std::exception` will be translated to strings by calling the `what()` method. For exception types that do not derive from `std::exception` - or if `what()` does not return a suitable string - use `CATCH_TRANSLATE_EXCEPTION`. This defines a function that takes your exception type, by reference, and returns a string. It can appear anywhere in the code - it doesn't have to be in the same translation unit. For example:
|
||||
|
||||
```
|
||||
CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
|
||||
return ex.message();
|
||||
```cpp
|
||||
CATCH_TRANSLATE_EXCEPTION( MyType const& ex ) {
|
||||
return ex.message();
|
||||
}
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
> Introduced in Catch2 2.8.0.
|
||||
|
||||
Enums that already have a `<<` overload for `std::ostream` will convert to strings as expected.
|
||||
If you only need to convert enums to strings for test reporting purposes you can provide a `StringMaker` specialisations as any other type.
|
||||
However, as a convenience, Catch provides the `REGISTER_ENUM` helper macro that will generate the `StringMaker` specialiation for you with minimal code.
|
||||
Simply provide it the (qualified) enum name, followed by all the enum values, and you're done!
|
||||
|
||||
E.g.
|
||||
|
||||
```cpp
|
||||
enum class Fruits { Banana, Apple, Mango };
|
||||
|
||||
CATCH_REGISTER_ENUM( Fruits, Fruits::Banana, Fruits::Apple, Fruits::Mango )
|
||||
|
||||
TEST_CASE() {
|
||||
REQUIRE( Fruits::Mango == Fruits::Apple );
|
||||
}
|
||||
```
|
||||
|
||||
... or if the enum is in a namespace:
|
||||
```cpp
|
||||
namespace Bikeshed {
|
||||
enum class Colours { Red, Green, Blue };
|
||||
}
|
||||
|
||||
// Important!: This macro must appear at top level scope - not inside a namespace
|
||||
// You can fully qualify the names, or use a using if you prefer
|
||||
CATCH_REGISTER_ENUM( Bikeshed::Colours,
|
||||
Bikeshed::Colours::Red,
|
||||
Bikeshed::Colours::Green,
|
||||
Bikeshed::Colours::Blue )
|
||||
|
||||
TEST_CASE() {
|
||||
REQUIRE( Bikeshed::Colours::Red == Bikeshed::Colours::Blue );
|
||||
}
|
||||
```
|
||||
|
||||
## Floating point precision
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1614) in Catch2 2.8.0.
|
||||
|
||||
Catch provides a built-in `StringMaker` specialization for both `float`
|
||||
and `double`. By default, it uses what we think is a reasonable precision,
|
||||
but you can customize it by modifying the `precision` static variable
|
||||
inside the `StringMaker` specialization, like so:
|
||||
|
||||
```cpp
|
||||
Catch::StringMaker<float>::precision = 15;
|
||||
const float testFloat1 = 1.12345678901234567899f;
|
||||
const float testFloat2 = 1.12345678991234567899f;
|
||||
REQUIRE(testFloat1 == testFloat2);
|
||||
```
|
||||
|
||||
This assertion will fail and print out the `testFloat1` and `testFloat2`
|
||||
to 15 decimal places.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
233
docs/tutorial.md
233
docs/tutorial.md
@ -1,31 +1,26 @@
|
||||
<a id="top"></a>
|
||||
# Tutorial
|
||||
|
||||
**Contents**
|
||||
[Getting Catch](#getting-catch)
|
||||
[Where to put it?](#where-to-put-it)
|
||||
[Writing tests](#writing-tests)
|
||||
[Test cases and sections](#test-cases-and-sections)
|
||||
[BDD-Style](#bdd-style)
|
||||
[Scaling up](#scaling-up)
|
||||
[Next steps](#next-steps)
|
||||
|
||||
## Getting Catch
|
||||
|
||||
The simplest way to get Catch is to download the latest [single header version](https://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
|
||||
|
||||
The full source for Catch, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
|
||||
**Contents**<br>
|
||||
[Getting Catch2](#getting-catch2)<br>
|
||||
[Writing tests](#writing-tests)<br>
|
||||
[Test cases and sections](#test-cases-and-sections)<br>
|
||||
[BDD style testing](#bdd-style-testing)<br>
|
||||
[Data and Type driven tests](#data-and-type-driven-tests)<br>
|
||||
[Next steps](#next-steps)<br>
|
||||
|
||||
|
||||
## Where to put it?
|
||||
## Getting Catch2
|
||||
|
||||
Catch is header only. All you need to do is drop the file(s) somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](http://www.levelofindirection.com/journal/2011/5/27/unit-testing-in-c-and-objective-c-just-got-ridiculously-easi.html).
|
||||
Ideally you should be using Catch2 through its [CMake integration](cmake-integration.md#top).
|
||||
Catch2 also provides pkg-config files and single TU distribution, but this
|
||||
documentation will assume you are using CMake. If you are using single-TU
|
||||
distribution instead, remember to replace the included header with `catch_amalgamated.hpp`.
|
||||
|
||||
The rest of this tutorial will assume that the Catch single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
|
||||
|
||||
## Writing tests
|
||||
|
||||
Let's start with a really simple example. Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).
|
||||
Let's start with a really simple example ([code](../examples/010-TestCase.cpp)). Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).
|
||||
|
||||
```c++
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
@ -33,11 +28,8 @@ unsigned int Factorial( unsigned int number ) {
|
||||
}
|
||||
```
|
||||
|
||||
To keep things simple we'll put everything in a single file (<a href="#scaling-up">see later for more on how to structure your test files</a>)
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
return number <= 1 ? number : Factorial(number-1)*number;
|
||||
@ -53,13 +45,10 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
|
||||
This will compile to a complete executable which responds to [command line arguments](command-line.md#top). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
|
||||
|
||||
If you run this as written it will pass. Everything is good. Right?
|
||||
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
|
||||
|
||||
What is the bug? Well what is the factorial of zero?
|
||||
[The factorial of zero is one](http://mathforum.org/library/drmath/view/57128.html) - which is just one of those things you have to know (and remember!).
|
||||
|
||||
Let's add that to the test case:
|
||||
Anyway, as the tests above as written will pass, but there is a bug.
|
||||
The problem is that `Factorial(0)` should return 1 (due to [its
|
||||
definition](https://en.wikipedia.org/wiki/Factorial#Factorial_of_zero)).
|
||||
Let's add that as an assertion to the test case:
|
||||
|
||||
```c++
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
@ -71,7 +60,8 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
}
|
||||
```
|
||||
|
||||
Now we get a failure - something like:
|
||||
After another compile & run cycle, we will see a test failure. The output
|
||||
will look something like:
|
||||
|
||||
```
|
||||
Example.cpp:9: FAILED:
|
||||
@ -80,181 +70,156 @@ with expansion:
|
||||
0 == 1
|
||||
```
|
||||
|
||||
Note that we get the actual return value of Factorial(0) printed for us (0) - even though we used a natural expression with the == operator. That lets us immediately see what the problem is.
|
||||
|
||||
Let's change the factorial function to:
|
||||
Note that the output contains both the original expression,
|
||||
`REQUIRE( Factorial(0) == 1 )` and the actual value returned by the call
|
||||
to the `Factorial` function: `0`.
|
||||
|
||||
We can fix this bug by slightly modifying the `Factorial` function to:
|
||||
```c++
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
return number > 1 ? Factorial(number-1)*number : 1;
|
||||
}
|
||||
```
|
||||
|
||||
Now all the tests pass.
|
||||
|
||||
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
|
||||
|
||||
### What did we do here?
|
||||
|
||||
Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take moment to consider those before we move on.
|
||||
Although this was a simple test it's been enough to demonstrate a few
|
||||
things about how Catch2 is used. Let's take a moment to consider those
|
||||
before we move on.
|
||||
|
||||
* We introduce test cases with the `TEST_CASE` macro. This macro takes
|
||||
one or two string arguments - a free form test name and, optionally,
|
||||
one or more tags (for more see [Test cases and Sections](#test-cases-and-sections)).
|
||||
* The test automatically self-registers with the test runner, and user
|
||||
does not have do anything more to ensure that it is picked up by the test
|
||||
framework. _Note that you can run specific test, or set of tests,
|
||||
through the [command line](command-line.md#top)._
|
||||
* The individual test assertions are written using the `REQUIRE` macro.
|
||||
It accepts a boolean expression, and uses expression templates to
|
||||
internally decompose it, so that it can be individually stringified
|
||||
on test failure.
|
||||
|
||||
On the last point, note that there are more testing macros available,
|
||||
because not all useful checks can be expressed as a simple boolean
|
||||
expression. As an example, checking that an expression throws an exception
|
||||
is done with the `REQUIRE_THROWS` macro. More on that later.
|
||||
|
||||
1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md#top). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md#top)).
|
||||
2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>, ). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md#top) for more information on running tests.
|
||||
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
|
||||
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
|
||||
|
||||
<a id="test-cases-and-sections"></a>
|
||||
## Test cases and sections
|
||||
|
||||
Most test frameworks have a class-based fixture mechanism. That is, test cases map to methods on a class and common setup and teardown can be performed in ```setup()``` and ```teardown()``` methods (or constructor/ destructor in languages, like C++, that support deterministic destruction).
|
||||
Like most test frameworks, Catch2 supports a class-based fixture mechanism,
|
||||
where individual tests are methods on class and setup/teardown can be
|
||||
done in constructor/destructor of the type.
|
||||
|
||||
While Catch fully supports this way of working there are a few problems with the approach. In particular the way your code must be split up, and the blunt granularity of it, may cause problems. You can only have one setup/ teardown pair across a set of methods, but sometimes you want slightly different setup in each method, or you may even want several levels of setup (a concept which we will clarify later on in this tutorial). It was <a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html">problems like these</a> that led James Newkirk, who led the team that built NUnit, to start again from scratch and <a href="http://jamesnewkirk.typepad.com/posts/2007/09/announcing-xuni.html">build xUnit</a>).
|
||||
|
||||
Catch takes a different approach (to both NUnit and xUnit) that is a more natural fit for C++ and the C family of languages. This is best explained through an example:
|
||||
However, their use in Catch2 is rare, because idiomatic Catch2 tests
|
||||
instead use _sections_ to share setup and teardown code between test code.
|
||||
This is best explained through an example ([code](../examples/100-Fix-Section.cpp)):
|
||||
|
||||
```c++
|
||||
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
|
||||
SECTION( "resizing bigger changes size and capacity" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
SECTION( "resizing smaller changes size but not capacity" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
SECTION( "reserving bigger changes capacity but not size" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
SECTION( "reserving smaller does not change size or capacity" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For each ```SECTION``` the ```TEST_CASE``` is executed from the start - so as we enter each section we know that size is 5 and capacity is at least 5. We enforced those requirements with the ```REQUIRE```s at the top level so we can be confident in them.
|
||||
This works because the ```SECTION``` macro contains an if statement that calls back into Catch to see if the section should be executed. One leaf section is executed on each run through a ```TEST_CASE```. The other sections are skipped. Next time through the next section is executed, and so on until no new sections are encountered.
|
||||
For each `SECTION` the `TEST_CASE` is executed from the start. This means
|
||||
that each section is entered with a freshly constructed vector `v`, that
|
||||
we know has size 5 and capacity at least 5, because the two assertions
|
||||
are also checked before the section is entered. Each run through a test
|
||||
case will execute one, and only one, leaf section.
|
||||
|
||||
So far so good - this is already an improvement on the setup/teardown approach because now we see our setup code inline and use the stack.
|
||||
Section can also be nested, in which case the parent section can be
|
||||
entered multiple times, once for each leaf section. Nested sections are
|
||||
most useful when you have multiple tests that share part of the set up.
|
||||
To continue on the vector example above, you could add a check that
|
||||
`std::vector::reserve` does not remove unused excess capacity, like this:
|
||||
|
||||
The power of sections really shows, however, when we need to execute a sequence of, checked, operations. Continuing the vector example, we might want to verify that attempting to reserve a capacity smaller than the current capacity of the vector changes nothing. We can do that, naturally, like so:
|
||||
|
||||
```c++
|
||||
```cpp
|
||||
SECTION( "reserving bigger changes capacity but not size" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
|
||||
SECTION( "reserving smaller again does not change capacity" ) {
|
||||
SECTION( "reserving down unused capacity does not change capacity" ) {
|
||||
v.reserve( 7 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Sections can be nested to an arbitrary depth (limited only by your stack size). Each leaf section (i.e. a section that contains no nested sections) will be executed exactly once, on a separate path of execution from any other leaf section (so no leaf section can interfere with another). A failure in a parent section will prevent nested sections from running - but then that's the idea.
|
||||
Another way to look at sections is that they are a way to define a tree
|
||||
of paths through the test. Each section represents a node, and the final
|
||||
tree is walked in depth-first manner, with each path only visiting only
|
||||
one leaf node.
|
||||
|
||||
## BDD-Style
|
||||
There is no practical limit on nesting sections, as long as your compiler
|
||||
can handle them, but keep in mind that overly nested sections can become
|
||||
unreadable. From experience, having section nest more than 3 levels is
|
||||
usually very hard to follow and not worth the removed duplication.
|
||||
|
||||
If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md#top).
|
||||
|
||||
The vector example can be adjusted to use these macros like so:
|
||||
## BDD style testing
|
||||
|
||||
```c++
|
||||
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||
Catch2 also provides some basic support for BDD-style testing. There are
|
||||
macro aliases for `TEST_CASE` and `SECTIONS` that you can use so that
|
||||
the resulting tests read as BDD spec. `SCENARIO` acts as a `TEST_CASE`
|
||||
with "Scenario: " name prefix. Then there are `GIVEN`, `WHEN`, `THEN`
|
||||
(and their variants with `AND_` prefix), which act as a `SECTION`,
|
||||
similarly prefixed with the macro name.
|
||||
|
||||
GIVEN( "A vector with some items" ) {
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
WHEN( "the size is increased" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
THEN( "the size and capacity change" ) {
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "the size is reduced" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
THEN( "the size changes but not capacity" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
WHEN( "more capacity is reserved" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
THEN( "the capacity changes but not the size" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "less capacity is reserved" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
THEN( "neither size nor capacity are changed" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
For more details on the macros look at the [test cases and
|
||||
sections](test-cases-and-sections.md#top) part of the reference docs,
|
||||
or at the [vector example done with BDD macros](../examples/120-Bdd-ScenarioGivenWhenThen.cpp).
|
||||
|
||||
Conveniently, these tests will be reported as follows when run:
|
||||
|
||||
```
|
||||
Scenario: vectors can be sized and resized
|
||||
Given: A vector with some items
|
||||
When: more capacity is reserved
|
||||
Then: the capacity changes but not the size
|
||||
```
|
||||
## Data and Type driven tests
|
||||
|
||||
<a id="scaling-up"></a>
|
||||
## Scaling up
|
||||
Test cases in Catch2 can also be driven by types, input data, or both
|
||||
at the same time.
|
||||
|
||||
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
|
||||
|
||||
The requirement is that the following block of code ([or equivalent](own-main.md#top)):
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
```
|
||||
|
||||
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
|
||||
|
||||
In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md#top).
|
||||
|
||||
Do not write your tests in header files!
|
||||
For more details look into the Catch2 reference, either at the
|
||||
[type parametrized test cases](test-cases-and-sections.md#type-parametrised-test-cases),
|
||||
or [data generators](generators.md#top).
|
||||
|
||||
|
||||
## Next steps
|
||||
|
||||
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
|
||||
This page is a brief introduction to get you up and running with Catch2,
|
||||
and to show the basic features of Catch2. The features mentioned here
|
||||
can get you quite far, but there are many more. However, you can read
|
||||
about these as you go, in the ever-growing [reference section](Readme.md#top)
|
||||
of the documentation.
|
||||
|
||||
Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md#top) for what's available.
|
||||
|
||||
---
|
||||
|
||||
|
95
docs/usage-tips.md
Normal file
95
docs/usage-tips.md
Normal file
@ -0,0 +1,95 @@
|
||||
<a id="top"></a>
|
||||
# Best practices and other tips on using Catch2
|
||||
|
||||
## Running tests
|
||||
|
||||
Your tests should be run in a manner roughly equivalent with:
|
||||
|
||||
```
|
||||
./tests --order rand --warn NoAssertions
|
||||
```
|
||||
|
||||
Notice that all the tests are run in a large batch, their relative order
|
||||
is randomized, and that you ask Catch2 to fail test whose leaf-path
|
||||
does not contain an assertion.
|
||||
|
||||
The reason I recommend running all your tests in the same process is that
|
||||
this exposes your tests to interference from their runs. This can be both
|
||||
positive interference, where the changes in global state from previous
|
||||
test allow later tests to pass, but also negative interference, where
|
||||
changes in global state from previous test causes later tests to fail.
|
||||
|
||||
In my experience, interference, especially destructive interference,
|
||||
usually comes from errors in the code under test, rather than the tests
|
||||
themselves. This means that by allowing interference to happen, our tests
|
||||
can find these issues. Obviously, to shake out interference coming from
|
||||
different orderings of tests, the test order also need to be shuffled
|
||||
between runs.
|
||||
|
||||
However, running all tests in a single batch eventually becomes impractical
|
||||
as they will take too long to run, and you will want to run your tests
|
||||
in parallel.
|
||||
|
||||
|
||||
<a id="parallel-tests"></a>
|
||||
## Running tests in parallel
|
||||
|
||||
There are multiple ways of running tests in parallel, with various level
|
||||
of structure. If you are using CMake and CTest, then we provide a helper
|
||||
function [`catch_discover_tests`](cmake-integration.md#automatic-test-registration)
|
||||
that registers each Catch2 `TEST_CASE` as a single CTest test, which
|
||||
is then run in a separate process. This is an easy way to set up parallel
|
||||
tests if you are already using CMake & CTest to run your tests, but you
|
||||
will lose the advantage of running tests in batches.
|
||||
|
||||
|
||||
Catch2 also supports [splitting tests in a binary into multiple
|
||||
shards](command-line.md#test-sharding). This can be used by any test
|
||||
runner to run batches of tests in parallel. Do note that when selecting
|
||||
on the number of shards, you should have more shards than there are cores,
|
||||
to avoid issues with long running tests getting accidentally grouped in
|
||||
the same shard, and causing long-tailed execution time.
|
||||
|
||||
**Note that naively composing sharding and random ordering of tests will break.**
|
||||
|
||||
Invoking Catch2 test executable like this
|
||||
|
||||
```text
|
||||
./tests --order rand --shard-index 0 --shard-count 3
|
||||
./tests --order rand --shard-index 1 --shard-count 3
|
||||
./tests --order rand --shard-index 2 --shard-count 3
|
||||
```
|
||||
|
||||
does not guarantee covering all tests inside the executable, because
|
||||
each invocation will have its own random seed, thus it will have its own
|
||||
random order of tests and thus the partitioning of tests into shards will
|
||||
be different as well.
|
||||
|
||||
To do this properly, you need the individual shards to share the random
|
||||
seed, e.g.
|
||||
```text
|
||||
./tests --order rand --shard-index 0 --shard-count 3 --rng-seed 0xBEEF
|
||||
./tests --order rand --shard-index 1 --shard-count 3 --rng-seed 0xBEEF
|
||||
./tests --order rand --shard-index 2 --shard-count 3 --rng-seed 0xBEEF
|
||||
```
|
||||
|
||||
|
||||
## Organizing tests into binaries
|
||||
|
||||
Both overly large and overly small test binaries can cause issues. Overly
|
||||
large test binaries have to be recompiled and relinked often, and the
|
||||
link times are usually also long. Overly small test binaries in turn pay
|
||||
significant overhead from linking against Catch2 more often per compiled
|
||||
test case, and also make it hard/impossible to run tests in batches.
|
||||
|
||||
Because there is no hard and fast rule for the right size of a test binary,
|
||||
I recommend having 1:1 correspondence between libraries in project and test
|
||||
binaries. (At least if it is possible, in some cases it is not.) Having
|
||||
a test binary for each library in project keeps related tests together,
|
||||
and makes tests easy to navigate by reflecting the project's organizational
|
||||
structure.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@ -6,40 +6,53 @@ including (but not limited to),
|
||||
[Google Test](http://code.google.com/p/googletest/),
|
||||
[Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html),
|
||||
[CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page),
|
||||
[Cute](http://r2.ifs.hsr.ch/cute),
|
||||
[Cute](http://www.cute-test.com), and
|
||||
[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).
|
||||
|
||||
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
|
||||
So what does Catch2 bring to the party that differentiates it from these? Apart from the catchy name, of course.
|
||||
|
||||
|
||||
## Key Features
|
||||
|
||||
* Quick and Really easy to get started. Just download catch.hpp, `#include` it and you're away.
|
||||
* No external dependencies. As long as you can compile C++11 and have a C++ standard library available.
|
||||
* Quick and easy to get started. Just download two files, add them into your project and you're away.
|
||||
* No external dependencies. As long as you can compile C++14 and have the C++ standard library available.
|
||||
* Write test cases as, self-registering, functions (or methods, if you prefer).
|
||||
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
|
||||
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
|
||||
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
|
||||
* Tests are named using free-form strings - no more couching names in legal identifiers.
|
||||
|
||||
|
||||
## Other core features
|
||||
|
||||
* Tests can be tagged for easily running ad-hoc groups of tests.
|
||||
* Failures can (optionally) break into the debugger on Windows and Mac.
|
||||
* Failures can (optionally) break into the debugger on common platforms.
|
||||
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
|
||||
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
|
||||
* A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
|
||||
* A command line parser is provided and can still be used if you choose to provided your own main() function.
|
||||
* Catch can test itself.
|
||||
* Alternative assertion macro(s) report failures but don't abort the test case
|
||||
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
|
||||
* Good set of facilities for floating point comparisons (`Catch::Approx` and full set of matchers)
|
||||
* Internal and friendly macros are isolated so name clashes can be managed
|
||||
* Matchers
|
||||
* Data generators (data driven test support)
|
||||
* Hamcrest-style Matchers for testing complex properties
|
||||
* Microbenchmarking support
|
||||
|
||||
## Who else is using Catch?
|
||||
|
||||
See the list of [open source projects using Catch](opensource-users.md#top).
|
||||
## Who else is using Catch2?
|
||||
|
||||
See the [tutorial](tutorial.md#top) to get more of a taste of using Catch in practice
|
||||
A whole lot of people. According to the 2021 Jetbrains C++ ecosystem survey,
|
||||
about 11% of C++ programmers use Catch2 for unit testing, making it the
|
||||
second most popular unit testing framework.
|
||||
|
||||
You can also take a look at the (incomplete) list of [open source projects](opensource-users.md#top)
|
||||
or the (very incomplete) list of [commercial users of Catch2](commercial-users.md#top)
|
||||
for some idea on who else also uses Catch2.
|
||||
|
||||
---
|
||||
|
||||
See the [tutorial](tutorial.md#top) to get more of a taste of using
|
||||
Catch2 in practice.
|
||||
|
||||
---
|
||||
|
||||
|
33
examples/010-TestCase.cpp
Normal file
33
examples/010-TestCase.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// 010-TestCase.cpp
|
||||
// And write tests in the same file:
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
static int Factorial( int number ) {
|
||||
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
||||
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||
}
|
||||
|
||||
TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) {
|
||||
REQUIRE( Factorial(0) == 1 );
|
||||
}
|
||||
|
||||
TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 010-TestCase 010-TestCase.cpp && 010-TestCase --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 010-TestCase.cpp && 010-TestCase --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 010-TestCase --reporter compact --success
|
||||
// 010-TestCase.cpp:14: failed: Factorial(0) == 1 for: 0 == 1
|
||||
// 010-TestCase.cpp:18: passed: Factorial(1) == 1 for: 1 == 1
|
||||
// 010-TestCase.cpp:19: passed: Factorial(2) == 2 for: 2 == 2
|
||||
// 010-TestCase.cpp:20: passed: Factorial(3) == 6 for: 6 == 6
|
||||
// 010-TestCase.cpp:21: passed: Factorial(10) == 3628800 for: 3628800 (0x375f00) == 3628800 (0x375f00)
|
||||
// Failed 1 test case, failed 1 assertion.
|
29
examples/020-TestCase-1.cpp
Normal file
29
examples/020-TestCase-1.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// 020-TestCase-1.cpp
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) {
|
||||
}
|
||||
|
||||
// ^^^
|
||||
// Normally no TEST_CASEs in this file.
|
||||
// Here just to show there are two source files via option --list-tests.
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 020-TestCase-1.cpp
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 020-TestCase TestCase-1.o 020-TestCase-2.cpp && 020-TestCase --success
|
||||
//
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -c 020-TestCase-1.cpp
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -Fe020-TestCase.exe 020-TestCase-1.obj 020-TestCase-2.cpp && 020-TestCase --success
|
||||
|
||||
// Expected test case listing:
|
||||
//
|
||||
// prompt> 020-TestCase --list-tests *
|
||||
// Matching test cases:
|
||||
// 1: All test cases reside in other .cpp files (empty)
|
||||
// [multi-file:1]
|
||||
// 2: Factorial of 0 is computed (fail)
|
||||
// [multi-file:2]
|
||||
// 2: Factorials of 1 and higher are computed (pass)
|
||||
// [multi-file:2]
|
||||
// 3 matching test cases
|
33
examples/020-TestCase-2.cpp
Normal file
33
examples/020-TestCase-2.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// 020-TestCase-2.cpp
|
||||
|
||||
// main() provided by Catch in file 020-TestCase-1.cpp.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
static int Factorial( int number ) {
|
||||
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
||||
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||
}
|
||||
|
||||
TEST_CASE( "2: Factorial of 0 is 1 (fail)", "[multi-file:2]" ) {
|
||||
REQUIRE( Factorial(0) == 1 );
|
||||
}
|
||||
|
||||
TEST_CASE( "2: Factorials of 1 and higher are computed (pass)", "[multi-file:2]" ) {
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
||||
|
||||
// Compile: see 020-TestCase-1.cpp
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 020-TestCase --reporter compact --success
|
||||
// 020-TestCase-2.cpp:13: failed: Factorial(0) == 1 for: 0 == 1
|
||||
// 020-TestCase-2.cpp:17: passed: Factorial(1) == 1 for: 1 == 1
|
||||
// 020-TestCase-2.cpp:18: passed: Factorial(2) == 2 for: 2 == 2
|
||||
// 020-TestCase-2.cpp:19: passed: Factorial(3) == 6 for: 6 == 6
|
||||
// 020-TestCase-2.cpp:20: passed: Factorial(10) == 3628800 for: 3628800 (0x375f00) == 3628800 (0x375f00)
|
||||
// Failed 1 test case, failed 1 assertion.
|
74
examples/030-Asn-Require-Check.cpp
Normal file
74
examples/030-Asn-Require-Check.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
// 030-Asn-Require-Check.cpp
|
||||
|
||||
// Catch has two natural expression assertion macro's:
|
||||
// - REQUIRE() stops at first failure.
|
||||
// - CHECK() continues after failure.
|
||||
|
||||
// There are two variants to support decomposing negated expressions:
|
||||
// - REQUIRE_FALSE() stops at first failure.
|
||||
// - CHECK_FALSE() continues after failure.
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
static std::string one() {
|
||||
return "1";
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert that something is true (pass)", "[require]" ) {
|
||||
REQUIRE( one() == "1" );
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert that something is true (fail)", "[require]" ) {
|
||||
REQUIRE( one() == "x" );
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert that something is true (stop at first failure)", "[require]" ) {
|
||||
WARN( "REQUIRE stops at first failure:" );
|
||||
|
||||
REQUIRE( one() == "x" );
|
||||
REQUIRE( one() == "1" );
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert that something is true (continue after failure)", "[check]" ) {
|
||||
WARN( "CHECK continues after failure:" );
|
||||
|
||||
CHECK( one() == "x" );
|
||||
REQUIRE( one() == "1" );
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert that something is false (stops at first failure)", "[require-false]" ) {
|
||||
WARN( "REQUIRE_FALSE stops at first failure:" );
|
||||
|
||||
REQUIRE_FALSE( one() == "1" );
|
||||
REQUIRE_FALSE( one() != "1" );
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert that something is false (continue after failure)", "[check-false]" ) {
|
||||
WARN( "CHECK_FALSE continues after failure:" );
|
||||
|
||||
CHECK_FALSE( one() == "1" );
|
||||
REQUIRE_FALSE( one() != "1" );
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 030-Asn-Require-Check 030-Asn-Require-Check.cpp && 030-Asn-Require-Check --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 030-Asn-Require-Check.cpp && 030-Asn-Require-Check --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 030-Asn-Require-Check.exe --reporter compact --success
|
||||
// 030-Asn-Require-Check.cpp:20: passed: one() == "1" for: "1" == "1"
|
||||
// 030-Asn-Require-Check.cpp:24: failed: one() == "x" for: "1" == "x"
|
||||
// 030-Asn-Require-Check.cpp:28: warning: 'REQUIRE stops at first failure:'
|
||||
// 030-Asn-Require-Check.cpp:30: failed: one() == "x" for: "1" == "x"
|
||||
// 030-Asn-Require-Check.cpp:35: warning: 'CHECK continues after failure:'
|
||||
// 030-Asn-Require-Check.cpp:37: failed: one() == "x" for: "1" == "x"
|
||||
// 030-Asn-Require-Check.cpp:38: passed: one() == "1" for: "1" == "1"
|
||||
// 030-Asn-Require-Check.cpp:42: warning: 'REQUIRE_FALSE stops at first failure:'
|
||||
// 030-Asn-Require-Check.cpp:44: failed: !(one() == "1") for: !("1" == "1")
|
||||
// 030-Asn-Require-Check.cpp:49: warning: 'CHECK_FALSE continues after failure:'
|
||||
// 030-Asn-Require-Check.cpp:51: failed: !(one() == "1") for: !("1" == "1")
|
||||
// 030-Asn-Require-Check.cpp:52: passed: !(one() != "1") for: !("1" != "1")
|
||||
// Failed 5 test cases, failed 5 assertions.
|
70
examples/100-Fix-Section.cpp
Normal file
70
examples/100-Fix-Section.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// 100-Fix-Section.cpp
|
||||
|
||||
// Catch has two ways to express fixtures:
|
||||
// - Sections (this file)
|
||||
// - Traditional class-based fixtures
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
// For each section, vector v is anew:
|
||||
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
SECTION( "resizing bigger changes size and capacity" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
SECTION( "resizing smaller changes size but not capacity" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
SECTION( "reserving bigger changes capacity but not size" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
SECTION( "reserving smaller does not change size or capacity" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 100-Fix-Section 100-Fix-Section.cpp && 100-Fix-Section --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 100-Fix-Section.cpp && 100-Fix-Section --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 100-Fix-Section.exe --reporter compact --success
|
||||
// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
|
||||
// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 100-Fix-Section.cpp:23: passed: v.size() == 10 for: 10 == 10
|
||||
// 100-Fix-Section.cpp:24: passed: v.capacity() >= 10 for: 10 >= 10
|
||||
// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
|
||||
// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 100-Fix-Section.cpp:29: passed: v.size() == 0 for: 0 == 0
|
||||
// 100-Fix-Section.cpp:30: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
|
||||
// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 100-Fix-Section.cpp:35: passed: v.size() == 5 for: 5 == 5
|
||||
// 100-Fix-Section.cpp:36: passed: v.capacity() >= 10 for: 10 >= 10
|
||||
// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5
|
||||
// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 100-Fix-Section.cpp:41: passed: v.size() == 5 for: 5 == 5
|
||||
// 100-Fix-Section.cpp:42: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// Passed 1 test case with 16 assertions.
|
66
examples/110-Fix-ClassFixture.cpp
Normal file
66
examples/110-Fix-ClassFixture.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
// 110-Fix-ClassFixture.cpp
|
||||
|
||||
// Catch has two ways to express fixtures:
|
||||
// - Sections
|
||||
// - Traditional class-based fixtures (this file)
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
class DBConnection
|
||||
{
|
||||
public:
|
||||
static DBConnection createConnection( std::string const & /*dbName*/ ) {
|
||||
return DBConnection();
|
||||
}
|
||||
|
||||
bool executeSQL( std::string const & /*query*/, int const /*id*/, std::string const & arg ) {
|
||||
if ( arg.length() == 0 ) {
|
||||
throw std::logic_error("empty SQL query argument");
|
||||
}
|
||||
return true; // ok
|
||||
}
|
||||
};
|
||||
|
||||
class UniqueTestsFixture
|
||||
{
|
||||
protected:
|
||||
UniqueTestsFixture()
|
||||
: conn( DBConnection::createConnection( "myDB" ) )
|
||||
{}
|
||||
|
||||
int getID() {
|
||||
return ++uniqueID;
|
||||
}
|
||||
|
||||
protected:
|
||||
DBConnection conn;
|
||||
|
||||
private:
|
||||
static int uniqueID;
|
||||
};
|
||||
|
||||
int UniqueTestsFixture::uniqueID = 0;
|
||||
|
||||
TEST_CASE_METHOD( UniqueTestsFixture, "Create Employee/No Name", "[create]" ) {
|
||||
REQUIRE_THROWS( conn.executeSQL( "INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "") );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD( UniqueTestsFixture, "Create Employee/Normal", "[create]" ) {
|
||||
REQUIRE( conn.executeSQL( "INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "Joe Bloggs" ) );
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 110-Fix-ClassFixture 110-Fix-ClassFixture.cpp && 110-Fix-ClassFixture --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 110-Fix-ClassFixture.cpp && 110-Fix-ClassFixture --success
|
||||
//
|
||||
// Compile with pkg-config:
|
||||
// - g++ -std=c++14 -Wall $(pkg-config catch2-with-main --cflags) -o 110-Fix-ClassFixture 110-Fix-ClassFixture.cpp $(pkg-config catch2-with-main --libs)
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 110-Fix-ClassFixture.exe --reporter compact --success
|
||||
// 110-Fix-ClassFixture.cpp:47: passed: conn.executeSQL( "INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "")
|
||||
// 110-Fix-ClassFixture.cpp:51: passed: conn.executeSQL( "INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "Joe Bloggs" ) for: true
|
||||
// Passed both 2 test cases with 2 assertions.
|
73
examples/120-Bdd-ScenarioGivenWhenThen.cpp
Normal file
73
examples/120-Bdd-ScenarioGivenWhenThen.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp
|
||||
|
||||
// main() provided by linkage with Catch2WithMain
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
GIVEN( "A vector with some items" ) {
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
WHEN( "the size is increased" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
THEN( "the size and capacity change" ) {
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "the size is reduced" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
THEN( "the size changes but not capacity" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
WHEN( "more capacity is reserved" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
THEN( "the capacity changes but not the size" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "less capacity is reserved" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
THEN( "neither size nor capacity are changed" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 120-Bdd-ScenarioGivenWhenThen 120-Bdd-ScenarioGivenWhenThen.cpp && 120-Bdd-ScenarioGivenWhenThen --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 120-Bdd-ScenarioGivenWhenThen.cpp && 120-Bdd-ScenarioGivenWhenThen --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 120-Bdd-ScenarioGivenWhenThen.exe --reporter compact --success
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:19: passed: v.size() == 10 for: 10 == 10
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:20: passed: v.capacity() >= 10 for: 10 >= 10
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:27: passed: v.size() == 0 for: 0 == 0
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:28: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:35: passed: v.size() == 5 for: 5 == 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:36: passed: v.capacity() >= 10 for: 10 >= 10
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:43: passed: v.size() == 5 for: 5 == 5
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp:44: passed: v.capacity() >= 5 for: 5 >= 5
|
||||
// Passed 1 test case with 16 assertions.
|
429
examples/210-Evt-EventListeners.cpp
Normal file
429
examples/210-Evt-EventListeners.cpp
Normal file
@ -0,0 +1,429 @@
|
||||
// 210-Evt-EventListeners.cpp
|
||||
|
||||
// Contents:
|
||||
// 1. Printing of listener data
|
||||
// 2. My listener and registration
|
||||
// 3. Test cases
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <iostream>
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 1. Printing of listener data:
|
||||
//
|
||||
|
||||
|
||||
namespace {
|
||||
std::string ws(int const level) {
|
||||
return std::string( 2 * level, ' ' );
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Catch::Tag t) {
|
||||
return out << "original: " << t.original;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
||||
os << "{ ";
|
||||
for ( const auto& x : v )
|
||||
os << x << ", ";
|
||||
return os << "}";
|
||||
}
|
||||
// struct SourceLineInfo {
|
||||
// char const* file;
|
||||
// std::size_t line;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::SourceLineInfo const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- file: " << info.file << "\n"
|
||||
<< ws(level+1) << "- line: " << info.line << "\n";
|
||||
}
|
||||
|
||||
//struct MessageInfo {
|
||||
// std::string macroName;
|
||||
// std::string message;
|
||||
// SourceLineInfo lineInfo;
|
||||
// ResultWas::OfType type;
|
||||
// unsigned int sequence;
|
||||
//};
|
||||
|
||||
void print( std::ostream& os, int const level, Catch::MessageInfo const& info ) {
|
||||
os << ws(level+1) << "- macroName: '" << info.macroName << "'\n"
|
||||
<< ws(level+1) << "- message '" << info.message << "'\n";
|
||||
print( os,level+1 , "- lineInfo", info.lineInfo );
|
||||
os << ws(level+1) << "- sequence " << info.sequence << "\n";
|
||||
}
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, std::vector<Catch::MessageInfo> const& v ) {
|
||||
os << ws(level ) << title << ":\n";
|
||||
for ( const auto& x : v )
|
||||
{
|
||||
os << ws(level+1) << "{\n";
|
||||
print( os, level+2, x );
|
||||
os << ws(level+1) << "}\n";
|
||||
}
|
||||
// os << ws(level+1) << "\n";
|
||||
}
|
||||
|
||||
// struct TestRunInfo {
|
||||
// std::string name;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestRunInfo const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- name: " << info.name << "\n";
|
||||
}
|
||||
|
||||
// struct Counts {
|
||||
// std::size_t total() const;
|
||||
// bool allPassed() const;
|
||||
// bool allOk() const;
|
||||
//
|
||||
// std::size_t passed = 0;
|
||||
// std::size_t failed = 0;
|
||||
// std::size_t failedButOk = 0;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::Counts const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- total(): " << info.total() << "\n"
|
||||
<< ws(level+1) << "- allPassed(): " << info.allPassed() << "\n"
|
||||
<< ws(level+1) << "- allOk(): " << info.allOk() << "\n"
|
||||
<< ws(level+1) << "- passed: " << info.passed << "\n"
|
||||
<< ws(level+1) << "- failed: " << info.failed << "\n"
|
||||
<< ws(level+1) << "- failedButOk: " << info.failedButOk << "\n";
|
||||
}
|
||||
|
||||
// struct Totals {
|
||||
// Counts assertions;
|
||||
// Counts testCases;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::Totals const& info ) {
|
||||
os << ws(level) << title << ":\n";
|
||||
print( os, level+1, "- assertions", info.assertions );
|
||||
print( os, level+1, "- testCases" , info.testCases );
|
||||
}
|
||||
|
||||
// struct TestRunStats {
|
||||
// TestRunInfo runInfo;
|
||||
// Totals totals;
|
||||
// bool aborting;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestRunStats const& info ) {
|
||||
os << ws(level) << title << ":\n";
|
||||
print( os, level+1 , "- runInfo", info.runInfo );
|
||||
print( os, level+1 , "- totals" , info.totals );
|
||||
os << ws(level+1) << "- aborting: " << info.aborting << "\n";
|
||||
}
|
||||
|
||||
// struct Tag {
|
||||
// StringRef original, lowerCased;
|
||||
// };
|
||||
//
|
||||
//
|
||||
// enum class TestCaseProperties : uint8_t {
|
||||
// None = 0,
|
||||
// IsHidden = 1 << 1,
|
||||
// ShouldFail = 1 << 2,
|
||||
// MayFail = 1 << 3,
|
||||
// Throws = 1 << 4,
|
||||
// NonPortable = 1 << 5,
|
||||
// Benchmark = 1 << 6
|
||||
// };
|
||||
//
|
||||
//
|
||||
// struct TestCaseInfo : NonCopyable {
|
||||
//
|
||||
// bool isHidden() const;
|
||||
// bool throws() const;
|
||||
// bool okToFail() const;
|
||||
// bool expectedToFail() const;
|
||||
//
|
||||
//
|
||||
// std::string name;
|
||||
// std::string className;
|
||||
// std::vector<Tag> tags;
|
||||
// SourceLineInfo lineInfo;
|
||||
// TestCaseProperties properties = TestCaseProperties::None;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseInfo const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- isHidden(): " << info.isHidden() << "\n"
|
||||
<< ws(level+1) << "- throws(): " << info.throws() << "\n"
|
||||
<< ws(level+1) << "- okToFail(): " << info.okToFail() << "\n"
|
||||
<< ws(level+1) << "- expectedToFail(): " << info.expectedToFail() << "\n"
|
||||
<< ws(level+1) << "- tagsAsString(): '" << info.tagsAsString() << "'\n"
|
||||
<< ws(level+1) << "- name: '" << info.name << "'\n"
|
||||
<< ws(level+1) << "- className: '" << info.className << "'\n"
|
||||
<< ws(level+1) << "- tags: " << info.tags << "\n";
|
||||
print( os, level+1 , "- lineInfo", info.lineInfo );
|
||||
os << ws(level+1) << "- properties (flags): 0x" << std::hex << static_cast<uint32_t>(info.properties) << std::dec << "\n";
|
||||
}
|
||||
|
||||
// struct TestCaseStats {
|
||||
// TestCaseInfo testInfo;
|
||||
// Totals totals;
|
||||
// std::string stdOut;
|
||||
// std::string stdErr;
|
||||
// bool aborting;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseStats const& info ) {
|
||||
os << ws(level ) << title << ":\n";
|
||||
print( os, level+1 , "- testInfo", *info.testInfo );
|
||||
print( os, level+1 , "- totals" , info.totals );
|
||||
os << ws(level+1) << "- stdOut: " << info.stdOut << "\n"
|
||||
<< ws(level+1) << "- stdErr: " << info.stdErr << "\n"
|
||||
<< ws(level+1) << "- aborting: " << info.aborting << "\n";
|
||||
}
|
||||
|
||||
// struct SectionInfo {
|
||||
// std::string name;
|
||||
// std::string description;
|
||||
// SourceLineInfo lineInfo;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::SectionInfo const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- name: " << info.name << "\n";
|
||||
print( os, level+1 , "- lineInfo", info.lineInfo );
|
||||
}
|
||||
|
||||
// struct SectionStats {
|
||||
// SectionInfo sectionInfo;
|
||||
// Counts assertions;
|
||||
// double durationInSeconds;
|
||||
// bool missingAssertions;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::SectionStats const& info ) {
|
||||
os << ws(level ) << title << ":\n";
|
||||
print( os, level+1 , "- sectionInfo", info.sectionInfo );
|
||||
print( os, level+1 , "- assertions" , info.assertions );
|
||||
os << ws(level+1) << "- durationInSeconds: " << info.durationInSeconds << "\n"
|
||||
<< ws(level+1) << "- missingAssertions: " << info.missingAssertions << "\n";
|
||||
}
|
||||
|
||||
// struct AssertionInfo
|
||||
// {
|
||||
// StringRef macroName;
|
||||
// SourceLineInfo lineInfo;
|
||||
// StringRef capturedExpression;
|
||||
// ResultDisposition::Flags resultDisposition;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionInfo const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- macroName: '" << info.macroName << "'\n";
|
||||
print( os, level+1 , "- lineInfo" , info.lineInfo );
|
||||
os << ws(level+1) << "- capturedExpression: '" << info.capturedExpression << "'\n"
|
||||
<< ws(level+1) << "- resultDisposition (flags): 0x" << std::hex << info.resultDisposition << std::dec << "\n";
|
||||
}
|
||||
|
||||
//struct AssertionResultData
|
||||
//{
|
||||
// std::string reconstructExpression() const;
|
||||
//
|
||||
// std::string message;
|
||||
// mutable std::string reconstructedExpression;
|
||||
// LazyExpression lazyExpression;
|
||||
// ResultWas::OfType resultType;
|
||||
//};
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionResultData const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- reconstructExpression(): '" << info.reconstructExpression() << "'\n"
|
||||
<< ws(level+1) << "- message: '" << info.message << "'\n"
|
||||
<< ws(level+1) << "- lazyExpression: '" << "(info.lazyExpression)" << "'\n"
|
||||
<< ws(level+1) << "- resultType: '" << info.resultType << "'\n";
|
||||
}
|
||||
|
||||
//class AssertionResult {
|
||||
// bool isOk() const;
|
||||
// bool succeeded() const;
|
||||
// ResultWas::OfType getResultType() const;
|
||||
// bool hasExpression() const;
|
||||
// bool hasMessage() const;
|
||||
// std::string getExpression() const;
|
||||
// std::string getExpressionInMacro() const;
|
||||
// bool hasExpandedExpression() const;
|
||||
// std::string getExpandedExpression() const;
|
||||
// std::string getMessage() const;
|
||||
// SourceLineInfo getSourceInfo() const;
|
||||
// std::string getTestMacroName() const;
|
||||
//
|
||||
// AssertionInfo m_info;
|
||||
// AssertionResultData m_resultData;
|
||||
//};
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionResult const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
<< ws(level+1) << "- isOk(): " << info.isOk() << "\n"
|
||||
<< ws(level+1) << "- succeeded(): " << info.succeeded() << "\n"
|
||||
<< ws(level+1) << "- getResultType(): " << info.getResultType() << "\n"
|
||||
<< ws(level+1) << "- hasExpression(): " << info.hasExpression() << "\n"
|
||||
<< ws(level+1) << "- hasMessage(): " << info.hasMessage() << "\n"
|
||||
<< ws(level+1) << "- getExpression(): '" << info.getExpression() << "'\n"
|
||||
<< ws(level+1) << "- getExpressionInMacro(): '" << info.getExpressionInMacro() << "'\n"
|
||||
<< ws(level+1) << "- hasExpandedExpression(): " << info.hasExpandedExpression() << "\n"
|
||||
<< ws(level+1) << "- getExpandedExpression(): " << info.getExpandedExpression() << "'\n"
|
||||
<< ws(level+1) << "- getMessage(): '" << info.getMessage() << "'\n";
|
||||
print( os, level+1 , "- getSourceInfo(): ", info.getSourceInfo() );
|
||||
os << ws(level+1) << "- getTestMacroName(): '" << info.getTestMacroName() << "'\n";
|
||||
|
||||
print( os, level+1 , "- *** m_info (AssertionInfo)", info.m_info );
|
||||
print( os, level+1 , "- *** m_resultData (AssertionResultData)", info.m_resultData );
|
||||
}
|
||||
|
||||
// struct AssertionStats {
|
||||
// AssertionResult assertionResult;
|
||||
// std::vector<MessageInfo> infoMessages;
|
||||
// Totals totals;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::AssertionStats const& info ) {
|
||||
os << ws(level ) << title << ":\n";
|
||||
print( os, level+1 , "- assertionResult", info.assertionResult );
|
||||
print( os, level+1 , "- infoMessages", info.infoMessages );
|
||||
print( os, level+1 , "- totals", info.totals );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 2. My listener and registration:
|
||||
//
|
||||
|
||||
char const * dashed_line =
|
||||
"--------------------------------------------------------------------------";
|
||||
|
||||
|
||||
struct MyListener : Catch::EventListenerBase {
|
||||
|
||||
using EventListenerBase::EventListenerBase; // inherit constructor
|
||||
|
||||
// Get rid of Wweak-tables
|
||||
~MyListener() override;
|
||||
|
||||
// The whole test run starting
|
||||
void testRunStarting( Catch::TestRunInfo const& testRunInfo ) override {
|
||||
std::cout
|
||||
<< std::boolalpha
|
||||
<< "\nEvent: testRunStarting:\n";
|
||||
print( std::cout, 1, "- testRunInfo", testRunInfo );
|
||||
}
|
||||
|
||||
// The whole test run ending
|
||||
void testRunEnded( Catch::TestRunStats const& testRunStats ) override {
|
||||
std::cout
|
||||
<< dashed_line
|
||||
<< "\nEvent: testRunEnded:\n";
|
||||
print( std::cout, 1, "- testRunStats", testRunStats );
|
||||
}
|
||||
|
||||
// A test is being skipped (because it is "hidden")
|
||||
void skipTest( Catch::TestCaseInfo const& testInfo ) override {
|
||||
std::cout
|
||||
<< dashed_line
|
||||
<< "\nEvent: skipTest:\n";
|
||||
print( std::cout, 1, "- testInfo", testInfo );
|
||||
}
|
||||
|
||||
// Test cases starting
|
||||
void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override {
|
||||
std::cout
|
||||
<< dashed_line
|
||||
<< "\nEvent: testCaseStarting:\n";
|
||||
print( std::cout, 1, "- testInfo", testInfo );
|
||||
}
|
||||
|
||||
// Test cases ending
|
||||
void testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override {
|
||||
std::cout << "\nEvent: testCaseEnded:\n";
|
||||
print( std::cout, 1, "testCaseStats", testCaseStats );
|
||||
}
|
||||
|
||||
// Sections starting
|
||||
void sectionStarting( Catch::SectionInfo const& sectionInfo ) override {
|
||||
std::cout << "\nEvent: sectionStarting:\n";
|
||||
print( std::cout, 1, "- sectionInfo", sectionInfo );
|
||||
}
|
||||
|
||||
// Sections ending
|
||||
void sectionEnded( Catch::SectionStats const& sectionStats ) override {
|
||||
std::cout << "\nEvent: sectionEnded:\n";
|
||||
print( std::cout, 1, "- sectionStats", sectionStats );
|
||||
}
|
||||
|
||||
// Assertions before/ after
|
||||
void assertionStarting( Catch::AssertionInfo const& assertionInfo ) override {
|
||||
std::cout << "\nEvent: assertionStarting:\n";
|
||||
print( std::cout, 1, "- assertionInfo", assertionInfo );
|
||||
}
|
||||
|
||||
void assertionEnded( Catch::AssertionStats const& assertionStats ) override {
|
||||
std::cout << "\nEvent: assertionEnded:\n";
|
||||
print( std::cout, 1, "- assertionStats", assertionStats );
|
||||
}
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
CATCH_REGISTER_LISTENER( MyListener )
|
||||
|
||||
// Get rid of Wweak-tables
|
||||
MyListener::~MyListener() {}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 3. Test cases:
|
||||
//
|
||||
|
||||
TEST_CASE( "1: Hidden testcase", "[.hidden]" ) {
|
||||
}
|
||||
|
||||
TEST_CASE( "2: Testcase with sections", "[tag-A][tag-B]" ) {
|
||||
|
||||
int i = 42;
|
||||
|
||||
REQUIRE( i == 42 );
|
||||
|
||||
SECTION("Section 1") {
|
||||
INFO("Section 1");
|
||||
i = 7;
|
||||
SECTION("Section 1.1") {
|
||||
INFO("Section 1.1");
|
||||
REQUIRE( i == 42 );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Section 2") {
|
||||
INFO("Section 2");
|
||||
REQUIRE( i == 42 );
|
||||
}
|
||||
WARN("At end of test case");
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
int fortytwo() const {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE_METHOD( Fixture, "3: Testcase with class-based fixture", "[tag-C][tag-D]" ) {
|
||||
REQUIRE( fortytwo() == 42 );
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 210-Evt-EventListeners 210-Evt-EventListeners.cpp && 210-Evt-EventListeners --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 210-Evt-EventListeners.cpp && 210-Evt-EventListeners --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
// prompt> 210-Evt-EventListeners --reporter compact --success
|
||||
// result omitted for brevity.
|
55
examples/231-Cfg-OutputStreams.cpp
Normal file
55
examples/231-Cfg-OutputStreams.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// 231-Cfg-OutputStreams.cpp
|
||||
// Show how to replace the streams with a simple custom made streambuf.
|
||||
|
||||
// Note that this reimplementation _does not_ follow `std::cerr`
|
||||
// semantic, because it buffers the output. For most uses however,
|
||||
// there is no important difference between having `std::cerr` buffered
|
||||
// or unbuffered.
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
|
||||
class out_buff : public std::stringbuf {
|
||||
std::FILE* m_stream;
|
||||
public:
|
||||
out_buff(std::FILE* stream):m_stream(stream) {}
|
||||
~out_buff();
|
||||
int sync() override {
|
||||
int ret = 0;
|
||||
for (unsigned char c : str()) {
|
||||
if (putc(c, m_stream) == EOF) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Reset the buffer to avoid printing it multiple times
|
||||
str("");
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
out_buff::~out_buff() { pubsync(); }
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Wexit-time-destructors" // static variables in cout/cerr/clog
|
||||
#endif
|
||||
|
||||
namespace Catch {
|
||||
std::ostream& cout() {
|
||||
static std::ostream ret(new out_buff(stdout));
|
||||
return ret;
|
||||
}
|
||||
std::ostream& clog() {
|
||||
static std::ostream ret(new out_buff(stderr));
|
||||
return ret;
|
||||
}
|
||||
std::ostream& cerr() {
|
||||
return clog();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("This binary uses putc to write out output", "[compilation-only]") {
|
||||
SUCCEED("Nothing to test.");
|
||||
}
|
69
examples/300-Gen-OwnGenerator.cpp
Normal file
69
examples/300-Gen-OwnGenerator.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// 300-Gen-OwnGenerator.cpp
|
||||
// Shows how to define a custom generator.
|
||||
|
||||
// Specifically we will implement a random number generator for integers
|
||||
// It will have infinite capacity and settable lower/upper bound
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace {
|
||||
|
||||
// This class shows how to implement a simple generator for Catch tests
|
||||
class RandomIntGenerator : public Catch::Generators::IGenerator<int> {
|
||||
std::minstd_rand m_rand;
|
||||
std::uniform_int_distribution<> m_dist;
|
||||
int current_number;
|
||||
public:
|
||||
|
||||
RandomIntGenerator(int low, int high):
|
||||
m_rand(std::random_device{}()),
|
||||
m_dist(low, high)
|
||||
{
|
||||
static_cast<void>(next());
|
||||
}
|
||||
|
||||
int const& get() const override;
|
||||
bool next() override {
|
||||
current_number = m_dist(m_rand);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Avoids -Wweak-vtables
|
||||
int const& RandomIntGenerator::get() const {
|
||||
return current_number;
|
||||
}
|
||||
|
||||
// This helper function provides a nicer UX when instantiating the generator
|
||||
// Notice that it returns an instance of GeneratorWrapper<int>, which
|
||||
// is a value-wrapper around std::unique_ptr<IGenerator<int>>.
|
||||
Catch::Generators::GeneratorWrapper<int> random(int low, int high) {
|
||||
return Catch::Generators::GeneratorWrapper<int>(
|
||||
new RandomIntGenerator(low, high)
|
||||
// Another possibility:
|
||||
// Catch::Detail::make_unique<RandomIntGenerator>(low, high)
|
||||
);
|
||||
}
|
||||
|
||||
} // end anonymous namespaces
|
||||
|
||||
// The two sections in this test case are equivalent, but the first one
|
||||
// is much more readable/nicer to use
|
||||
TEST_CASE("Generating random ints", "[example][generator]") {
|
||||
SECTION("Nice UX") {
|
||||
auto i = GENERATE(take(100, random(-100, 100)));
|
||||
REQUIRE(i >= -100);
|
||||
REQUIRE(i <= 100);
|
||||
}
|
||||
SECTION("Creating the random generator directly") {
|
||||
auto i = GENERATE(take(100, GeneratorWrapper<int>(Catch::Detail::make_unique<RandomIntGenerator>(-100, 100))));
|
||||
REQUIRE(i >= -100);
|
||||
REQUIRE(i <= 100);
|
||||
}
|
||||
}
|
||||
|
||||
// Compiling and running this file will result in 400 successful assertions
|
60
examples/301-Gen-MapTypeConversion.cpp
Normal file
60
examples/301-Gen-MapTypeConversion.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
// 301-Gen-MapTypeConversion.cpp
|
||||
// Shows how to use map to modify generator's return type.
|
||||
|
||||
// Specifically we wrap a std::string returning generator with a generator
|
||||
// that converts the strings using stoi, so the returned type is actually
|
||||
// an int.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns a line from a stream. You could have it e.g. read lines from
|
||||
// a file, but to avoid problems with paths in examples, we will use
|
||||
// a fixed stringstream.
|
||||
class LineGenerator : public Catch::Generators::IGenerator<std::string> {
|
||||
std::string m_line;
|
||||
std::stringstream m_stream;
|
||||
public:
|
||||
LineGenerator() {
|
||||
m_stream.str("1\n2\n3\n4\n");
|
||||
if (!next()) {
|
||||
Catch::Generators::Detail::throw_generator_exception("Couldn't read a single line");
|
||||
}
|
||||
}
|
||||
|
||||
std::string const& get() const override;
|
||||
|
||||
bool next() override {
|
||||
return !!std::getline(m_stream, m_line);
|
||||
}
|
||||
};
|
||||
|
||||
std::string const& LineGenerator::get() const {
|
||||
return m_line;
|
||||
}
|
||||
|
||||
// This helper function provides a nicer UX when instantiating the generator
|
||||
// Notice that it returns an instance of GeneratorWrapper<std::string>, which
|
||||
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
|
||||
Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
|
||||
return Catch::Generators::GeneratorWrapper<std::string>(
|
||||
new LineGenerator()
|
||||
);
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
|
||||
TEST_CASE("filter can convert types inside the generator expression", "[example][generator]") {
|
||||
auto num = GENERATE(map<int>([](std::string const& line) { return std::stoi(line); },
|
||||
lines("fake-file")));
|
||||
|
||||
REQUIRE(num > 0);
|
||||
}
|
||||
|
||||
// Compiling and running this file will result in 4 successful assertions
|
55
examples/302-Gen-Table.cpp
Normal file
55
examples/302-Gen-Table.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// 302-Gen-Table.cpp
|
||||
// Shows how to use table to run a test many times with different inputs. Lifted from examples on
|
||||
// issue #850.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <string>
|
||||
|
||||
struct TestSubject {
|
||||
// this is the method we are going to test. It returns the length of the
|
||||
// input string.
|
||||
size_t GetLength( const std::string& input ) const { return input.size(); }
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE("Table allows pre-computed test inputs and outputs", "[example][generator]") {
|
||||
using std::make_tuple;
|
||||
// do setup here as normal
|
||||
TestSubject subj;
|
||||
|
||||
SECTION("This section is run for each row in the table") {
|
||||
std::string test_input;
|
||||
size_t expected_output;
|
||||
std::tie( test_input, expected_output ) =
|
||||
GENERATE( table<std::string, size_t>(
|
||||
{ /* In this case one of the parameters to our test case is the
|
||||
* expected output, but this is not required. There could be
|
||||
* multiple expected values in the table, which can have any
|
||||
* (fixed) number of columns.
|
||||
*/
|
||||
make_tuple( "one", 3 ),
|
||||
make_tuple( "two", 3 ),
|
||||
make_tuple( "three", 5 ),
|
||||
make_tuple( "four", 4 ) } ) );
|
||||
|
||||
// run the test
|
||||
auto result = subj.GetLength(test_input);
|
||||
// capture the input data to go with the outputs.
|
||||
CAPTURE(test_input);
|
||||
// check it matches the pre-calculated data
|
||||
REQUIRE(result == expected_output);
|
||||
} // end section
|
||||
}
|
||||
|
||||
/* Possible simplifications where less legacy toolchain support is needed:
|
||||
*
|
||||
* - With libstdc++6 or newer, the make_tuple() calls can be ommitted
|
||||
* (technically C++17 but does not require -std in GCC/Clang). See
|
||||
* https://stackoverflow.com/questions/12436586/tuple-vector-and-initializer-list
|
||||
*
|
||||
* - In C++17 mode std::tie() and the preceding variable delcarations can be
|
||||
* replaced by structured bindings: auto [test_input, expected] = GENERATE(
|
||||
* table<std::string, size_t>({ ...
|
||||
*/
|
||||
// Compiling and running this file will result in 4 successful assertions
|
35
examples/310-Gen-VariablesInGenerators.cpp
Normal file
35
examples/310-Gen-VariablesInGenerators.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// 310-Gen-VariablesInGenerator.cpp
|
||||
// Shows how to use variables when creating generators.
|
||||
|
||||
// Note that using variables inside generators is dangerous and should
|
||||
// be done only if you know what you are doing, because the generators
|
||||
// _WILL_ outlive the variables -- thus they should be either captured
|
||||
// by value directly, or copied by the generators during construction.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||
#include <catch2/generators/catch_generators_random.hpp>
|
||||
|
||||
TEST_CASE("Generate random doubles across different ranges",
|
||||
"[generator][example][advanced]") {
|
||||
// Workaround for old libstdc++
|
||||
using record = std::tuple<double, double>;
|
||||
// Set up 3 ranges to generate numbers from
|
||||
auto r = GENERATE(table<double, double>({
|
||||
record{3, 4},
|
||||
record{-4, -3},
|
||||
record{10, 1000}
|
||||
}));
|
||||
|
||||
// This will not compile (intentionally), because it accesses a variable
|
||||
// auto number = GENERATE(take(50, random(std::get<0>(r), std::get<1>(r))));
|
||||
|
||||
// GENERATE_COPY copies all variables mentioned inside the expression
|
||||
// thus this will work.
|
||||
auto number = GENERATE_COPY(take(50, random(std::get<0>(r), std::get<1>(r))));
|
||||
|
||||
REQUIRE(std::abs(number) > 0);
|
||||
}
|
||||
|
||||
// Compiling and running this file will result in 150 successful assertions
|
||||
|
43
examples/311-Gen-CustomCapture.cpp
Normal file
43
examples/311-Gen-CustomCapture.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// 311-Gen-CustomCapture.cpp
|
||||
// Shows how to provide custom capture list to the generator expression
|
||||
|
||||
// Note that using variables inside generators is dangerous and should
|
||||
// be done only if you know what you are doing, because the generators
|
||||
// _WILL_ outlive the variables. Also, even if you know what you are
|
||||
// doing, you should probably use GENERATE_COPY or GENERATE_REF macros
|
||||
// instead. However, if your use case requires having a
|
||||
// per-variable custom capture list, this example shows how to achieve
|
||||
// that.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||
#include <catch2/generators/catch_generators_random.hpp>
|
||||
|
||||
TEST_CASE("Generate random doubles across different ranges",
|
||||
"[generator][example][advanced]") {
|
||||
// Workaround for old libstdc++
|
||||
using record = std::tuple<double, double>;
|
||||
// Set up 3 ranges to generate numbers from
|
||||
auto r1 = GENERATE(table<double, double>({
|
||||
record{3, 4},
|
||||
record{-4, -3},
|
||||
record{10, 1000}
|
||||
}));
|
||||
|
||||
auto r2(r1);
|
||||
|
||||
// This will take r1 by reference and r2 by value.
|
||||
// Note that there are no advantages for doing so in this example,
|
||||
// it is done only for expository purposes.
|
||||
auto number = Catch::Generators::generate( "custom capture generator", CATCH_INTERNAL_LINEINFO,
|
||||
[&r1, r2]{
|
||||
using namespace Catch::Generators;
|
||||
return makeGenerators(take(50, random(std::get<0>(r1), std::get<1>(r2))));
|
||||
}
|
||||
);
|
||||
|
||||
REQUIRE(std::abs(number) > 0);
|
||||
}
|
||||
|
||||
// Compiling and running this file will result in 150 successful assertions
|
||||
|
63
examples/CMakeLists.txt
Normal file
63
examples/CMakeLists.txt
Normal file
@ -0,0 +1,63 @@
|
||||
cmake_minimum_required( VERSION 3.5 )
|
||||
|
||||
project( Catch2Examples LANGUAGES CXX )
|
||||
|
||||
message( STATUS "Examples included" )
|
||||
|
||||
|
||||
# Some one-offs first:
|
||||
# 1) Tests and main in one file
|
||||
add_executable( 010-TestCase
|
||||
010-TestCase.cpp
|
||||
)
|
||||
|
||||
# 2) Tests and main across two files
|
||||
add_executable( 020-MultiFile
|
||||
020-TestCase-1.cpp
|
||||
020-TestCase-2.cpp
|
||||
)
|
||||
|
||||
add_executable(231-Cfg_OutputStreams
|
||||
231-Cfg-OutputStreams.cpp
|
||||
)
|
||||
target_link_libraries(231-Cfg_OutputStreams Catch2_buildall_interface)
|
||||
target_compile_definitions(231-Cfg_OutputStreams PUBLIC CATCH_CONFIG_NOSTDOUT)
|
||||
|
||||
# These examples use the standard separate compilation
|
||||
set( SOURCES_IDIOMATIC_EXAMPLES
|
||||
030-Asn-Require-Check.cpp
|
||||
100-Fix-Section.cpp
|
||||
110-Fix-ClassFixture.cpp
|
||||
120-Bdd-ScenarioGivenWhenThen.cpp
|
||||
210-Evt-EventListeners.cpp
|
||||
300-Gen-OwnGenerator.cpp
|
||||
301-Gen-MapTypeConversion.cpp
|
||||
302-Gen-Table.cpp
|
||||
310-Gen-VariablesInGenerators.cpp
|
||||
311-Gen-CustomCapture.cpp
|
||||
)
|
||||
|
||||
string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" )
|
||||
set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} )
|
||||
|
||||
|
||||
foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} )
|
||||
add_executable( ${name}
|
||||
${EXAMPLES_DIR}/${name}.cpp )
|
||||
endforeach()
|
||||
|
||||
set(ALL_EXAMPLE_TARGETS
|
||||
${TARGETS_IDIOMATIC_EXAMPLES}
|
||||
010-TestCase
|
||||
020-MultiFile
|
||||
)
|
||||
|
||||
foreach( name ${ALL_EXAMPLE_TARGETS} )
|
||||
target_link_libraries( ${name} Catch2 Catch2WithMain )
|
||||
set_property(TARGET ${name} PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET ${name} PROPERTY CXX_EXTENSIONS OFF)
|
||||
endforeach()
|
||||
|
||||
|
||||
list(APPEND CATCH_WARNING_TARGETS ${ALL_EXAMPLE_TARGETS})
|
||||
set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
|
220
extras/Catch.cmake
Normal file
220
extras/Catch.cmake
Normal file
@ -0,0 +1,220 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
Catch
|
||||
-----
|
||||
|
||||
This module defines a function to help use the Catch test framework.
|
||||
|
||||
The :command:`catch_discover_tests` discovers tests by asking the compiled test
|
||||
executable to enumerate its tests. This does not require CMake to be re-run
|
||||
when tests change. However, it may not work in a cross-compiling environment,
|
||||
and setting test properties is less convenient.
|
||||
|
||||
This command is intended to replace use of :command:`add_test` to register
|
||||
tests, and will create a separate CTest test for each Catch test case. Note
|
||||
that this is in some cases less efficient, as common set-up and tear-down logic
|
||||
cannot be shared by multiple test cases executing in the same instance.
|
||||
However, it provides more fine-grained pass/fail information to CTest, which is
|
||||
usually considered as more beneficial. By default, the CTest test name is the
|
||||
same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
|
||||
|
||||
.. command:: catch_discover_tests
|
||||
|
||||
Automatically add tests with CTest by querying the compiled test executable
|
||||
for available tests::
|
||||
|
||||
catch_discover_tests(target
|
||||
[TEST_SPEC arg1...]
|
||||
[EXTRA_ARGS arg1...]
|
||||
[WORKING_DIRECTORY dir]
|
||||
[TEST_PREFIX prefix]
|
||||
[TEST_SUFFIX suffix]
|
||||
[PROPERTIES name1 value1...]
|
||||
[TEST_LIST var]
|
||||
[REPORTER reporter]
|
||||
[OUTPUT_DIR dir]
|
||||
[OUTPUT_PREFIX prefix}
|
||||
[OUTPUT_SUFFIX suffix]
|
||||
)
|
||||
|
||||
``catch_discover_tests`` sets up a post-build command on the test executable
|
||||
that generates the list of tests by parsing the output from running the test
|
||||
with the ``--list-test-names-only`` argument. This ensures that the full
|
||||
list of tests is obtained. Since test discovery occurs at build time, it is
|
||||
not necessary to re-run CMake when the list of tests changes.
|
||||
However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set
|
||||
in order to function in a cross-compiling environment.
|
||||
|
||||
Additionally, setting properties on tests is somewhat less convenient, since
|
||||
the tests are not available at CMake time. Additional test properties may be
|
||||
assigned to the set of tests as a whole using the ``PROPERTIES`` option. If
|
||||
more fine-grained test control is needed, custom content may be provided
|
||||
through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES`
|
||||
directory property. The set of discovered tests is made accessible to such a
|
||||
script via the ``<target>_TESTS`` variable.
|
||||
|
||||
The options are:
|
||||
|
||||
``target``
|
||||
Specifies the Catch executable, which must be a known CMake executable
|
||||
target. CMake will substitute the location of the built executable when
|
||||
running the test.
|
||||
|
||||
``TEST_SPEC arg1...``
|
||||
Specifies test cases, wildcarded test cases, tags and tag expressions to
|
||||
pass to the Catch executable with the ``--list-test-names-only`` argument.
|
||||
|
||||
``EXTRA_ARGS arg1...``
|
||||
Any extra arguments to pass on the command line to each test case.
|
||||
|
||||
``WORKING_DIRECTORY dir``
|
||||
Specifies the directory in which to run the discovered test cases. If this
|
||||
option is not provided, the current binary directory is used.
|
||||
|
||||
``TEST_PREFIX prefix``
|
||||
Specifies a ``prefix`` to be prepended to the name of each discovered test
|
||||
case. This can be useful when the same test executable is being used in
|
||||
multiple calls to ``catch_discover_tests()`` but with different
|
||||
``TEST_SPEC`` or ``EXTRA_ARGS``.
|
||||
|
||||
``TEST_SUFFIX suffix``
|
||||
Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
|
||||
every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
|
||||
be specified.
|
||||
|
||||
``PROPERTIES name1 value1...``
|
||||
Specifies additional properties to be set on all tests discovered by this
|
||||
invocation of ``catch_discover_tests``.
|
||||
|
||||
``TEST_LIST var``
|
||||
Make the list of tests available in the variable ``var``, rather than the
|
||||
default ``<target>_TESTS``. This can be useful when the same test
|
||||
executable is being used in multiple calls to ``catch_discover_tests()``.
|
||||
Note that this variable is only available in CTest.
|
||||
|
||||
``REPORTER reporter``
|
||||
Use the specified reporter when running the test case. The reporter will
|
||||
be passed to the Catch executable as ``--reporter reporter``.
|
||||
|
||||
``OUTPUT_DIR dir``
|
||||
If specified, the parameter is passed along as
|
||||
``--out dir/<test_name>`` to Catch executable. The actual file name is the
|
||||
same as the test name. This should be used instead of
|
||||
``EXTRA_ARGS --out foo`` to avoid race conditions writing the result output
|
||||
when using parallel test execution.
|
||||
|
||||
``OUTPUT_PREFIX prefix``
|
||||
May be used in conjunction with ``OUTPUT_DIR``.
|
||||
If specified, ``prefix`` is added to each output file name, like so
|
||||
``--out dir/prefix<test_name>``.
|
||||
|
||||
``OUTPUT_SUFFIX suffix``
|
||||
May be used in conjunction with ``OUTPUT_DIR``.
|
||||
If specified, ``suffix`` is added to each output file name, like so
|
||||
``--out dir/<test_name>suffix``. This can be used to add a file extension to
|
||||
the output e.g. ".xml".
|
||||
|
||||
``DL_PATHS path...``
|
||||
Specifies paths that need to be set for the dynamic linker to find shared
|
||||
libraries/DLLs when running the test executable (PATH/LD_LIBRARY_PATH respectively).
|
||||
These paths will both be set when retrieving the list of test cases from the
|
||||
test executable and when the tests are executed themselves. This requires
|
||||
cmake/ctest >= 3.22.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
function(catch_discover_tests TARGET)
|
||||
cmake_parse_arguments(
|
||||
""
|
||||
""
|
||||
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;REPORTER;OUTPUT_DIR;OUTPUT_PREFIX;OUTPUT_SUFFIX"
|
||||
"TEST_SPEC;EXTRA_ARGS;PROPERTIES;DL_PATHS"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
if(NOT _WORKING_DIRECTORY)
|
||||
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
if(NOT _TEST_LIST)
|
||||
set(_TEST_LIST ${TARGET}_TESTS)
|
||||
endif()
|
||||
|
||||
if (_DL_PATHS)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.22.0")
|
||||
message(FATAL_ERROR "The DL_PATHS option requires at least cmake 3.22")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
## Generate a unique name based on the extra arguments
|
||||
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS} ${_REPORTER} ${_OUTPUT_DIR} ${_OUTPUT_PREFIX} ${_OUTPUT_SUFFIX}")
|
||||
string(SUBSTRING ${args_hash} 0 7 args_hash)
|
||||
|
||||
# Define rule to generate test list for aforementioned test executable
|
||||
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
|
||||
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
|
||||
get_property(crosscompiling_emulator
|
||||
TARGET ${TARGET}
|
||||
PROPERTY CROSSCOMPILING_EMULATOR
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET} POST_BUILD
|
||||
BYPRODUCTS "${ctest_tests_file}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "TEST_TARGET=${TARGET}"
|
||||
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
|
||||
-D "TEST_EXECUTOR=${crosscompiling_emulator}"
|
||||
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
|
||||
-D "TEST_SPEC=${_TEST_SPEC}"
|
||||
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
|
||||
-D "TEST_PROPERTIES=${_PROPERTIES}"
|
||||
-D "TEST_PREFIX=${_TEST_PREFIX}"
|
||||
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
|
||||
-D "TEST_LIST=${_TEST_LIST}"
|
||||
-D "TEST_REPORTER=${_REPORTER}"
|
||||
-D "TEST_OUTPUT_DIR=${_OUTPUT_DIR}"
|
||||
-D "TEST_OUTPUT_PREFIX=${_OUTPUT_PREFIX}"
|
||||
-D "TEST_OUTPUT_SUFFIX=${_OUTPUT_SUFFIX}"
|
||||
-D "TEST_DL_PATHS=${_DL_PATHS}"
|
||||
-D "CTEST_FILE=${ctest_tests_file}"
|
||||
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
file(WRITE "${ctest_include_file}"
|
||||
"if(EXISTS \"${ctest_tests_file}\")\n"
|
||||
" include(\"${ctest_tests_file}\")\n"
|
||||
"else()\n"
|
||||
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n"
|
||||
"endif()\n"
|
||||
)
|
||||
|
||||
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
||||
# Add discovered tests to directory TEST_INCLUDE_FILES
|
||||
set_property(DIRECTORY
|
||||
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
|
||||
)
|
||||
else()
|
||||
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
|
||||
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
|
||||
if (NOT ${test_include_file_set})
|
||||
set_property(DIRECTORY
|
||||
PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}"
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Cannot set more than one TEST_INCLUDE_FILE"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
###############################################################################
|
||||
|
||||
set(_CATCH_DISCOVER_TESTS_SCRIPT
|
||||
${CMAKE_CURRENT_LIST_DIR}/CatchAddTests.cmake
|
||||
CACHE INTERNAL "Catch2 full path to CatchAddTests.cmake helper file"
|
||||
)
|
154
extras/CatchAddTests.cmake
Normal file
154
extras/CatchAddTests.cmake
Normal file
@ -0,0 +1,154 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
set(prefix "${TEST_PREFIX}")
|
||||
set(suffix "${TEST_SUFFIX}")
|
||||
set(spec ${TEST_SPEC})
|
||||
set(extra_args ${TEST_EXTRA_ARGS})
|
||||
set(properties ${TEST_PROPERTIES})
|
||||
set(reporter ${TEST_REPORTER})
|
||||
set(output_dir ${TEST_OUTPUT_DIR})
|
||||
set(output_prefix ${TEST_OUTPUT_PREFIX})
|
||||
set(output_suffix ${TEST_OUTPUT_SUFFIX})
|
||||
set(dl_paths ${TEST_DL_PATHS})
|
||||
set(script)
|
||||
set(suite)
|
||||
set(tests)
|
||||
|
||||
if(WIN32)
|
||||
set(dl_paths_variable_name PATH)
|
||||
else()
|
||||
set(dl_paths_variable_name LD_LIBRARY_PATH)
|
||||
endif()
|
||||
|
||||
function(add_command NAME)
|
||||
set(_args "")
|
||||
# use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments
|
||||
math(EXPR _last_arg ${ARGC}-1)
|
||||
foreach(_n RANGE 1 ${_last_arg})
|
||||
set(_arg "${ARGV${_n}}")
|
||||
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
|
||||
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
|
||||
else()
|
||||
set(_args "${_args} ${_arg}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Run test executable to get list of available tests
|
||||
if(NOT EXISTS "${TEST_EXECUTABLE}")
|
||||
message(FATAL_ERROR
|
||||
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(dl_paths)
|
||||
cmake_path(CONVERT "${dl_paths}" TO_NATIVE_PATH_LIST paths)
|
||||
set(ENV{${dl_paths_variable_name}} "${paths}")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet
|
||||
OUTPUT_VARIABLE output
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||
)
|
||||
if(NOT ${result} EQUAL 0)
|
||||
message(FATAL_ERROR
|
||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
||||
" Result: ${result}\n"
|
||||
" Output: ${output}\n"
|
||||
)
|
||||
endif()
|
||||
|
||||
string(REPLACE "\n" ";" output "${output}")
|
||||
|
||||
# Run test executable to get list of available reporters
|
||||
execute_process(
|
||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-reporters
|
||||
OUTPUT_VARIABLE reporters_output
|
||||
RESULT_VARIABLE reporters_result
|
||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||
)
|
||||
if(NOT ${reporters_result} EQUAL 0)
|
||||
message(FATAL_ERROR
|
||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
||||
" Result: ${reporters_result}\n"
|
||||
" Output: ${reporters_output}\n"
|
||||
)
|
||||
endif()
|
||||
string(FIND "${reporters_output}" "${reporter}" reporter_is_valid)
|
||||
if(reporter AND ${reporter_is_valid} EQUAL -1)
|
||||
message(FATAL_ERROR
|
||||
"\"${reporter}\" is not a valid reporter!\n"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Prepare reporter
|
||||
if(reporter)
|
||||
set(reporter_arg "--reporter ${reporter}")
|
||||
endif()
|
||||
|
||||
# Prepare output dir
|
||||
if(output_dir AND NOT IS_ABSOLUTE ${output_dir})
|
||||
set(output_dir "${TEST_WORKING_DIR}/${output_dir}")
|
||||
if(NOT EXISTS ${output_dir})
|
||||
file(MAKE_DIRECTORY ${output_dir})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(dl_paths)
|
||||
foreach(path ${dl_paths})
|
||||
cmake_path(NATIVE_PATH path native_path)
|
||||
list(APPEND environment_modifications "${dl_paths_variable_name}=path_list_prepend:${native_path}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Parse output
|
||||
foreach(line ${output})
|
||||
set(test ${line})
|
||||
# Escape characters in test case names that would be parsed by Catch2
|
||||
set(test_name ${test})
|
||||
foreach(char , [ ])
|
||||
string(REPLACE ${char} "\\${char}" test_name ${test_name})
|
||||
endforeach(char)
|
||||
# ...add output dir
|
||||
if(output_dir)
|
||||
string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name})
|
||||
set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}")
|
||||
endif()
|
||||
|
||||
# ...and add to script
|
||||
add_command(add_test
|
||||
"${prefix}${test}${suffix}"
|
||||
${TEST_EXECUTOR}
|
||||
"${TEST_EXECUTABLE}"
|
||||
"${test_name}"
|
||||
${extra_args}
|
||||
"${reporter_arg}"
|
||||
"${output_dir_arg}"
|
||||
)
|
||||
add_command(set_tests_properties
|
||||
"${prefix}${test}${suffix}"
|
||||
PROPERTIES
|
||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||
${properties}
|
||||
)
|
||||
|
||||
if(environment_modifications)
|
||||
add_command(set_tests_properties
|
||||
"${prefix}${test}${suffix}"
|
||||
PROPERTIES
|
||||
ENVIRONMENT_MODIFICATION "${environment_modifications}")
|
||||
endif()
|
||||
|
||||
list(APPEND tests "${prefix}${test}${suffix}")
|
||||
endforeach()
|
||||
|
||||
# Create a list of all discovered tests, which users may use to e.g. set
|
||||
# properties on the tests
|
||||
add_command(set ${TEST_LIST} ${tests})
|
||||
|
||||
# Write CTest script
|
||||
file(WRITE "${CTEST_FILE}" "${script}")
|
66
extras/CatchShardTests.cmake
Normal file
66
extras/CatchShardTests.cmake
Normal file
@ -0,0 +1,66 @@
|
||||
|
||||
# Copyright Catch2 Authors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
# Supported optional args:
|
||||
# * SHARD_COUNT - number of shards to split target's tests into
|
||||
# * REPORTER - reporter spec to use for tests
|
||||
# * TEST_SPEC - test spec used for filtering tests
|
||||
function(catch_add_sharded_tests TARGET)
|
||||
if (${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
||||
message(FATAL_ERROR "add_sharded_catch_tests only supports CMake versions 3.10.0 and up")
|
||||
endif()
|
||||
|
||||
cmake_parse_arguments(
|
||||
""
|
||||
""
|
||||
"SHARD_COUNT;REPORTER;TEST_SPEC"
|
||||
""
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
if (NOT DEFINED _SHARD_COUNT)
|
||||
set(_SHARD_COUNT 2)
|
||||
endif()
|
||||
|
||||
# Generate a unique name based on the extra arguments
|
||||
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS} ${_REPORTER} ${_OUTPUT_DIR} ${_OUTPUT_PREFIX} ${_OUTPUT_SUFFIX} ${_SHARD_COUNT}")
|
||||
string(SUBSTRING ${args_hash} 0 7 args_hash)
|
||||
|
||||
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-sharded-tests-include-${args_hash}.cmake")
|
||||
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-sharded-tests-impl-${args_hash}.cmake")
|
||||
|
||||
file(WRITE "${ctest_include_file}"
|
||||
"if(EXISTS \"${ctest_tests_file}\")\n"
|
||||
" include(\"${ctest_tests_file}\")\n"
|
||||
"else()\n"
|
||||
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n"
|
||||
"endif()\n"
|
||||
)
|
||||
|
||||
set_property(DIRECTORY
|
||||
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
|
||||
)
|
||||
|
||||
set(shard_impl_script_file "${CMAKE_CURRENT_LIST_DIR}/CatchShardTestsImpl.cmake")
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${TARGET} POST_BUILD
|
||||
BYPRODUCTS "${ctest_tests_file}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "TARGET_NAME=${TARGET}"
|
||||
-D "TEST_BINARY=$<TARGET_FILE:${TARGET}>"
|
||||
-D "CTEST_FILE=${ctest_tests_file}"
|
||||
-D "SHARD_COUNT=${_SHARD_COUNT}"
|
||||
-D "REPORTER_SPEC=${_REPORTER}"
|
||||
-D "TEST_SPEC=${_TEST_SPEC}"
|
||||
-P "${shard_impl_script_file}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
|
||||
endfunction()
|
52
extras/CatchShardTestsImpl.cmake
Normal file
52
extras/CatchShardTestsImpl.cmake
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
# Copyright Catch2 Authors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
# Indirection for CatchShardTests that allows us to delay the script
|
||||
# file generation until build time.
|
||||
|
||||
# Expected args:
|
||||
# * TEST_BINARY - full path to the test binary to run sharded
|
||||
# * CTEST_FILE - full path to ctest script file to write to
|
||||
# * TARGET_NAME - name of the target to shard (used for test names)
|
||||
# * SHARD_COUNT - number of shards to split the binary into
|
||||
# Optional args:
|
||||
# * REPORTER_SPEC - reporter specs to be passed down to the binary
|
||||
# * TEST_SPEC - test spec to pass down to the test binary
|
||||
|
||||
if(NOT EXISTS "${TEST_BINARY}")
|
||||
message(FATAL_ERROR
|
||||
"Specified test binary '${TEST_BINARY}' does not exist"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(other_args "")
|
||||
if (TEST_SPEC)
|
||||
set(other_args "${other_args} ${TEST_SPEC}")
|
||||
endif()
|
||||
if (REPORTER_SPEC)
|
||||
set(other_args "${other_args} --reporter ${REPORTER_SPEC}")
|
||||
endif()
|
||||
|
||||
# foreach RANGE in cmake is inclusive of the end, so we have to adjust it
|
||||
math(EXPR adjusted_shard_count "${SHARD_COUNT} - 1")
|
||||
|
||||
file(WRITE "${CTEST_FILE}"
|
||||
"string(RANDOM LENGTH 8 ALPHABET \"0123456789abcdef\" rng_seed)\n"
|
||||
"\n"
|
||||
"foreach(shard_idx RANGE ${adjusted_shard_count})\n"
|
||||
" add_test(${TARGET_NAME}-shard-" [[${shard_idx}]] "/${adjusted_shard_count}\n"
|
||||
" ${TEST_BINARY}"
|
||||
" --shard-index " [[${shard_idx}]]
|
||||
" --shard-count ${SHARD_COUNT}"
|
||||
" --rng-seed " [[0x${rng_seed}]]
|
||||
" --order rand"
|
||||
"${other_args}"
|
||||
"\n"
|
||||
" )\n"
|
||||
"endforeach()\n"
|
||||
)
|
@ -1,9 +1,11 @@
|
||||
#==================================================================================================#
|
||||
# supported macros #
|
||||
# - TEST_CASE, #
|
||||
# - TEMPLATE_TEST_CASE #
|
||||
# - SCENARIO, #
|
||||
# - TEST_CASE_METHOD, #
|
||||
# - CATCH_TEST_CASE, #
|
||||
# - CATCH_TEMPLATE_TEST_CASE #
|
||||
# - CATCH_SCENARIO, #
|
||||
# - CATCH_TEST_CASE_METHOD. #
|
||||
# #
|
||||
@ -36,17 +38,35 @@
|
||||
# -- adds fixture class name to the test name #
|
||||
# PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME (Default ON) #
|
||||
# -- adds cmake target name to the test name #
|
||||
# PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS (Default OFF) #
|
||||
# -- causes CMake to rerun when file with tests changes so that new tests will be discovered #
|
||||
# #
|
||||
# One can also set (locally) the optional variable OptionalCatchTestLauncher to precise the way #
|
||||
# a test should be run. For instance to use test MPI, one can write #
|
||||
# set(OptionalCatchTestLauncher ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${NUMPROC}) #
|
||||
# just before calling this ParseAndAddCatchTests function #
|
||||
# #
|
||||
# The AdditionalCatchParameters optional variable can be used to pass extra argument to the test #
|
||||
# command. For example, to include successful tests in the output, one can write #
|
||||
# set(AdditionalCatchParameters --success) #
|
||||
# #
|
||||
# After the script, the ParseAndAddCatchTests_TESTS property for the target, and for each source #
|
||||
# file in the target is set, and contains the list of the tests extracted from that target, or #
|
||||
# from that file. This is useful, for example to add further labels or properties to the tests. #
|
||||
# #
|
||||
#==================================================================================================#
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
if (CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
|
||||
message(FATAL_ERROR "ParseAndAddCatchTests requires CMake 2.8.8 or newer")
|
||||
endif()
|
||||
|
||||
option(PARSE_CATCH_TESTS_VERBOSE "Print Catch to CTest parser debug messages" OFF)
|
||||
option(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS "Exclude tests with [!hide], [.] or [.foo] tags" OFF)
|
||||
option(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME "Add fixture class name to the test name" ON)
|
||||
option(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME "Add target name to the test name" ON)
|
||||
option(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS "Add test file to CMAKE_CONFIGURE_DEPENDS property" OFF)
|
||||
|
||||
function(PrintDebugMessage)
|
||||
function(ParseAndAddCatchTests_PrintDebugMessage)
|
||||
if(PARSE_CATCH_TESTS_VERBOSE)
|
||||
message(STATUS "ParseAndAddCatchTests: ${ARGV}")
|
||||
endif()
|
||||
@ -57,7 +77,7 @@ endfunction()
|
||||
# - full line comments (i.e. // ... )
|
||||
# contents have been read into '${CppCode}'.
|
||||
# !keep partial line comments
|
||||
function(RemoveComments CppCode)
|
||||
function(ParseAndAddCatchTests_RemoveComments CppCode)
|
||||
string(ASCII 2 CMakeBeginBlockComment)
|
||||
string(ASCII 3 CMakeEndBlockComment)
|
||||
string(REGEX REPLACE "/\\*" "${CMakeBeginBlockComment}" ${CppCode} "${${CppCode}}")
|
||||
@ -69,30 +89,53 @@ function(RemoveComments CppCode)
|
||||
endfunction()
|
||||
|
||||
# Worker function
|
||||
function(ParseFile SourceFile TestTarget)
|
||||
function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
|
||||
# If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
|
||||
if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
|
||||
return()
|
||||
endif()
|
||||
# According to CMake docs EXISTS behavior is well-defined only for full paths.
|
||||
get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
|
||||
if(NOT EXISTS ${SourceFile})
|
||||
message(WARNING "Cannot find source file: ${SourceFile}")
|
||||
return()
|
||||
endif()
|
||||
PrintDebugMessage("parsing ${SourceFile}")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
|
||||
file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
|
||||
|
||||
# Remove block and fullline comments
|
||||
RemoveComments(Contents)
|
||||
ParseAndAddCatchTests_RemoveComments(Contents)
|
||||
|
||||
# Find definition of test names
|
||||
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^\)]+\\)+[ \t\n]*{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
|
||||
# https://regex101.com/r/JygOND/1
|
||||
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
|
||||
|
||||
if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
|
||||
set_property(
|
||||
DIRECTORY
|
||||
APPEND
|
||||
PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
|
||||
)
|
||||
endif()
|
||||
|
||||
# check CMP0110 policy for new add_test() behavior
|
||||
if(POLICY CMP0110)
|
||||
cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
|
||||
else()
|
||||
# just to be thorough explicitly set the variable
|
||||
set(_cmp0110_value)
|
||||
endif()
|
||||
|
||||
foreach(TestName ${Tests})
|
||||
# Strip newlines
|
||||
string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
|
||||
|
||||
# Get test type and fixture if applicable
|
||||
string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
|
||||
string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
|
||||
string(REPLACE "${TestType}(" "" TestFixture "${TestTypeAndFixture}")
|
||||
string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
|
||||
string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
|
||||
string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
|
||||
|
||||
# Get string parts of test definition
|
||||
string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
|
||||
@ -112,7 +155,7 @@ function(ParseFile SourceFile TestTarget)
|
||||
if("${TestType}" STREQUAL "SCENARIO")
|
||||
set(Name "Scenario: ${Name}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND TestFixture)
|
||||
if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture )
|
||||
set(CTestName "${TestFixture}:${Name}")
|
||||
else()
|
||||
set(CTestName "${Name}")
|
||||
@ -131,11 +174,13 @@ function(ParseFile SourceFile TestTarget)
|
||||
endif()
|
||||
string(REPLACE "]" ";" Tags "${Tags}")
|
||||
string(REPLACE "[" "" Tags "${Tags}")
|
||||
else()
|
||||
# unset tags variable from previous loop
|
||||
unset(Tags)
|
||||
endif()
|
||||
|
||||
list(APPEND Labels ${Tags})
|
||||
|
||||
list(FIND Labels "!hide" IndexOfHideLabel)
|
||||
set(HiddenTagFound OFF)
|
||||
foreach(label ${Labels})
|
||||
string(REGEX MATCH "^!hide|^\\." result ${label})
|
||||
@ -144,30 +189,64 @@ function(ParseFile SourceFile TestTarget)
|
||||
break()
|
||||
endif(result)
|
||||
endforeach(label)
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound})
|
||||
PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
|
||||
else()
|
||||
PrintDebugMessage("Adding test \"${CTestName}\"")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"")
|
||||
if(Labels)
|
||||
PrintDebugMessage("Setting labels to ${Labels}")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}")
|
||||
endif()
|
||||
|
||||
# Escape commas in the test spec
|
||||
string(REPLACE "," "\\," Name ${Name})
|
||||
|
||||
# Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary,
|
||||
# only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1
|
||||
# And properly introduced in 3.19 with the CMP0110 policy
|
||||
if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround")
|
||||
else()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround")
|
||||
set(CTestName "\"${CTestName}\"")
|
||||
endif()
|
||||
|
||||
# Handle template test cases
|
||||
if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*")
|
||||
set(Name "${Name} - *")
|
||||
endif()
|
||||
|
||||
# Add the test and set its properties
|
||||
add_test(NAME "\"${CTestName}\"" COMMAND ${TestTarget} ${Name} ${AdditionalCatchParameters})
|
||||
set_tests_properties("\"${CTestName}\"" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
|
||||
LABELS "${Labels}")
|
||||
add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
|
||||
# Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property")
|
||||
set_tests_properties("${CTestName}" PROPERTIES DISABLED ON)
|
||||
else()
|
||||
set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
|
||||
LABELS "${Labels}")
|
||||
endif()
|
||||
set_property(
|
||||
TARGET ${TestTarget}
|
||||
APPEND
|
||||
PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
|
||||
set_property(
|
||||
SOURCE ${SourceFile}
|
||||
APPEND
|
||||
PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
|
||||
endif()
|
||||
|
||||
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# entry point
|
||||
function(ParseAndAddCatchTests TestTarget)
|
||||
PrintDebugMessage("Started parsing ${TestTarget}")
|
||||
message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
|
||||
get_target_property(SourceFiles ${TestTarget} SOURCES)
|
||||
PrintDebugMessage("Found the following sources: ${SourceFiles}")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
|
||||
foreach(SourceFile ${SourceFiles})
|
||||
ParseFile(${SourceFile} ${TestTarget})
|
||||
ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget})
|
||||
endforeach()
|
||||
PrintDebugMessage("Finished parsing ${TestTarget}")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}")
|
||||
endfunction()
|
10360
extras/catch_amalgamated.cpp
Normal file
10360
extras/catch_amalgamated.cpp
Normal file
File diff suppressed because it is too large
Load Diff
12233
extras/catch_amalgamated.hpp
Normal file
12233
extras/catch_amalgamated.hpp
Normal file
File diff suppressed because it is too large
Load Diff
16
extras/gdbinit
Normal file
16
extras/gdbinit
Normal file
@ -0,0 +1,16 @@
|
||||
#
|
||||
# This file provides a way to skip stepping into Catch code when debugging with gdb.
|
||||
#
|
||||
# With the gdb "skip" command you can tell gdb to skip files or functions during debugging.
|
||||
# see https://xaizek.github.io/2016-05-26/skipping-standard-library-in-gdb/ for an example
|
||||
#
|
||||
# Basically the following line tells gdb to skip all functions containing the
|
||||
# regexp "Catch", which matches the complete Catch namespace.
|
||||
# If you want to skip just some parts of the Catch code you can modify the
|
||||
# regexp accordingly.
|
||||
#
|
||||
# If you want to permanently skip stepping into Catch code copy the following
|
||||
# line into your ~/.gdbinit file
|
||||
#
|
||||
|
||||
skip -rfu Catch
|
16
extras/lldbinit
Normal file
16
extras/lldbinit
Normal file
@ -0,0 +1,16 @@
|
||||
#
|
||||
# This file provides a way to skip stepping into Catch code when debugging with lldb.
|
||||
#
|
||||
# With the setting "target.process.thread.step-avoid-regexp" you can tell lldb
|
||||
# to skip functions matching the regexp
|
||||
#
|
||||
# Basically the following line tells lldb to skip all functions containing the
|
||||
# regexp "Catch", which matches the complete Catch namespace.
|
||||
# If you want to skip just some parts of the Catch code you can modify the
|
||||
# regexp accordingly.
|
||||
#
|
||||
# If you want to permanently skip stepping into Catch code copy the following
|
||||
# line into your ~/.lldbinit file
|
||||
#
|
||||
|
||||
settings set target.process.thread.step-avoid-regexp Catch
|
20
fuzzing/CMakeLists.txt
Normal file
20
fuzzing/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# License: Boost 1.0
|
||||
# By Paul Dreik 2020
|
||||
|
||||
# add a library that brings in the main() function from libfuzzer
|
||||
# and has all the dependencies, so the individual fuzzers can be
|
||||
# added one line each.
|
||||
add_library(fuzzhelper NullOStream.h NullOStream.cpp)
|
||||
target_link_libraries(fuzzhelper PUBLIC Catch2::Catch2)
|
||||
|
||||
# use C++17 so we can get string_view
|
||||
target_compile_features(fuzzhelper PUBLIC cxx_std_17)
|
||||
|
||||
# This should be possible to set from the outside to be oss-fuzz compatible,
|
||||
# fix later. For now, target libFuzzer only.
|
||||
target_link_options(fuzzhelper PUBLIC "-fsanitize=fuzzer")
|
||||
|
||||
foreach(fuzzer TestSpecParser XmlWriter textflow)
|
||||
add_executable(fuzz_${fuzzer} fuzz_${fuzzer}.cpp)
|
||||
target_link_libraries(fuzz_${fuzzer} PRIVATE fuzzhelper)
|
||||
endforeach()
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user