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_PROPERTIES keyword in ecbuild_add_test #76

Merged
merged 3 commits into from
Jan 15, 2025
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
9 changes: 8 additions & 1 deletion cmake/ecbuild_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
# PROPERTIES : optional
# custom properties to set on the target
#
# TEST_PROPERTIES : optional
# custom properties to set on the test
#
# ENVIRONMENT : optional
# list of environment variables to set in the test environment
#
Expand Down Expand Up @@ -185,7 +188,7 @@ function( ecbuild_add_test )
set( single_value_args TARGET ENABLED COMMAND TYPE LINKER_LANGUAGE MPI OMP WORKING_DIRECTORY )
set( multi_value_args SOURCES OBJECTS LIBS INCLUDES TEST_DEPENDS DEPENDS LABELS ARGS
PERSISTENT DEFINITIONS RESOURCES TEST_DATA CFLAGS
CXXFLAGS FFLAGS GENERATED CONDITION PROPERTIES ENVIRONMENT )
CXXFLAGS FFLAGS GENERATED CONDITION TEST_PROPERTIES PROPERTIES ENVIRONMENT )

cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} )

Expand Down Expand Up @@ -467,6 +470,10 @@ function( ecbuild_add_test )
set_target_properties( ${_PAR_TARGET} PROPERTIES ${_PAR_PROPERTIES} )
endif()

if( DEFINED _PAR_TEST_PROPERTIES )
set_tests_properties( ${_PAR_TARGET} PROPERTIES ${_PAR_TEST_PROPERTIES} )
endif()

# get test data

if( _PAR_TEST_DATA )
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ add_subdirectory( interface_library )
add_subdirectory( project_import )
add_subdirectory( project_summary )
add_subdirectory( ecbuild_override_compiler_flags )
add_subdirectory( test_properties )
7 changes: 7 additions & 0 deletions tests/test_properties/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

ecbuild_add_test(
TARGET test_ecbuild_test_properties
TYPE SCRIPT
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build-and-run.sh
ENVIRONMENT CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
)
20 changes: 20 additions & 0 deletions tests/test_properties/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -e

HERE=${CMAKE_CURRENT_BINARY_DIR:-"$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd -P )"}
SOURCE=${CMAKE_CURRENT_SOURCE_DIR:-$HERE}

# Add ecbuild to path
export PATH=$SOURCE/../../bin:$PATH
echo $PATH
echo $SOURCE

# Build the project
ecbuild $SOURCE/test_project -B $HERE/build

# Run only one specific test (which should invoke the others)
(cd $HERE/build; ctest -R write_world_after_hello) # Avoid using --test-dir option in ctest

# Check if the output is as expected
echo -n "Hello, World!" | diff - $HERE/build/output.txt
25 changes: 25 additions & 0 deletions tests/test_properties/test_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)

find_package( ecbuild REQUIRED )
project( test_test_properties VERSION 0.1.0 LANGUAGES NONE )

ecbuild_add_test(
TARGET clean_output
TEST_PROPERTIES FIXTURES_SETUP clean_output
COMMAND ${CMAKE_COMMAND}
ARGS -E remove ${CMAKE_CURRENT_BINARY_DIR}/output.txt
)

ecbuild_add_test(
TARGET write_hello
TEST_PROPERTIES FIXTURES_SETUP write_hello FIXTURES_REQUIRED clean_output
COMMAND bash
ARGS -c "echo -n 'Hello, ' >> ${CMAKE_CURRENT_BINARY_DIR}/output.txt"
)

ecbuild_add_test(
TARGET write_world_after_hello
TEST_PROPERTIES FIXTURES_REQUIRED write_hello
COMMAND bash
ARGS -c "echo -n 'World!' >> ${CMAKE_CURRENT_BINARY_DIR}/output.txt"
)
Loading