Skip to content

Commit

Permalink
tests: first step towards automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
riebl committed Jul 7, 2021
1 parent 1835fc4 commit 4e4256c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project(OmnetppCmakeTests)
cmake_minimum_required(VERSION 3.13)
enable_testing()

add_test(NAME FindOMNeT++
COMMAND ${CMAKE_COMMAND}
-DBUILD_DIRECTORY=${PROJECT_BINARY_DIR}
-DTEST_SUITE=find-omnetpp
-P RunTestSuite.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
12 changes: 12 additions & 0 deletions tests/RunTestSuite.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if(NOT TEST_SUITE)
message(FATAL_ERROR "run_test: missing TEST_SUITE parameter")
endif()
if(NOT BUILD_DIRECTORY)
message(FATAL_ERROR "run_test: missing BUILD_DIRECTORY parameter")
endif()

execute_process(COMMAND ${CMAKE_COMMAND} -S ${TEST_SUITE} -B ${BUILD_DIRECTORY}/${TEST_SUITE}
RESULT_VARIABLE setup_test_suite)
if(setup_test_suite)
message(FATAL_ERROR "run_test: setting up test suite failed")
endif()
19 changes: 19 additions & 0 deletions tests/TestSuiteHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(OMNETPP_CMAKE_ROOT ${CMAKE_CURRENT_LIST_DIR}/..)

macro(require_envvar)
set(envvar_list "${ARGN}")
foreach(envvar IN LISTS envvar_list)
if(NOT DEFINED ENV{${envvar}})
message(FATAL_ERROR "require_envvar: ${envvar} is missing")
endif()
endforeach()
endmacro()

macro(expect_strequal expected actual)
if(NOT DEFINED ${actual})
message(FATAL_ERROR "expect_strequal: variable ${actual} does not exist")
endif()
if(NOT "${expected}" STREQUAL "${${actual}}")
message(FATAL_ERROR "Expected ${actual} to equal \"${expected}\", but it is \"${${actual}}\"")
endif()
endmacro()
10 changes: 10 additions & 0 deletions tests/find-omnetpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project(FindOmnetppTest)
cmake_minimum_required(VERSION 3.13)
include(${PROJECT_SOURCE_DIR}/../TestSuiteHelpers.cmake)
set(CMAKE_MODULE_PATH ${OMNETPP_CMAKE_ROOT})

find_package(OmnetPP REQUIRED)

require_envvar(EXPECTED_OMNETPP_ROOT EXPECTED_OMNETPP_VERSION)
expect_strequal($ENV{EXPECTED_OMNETPP_ROOT} OMNETPP_ROOT)
expect_strequal($ENV{EXPECTED_OMNETPP_VERSION} OMNETPP_VERSION)

0 comments on commit 4e4256c

Please sign in to comment.