forked from martinmoene/lest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-select.cpp
59 lines (47 loc) · 1.85 KB
/
05-select.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
// C++11 - select and omit tests from the command line.
#include "lest.hpp"
using namespace std;
const lest::test specification[] =
{
CASE( "Empty string has length zero (succeed)" )
{
EXPECT( 0u == string( ).length() );
EXPECT( 0u == string("").length() );
EXPECT_NOT( 0u < string("").length() );
},
CASE( "Text compares lexically (fail)" )
{
EXPECT( string("hello") > string("world") );
},
CASE( "Unexpected exception is reported" )
{
EXPECT( (throw std::runtime_error("surprise!"), true) );
},
CASE( "Unspecified expected exception is captured" )
{
EXPECT_THROWS( throw std::runtime_error("surprise!") );
},
CASE( "Specified expected exception is captured" )
{
EXPECT_THROWS_AS( throw std::bad_alloc(), std::bad_alloc );
},
CASE( "Expected exception is reported missing" )
{
EXPECT_THROWS( true );
},
CASE( "Specific expected exception is reported missing" )
{
EXPECT_THROWS_AS( true, std::runtime_error );
},
};
int main( int argc, char * argv[] )
{
return lest::run( specification, argc, argv );
}
// cl -nologo -Wall -EHsc -I../include/lest 05-select.cpp && 05-select
// g++ -Wall -Wextra -std=c++11 -I../include/lest -o 05-select.exe 05-select.cpp && 05-select
// 05-select.cpp:17: failed: Text compares lexically (fail): string("hello") > string("world") for "hello" > "world"
// 05-select.cpp:22: failed: got unexpected exception with message "surprise!": Unexpected exception is reported: (throw std::runtime_error("surprise!"), true)
// 05-select.cpp:37: failed: didn't get exception: Expected exception is reported missing: true
// 05-select.cpp:42: failed: didn't get exception of type std::runtime_error: Specific expected exception is reported missing: true
// 4 out of 7 selected tests failed.