-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathtest-catch.cpp
60 lines (41 loc) · 990 Bytes
/
test-catch.cpp
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
#include <testthat.h>
#include <string>
#include <stdexcept>
#include <exception>
namespace {
void ouch() {
std::string message = "logic";
throw std::logic_error(message);
}
} // anonymous namespace
context("Catch: Example Unit Test") {
test_that("4 + 4 == 8") {
expect_true((4 + 4) == 8);
}
}
context("Catch: A second context") {
test_that("2 - 2 == 0") {
expect_true((2 - 2) == 0);
}
test_that("-1 is negative") {
expect_true((-1 < 0));
}
}
context("Catch: Respect 'src/Makevars'") {
bool compiling_testthat;
#ifdef COMPILING_TESTTHAT
compiling_testthat = true;
#else
compiling_testthat = false;
#endif
test_that("COMPILING_TESTTHAT is inherited from 'src/Makevars'") {
expect_true(compiling_testthat);
}
}
context("Catch: Exception handling") {
test_that("we can use Catch to test for exceptions") {
expect_error(ouch());
expect_error_as(ouch(), std::exception);
expect_error_as(ouch(), std::logic_error);
}
}