Skip to content
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

Add Test Creation Function #127

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,18 @@ include(cmake/Assertion.cmake)
if(ASSERT_ENABLE_TESTS)
enable_testing()

add_test(
NAME "inclusion of other modules"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/IncludeOtherModules.cmake)

add_test(
NAME "failure invocation"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/Fail.cmake)

add_test(
NAME "condition assertions"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/Assert.cmake)

add_test(
NAME "fatal error assertions"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/AssertFatalError.cmake)

add_test(
NAME "execute process assertions"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/AssertExecuteProcess.cmake)

add_test(
NAME "section creation"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/SectionCreation.cmake)
assertion_add_test(
"inclusion of other modules" test/IncludeOtherModules.cmake)

assertion_add_test("test creation" test/TestCreation.cmake)
assertion_add_test("failure invocation" test/Fail.cmake)
assertion_add_test("condition assertions" test/Assert.cmake)
assertion_add_test("fatal error assertions" test/AssertFatalError.cmake)

assertion_add_test(
"execute process assertions" test/AssertExecuteProcess.cmake)

assertion_add_test("section creation" test/SectionCreation.cmake)
endif()

if(ASSERT_ENABLE_INSTALL)
Expand Down
13 changes: 13 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ cmake_minimum_required(VERSION 3.17)
# This variable contains the path to the included `Assertion.cmake` module.
set(ASSERTION_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}")

# Add a new test that runs a CMake file in script mode.
#
# assertion_add_test(<name> <file>)
#
# This function adds a new test named `<name>` that will run the specified
# `<file>` CMake file in script mode.
function(assertion_add_test NAME FILE)
add_test(
NAME "${NAME}"
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
endfunction()

# Throws a formatted fatal error message.
#
# fail(<lines>...)
Expand Down
12 changes: 12 additions & 0 deletions test/TestCreation.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
section("it should correctly create a new test")
function(add_test)
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "NAME" "COMMAND")
assert(ARG_NAME STREQUAL "some test")

set(EXPECTED_COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/some_test.cmake)
assert(ARG_COMMAND STREQUAL EXPECTED_COMMAND)
endfunction()

assertion_add_test("some test" some_test.cmake)
endsection()