Skip to content

Commit 607a54c

Browse files
committed
finish "step8":exercise 1
1 parent 46bcb68 commit 607a54c

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎Step8/CMakeLists.txt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ option(TUTORIAL_ENABLE_IPO "Check for and use IPO support" ON)
88

99
# TODO6: Add a default-ON option named BUILD_TESTING with a doc string of:
1010
# "Enable testing and build tests"
11-
11+
option(BUILD_TESTING "Enable testing and build tests" ON)
1212
if(TUTORIAL_ENABLE_IPO)
1313
include(CheckIPOSupported)
1414
check_ipo_supported(RESULT result OUTPUT output)
@@ -25,5 +25,9 @@ endif()
2525

2626
# TODO7: Conditional on the value of BUILD_TESTING, enable testing and add the
2727
# Tests subdirectory to the project
28+
if(BUILD_TESTING)
29+
enable_testing()
30+
add_subdirectory(Tests)
31+
endif()
2832

2933
add_subdirectory(MathFunctions)

‎Step8/CMakePresets.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"description": "Preset to use with the tutorial",
88
"binaryDir": "${sourceDir}/build",
99
"cacheVariables": {
10+
"CMAKE_CXX_COMPILER":"g++-13",
11+
"CMAKE_EXPORT_COMPILE_COMMANDS":"ON",
12+
1013
"TUTORIAL_USE_STD_SQRT": "OFF",
1114
"TUTORIAL_ENABLE_IPO": "OFF"
1215
}

‎Step8/Tests/CMakeLists.txt‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# TODO1: Add an executable target for the tests
2-
2+
add_executable(TestMath)
33
# TODO2: Add the TestMathFunctions.cxx file to the test target's sources
4-
4+
target_sources(TestMath
5+
PRIVATE
6+
TestMathFunctions.cxx)
57
# TODO3: Add the MathFunctions library to the test target's link libraries
6-
8+
target_link_libraries(TestMath
9+
PRIVATE
10+
MathFunctions)
711
# TODO4: Write a function that takes a single operation name as an argument.
812
# The function will call add_test() with the operation name as the NAME
913
# of the test, and a COMMAND of the form: <TestTarget> <operation name>
10-
11-
14+
function(MathFunctionTest op)
15+
add_test(
16+
NAME ${op}
17+
COMMAND TestMath ${op}
18+
)
19+
endfunction(MathFunctionTest op)
1220
# TODO5: Call the function for all four supported operations:
1321
# add, mul, sqrt, sub
22+
MathFunctionTest(add)
23+
MathFunctionTest(mul)
24+
MathFunctionTest(sqrt)
25+
MathFunctionTest(sub)

0 commit comments

Comments
 (0)