-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wire up support for selftests #102
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b4832fa
cmake: drop unused `BUILD_TESTS` option
pks-t 759d092
clar: allow overriding current file, line and function
pks-t 671f47e
clar: fix platform-specific use of error codes
pks-t 6341120
clar: fix platform-specific behaviour of "%p"
pks-t 2392c8a
test: split out examples into their own directory
pks-t 48bb9c8
test: move tests into subdirectory
pks-t 7019cdd
test: drop global test counter
pks-t 28eb749
test: deterministic pointers
pks-t 724698a
test: exercise the clar itself
pks-t f68801e
ci: wire up support for testing
pks-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,28 @@ | ||
find_package(Python COMPONENTS Interpreter REQUIRED) | ||
|
||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite" | ||
COMMAND "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/generate.py" --output "${CMAKE_CURRENT_BINARY_DIR}" | ||
DEPENDS main.c example.c | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
) | ||
|
||
add_executable(example) | ||
set_target_properties(example PROPERTIES | ||
C_STANDARD 90 | ||
C_STANDARD_REQUIRED ON | ||
C_EXTENSIONS OFF | ||
) | ||
target_sources(example PRIVATE | ||
main.c | ||
example.c | ||
"${CMAKE_CURRENT_BINARY_DIR}/clar.suite" | ||
) | ||
target_compile_definitions(example PRIVATE) | ||
target_compile_options(example PRIVATE | ||
$<IF:$<CXX_COMPILER_ID:MSVC>,/W4,-Wall> | ||
) | ||
target_include_directories(example PRIVATE | ||
"${CMAKE_SOURCE_DIR}" | ||
"${CMAKE_CURRENT_BINARY_DIR}" | ||
) | ||
target_link_libraries(example clar) |
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,6 @@ | ||
#include "clar.h" | ||
|
||
void test_example__simple_assert(void) | ||
{ | ||
cl_assert_equal_i(1, 1); | ||
} |
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,39 +1,54 @@ | ||
add_subdirectory(selftest_suite) | ||
|
||
find_package(Python COMPONENTS Interpreter REQUIRED) | ||
|
||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite" | ||
COMMAND "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/generate.py" --output "${CMAKE_CURRENT_BINARY_DIR}" | ||
DEPENDS main.c sample.c clar_test.h | ||
DEPENDS main.c selftest.c | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
) | ||
|
||
add_executable(clar_test) | ||
set_target_properties(clar_test PROPERTIES | ||
add_executable(selftest) | ||
set_target_properties(selftest PROPERTIES | ||
C_STANDARD 90 | ||
C_STANDARD_REQUIRED ON | ||
C_EXTENSIONS OFF | ||
) | ||
|
||
# MSVC generates all kinds of warnings. We may want to fix these in the future | ||
# and then unconditionally treat warnings as errors. | ||
if(NOT MSVC) | ||
set_target_properties(clar_test PROPERTIES | ||
if (NOT MSVC) | ||
set_target_properties(selftest PROPERTIES | ||
COMPILE_WARNING_AS_ERROR ON | ||
) | ||
endif() | ||
|
||
target_sources(clar_test PRIVATE | ||
target_sources(selftest PRIVATE | ||
main.c | ||
sample.c | ||
selftest.c | ||
"${CMAKE_CURRENT_BINARY_DIR}/clar.suite" | ||
) | ||
target_compile_definitions(clar_test PRIVATE | ||
CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/" | ||
target_compile_definitions(selftest PRIVATE | ||
CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/expected/" | ||
) | ||
target_compile_options(clar_test PRIVATE | ||
target_compile_options(selftest PRIVATE | ||
$<IF:$<CXX_COMPILER_ID:MSVC>,/W4,-Wall> | ||
) | ||
target_include_directories(clar_test PRIVATE | ||
target_include_directories(selftest PRIVATE | ||
"${CMAKE_SOURCE_DIR}" | ||
"${CMAKE_CURRENT_BINARY_DIR}" | ||
) | ||
target_link_libraries(clar_test clar) | ||
target_link_libraries(selftest clar) | ||
|
||
add_test(NAME build_selftest_suite | ||
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config "$<CONFIG>" --target selftest_suite | ||
) | ||
set_tests_properties(build_selftest_suite PROPERTIES FIXTURES_SETUP clar_test_fixture) | ||
|
||
add_test(NAME build_selftest | ||
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config "$<CONFIG>" --target selftest | ||
) | ||
set_tests_properties(build_selftest PROPERTIES FIXTURES_SETUP clar_test_fixture) | ||
|
||
add_test(NAME selftest COMMAND "${CMAKE_CURRENT_BINARY_DIR}/selftest" "$<TARGET_FILE:selftest_suite>") | ||
set_tests_properties(selftest PROPERTIES FIXTURES_REQUIRED clar_test_fixture) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Usage: selftest [options] | ||
|
||
Options: | ||
-sname Run only the suite with `name` (can go to individual test name) | ||
-iname Include the suite with `name` | ||
-xname Exclude the suite with `name` | ||
-v Increase verbosity (show suite names) | ||
-q Only report tests that had an error | ||
-Q Quit as soon as a test fails | ||
-t Display results in tap format | ||
-l Print suite names | ||
-r[filename] Write summary file (to the optional filename) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is
if(BUILD_TESTING)
but this isoption(BUILD_TEST ...
above.I noticed because we introduce the
option(BUILD_EXAMPLE ...
below. I think we should have theoption
s specified in the same place, and that we probably wantBUILD_TEST
, notBUILD_TESTING
. (I would actually preferBUILD_TESTS
andBUILD_EXAMPLES
, as plural, but I wouldn't block over that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethomson
BUILD_TESTING
is actually set up viainclude(CTest)
, so it is what CMake itself declares to be the official option. So personally I'd agree thatBUILD_TEST
is saner, but CMake disagrees with both of us :/But yeah, you're right, we still have the old
BUILD_TESTS
in here, which has in fact been introduced via f255c0b (ci: convert to use CMake, 2024-09-05). Let me drop that.