From 1d65e2196349c0be4830f6d911f0c44b0579d146 Mon Sep 17 00:00:00 2001 From: --replace-all Date: Wed, 8 Jan 2025 09:49:45 +0000 Subject: [PATCH 1/3] Add `TEST_PROPERTIES` keyword in `ecbuild_add_test` --- cmake/ecbuild_add_test.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/ecbuild_add_test.cmake b/cmake/ecbuild_add_test.cmake index 9f5bad86..0b455d73 100644 --- a/cmake/ecbuild_add_test.cmake +++ b/cmake/ecbuild_add_test.cmake @@ -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 # @@ -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} ) @@ -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 ) From 879bb3a0725c363d91b52453a1fe723096f678d8 Mon Sep 17 00:00:00 2001 From: Kevin Nobel Date: Tue, 14 Jan 2025 13:42:29 +0000 Subject: [PATCH 2/3] Add test for new `TEST_PROPERTIES` keyword --- tests/CMakeLists.txt | 1 + tests/test_properties/CMakeLists.txt | 7 ++++++ tests/test_properties/build-and-run.sh | 20 +++++++++++++++ .../test_project/CMakeLists.txt | 25 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 tests/test_properties/CMakeLists.txt create mode 100755 tests/test_properties/build-and-run.sh create mode 100644 tests/test_properties/test_project/CMakeLists.txt diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b68b2781..d95f6c7a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 ) diff --git a/tests/test_properties/CMakeLists.txt b/tests/test_properties/CMakeLists.txt new file mode 100644 index 00000000..db64bca8 --- /dev/null +++ b/tests/test_properties/CMakeLists.txt @@ -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} +) diff --git a/tests/test_properties/build-and-run.sh b/tests/test_properties/build-and-run.sh new file mode 100755 index 00000000..518a647c --- /dev/null +++ b/tests/test_properties/build-and-run.sh @@ -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) +ctest --test-dir $HERE/build -R write_world_after_hello + +# Check if the output is as expected +echo -n "Hello, World!" | diff - $HERE/build/output.txt diff --git a/tests/test_properties/test_project/CMakeLists.txt b/tests/test_properties/test_project/CMakeLists.txt new file mode 100644 index 00000000..302691ed --- /dev/null +++ b/tests/test_properties/test_project/CMakeLists.txt @@ -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" +) From 3b5db9c069a51c9bb0fe4a6b3ff36416a9fabdc2 Mon Sep 17 00:00:00 2001 From: Kevin Nobel Date: Wed, 15 Jan 2025 10:41:45 +0000 Subject: [PATCH 3/3] Avoid using `--test-dir` option in `ctest` --- tests/test_properties/build-and-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_properties/build-and-run.sh b/tests/test_properties/build-and-run.sh index 518a647c..24ecbe3e 100755 --- a/tests/test_properties/build-and-run.sh +++ b/tests/test_properties/build-and-run.sh @@ -14,7 +14,7 @@ echo $SOURCE ecbuild $SOURCE/test_project -B $HERE/build # Run only one specific test (which should invoke the others) -ctest --test-dir $HERE/build -R write_world_after_hello +(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