Skip to content

Commit 302ff5b

Browse files
committed
Use CTest for running tests
and update names of test sources and build targets
1 parent 5683dfc commit 302ff5b

File tree

1 file changed

+82
-61
lines changed

1 file changed

+82
-61
lines changed

CMakeLists.txt

+82-61
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
22

33
project(BigInt)
44

5-
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
5+
if(ENABLE_COVERAGE)
66
set(CMAKE_BUILD_TYPE Coverage)
77
else()
88
set(CMAKE_BUILD_TYPE Debug)
@@ -17,75 +17,96 @@ include_directories(include)
1717
set(CMAKE_CXX_STANDARD 14)
1818
set(CMAKE_CXX_FLAGS "-g -O0 -Wall -Wextra -pedantic-errors")
1919

20-
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
21-
# Add coverage flags
22-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
23-
24-
# Include code coverage module
25-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/modules/")
26-
include(CodeCoverage)
27-
set(LCOV_REMOVE_EXTRA "'/usr/*'" "'test/*'" "'build/*'" "'include/third_party/*'")
28-
endif()
29-
3020
# Test runner
3121
add_library(TestRunner STATIC
3222
test/test_runner.cpp)
3323

3424
# Constructors:
35-
add_executable(Constructors.Test
36-
test/constructors/constructors.test.cpp)
37-
target_link_libraries(Constructors.Test TestRunner)
25+
add_executable(ConstructorsTest
26+
test/constructors/constructors.cpp)
27+
target_link_libraries(ConstructorsTest TestRunner)
3828

3929
# Functions:
40-
add_executable(Functions.Conversion.Test
41-
test/functions/conversion.test.cpp)
42-
target_link_libraries(Functions.Conversion.Test TestRunner)
30+
add_executable(FunctionsConversionTest
31+
test/functions/conversion.cpp)
32+
target_link_libraries(FunctionsConversionTest TestRunner)
4333

44-
add_executable(Functions.Math.Test
45-
test/functions/math.test.cpp)
46-
target_link_libraries(Functions.Math.Test TestRunner)
34+
add_executable(FunctionsMathTest
35+
test/functions/math.cpp)
36+
target_link_libraries(FunctionsMathTest TestRunner)
4737

48-
add_executable(Functions.Random.Test
49-
test/functions/random.test.cpp)
50-
target_link_libraries(Functions.Random.Test TestRunner)
38+
add_executable(FunctionsRandomTest
39+
test/functions/random.cpp)
40+
target_link_libraries(FunctionsRandomTest TestRunner)
5141

5242
# Operators:
53-
add_executable(Operators.ArithmeticAssignment.Test
54-
test/operators/arithmetic_assignment.test.cpp)
55-
target_link_libraries(Operators.ArithmeticAssignment.Test TestRunner)
56-
57-
add_executable(Operators.Assignment.Test
58-
test/operators/assignment.test.cpp)
59-
target_link_libraries(Operators.Assignment.Test TestRunner)
60-
61-
add_executable(Operators.BinaryArithmetic.Test
62-
test/operators/binary_arithmetic.test.cpp)
63-
target_link_libraries(Operators.BinaryArithmetic.Test TestRunner)
64-
65-
add_executable(Operators.IncrementDecrement.Test
66-
test/operators/increment_decrement.test.cpp)
67-
target_link_libraries(Operators.IncrementDecrement.Test TestRunner)
68-
69-
add_executable(Operators.IOStream.Test
70-
test/operators/io_stream.test.cpp)
71-
target_link_libraries(Operators.IOStream.Test TestRunner)
72-
73-
add_executable(Operators.Relational.Test
74-
test/operators/relational.test.cpp)
75-
target_link_libraries(Operators.Relational.Test TestRunner)
76-
77-
add_executable(Operators.UnaryArithmetic.Test
78-
test/operators/unary_arithmetic.test.cpp)
79-
target_link_libraries(Operators.UnaryArithmetic.Test TestRunner)
80-
81-
# Combined test
82-
add_executable(Combined.Test
83-
build/combined.test.cpp)
84-
target_link_libraries(Combined.Test TestRunner)
85-
86-
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
87-
# Target for combined test coverage
88-
SETUP_TARGET_FOR_COVERAGE(combined_test_coverage # make target
89-
Combined.Test # executable
90-
coverage) # directory
43+
add_executable(OperatorsArithmeticAssignmentTest
44+
test/operators/arithmetic_assignment.cpp)
45+
target_link_libraries(OperatorsArithmeticAssignmentTest TestRunner)
46+
47+
add_executable(OperatorsAssignmentTest
48+
test/operators/assignment.cpp)
49+
target_link_libraries(OperatorsAssignmentTest TestRunner)
50+
51+
add_executable(OperatorsBinaryArithmeticTest
52+
test/operators/binary_arithmetic.cpp)
53+
target_link_libraries(OperatorsBinaryArithmeticTest TestRunner)
54+
55+
add_executable(OperatorsIncrementDecrementTest
56+
test/operators/increment_decrement.cpp)
57+
target_link_libraries(OperatorsIncrementDecrementTest TestRunner)
58+
59+
add_executable(OperatorsIOStreamTest
60+
test/operators/io_stream.cpp)
61+
target_link_libraries(OperatorsIOStreamTest TestRunner)
62+
63+
add_executable(OperatorsRelationalTest
64+
test/operators/relational.cpp)
65+
target_link_libraries(OperatorsRelationalTest TestRunner)
66+
67+
add_executable(OperatorsUnaryArithmeticTest
68+
test/operators/unary_arithmetic.cpp)
69+
target_link_libraries(OperatorsUnaryArithmeticTest TestRunner)
70+
71+
if(ENABLE_COVERAGE)
72+
# Include code coverage module
73+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
74+
find_package(codecov)
75+
add_coverage(ConstructorsTest)
76+
add_coverage(FunctionsConversionTest)
77+
add_coverage(FunctionsMathTest)
78+
add_coverage(FunctionsRandomTest)
79+
add_coverage(OperatorsArithmeticAssignmentTest)
80+
add_coverage(OperatorsAssignmentTest)
81+
add_coverage(OperatorsBinaryArithmeticTest)
82+
add_coverage(OperatorsIncrementDecrementTest)
83+
add_coverage(OperatorsIOStreamTest)
84+
add_coverage(OperatorsRelationalTest)
85+
add_coverage(OperatorsUnaryArithmeticTest)
86+
list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'" "'include/third_party/*'")
87+
coverage_evaluate()
9188
endif()
89+
90+
include(CTest)
91+
add_test(NAME ConstructorsTest
92+
COMMAND $<TARGET_FILE:ConstructorsTest>)
93+
add_test(NAME FunctionsConversionTest
94+
COMMAND $<TARGET_FILE:FunctionsConversionTest>)
95+
add_test(NAME FunctionsMathTest
96+
COMMAND $<TARGET_FILE:FunctionsMathTest>)
97+
add_test(NAME FunctionsRandomTest
98+
COMMAND $<TARGET_FILE:FunctionsRandomTest>)
99+
add_test(NAME OperatorsArithmeticAssignmentTest
100+
COMMAND $<TARGET_FILE:OperatorsArithmeticAssignmentTest>)
101+
add_test(NAME OperatorsAssignmentTest
102+
COMMAND $<TARGET_FILE:OperatorsAssignmentTest>)
103+
add_test(NAME OperatorsBinaryArithmeticTest
104+
COMMAND $<TARGET_FILE:OperatorsBinaryArithmeticTest>)
105+
add_test(NAME OperatorsIncrementDecrementTest
106+
COMMAND $<TARGET_FILE:OperatorsIncrementDecrementTest>)
107+
add_test(NAME OperatorsIOStreamTest
108+
COMMAND $<TARGET_FILE:OperatorsIOStreamTest>)
109+
add_test(NAME OperatorsRelationalTest
110+
COMMAND $<TARGET_FILE:OperatorsRelationalTest>)
111+
add_test(NAME OperatorsUnaryArithmeticTest
112+
COMMAND $<TARGET_FILE:OperatorsUnaryArithmeticTest>)

0 commit comments

Comments
 (0)