Skip to content

Commit 0cdf988

Browse files
committed
split positive and negative test cases
1 parent cc3b5b0 commit 0cdf988

10 files changed

Lines changed: 140 additions & 92 deletions

CMakeLists.txt

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,49 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
77
if(MSVC)
88
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") # CMake already contains W3 in its flags
99
else()
10-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra-semi -O1 -g -fsanitize=address -fno-omit-frame-pointer")
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra-semi -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer")
1111
endif()
1212

1313

1414
find_package(GTest REQUIRED)
1515
include(GoogleTest)
1616

17-
add_executable(just_simple_test just_simple_test.cpp simple_test.h)
17+
add_executable(
18+
just_simple_test_ok
19+
examples/just_simple_test_ok.cpp
20+
simple_test.h
21+
)
1822

19-
add_executable(test_using_simple_test test_using_simple_test.cpp gtest_compatible_test.h simple_test.h)
23+
add_executable(
24+
just_simple_test_failures
25+
examples/just_simple_test_failures.cpp
26+
simple_test.h
27+
)
2028

21-
add_executable(test_using_gtest test_using_gtest.cpp gtest_compatible_test.h)
22-
target_link_libraries(test_using_gtest GTest::gtest GTest::gtest_main)
29+
add_executable(
30+
test_using_simple_test_ok
31+
examples/test_using_simple_test_ok.cpp
32+
examples/gtest_compatible_test_ok.h
33+
simple_test.h
34+
)
35+
36+
add_executable(
37+
test_using_simple_test_failures
38+
examples/test_using_simple_test_failures.cpp
39+
examples/gtest_compatible_test_failures.h
40+
simple_test.h
41+
)
42+
43+
add_executable(
44+
test_using_gtest_ok
45+
examples/test_using_gtest_ok.cpp
46+
examples/gtest_compatible_test_ok.h
47+
)
48+
target_link_libraries(test_using_gtest_ok GTest::gtest GTest::gtest_main)
49+
50+
add_executable(
51+
test_using_gtest_failures
52+
examples/test_using_gtest_failures.cpp
53+
examples/gtest_compatible_test_failures.h
54+
)
55+
target_link_libraries(test_using_gtest_failures GTest::gtest GTest::gtest_main)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
// gtest or simple_test shall be included prior to this one.
4+
5+
#include <cassert>
6+
#include <vector>
7+
8+
TEST(simple_test, lots_of_failed_expectations) {
9+
EXPECT_EQ(123, 456);
10+
EXPECT_TRUE(false);
11+
EXPECT_STREQ("hello", "world");
12+
EXPECT_STRNE("hello\0one", "hello\0two");
13+
std::cout << "some went wrong (or not...)" << std::endl;
14+
}
15+
16+
TEST(simple_test, some_assertion_failed) {
17+
ASSERT_EQ(123, 456);
18+
assert(false); // unreachable
19+
}
20+
21+
TEST(simple_test, raised_exception) {
22+
throw std::runtime_error("ooo");
23+
assert(false); // unreachable
24+
}
25+
26+
TEST(simple_test, some_fault_1) {
27+
FAIL(); // comments not supported yet
28+
assert(false); // unreachable
29+
}
30+
31+
TEST(simple_test, compare_floats_implicitly_failed) {
32+
const auto pivot = 123.4;
33+
const auto epsilon = 0.1;
34+
const auto tiny = 0.001;
35+
36+
EXPECT_NEAR(pivot, pivot - epsilon - tiny, epsilon);
37+
EXPECT_NEAR(pivot, pivot + epsilon + tiny, epsilon);
38+
}
39+
40+
TEST(simple_test, compare_types_failed) {
41+
EXPECT_EQ(typeid(int), typeid(char));
42+
}
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@ TEST(simple_test, vector_capacity) {
1212
EXPECT_NE(0, xs.capacity());
1313
}
1414

15-
TEST(simple_test, lots_of_failed_expectations) {
16-
EXPECT_EQ(123, 456);
17-
EXPECT_TRUE(false);
18-
EXPECT_STREQ("hello", "world");
19-
EXPECT_STRNE("hello\0one", "hello\0two");
20-
std::cout << "some went wrong (or not...)" << std::endl;
21-
}
22-
23-
TEST(simple_test, some_assertion_failed) {
24-
ASSERT_EQ(123, 456);
25-
assert(false); // unreachable
26-
}
27-
28-
TEST(simple_test, raised_exception) {
29-
throw std::runtime_error("ooo");
30-
assert(false); // unreachable
31-
}
32-
3315
TEST(DISABLED_simple_test, some_disabled) {
3416
assert(false); // unreachable
3517
}
@@ -38,11 +20,6 @@ TEST(simple_test, DISABLED_something) {
3820
assert(false); // unreachable
3921
}
4022

41-
TEST(simple_test, some_fault_1) {
42-
FAIL(); // comments not supported yet
43-
assert(false); // unreachable
44-
}
45-
4623
TEST(simple_test, some_correct) {
4724
const char h1[] = "hello";
4825
const char h2[] = "hello";
@@ -90,19 +67,6 @@ TEST(simple_test, compare_floats_implicitly) {
9067
EXPECT_NEAR(pivot, pivot + epsilon, epsilon);
9168
}
9269

93-
TEST(simple_test, compare_floats_implicitly_failed) {
94-
const auto pivot = 123.4;
95-
const auto epsilon = 0.1;
96-
const auto tiny = 0.001;
97-
98-
EXPECT_NEAR(pivot, pivot - epsilon - tiny, epsilon);
99-
EXPECT_NEAR(pivot, pivot + epsilon + tiny, epsilon);
100-
}
101-
10270
TEST(simple_test, compare_types) {
10371
EXPECT_EQ(typeid(int), typeid(int));
10472
}
105-
106-
TEST(simple_test, compare_types_failed) {
107-
EXPECT_EQ(typeid(int), typeid(char)) << "intentionally wrong condition";
108-
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "../simple_test.h"
2+
#include <cassert>
3+
4+
#include <vector>
5+
6+
TEST(should_fail, vector_capacity) {
7+
std::vector<int> xs;
8+
xs.reserve(100500);
9+
xs.clear();
10+
EXPECT_CMP(xs.capacity(), ==, 0U) << " ahaha ? ahaha!";
11+
ASSERT_CMP(xs.size(), ==, 1U) << " ahaha ? ahaha!";
12+
}
13+
14+
TEST(should_fail, lots_of_failed_expectations) {
15+
EXPECT_CMP(123, ==, 456);
16+
EXPECT_BOOL(true, false);
17+
EXPECT_STRCMP("hello", >, "world");
18+
EXPECT_STRCMP("hello\0one", !=, "hello\0two");
19+
std::cout << "some went wrong (or not...)" << std::endl;
20+
}
21+
22+
TEST(should_fail, some_assertion_failed) {
23+
ASSERT_CMP(123, ==, 456);
24+
assert(false); // unreachable
25+
}
26+
27+
TEST(should_fail, raised_exception) {
28+
throw std::runtime_error("ooo");
29+
assert(false); // unreachable
30+
}
31+
32+
TEST(should_fail, some_fault_1) {
33+
ASSERTION_FAULT() << "comment " << 123 << " goes here";
34+
assert(false); // unreachable
35+
}
36+
37+
TEST(should_fail, some_fault_2) {
38+
ASSERTION_FAULT();
39+
assert(false); // unreachable
40+
}
41+
42+
TEST(should_fail, strings) {
43+
EXPECT_EQ("aaa\x11", "aaa\x12") << simple_print::verbose("bbb\x13");
44+
}
45+
46+
TESTING_MAIN()
Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,10 @@
1-
#include "simple_test.h"
1+
#include "../simple_test.h"
22
#include <cassert>
33

4-
#include <vector>
5-
6-
#include <cxxabi.h>
7-
8-
TEST(should_fail, vector_capacity) {
9-
std::vector<int> xs;
10-
xs.reserve(100500);
11-
xs.clear();
12-
EXPECT_CMP(xs.capacity(), ==, 0) << " ahaha ? ahaha!";
13-
ASSERT_CMP(xs.size(), ==, 1) << " ahaha ? ahaha!";
14-
}
15-
16-
TEST(should_fail, lots_of_failed_expectations) {
17-
EXPECT_CMP(123, ==, 456);
18-
EXPECT_BOOL(true, false);
19-
EXPECT_STRCMP("hello", >, "world");
20-
EXPECT_STRCMP("hello\0one", !=, "hello\0two");
21-
std::cout << "some went wrong (or not...)" << std::endl;
22-
}
23-
24-
TEST(should_fail, some_assertion_failed) {
25-
ASSERT_CMP(123, ==, 456);
26-
assert(false); // unreachable
27-
}
28-
29-
TEST(should_fail, raised_exception) {
30-
throw std::runtime_error("ooo");
31-
assert(false); // unreachable
32-
}
33-
344
TEST(MUST_SKIP, some_disabled, false) {
355
assert(false); // unreachable
366
}
377

38-
TEST(should_fail, some_fault_1) {
39-
ASSERTION_FAULT() << "comment " << 123 << " goes here";
40-
assert(false); // unreachable
41-
}
42-
43-
TEST(should_fail, some_fault_2) {
44-
ASSERTION_FAULT();
45-
assert(false); // unreachable
46-
}
47-
488
TEST(simple_test, some_correct) {
499
const char h1[] = "hello";
5010
const char h2[] = "hello";
@@ -121,10 +81,6 @@ TEST(gtest_like, variety) {
12181
EXPECT_NEAR(123.4, 123.5, 0.1);
12282
}
12383

124-
TEST(should_fail, strings) {
125-
EXPECT_EQ("aaa\x11", "aaa\x12") << simple_print::verbose("bbb\x13");
126-
}
127-
12884
SHOW_GREEN_ASSERTIONS(true); // global flag
12985
TEST(green, visible_1) {
13086
EXPECT_TRUE("You must see this") << "and this";
@@ -146,5 +102,4 @@ TEST(green, invisible_4) {
146102
}
147103

148104

149-
150105
TESTING_MAIN()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <gtest/gtest.h>
2+
#include "gtest_compatible_test_failures.h"
3+
4+
// main() in linked
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#include <gtest/gtest.h>
2-
#include "gtest_compatible_test.h"
2+
#include "gtest_compatible_test_ok.h"
33

44
// main() in linked
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "../simple_test.h"
2+
#include "gtest_compatible_test_failures.h"
3+
4+
TESTING_MAIN()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "../simple_test.h"
2+
#include "gtest_compatible_test_ok.h"
3+
4+
TESTING_MAIN()

test_using_simple_test.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)