-
Notifications
You must be signed in to change notification settings - Fork 1
/
temper.h
1599 lines (1273 loc) · 80.9 KB
/
temper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Temper
v2.0.1
Distributed under MIT License:
Copyright (c) 2021:
Dan Moody (daniel.guy.moody@gmail.com)
Mike Young (mikedotcoder@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
CONTENTS:
1. INTRO
2. INSTALLATION
3. QUICK START GUIDE
4. COMMAND LINE ARGS
5. CONTRIBUTING
6. CREDITS
7. CHANGELOG
1. INTRO
The new and improved C99, single-header-only, unit testing framework.
Distributed under the MIT license. See LICENSE file for details.
Features:
- Automatic test registration at compile time, simply write your test and it will get called for you.
- Parametric tests.
- Early exits for tests and a bunch of new condition macros.
- Handling errors from your program's log output (requires a bit of extra work on your part).
- Low friction, easily overridable functions to help hook Temper into your codebase.
- Support for Clang, GCC, and MSVC across Windows, Mac OS, and Linux on x64 ISAs (support for ARM in progress).
It's not a new feature but worth stressing. It's still just the one header file. Drop it into your project, tell it to run all tests somewhere in code and you're good to go! And once again; it's all written in C99 compliant code.
2. INSTALLATION
Download the latest release from the GitHub repository's release tab (https://github.com/dangmoody/Tantrum/releases/latest) and include `temper.h`.
3. QUICK START GUIDE
#define TEMPER_IMPLEMENTATION
#include <temper.h>
// write some tests
int main( int argc, char** argv )
{
TEMPER_RUN( argc, argv ); // Runs all your tests - parse 0 and NULL as parameters if you don't use start Args
return TEMPER_GET_EXIT_CODE(); // Fetches your return code
}
On Windows and Mac OS you shouldn't need to do anything extra on your part to get Temper to compile correctly. There should be no other dependencies that are required. If you find that there are, please submit a bug report (https://github.com/dangmoody/Tantrum/issues).
If you are compiling Temper on Linux and you are NOT overriding the default internal functions then you will need to make sure you pass the following arguments to your compiler/linker:
* `-ldl` - required if you're not overriding the `LoadEXEHandle()` and `UnloadEXEHandle()` functions.
* `-lpthread` - required if you're not overriding the `RunTestThread()` function.
* `--export-dynamic` - or some other equivalent, required to allow the compiler to export the test functions so they can be called dynamically by Temper at runtime.
When compiled, this will then produce an executable that will run all tests you have defined and return `TEMPDERDEV__EXIT_SUCCESS` (overridable) if there were no errors. If there were errors then the program will return `TEMPDERDEV__EXIT_FAILURE` (overridable).
4. COMMAND LINE ARGS
Temper supports the following command line arguments:
[-h|--help]
Shows this help and then exits.
-t <test>
Only run the test with the given name.
-s <suite>
Only run tests in the suite with the given name.
-p
Enable partial filtering, which will only run tests and suites that contain the text specified in the filters.
--time-unit [seconds|ms|us|ns|clocks]
Set the units to measure test times in.
The default is microseconds.
-f
Only log tests that fail.
5. CONTRIBUTING
Yes!
If you want to submit an idea/bug then use the GitHub issue tracker (https://github.com/dangmoody/Tantrum/issues).
If you want to submit code then we are open to pull requests. See contributing.md for details.
6. CREDITS
Programming:
Dan Moody
Mike Young
Special Thanks:
Danny Grezel - logo!
Zack Dutton - bug reports and testing
7. CHANGELOG
v2.1.0, <INSERT RELEASE DATE HERE>:
* Added support for Raspberry Pi (64-bit)!
* Errors are now logged explicitly to stderr. Everything else is now logged explicitly to stdout.
* Unified the names of the test macros for better searchability/auto-completion:
* Renamed `TEMPER_SUITE_TEST` to `TEMPER_TEST_SUITE`.
* Renamed `TEMPER_PARAMETRIC` to `TEMPER_TEST_PARAMETRIC`.
* Renamed `TEMPER_SUITE_PARAMETRIC` to `TEMPER_TEST_PARAMETRIC_SUITE`.
* Added new cmd line arg `-f`:
* If enabled, Temper will only log tests that failed. Tests that succeeded will not output anything.
* This is useful when the program has a lot of tests.
* `assert.h` is no longer included if you #define over `TEMPERDEV_ASSERT`.
v2.0.1, 12/06/2022:
* Rename __temper_test_info_fetcher_ struct prefix to TEMPERDEV_TEST_INFO_FETCHER to avoid triggering compiler warnings on the user's end.
* Rename all macros to no longer include double underscores anywhere. For example, TEMPERDEV__COLOR_YELLOW is now called TEMPERDEV_COLOR_YELLOW.
* Replaced certain overridable #defines with function pointers for better ease-of-use.
* Ignore additional bogus warning for Clang 14.
v2.0.0, 02/04/2021:
* Nearly everything has been completely re-written from scratch.
* Tests are now self-registering. All you need to do now is write the test code and the tests will get called automatically for you (unless the test is marked as skipped).
* Because of this, the functions `TEMPER_RUN_TEST` and `TEMPER_SKIP_TEST` have been removed.
* If you want to skip a test now you must now do so by setting the test flag.
* Due to how tests are now registered, `TEMPER_SUITE` has also been removed.
* Suite names are now specified per-test, to allow for being able to specify tests in the same suite across multiple source files.
* Added parametric testing.
* Added tests that have OnBeforeTest() and OnAfterTest() callbacks.
* Added partial filtering for tests and suites.
* When enabled, will search for suites/tests that only contain the filter given instead of searching for an exact match.
* Disabled by default. Use `-p` command line argument to enable.
* Added some more check functions to make it nicer when writing tests:
* TEMPER_CHECK_EQUAL
* TEMPER_CHECK_FLOAT_EQUAL
* TEMPER_CHECK_ALMOST_EQUAL
* TEMPER_CHECK_NOT_ALMOST_EQUAL
* Added self-testing functionality (useful only for Temper developers).
* Removed `TEMPER_DEFS` in favour of `TEMPER_RUN( argc, argv ) which you call inside main()`.
* Including Temper now requires defining `TEMPER_IMPLEMENTATION` (same as stb).
* Each test now runs in its own thread.
* This allows tests to always exit even if a test is aborted when running code not directly inside the test function.
* Made nearly all of the internal API extendable/overridable to help hook Temper into your codebase.
* Removed the `-a` command line argument since this is now configured per check per test.
* The default console output is no longer on one line to be more accomodating of test suites that have console output.
* Tests that fail will no longer exit on the first failure, they will report all failures before exiting.
* If you want a test to exit if it fails use the `_A` suffix on your test function.
* Colored text console output is now always on.
* Therefore the command line argument `-c` has been removed.
* Removed `TEMPER_SUITE_EXTERN` and `TEMPER_TEST_EXTERN` since there is now no need for them.
v1.1.1, 01/10/2019:
* Fix bug when parsing the --time-unit command line argument.
v1.1.0, 22/09/2019:
* Tests now display how long they took to run (defaulting to milliseconds).
* You can configure this yourself via the --time-unit command line argument.
* The unit you set must be either: "seconds", "ms", "us", "ns", or "clocks" (without speech marks).
v1.0.1, 16/04/2019:
* Support for macOS.
* Fixed some other weird issues appearing on some other flavours of Clang and GCC on Linux.
v1.0.0, 13/02/2019:
* Initial release.
===========================================================================
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#if defined( __clang__ )
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#pragma clang diagnostic ignored "-Wtypedef-redefinition"
#if __has_warning( "-Wdeclaration-after-statement" )
#pragma clang diagnostic ignored "-Wdeclaration-after-statement" // clang 14 moans about this but its bullshit
#endif // __has_warning( "-Wdeclaration-after-statement" )
#if __has_warning( "-Wunsafe-buffer-usage" )
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // clang 17 bullshit
#endif // __has_warning( "-Wunsafe-buffer-usage" )
#if defined( __APPLE__ )
// DM: only disabling this one to avoid a warning that gets generated when trying to convert function pointers to void*
// if anyone knows of a better way to get around that without disabling all pedantic warnings I'd love to hear about it
// submit an issue telling me how: https://github.com/dangmoody/Temper/issues
#pragma clang diagnostic ignored "-Wpedantic"
#endif
#elif defined( __GNUC__ ) // defined( __clang__ )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
// DM: only disabling this one to avoid a warning that gets generated when trying to convert function pointers to void*
// if anyone knows of a better way to get around that without disabling all pedantic warnings I'd love to hear about it
// submit an issue telling me how: https://github.com/dangmoody/Temper/issues
#pragma GCC diagnostic ignored "-Wpedantic"
#elif defined( _MSC_VER )
#pragma warning( push, 4 )
#pragma warning( disable : 4505 ) // unused function
#endif // defined( __clang__ )
#if defined( __linux__ ) || defined( __APPLE__ )
#pragma push_macro( "_POSIX_C_SOURCE" )
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200112L
#endif
#if defined( __APPLE__ ) || defined( __linux__ )
#include <unistd.h>
#include <dlfcn.h> // dlopen, dlsym, dlclose
#include <errno.h>
#include <sys/stat.h> // lstat
#if defined( __linux__ )
#include <linux/limits.h> // PATH_MAX
#elif defined( __APPLE__ )
#include <sys/syslimits.h> // PATH_MAX
#include <mach-o/dyld.h> // _NSGetExecutablePath()
#endif
#include <time.h>
#include <pthread.h>
#endif
#include <stdio.h> // printf, snprintf
#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
#include <stdarg.h> // va_arg
#include <string.h> // strcmp, strstr
#include <stdint.h>
#ifndef __cplusplus
#include <stdbool.h>
#endif
//==========================================================
// Public API
//==========================================================
// Initialises and runs Temper.
#define TEMPER_RUN( argc, argv ) \
g_temperTestContext.exitCode = TemperExecuteAllTestsWithArgumentsInternal( argc, argv )
//----------------------------------------------------------
// Returns 'TEMPERDEV_EXIT_SUCCESS' if all tests passed, otherwise returns 'TEMPERDEV_EXIT_FAULURE'
#define TEMPER_GET_EXIT_CODE() g_temperTestContext.exitCode
//----------------------------------------------------------
// PARAMETRIC TEST MACROS
//----------------------------------------------------------
#define TEMPER_TEST( testName, runFlag ) TEMPERDEV_DEFINE_TEST( NULL, testName, NULL, NULL, runFlag )
#define TEMPER_TEST_C( testName, onBefore, onAfter, runFlag ) TEMPERDEV_DEFINE_TEST( NULL, testName, onBefore, onAfter, runFlag )
#define TEMPER_TEST_SUITE( suiteName, testName, runFlag ) TEMPERDEV_DEFINE_TEST( #suiteName, testName, NULL, NULL, runFlag )
#define TEMPER_TEST_SUITE_C( suiteName, testName, onBefore, onAfter, runFlag ) TEMPERDEV_DEFINE_TEST( #suiteName, testName, onBefore, onAfter, runFlag )
#define TEMPER_TEST_PARAMETRIC( testName, runFlag, ... ) TEMPERDEV_DEFINE_PARAMETRIC( NULL, testName, NULL, NULL, runFlag, __VA_ARGS__ )
#define TEMPER_TEST_PARAMETRIC_C( testName, onBefore, onAfter, runFlag, ... ) TEMPERDEV_DEFINE_PARAMETRIC( NULL, testName, onBefore, onAfter, runFlag, __VA_ARGS__ )
#define TEMPER_TEST_PARAMETRIC_SUITE( suiteName, testName, runFlag, ... ) TEMPERDEV_DEFINE_PARAMETRIC( #suiteName, testName, NULL, NULL, runFlag, __VA_ARGS__ )
#define TEMPER_TEST_PARAMETRIC_SUITE_C( suiteName, testName, onBefore, onAfter, runFlag, ... ) TEMPERDEV_DEFINE_PARAMETRIC( #suiteName, testName, onBefore, onAfter, runFlag, __VA_ARGS__ )
#define TEMPER_INVOKE_PARAMETRIC_TEST( testName, ... ) TEMPERDEV_INVOKE_PARAMETRIC_TEST( __COUNTER__, testName, __VA_ARGS__ )
//----------------------------------------------------------
// COMMON COMPARISON MACROS
//----------------------------------------------------------
#define TEMPER_CHECK_TRUE( condition ) TemperTestTrueInternal( condition, "TEMPER_CHECK_TRUE(" #condition ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_TRUE_M( condition, ... ) TemperTestTrueInternal( condition, "TEMPER_CHECK_TRUE_M(" #condition ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_TRUE_A( condition ) TemperTestTrueInternal( condition, "TEMPER_CHECK_TRUE_A(" #condition ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_TRUE_Q( condition ) TemperTestTrueInternal( condition, "TEMPER_CHECK_TRUE_Q(" #condition ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_TRUE_AM( condition, ... ) TemperTestTrueInternal( condition, "TEMPER_CHECK_TRUE_AM(" #condition ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_TRUE_QM( condition, ... ) TemperTestTrueInternal( condition, "TEMPER_CHECK_TRUE_QM(" #condition ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FALSE( condition ) TemperTestTrueInternal( !(condition), "TEMPER_CHECK_FALSE(" #condition ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FALSE_M( condition, ... ) TemperTestTrueInternal( !(condition), "TEMPER_CHECK_FALSE_M(" #condition ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FALSE_A( condition ) TemperTestTrueInternal( !(condition), "TEMPER_CHECK_FALSE_A(" #condition ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FALSE_Q( condition ) TemperTestTrueInternal( !(condition), "TEMPER_CHECK_FALSE_Q(" #condition ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FALSE_AM( condition, ... ) TemperTestTrueInternal( !(condition), "TEMPER_CHECK_FALSE_AM(" #condition ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FALSE_QM( condition, ... ) TemperTestTrueInternal( !(condition), "TEMPER_CHECK_FALSE_QM(" #condition ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_EQUAL( a, b ) TemperTestTrueInternal( a == b, "TEMPER_CHECK_EQUAL(" #a ", " #b ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_EQUAL_M( a, b, ... ) TemperTestTrueInternal( a == b, "TEMPER_CHECK_EQUAL_M(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_EQUAL_A( a, b ) TemperTestTrueInternal( a == b, "TEMPER_CHECK_EQUAL_A(" #a ", " #b ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_EQUAL_Q( a, b ) TemperTestTrueInternal( a == b, "TEMPER_CHECK_EQUAL_Q(" #a ", " #b ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_EQUAL_AM( a, b, ... ) TemperTestTrueInternal( a == b, "TEMPER_CHECK_EQUAL_AM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_EQUAL_QM( a, b, ... ) TemperTestTrueInternal( a == b, "TEMPER_CHECK_EQUAL_QM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_EQUAL( a, b ) TemperTestTrueInternal( a != b, "TEMPER_CHECK_NOT_EQUAL(" #a ", " #b ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_EQUAL_M( a, b, ... ) TemperTestTrueInternal( a != b, "TEMPER_CHECK_NOT_EQUAL_M(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_EQUAL_A( a, b ) TemperTestTrueInternal( a != b, "TEMPER_CHECK_NOT_EQUAL_A(" #a ", " #b ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_EQUAL_Q( a, b ) TemperTestTrueInternal( a != b, "TEMPER_CHECK_NOT_EQUAL_Q(" #a ", " #b ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_EQUAL_AM( a, b, ... ) TemperTestTrueInternal( a != b, "TEMPER_CHECK_NOT_EQUAL_AM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_EQUAL_QM( a, b, ... ) TemperTestTrueInternal( a != b, "TEMPER_CHECK_NOT_EQUAL_QM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
//----------------------------------------------------------
// FLOAT COMPARISON MACROS
//----------------------------------------------------------
#define TEMPER_CHECK_FLOAT_EQUAL( a, b ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL(" #a ", " #b ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_EQUAL_M( a, b, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_M(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_EQUAL_A( a, b ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_A(" #a ", " #b ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_EQUAL_Q( a, b ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_Q(" #a ", " #b ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_EQUAL_AM( a, b, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_AM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_EQUAL_QM( a, b, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_QM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_FLOAT_EQUAL( a, b ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL(" #a ", " #b ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_FLOAT_EQUAL_M( a, b, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_M(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_FLOAT_EQUAL_A( a, b ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_A(" #a ", " #b ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_FLOAT_EQUAL_Q( a, b ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_Q(" #a ", " #b ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_FLOAT_EQUAL_AM( a, b, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_AM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_FLOAT_EQUAL_QM( a, b, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_FLOAT_EQUAL_QM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_WITHIN_RANGE( a, b, absoluteTolerance ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_ALMOST_EQUAL(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_WITHIN_RANGE_M( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_ALMOST_EQUAL_M(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_WITHIN_RANGE_A( a, b, absoluteTolerance ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_ALMOST_EQUAL_A(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_WITHIN_RANGE_Q( a, b, absoluteTolerance ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_ALMOST_EQUAL_Q(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_WITHIN_RANGE_AM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_ALMOST_EQUAL_AM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_WITHIN_RANGE_QM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_ALMOST_EQUAL_QM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_NOT_WITHIN_RANGE( a, b, absoluteTolerance ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_NOT_ALMOST_EQUAL(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_NOT_WITHIN_RANGE_M( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_NOT_ALMOST_EQUAL_M(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_NOT_WITHIN_RANGE_A( a, b, absoluteTolerance ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_NOT_ALMOST_EQUAL_A(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_NOT_WITHIN_RANGE_Q( a, b, absoluteTolerance ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_NOT_ALMOST_EQUAL_Q(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_FLOAT_NOT_WITHIN_RANGE_AM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_NOT_ALMOST_EQUAL_AM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_FLOAT_NOT_WITHIN_RANGE_QM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.FloatEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE ), "TEMPER_CHECK_NOT_ALMOST_EQUAL_QM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
//----------------------------------------------------------
// DOUBLE COMPARISON MACROS
//----------------------------------------------------------
#define TEMPER_CHECK_DOUBLE_EQUAL( a, b ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_EQUAL(" #a ", " #b ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_EQUAL_M( a, b, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_EQUAL_M(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_EQUAL_A( a, b ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_EQUAL_A(" #a ", " #b ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_EQUAL_Q( a, b ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_EQUAL_Q(" #a ", " #b ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_EQUAL_AM( a, b, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_EQUAL_AM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_EQUAL_QM( a, b, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_EQUAL_QM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_DOUBLE_EQUAL( a, b ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_EQUAL(" #a ", " #b ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_DOUBLE_EQUAL_M( a, b, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_EQUAL_M(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_DOUBLE_EQUAL_A( a, b ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_EQUAL_A(" #a ", " #b ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_DOUBLE_EQUAL_Q( a, b ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_EQUAL_Q(" #a ", " #b ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_NOT_DOUBLE_EQUAL_AM( a, b, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_EQUAL_AM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_NOT_DOUBLE_EQUAL_QM( a, b, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_EQUAL_QM(" #a ", " #b ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_WITHIN_RANGE( a, b, absoluteTolerance ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_S_EQUAL(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_WITHIN_RANGE_M( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_S_EQUAL_M(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_WITHIN_RANGE_A( a, b, absoluteTolerance ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_S_EQUAL_A(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_WITHIN_RANGE_Q( a, b, absoluteTolerance ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_S_EQUAL_Q(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_WITHIN_RANGE_AM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_S_EQUAL_AM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_WITHIN_RANGE_QM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_DOUBLE_S_EQUAL_QM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_NOT_WITHIN_RANGE( a, b, absoluteTolerance ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_S_EQUAL(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_NOT_WITHIN_RANGE_M( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_S_EQUAL_M(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_OKAY, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_NOT_WITHIN_RANGE_A( a, b, absoluteTolerance ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_S_EQUAL_A(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_NOT_WITHIN_RANGE_Q( a, b, absoluteTolerance ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_S_EQUAL_Q(" #a ", " #b ", " #absoluteTolerance ")", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, NULL, NULL )
#define TEMPER_CHECK_DOUBLE_NOT_WITHIN_RANGE_AM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_S_EQUAL_AM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_ABORT, __FILE__, __LINE__, __VA_ARGS__ )
#define TEMPER_CHECK_DOUBLE_NOT_WITHIN_RANGE_QM( a, b, absoluteTolerance, ... ) TemperTestTrueInternal( !g_temperTestContext.callbacks.DoubleEquals( a, b, absoluteTolerance, TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE ), "TEMPER_CHECK_NOT_DOUBLE_S_EQUAL_QM(" #a ", " #b ", " #absoluteTolerance ", ...)", TEMPER_FLAG_TEST_QUIT, __FILE__, __LINE__, __VA_ARGS__ )
//==========================================================
// User-Overridable Preprocessor defines
//
// By default, Temper will use it's own internal implementations for things.
// But you can override them to help hook Temper into your codebase.
// This must be done before including temper.h
//==========================================================
#ifndef TEMPERDEV_ASSERT
#include <assert.h>
#define TEMPERDEV_ASSERT assert
#endif
#ifndef TEMPERDEV_REALLOC
#define TEMPERDEV_REALLOC realloc
#endif
// The code that gets returned if all tests passed.
#ifndef TEMPERDEV_EXIT_SUCCESS
#define TEMPERDEV_EXIT_SUCCESS EXIT_SUCCESS
#endif
// The code that gets returned if at least one test failed.
#ifndef TEMPERDEV_EXIT_FAILURE
#define TEMPERDEV_EXIT_FAILURE EXIT_FAILURE
#endif
// Mainly used to avoid 'unused variable' warnings generated by compilers.
#ifndef TEMPERDEV_UNUSED
#define TEMPERDEV_UNUSED( x ) ( (void) x )
#endif
//==========================================================
// User-Overridable functions
//==========================================================
typedef enum temperTimeUnit_t {
TEMPER_TIME_UNIT_CLOCKS = 1,
TEMPER_TIME_UNIT_NS,
TEMPER_TIME_UNIT_US,
TEMPER_TIME_UNIT_MS,
TEMPER_TIME_UNIT_SECONDS
} temperTimeUnit_t;
//----------------------------------------------------------
typedef struct temperTestInfo_t temperTestInfo_t;
//----------------------------------------------------------
typedef struct temperCallbacks_t {
void* ( *Malloc )( size_t size );
void ( *Free )( void* ptr );
int ( *VFPrintf )( FILE* file, const char* fmt, va_list args );
int ( *SNPrintf )( char* s, size_t n, const char* format, ... );
int ( *VSNPrintf )( char* s, size_t n, const char* format, va_list args );
int ( *Dup )( int fileHandle ); // create second file descriptor
int ( *Dup2 )( int fileHandleSrc, int fileHandleDst ); // reassign file descriptor
int ( *Fileno )( FILE* handle );
FILE* ( *FOpen )( const char* filename, const char* mode );
int ( *FFlush )( FILE* file );
int ( *Strcmp )( const char* strA, const char* strB );
bool ( *StringContains )( const char* str, const char* substring );
// Returns a timestamp from the CPU in the 'timeUnit' format.
// See temperTimeUnit_t for time units.
double ( *GetTimestamp )( const temperTimeUnit_t timeUnit );
float ( *Maxf )( const float a, const float b );
float ( *Absf )( const float x );
double ( *Maxd )( const double a, const double b );
double ( *Absd )( const double x );
bool ( *FloatEquals )( const float a, const float b, const float absoluteTolerance, const float relativeTolerance );
bool ( *DoubleEquals )( const double a, const double b, const double absoluteTolerance, const double relativeTolerance );
void ( *Log )( FILE* file, const char* fmt, ... );
void ( *LogWarning )( const char* fmt, ... );
void ( *LogError )( const char* fmt, ... );
void ( *OnBeforeTest )( const temperTestInfo_t* information );
void ( *OnAfterTest )( const temperTestInfo_t* information );
void ( *RunTestThread )( temperTestInfo_t* information );
void ( *OnAllTestsFinished )( void );
} temperCallbacks_t;
//==========================================================
// Internal API
//
// You as the user probably don't want to be directly touching any of this.
//==========================================================
#define TEMPERDEV_BIT( x ) ( 1 << ( x ) )
#ifndef TEMPERDEV_INVALID_FILE_ID
#define TEMPERDEV_INVALID_FILE_ID -1
#endif
#if defined( _WIN32 )
#define TEMPERDEV_STDOUT_FILENO 1
#define TEMPERDEV_NULL_STDOUT "nul"
#elif defined( __APPLE__ ) || defined( __linux__ ) // defined( _WIN32 )
#define TEMPERDEV_STDOUT_FILENO STDOUT_FILENO
#define TEMPERDEV_NULL_STDOUT "/dev/null"
#else // defined( _WIN32 )
#error Unrecognised platform. It appears Temper does not support it. If you think this is a bug, please submit an issue at https://github.com/dangmoody/Temper/issues
#endif // defined( _WIN32 )
//----------------------------------------------------------
typedef uint8_t temperBool8;
//----------------------------------------------------------
typedef enum temperTestFlag_t {
TEMPER_FLAG_SHOULD_RUN = 0,
TEMPER_FLAG_SHOULD_SKIP,
TEMPER_FLAG_DEPRECATED
} temperTestFlag_t;
//----------------------------------------------------------
typedef enum temperTestInterruptFlag_t {
TEMPER_FLAG_TEST_OKAY = 0,
TEMPER_FLAG_TEST_ABORT,
TEMPER_FLAG_TEST_QUIT
} temperTestInterruptFlag_t;
//----------------------------------------------------------
typedef void( *temperTestCallbackOnBeforeTest_t )( void );
typedef void( *temperTestCallbackOnAfterTest_t )( void );
typedef void( *temperTestCallback_t )( void );
//----------------------------------------------------------
typedef struct temperTestInfo_t {
temperTestCallbackOnBeforeTest_t OnBeforeTest;
temperTestCallback_t TestFuncCallback;
temperTestCallbackOnAfterTest_t OnAfterTest;
double testTimeTaken;
temperTestFlag_t testingFlag;
uint32_t pad0;
const char* testNameStr;
const char* suiteNameStr;
} temperTestInfo_t;
//----------------------------------------------------------
// we have an option to only log tests that fail
// but we log things on-the-fly
// so in order to only log tests that fail (if the flag is turned on) we need to store all of the "fail" messages for later
// this struct contains the error message that WOULD be printed, so that we can hold on to it and then only print it at the end of a test if it has failed
typedef struct temperTestFailInfo_t {
char* msg;
} temperTestFailInfo_t;
//----------------------------------------------------------
typedef enum temperTestContextFlagBits_t {
TEMPERDEV_TEST_CONTEXT_FLAG_NEGATE_QUIT_ATTEMPTS = TEMPERDEV_BIT( 0 ),
TEMPERDEV_TEST_CONTEXT_FLAG_PARTIAL_FILTER = TEMPERDEV_BIT( 1 ),
TEMPERDEV_TEST_CONTEXT_FLAG_ONLY_SHOW_FAILED_TESTS = TEMPERDEV_BIT( 2 ),
} temperTestContextFlagBits_t;
typedef int32_t temperTestContextFlags_t;
//----------------------------------------------------------
typedef struct temperTestContext_t {
temperCallbacks_t callbacks;
uint64_t testInfosCount;
temperTestInfo_t* testInfos;
uint64_t deferredTestFailMessagesCount;
temperTestFailInfo_t* deferredTestFailMessages;
#ifdef _WIN32
int64_t timestampFrequency;
#endif
double currentTestStartTime;
double currentTestEndTime;
double totalExecutionTime;
uint32_t testsPassed;
uint32_t testsFailed;
uint32_t testsAborted;
uint32_t testsSkipped;
uint32_t testsQuit;
uint32_t totalTestsFoundWithFilters;
uint32_t totalTestsExecuted;
uint32_t currentTestErrorCount;
int32_t exitCode;
int32_t oldStdoutID;
int32_t nullStdoutID;
temperTestContextFlags_t flags;
temperTimeUnit_t timeUnit;
temperBool8 currentTestWasAborted;
temperBool8 pad0;
temperBool8 pad1;
temperBool8 pad2;
const char* suiteFilterPrevious;
const char* suiteFilter;
const char* testFilter;
} temperTestContext_t;
//----------------------------------------------------------
#ifdef __cplusplus
#define TEMPERDEV_EXTERN_C extern "C"
#else
#define TEMPERDEV_EXTERN_C extern
#endif
//----------------------------------------------------------
TEMPERDEV_EXTERN_C temperTestContext_t g_temperTestContext;
//----------------------------------------------------------
#if defined( _WIN32 )
#define TEMPERDEV_EXIT_TEST_THREAD() ExitThread( TEMPERDEV_EXIT_FAILURE )
#else
#define TEMPERDEV_EXIT_TEST_THREAD() pthread_exit( NULL )
#endif
//----------------------------------------------------------
#define TEMPERDEV_EPSILON_TOLERANCE_FLOAT_ABSOLUTE 1e-6f
#define TEMPERDEV_EPSILON_TOLERANCE_FLOAT_RELATIVE 1e-9f
#define TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_ABSOLUTE 1e-14
#define TEMPERDEV_EPSILON_TOLERANCE_DOUBLE_RELATIVE 1e-17
//----------------------------------------------------------
#define TEMPERDEV_CONCAT_( a, b ) a ## b
#define TEMPERDEV_CONCAT( a, b ) TEMPERDEV_CONCAT_( a, b ) // use this one
//----------------------------------------------------------
#define TEMPERDEV_STRINGIFY_( x ) #x
#define TEMPERDEV_STRINGIFY( x ) TEMPERDEV_STRINGIFY_( x ) // use this one
//----------------------------------------------------------
#if defined( __clang__ )
#define TEMPERDEV_DEFINE_TEST_INFO_FETCHER( testName ) \
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName )( void ) __attribute__( ( constructor ) ); \
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName )( void )
#elif defined( __GNUC__ )
#define TEMPERDEV_DEFINE_TEST_INFO_FETCHER( testName ) \
/* add 101 because gcc reserves constructors with priorities between 0 - 100 and __COUNTER__ starts at 0 */ \
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName )( void ) __attribute__( ( constructor( __COUNTER__ + 101 ) ) ); \
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName )( void )
#elif defined( _MSC_VER ) // defined( __GNUC__ ) || defined( __clang__ )
#ifdef _WIN64
#define TEMPERDEV_MSVC_PREFIX ""
#else
#define TEMPERDEV_MSVC_PREFIX "_"
#endif
#pragma section( ".CRT$XCU", read )
#define TEMPERDEV_DEFINE_TEST_INFO_FETCHER( testName ) \
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName )( void ); \
\
__pragma( comment( linker, "/include:" TEMPERDEV_MSVC_PREFIX TEMPERDEV_CONCAT( TEMPERDEV_STRINGIFY( testName ), "_FuncPtr" ) ) ) \
TEMPERDEV_EXTERN_C __declspec( allocate( ".CRT$XCU" ) ) void ( * TEMPERDEV_CONCAT( testName, _FuncPtr ) )( void ) = TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName ); \
\
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, testName )( void )
#endif // defined( _MSC_VER )
//----------------------------------------------------------
#define TEMPERDEV_DEFINE_TEST( suiteNameString, testName, onBeforeName, onAfterName, runFlag ) \
/*1. Create a function with a name matching the test.*/ \
void ( testName )( void ); \
\
/*2. This is what the runner will loop over to grab the test function as well as all the information concerning it*/ \
TEMPERDEV_DEFINE_TEST_INFO_FETCHER( testName ) { \
temperTestInfo_t testInfo; \
testInfo.OnBeforeTest = onBeforeName; \
testInfo.TestFuncCallback = testName; \
testInfo.OnAfterTest = onAfterName; \
testInfo.testingFlag = runFlag; \
testInfo.suiteNameStr = suiteNameString; \
testInfo.testNameStr = #testName; \
\
TemperAddTestInternal( &testInfo ); \
} \
\
/*3. The test function declared at Step1 is now declared here by the user*/ \
void ( testName )( void )
//----------------------------------------------------------
#define TEMPERDEV_DEFINE_PARAMETRIC( suiteNameString, testName, onBeforeName, onAfterName, runFlag, ... ) \
void TemperGetParametricTestInfo_ ## testName( temperTestInfo_t* outInfo ); \
void TemperGetParametricTestInfo_ ## testName( temperTestInfo_t* outInfo ) { \
outInfo->OnBeforeTest = onBeforeName; \
outInfo->OnAfterTest = onAfterName; \
outInfo->testingFlag = runFlag; \
outInfo->suiteNameStr = suiteNameString; \
outInfo->testNameStr = #testName; \
} \
\
void ( testName )( __VA_ARGS__ ); \
void ( testName )( __VA_ARGS__ )
//----------------------------------------------------------
#define TEMPERDEV_INVOKE_PARAMETRIC_TEST( counter, testName, ... ) \
void TEMPERDEV_CONCAT( TemperCallParametricTest_, TEMPERDEV_CONCAT( testName, counter ) )( void ); \
void TEMPERDEV_CONCAT( TemperCallParametricTest_, TEMPERDEV_CONCAT( testName, counter ) )( void ) { \
testName( __VA_ARGS__ ); \
} \
\
TEMPERDEV_DEFINE_TEST_INFO_FETCHER( TEMPERDEV_CONCAT( testName, counter ) ) { \
temperTestInfo_t testInfo; \
TemperGetParametricTestInfo_ ## testName( &testInfo ); \
testInfo.TestFuncCallback = TEMPERDEV_CONCAT( TemperCallParametricTest_, TEMPERDEV_CONCAT( testName, counter ) ); \
\
TemperAddTestInternal( &testInfo ); \
} \
\
void TEMPERDEV_CONCAT( TEMPERDEV_TEST_INFO_FETCHER_, TEMPERDEV_CONCAT( testName, counter ) )( void )
//----------------------------------------------------------
#if defined( _WIN32 )
#define TEMPERDEV_COLOR_DEFAULT 0x07
#define TEMPERDEV_COLOR_RED 0x0C
#define TEMPERDEV_COLOR_GREEN 0x02
#define TEMPERDEV_COLOR_YELLOW 0x0E
typedef uint32_t temperTextColor_t;
#elif defined( __linux__ ) || defined( __APPLE__ )
#define TEMPERDEV_COLOR_DEFAULT "\033[0m"
#define TEMPERDEV_COLOR_RED "\033[0;31m"
#define TEMPERDEV_COLOR_GREEN "\033[0;32m"
#define TEMPERDEV_COLOR_YELLOW "\033[1;33m"
typedef const char* temperTextColor_t;
#endif // defined( _WIN32 )
//----------------------------------------------------------
TEMPERDEV_EXTERN_C void TemperAddTestInternal( const temperTestInfo_t* newTestInfo );
TEMPERDEV_EXTERN_C void TemperTestTrueInternal( const bool condition, const char* conditionStr, const temperTestInterruptFlag_t testInteruptFlag, const char* file, const uint32_t line, const char* fmt, ... );
TEMPERDEV_EXTERN_C void TemperSetupInternal( void );
TEMPERDEV_EXTERN_C int TemperExecuteAllTestsInternal( void );
TEMPERDEV_EXTERN_C int TemperExecuteAllTestsWithArgumentsInternal( int argc, char** argv );
TEMPERDEV_EXTERN_C bool TemperFloatEqualsInternal( const float a, const float b, const float absoluteTolerance, const float relativeTolerance );
TEMPERDEV_EXTERN_C bool TemperDoubleEqualsInternal( const double a, const double b, const double absoluteTolerance, const double relativeTolerance );
//----------------------------------------------------------
#ifdef TEMPER_IMPLEMENTATION
#ifdef _WIN32
#include <Windows.h>
#include <io.h>
#endif
temperTestContext_t g_temperTestContext;
//----------------------------------------------------------
static void TemperSetTextColorInternal( const temperTextColor_t color ) {
#if defined( _WIN32 )
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), (WORD) color );
#elif defined( __APPLE__ ) || defined( __linux__ )
printf( "%s", color );
#else
#error Uncrecognised platform. It appears Temper does not support it. If you think this is a bug, please submit an issue at https://github.com/dangmoody/Temper/issues
#endif
}
//----------------------------------------------------------
static void TemperLogInternal( FILE* file, const char* fmt, ... ) {
TEMPERDEV_ASSERT( fmt );
va_list args;
va_start( args, fmt );
g_temperTestContext.callbacks.VFPrintf( file, fmt, args );
va_end( args );
}
//----------------------------------------------------------
static void TemperLogWarningInternal( const char* fmt, ... ) {
TEMPERDEV_ASSERT( fmt );
va_list args;
va_start( args, fmt );
TemperSetTextColorInternal( TEMPERDEV_COLOR_RED );
printf( "WARNING: " );
TemperSetTextColorInternal( TEMPERDEV_COLOR_YELLOW );
g_temperTestContext.callbacks.VFPrintf( stderr, fmt, args );
TemperSetTextColorInternal( TEMPERDEV_COLOR_DEFAULT );
va_end( args );
}
//----------------------------------------------------------
static void TemperLogErrorInternal( const char* fmt, ... ) {
TEMPERDEV_ASSERT( fmt );
va_list args;
va_start( args, fmt );
TemperSetTextColorInternal( TEMPERDEV_COLOR_RED );
printf( "ERROR: " );
TemperSetTextColorInternal( TEMPERDEV_COLOR_YELLOW );
g_temperTestContext.callbacks.VFPrintf( stderr, fmt, args );
TemperSetTextColorInternal( TEMPERDEV_COLOR_DEFAULT );
va_end( args );
}
//----------------------------------------------------------
static uint32_t TemperGetPercentInternal( uint32_t yourValue, uint32_t yourMax ) {
return (uint32_t) ( ( ( (float) yourValue ) / ( (float) yourMax ) ) * 100 );
}
//----------------------------------------------------------
static float TemperMaxfInternal( const float a, const float b ) {
return ( a > b ) ? a : b;
}
//----------------------------------------------------------
static float TemperAbsfInternal( const float x ) {
return g_temperTestContext.callbacks.Maxf( -x, x );
}
//----------------------------------------------------------
static double TemperMaxdInternal( const double a, const double b ) {
return ( a > b ) ? a : b;
}
//----------------------------------------------------------
static double TemperAbsdInternal( const double x ) {
return g_temperTestContext.callbacks.Maxd( -x, x );
}
//----------------------------------------------------------
// uses Christer Ericson's solution: https://realtimecollisiondetection.net/blog/?p=89
bool TemperFloatEqualsInternal( const float a, const float b, const float absoluteTolerance, const float relativeTolerance ) {
return g_temperTestContext.callbacks.Absf( a - b ) <= g_temperTestContext.callbacks.Maxf( absoluteTolerance, relativeTolerance * g_temperTestContext.callbacks.Maxf( g_temperTestContext.callbacks.Absf( a ), g_temperTestContext.callbacks.Absf( b ) ) );
}
//----------------------------------------------------------
// uses Christer Ericson's solution: https://realtimecollisiondetection.net/blog/?p=89
bool TemperDoubleEqualsInternal( const double a, const double b, const double absoluteTolerance, const double relativeTolerance ) {
return g_temperTestContext.callbacks.Absd( a - b ) <= g_temperTestContext.callbacks.Maxd( absoluteTolerance, relativeTolerance * g_temperTestContext.callbacks.Maxd( g_temperTestContext.callbacks.Absd( a ), g_temperTestContext.callbacks.Absd( b ) ) );
}
//----------------------------------------------------------
void TemperAddTestInternal( const temperTestInfo_t* newTestInfo ) {
TEMPERDEV_ASSERT( newTestInfo );
TEMPERDEV_ASSERT( newTestInfo->TestFuncCallback );
TEMPERDEV_ASSERT( newTestInfo->testNameStr );
uint64_t index = g_temperTestContext.testInfosCount++;
g_temperTestContext.testInfos = (temperTestInfo_t*) TEMPERDEV_REALLOC( g_temperTestContext.testInfos, g_temperTestContext.testInfosCount * sizeof( temperTestInfo_t ) );
temperTestInfo_t* testInfo = &g_temperTestContext.testInfos[index];
testInfo->OnBeforeTest = newTestInfo->OnBeforeTest;
testInfo->TestFuncCallback = newTestInfo->TestFuncCallback;
testInfo->OnAfterTest = newTestInfo->OnAfterTest;
testInfo->testingFlag = newTestInfo->testingFlag;
testInfo->suiteNameStr = newTestInfo->suiteNameStr;
testInfo->testNameStr = newTestInfo->testNameStr;
}
//----------------------------------------------------------
static const char* TemperGetNextArgInternal( const int argIndex, const int argc, char** argv ) {
TEMPERDEV_ASSERT( argc );
TEMPERDEV_ASSERT( argv );
return ( argIndex + 1 < argc ) ? argv[argIndex + 1] : NULL;
}
//----------------------------------------------------------
static bool TemperStringContainsInternal( const char* str, const char* substring ) {
return strstr( str, substring ) != NULL;
}
static double TemperGetTimestampInternal( const temperTimeUnit_t timeUnit ) {
// should never get here
TEMPERDEV_ASSERT( ( timeUnit > TEMPER_TIME_UNIT_CLOCKS && timeUnit <= TEMPER_TIME_UNIT_SECONDS ) && "Unrecognised time unit passed into TemperGetTimestampInternal().\n" );
#if defined( _WIN32 )
LARGE_INTEGER now;
QueryPerformanceCounter( &now );
switch ( timeUnit ) {
case TEMPER_TIME_UNIT_CLOCKS: return ( (double) now.QuadPart );
case TEMPER_TIME_UNIT_NS: return ( (double) ( now.QuadPart * 1000000000 ) / (double) g_temperTestContext.timestampFrequency );
case TEMPER_TIME_UNIT_US: return ( (double) ( now.QuadPart * 1000000 ) / (double) g_temperTestContext.timestampFrequency );
case TEMPER_TIME_UNIT_MS: return ( (double) ( now.QuadPart * 1000 ) / (double) g_temperTestContext.timestampFrequency );
case TEMPER_TIME_UNIT_SECONDS: return ( (double) ( now.QuadPart ) / (double) g_temperTestContext.timestampFrequency );
}
#elif defined( __APPLE__ ) || defined( __linux__ ) // defined( _WIN32 )
struct timespec now;
clock_gettime( CLOCK_MONOTONIC, &now );
int64_t clocks = (int64_t) ( now.tv_sec * 1000000000 + now.tv_nsec );
switch ( timeUnit ) {
case TEMPER_TIME_UNIT_CLOCKS: return (double) clocks;
case TEMPER_TIME_UNIT_NS: return (double) clocks;
case TEMPER_TIME_UNIT_US: return (double) clocks / 1000.0;
case TEMPER_TIME_UNIT_MS: return (double) clocks / 1000000.0;
case TEMPER_TIME_UNIT_SECONDS: return (double) clocks / 1000000000.0;
}
#else // defined( _WIN32 )
#error Unrecognised platform. It appears Temper does not support it. If you think this is a bug, please submit an issue at https://github.com/dangmoody/Temper/issues
#endif // defined( _WIN32 )
// never gets here
return 0.0;
}
//----------------------------------------------------------
static void TemperShowUsageInternal( void ) {
g_temperTestContext.callbacks.Log( stdout,
"Arguments:\n"
" [-h|--help]\n"
" Shows this help and then exits.\n"
"\n"
" -t <test>\n"
" Only run the test with the given name.\n"
"\n"
" -s <suite>\n"
" Only run tests in the suite with the given name.\n"
"\n"
" -p\n"
" Enable partial filtering, which will only run tests and suites that contain the text specified in the filters.\n"
"\n"
" -f\n"
" Only log tests that fail.\n"
"\n"
" --time-unit [seconds|ms|us|ns|clocks]\n"
" Set the units to measure test times in.\n"
" The default is microseconds.\n"
"\n"
);
}
//----------------------------------------------------------
static bool TemperHandleCommandLineArgumentsInternal( int argc, char** argv ) {
// parse command line args
for ( int argIndex = 0; argIndex < argc; argIndex++ ) {
const char* arg = argv[argIndex];
if ( g_temperTestContext.callbacks.Strcmp( arg, "-h" ) == 0 || g_temperTestContext.callbacks.Strcmp( arg, "--help" ) == 0 ) {
TemperShowUsageInternal();
return false;
}
if ( g_temperTestContext.callbacks.Strcmp( arg, "-s" ) == 0 ) {
const char* nextArg = TemperGetNextArgInternal( argIndex, argc, argv );
if ( !nextArg ) {
g_temperTestContext.callbacks.LogError( "Value for argument \"%s\" was not set.\n", arg );
TemperShowUsageInternal();
return false;
}
g_temperTestContext.suiteFilter = nextArg;
continue;
}
if ( g_temperTestContext.callbacks.Strcmp( arg, "-t" ) == 0 ) {
const char* nextArg = TemperGetNextArgInternal( argIndex, argc, argv );
if ( !nextArg ) {
g_temperTestContext.callbacks.LogError( "Value for argument \"%s\" was not set.\n", arg );
TemperShowUsageInternal();
return false;
}
g_temperTestContext.testFilter = nextArg;
continue;
}