@@ -60,6 +60,40 @@ TEST(RequiredCheckFailsOnFalse)
60
60
CHECK(exception);
61
61
}
62
62
63
+ bool ThrowsOnCall()
64
+ {
65
+ throw std::exception();
66
+ return false;
67
+ }
68
+
69
+ TEST(RequireCheckStopsTestOnException)
70
+ {
71
+ bool failure = false;
72
+ bool continued = false;
73
+ bool exception = false;
74
+
75
+ {
76
+ UnitTest::TestResults testResults;
77
+ ScopedCurrentTest scopedResults(testResults);
78
+
79
+ try
80
+ {
81
+ REQUIRE_CHECK(ThrowsOnCall());
82
+ continued = true;
83
+ }
84
+ catch (const UnitTest::RequiredCheckFailedException&)
85
+ {
86
+ exception = true;
87
+ }
88
+
89
+ failure = (testResults.GetFailureCount() > 0);
90
+ }
91
+
92
+ CHECK(failure);
93
+ CHECK(!continued);
94
+ CHECK(exception);
95
+ }
96
+
63
97
TEST(FailureReportsCorrectTestName)
64
98
{
65
99
RecordingReporter reporter;
@@ -149,6 +183,34 @@ TEST(RequiredCheckEqualFailsOnNotEqual)
149
183
CHECK(exception);
150
184
}
151
185
186
+ TEST(RequireEqualStopsTestOnException)
187
+ {
188
+ bool failure = false;
189
+ bool continued = false;
190
+ bool exception = false;
191
+
192
+ {
193
+ UnitTest::TestResults testResults;
194
+ ScopedCurrentTest scopedResults(testResults);
195
+
196
+ try
197
+ {
198
+ REQUIRE_EQUAL(false, ThrowsOnCall());
199
+ continued = true;
200
+ }
201
+ catch (const UnitTest::RequiredCheckFailedException&)
202
+ {
203
+ exception = true;
204
+ }
205
+
206
+ failure = (testResults.GetFailureCount() > 0);
207
+ }
208
+
209
+ CHECK(failure);
210
+ CHECK(!continued);
211
+ CHECK(exception);
212
+ }
213
+
152
214
TEST(RequiredCheckEqualFailureContainsCorrectDetails)
153
215
{
154
216
int line = 0;
@@ -267,6 +329,40 @@ TEST(RequiredCheckCloseFailsOnNotEqual)
267
329
CHECK(exception);
268
330
}
269
331
332
+ float ThrowsOnCallReturnsFloat()
333
+ {
334
+ throw std::exception();
335
+ return 0.0f;
336
+ }
337
+
338
+ TEST(RequireCloseStopsTestOnException)
339
+ {
340
+ bool failure = false;
341
+ bool continued = false;
342
+ bool exception = false;
343
+
344
+ {
345
+ UnitTest::TestResults testResults;
346
+ ScopedCurrentTest scopedResults(testResults);
347
+
348
+ try
349
+ {
350
+ REQUIRE_CLOSE(1.0f, ThrowsOnCallReturnsFloat(), 0.1f);
351
+ continued = true;
352
+ }
353
+ catch (const UnitTest::RequiredCheckFailedException&)
354
+ {
355
+ exception = true;
356
+ }
357
+
358
+ failure = (testResults.GetFailureCount() > 0);
359
+ }
360
+
361
+ CHECK(failure);
362
+ CHECK(!continued);
363
+ CHECK(exception);
364
+ }
365
+
270
366
TEST(RequiredCheckCloseFailureContainsCorrectDetails)
271
367
{
272
368
int line = 0;
@@ -382,6 +478,54 @@ TEST(RequiredCheckArrayCloseFailsOnNotEqual)
382
478
CHECK(exception);
383
479
}
384
480
481
+ // more convenient to use std::array<> here... not every compiler has it.
482
+ template<typename Type, std::size_t Count>
483
+ struct array_wrapper
484
+ {
485
+ Type operator[](std::size_t index) const
486
+ {
487
+ return values_[index];
488
+ }
489
+
490
+ Type values_[Count];
491
+ };
492
+
493
+ array_wrapper<int, 4> ThrowsOnCallReturnsArray()
494
+ {
495
+ throw std::exception();
496
+ return array_wrapper<int, 4>();
497
+ }
498
+
499
+ TEST(RequireCheckArrayStopsTestOnException)
500
+ {
501
+ bool failure = false;
502
+ bool continued = false;
503
+ bool exception = false;
504
+
505
+ {
506
+ UnitTest::TestResults testResults;
507
+ ScopedCurrentTest scopedResults(testResults);
508
+
509
+ int const data1[4] = { 0, 1, 2, 3 };
510
+
511
+ try
512
+ {
513
+ REQUIRE_ARRAY_CLOSE (data1, ThrowsOnCallReturnsArray(), 4, 0.01f);
514
+ continued = true;
515
+ }
516
+ catch (const UnitTest::RequiredCheckFailedException&)
517
+ {
518
+ exception = true;
519
+ }
520
+
521
+ failure = (testResults.GetFailureCount() > 0);
522
+ }
523
+
524
+ CHECK(failure);
525
+ CHECK(!continued);
526
+ CHECK(exception);
527
+ }
528
+
385
529
TEST(RequiredCheckArrayCloseFailureIncludesCheckExpectedAndActual)
386
530
{
387
531
RecordingReporter reporter;
@@ -660,6 +804,43 @@ TEST(RequiredCheckArray2DCloseFailsOnNotEqual)
660
804
CHECK(exception);
661
805
}
662
806
807
+ array_wrapper<array_wrapper<int, 2>, 2> ThrowsOnCallMultidimensionalArray()
808
+ {
809
+ throw std::exception();
810
+ return array_wrapper<array_wrapper<int, 2>, 2>();
811
+ }
812
+
813
+ TEST(RequiredCheckArray2DCloseStopsOnException)
814
+ {
815
+ bool failure = false;
816
+ bool continued = false;
817
+ bool exception = false;
818
+ {
819
+ RecordingReporter reporter;
820
+ UnitTest::TestResults testResults(&reporter);
821
+ ScopedCurrentTest scopedResults(testResults);
822
+
823
+ const float data[2][2] = { {0, 1}, {2, 3} };
824
+
825
+ try
826
+ {
827
+ REQUIRE_ARRAY2D_CLOSE(data, ThrowsOnCallMultidimensionalArray(), 2, 2, 0.01f);
828
+ continued = true;
829
+ }
830
+ catch (const UnitTest::RequiredCheckFailedException&)
831
+ {
832
+ exception = true;
833
+ }
834
+
835
+ failure = (testResults.GetFailureCount() > 0);
836
+ }
837
+
838
+ CHECK(failure);
839
+ CHECK(!continued);
840
+ CHECK(exception);
841
+ }
842
+
843
+
663
844
TEST(RequiredCheckArray2DCloseFailureIncludesCheckExpectedAndActual)
664
845
{
665
846
RecordingReporter reporter;
0 commit comments