Skip to content

Commit 015fdd8

Browse files
author
Kartik Kumar
committed
Add find_package for Catch2 to check if library is installed on system path first. Make various formatting updates.
1 parent b4939c0 commit 015fdd8

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

apps/cppbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "cppbase/cppbaseAll.hpp"
1111

12-
int main( const int numberOfInputs, const char* inputArguments[ ] )
12+
int main(const int numberOfInputs, const char* inputArguments[])
1313
{
1414
const int factorial = cppbase::computeFactorial(10);
1515
std::cout << "10! = " << factorial << std::endl;

apps/helloWorld.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <cstdlib>
88
#include <iostream>
99

10-
int main( const int numberOfInputs, const char* inputArguments[ ] )
10+
int main(const int numberOfInputs, const char* inputArguments[ ])
1111
{
1212
std::cout << "Hello World!" << std::endl;
1313
return EXIT_SUCCESS;

cmake

Submodule cmake updated 1 file

tests/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
# @TODO: add find_package call to use Catch2 that is already present and only fetch otherwise
1010
# @TODO: consider only using the Catch2 single header to avoid building the whole library (slow)
1111

12-
# Fetch Catch2 testing library
13-
FetchContent_Declare(
14-
Catch2
15-
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
16-
GIT_TAG v3.0.1 # or a later release
17-
)
18-
FetchContent_MakeAvailable(Catch2)
12+
find_package(Catch2 3 REQUIRED)
13+
if(TARGET Catch2::Catch2)
14+
message(STATUS "Found Catch2")
15+
else()
16+
# Fetch Catch2 testing library
17+
FetchContent_Declare(
18+
Catch2
19+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
20+
GIT_TAG v3.0.1 # or a later release
21+
)
22+
FetchContent_MakeAvailable(Catch2)
23+
endif(TARGET Catch2::Catch2)
1924

2025
# Add test executables and linked libraries
2126
add_executable(cppbase_tests testFactorial.cpp)

tests/testFactorial.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace cppbase
1313
namespace tests
1414
{
1515

16-
TEST_CASE( "Compute factorials", "[factorial]" )
16+
TEST_CASE("Compute factorials", "[factorial]")
1717
{
18-
REQUIRE( computeFactorial(1) == 1 );
19-
REQUIRE( computeFactorial(2) == 2 );
20-
REQUIRE( computeFactorial(3) == 6 );
21-
REQUIRE( computeFactorial(10) == 3628800 );
18+
REQUIRE(computeFactorial(1) == 1);
19+
REQUIRE(computeFactorial(2) == 2);
20+
REQUIRE(computeFactorial(3) == 6);
21+
REQUIRE(computeFactorial(10) == 3628800);
2222
}
2323

2424
} // namespace tests

0 commit comments

Comments
 (0)