Skip to content

Commit 16da8be

Browse files
committed
use ctest and set path to dbc files with a compile definition
1 parent 9395a5d commit 16da8be

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

.github/workflows/tests.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ jobs:
1717
- uses: actions/checkout@v3
1818

1919
- name: Configure CMake
20-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
20+
run: |
21+
mkdir build
22+
cd build
23+
cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ..
2124
2225
- name: Build
23-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j
26+
run: |
27+
cd build
28+
make
2429
2530
- name: Test
26-
working-directory: ${{github.workspace}}/build
27-
# Didn't configure to use ctest. Opted for a custom target to run instead
28-
run: cmake --build ${{github.workspace}}/build --target test -- -j
31+
run: |
32+
cd build
33+
ctest --output-on-failure
2934

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.10)
33
project(dbc)
44

55
option(DEBUG "use debug flag" NO)
6+
option(ENABLE_TESTS "Enable Unittests" ON)
67

78
# specify the C++ standard
89
set(CMAKE_CXX_STANDARD 11)
@@ -31,7 +32,11 @@ list(APPEND SOURCE ${PROJECT_SOURCE_DIR}/src/utils.cpp
3132
include_directories(src)
3233
include_directories(include)
3334

34-
add_subdirectory(test)
35+
if(ENABLE_TESTS)
36+
include(CTest)
37+
add_subdirectory(test)
38+
endif()
39+
3540
add_subdirectory(doc)
3641

3742
add_library(${PROJECT_NAME} STATIC ${SOURCE})

test/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project(tests VERSION 0.1.0)
1+
enable_testing()
22

33
# Download and build Catch2 test framework
44
Include(FetchContent)
@@ -14,9 +14,11 @@ list(APPEND TEST_SOURCES
1414
test_utils.cpp)
1515

1616
add_executable(tests ${TEST_SOURCES} ${SOURCE})
17+
target_compile_definitions(tests PRIVATE TESTDBCFILES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/dbcs")
1718
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
19+
target_sources(tests INTERFACE FILE_SET HEADERS
20+
TYPE HEADERS
21+
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
22+
FILES defines.hpp)
1823

19-
add_custom_target(test
20-
COMMAND ${PROJECT_NAME}
21-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
22-
DEPENDS ${PROJECT_NAME})
24+
add_test(NAME tests COMMAND $<TARGET_FILE:tests>)

test/defines.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <string>
22

33
// Correctly formated files
4-
static const std::string COMPLEX_DBC_FILE = "./dbcs/Complex.dbc";
5-
static const std::string SIMPLE_DBC_FILE = "./dbcs/Simple.dbc";
4+
static const std::string COMPLEX_DBC_FILE = std::string(TESTDBCFILES_PATH) + "/Complex.dbc";
5+
static const std::string SIMPLE_DBC_FILE = std::string(TESTDBCFILES_PATH) + "/Simple.dbc";
66

77
// Files with Errors
8-
static const std::string MISSING_NEW_SYMBOLS_DBC_FILE = "./dbcs/MissingNewSymbols.dbc";
9-
static const std::string MISSING_VERSION_DBC_FILE = "./dbcs/MissingVersion.dbc";
10-
static const std::string MISSING_BIT_TIMING_DBC_FILE = "./dbcs/MissingBitTiming.dbc";
11-
static const std::string TEXT_FILE = "./dbcs/TextFile.txt";
8+
static const std::string MISSING_NEW_SYMBOLS_DBC_FILE = std::string(TESTDBCFILES_PATH) + "/MissingNewSymbols.dbc";
9+
static const std::string MISSING_VERSION_DBC_FILE = std::string(TESTDBCFILES_PATH) + "/MissingVersion.dbc";
10+
static const std::string MISSING_BIT_TIMING_DBC_FILE = std::string(TESTDBCFILES_PATH) + "/MissingBitTiming.dbc";
11+
static const std::string TEXT_FILE = std::string(TESTDBCFILES_PATH) + "/TextFile.txt";

0 commit comments

Comments
 (0)