-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
66 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ jobs: | |
- name: Run unit tests | ||
run: | | ||
cd build/test | ||
./events_test | ||
find . -type f -executable -exec {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
# Include the directory with your source files | ||
include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard/utils) | ||
include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard/utils .) | ||
|
||
add_executable(events_test events_test.cpp test_lib.cpp) | ||
# Create a variable to store the list of test files | ||
file(GLOB TEST_SOURCES utils/*.cpp) | ||
|
||
target_compile_definitions(events_test PRIVATE UNIT_TEST) | ||
# Loop through each test source file and create an executable | ||
foreach(TEST_SOURCE ${TEST_SOURCES}) | ||
# Extract the test name without extension | ||
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE) | ||
|
||
target_link_libraries(events_test) # Link to the library from devboard/utils | ||
# Create an executable for the test | ||
add_executable(${TEST_NAME} ${TEST_SOURCE} test_lib.cpp) | ||
|
||
# Register your tests with CTest | ||
add_test(NAME MyProjectTests COMMAND events_test) | ||
# Apply the target_compile_definitions for the test | ||
target_compile_definitions(${TEST_NAME} PRIVATE UNIT_TEST) | ||
|
||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
|
||
MySerial Serial; | ||
|
||
unsigned long test_millis = 0; | ||
unsigned long testlib_millis = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// The test library must be included first! | ||
#include "timer.cpp" | ||
#include "../test_lib.h" | ||
|
||
/* Helper functions */ | ||
|
||
/* Test functions */ | ||
|
||
TEST(timer_test) { | ||
unsigned long test_interval = 10; | ||
|
||
testlib_millis = 0; | ||
MyTimer timer(test_interval); | ||
ASSERT_EQ(timer.elapsed(), false); | ||
|
||
testlib_millis = test_interval - 1; | ||
ASSERT_EQ(timer.elapsed(), false); | ||
|
||
testlib_millis = test_interval; | ||
ASSERT_EQ(timer.elapsed(), true); | ||
ASSERT_EQ(timer.elapsed(), false); | ||
|
||
testlib_millis = 2 * test_interval - 1; | ||
ASSERT_EQ(timer.elapsed(), false); | ||
|
||
testlib_millis = 2 * test_interval; | ||
ASSERT_EQ(timer.elapsed(), true); | ||
ASSERT_EQ(timer.elapsed(), false); | ||
} | ||
|
||
TEST_MAIN(); |