Skip to content

Commit

Permalink
Add tests according to Github issue #65
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbento committed Nov 5, 2024
1 parent 3ea1a7a commit 662902f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_subdirectory( ecbuild_find_package )
add_subdirectory( ecbuild_add_option )
add_subdirectory( ecbuild_add_flags )
add_subdirectory( find_ecbuild )
add_subdirectory( project_import )
add_subdirectory( ecbuild_shared_libs )
add_subdirectory( interface_library )
add_subdirectory( project_import )
add_subdirectory( project_summary )
7 changes: 7 additions & 0 deletions tests/project_summary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

ecbuild_add_test(
TARGET test_ecbuild_project_summary
TYPE SCRIPT
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure.sh
ENVIRONMENT CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
)
9 changes: 9 additions & 0 deletions tests/project_summary/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

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

# --------------------- cleanup ------------------------
echo "cleaning $HERE"
rm -rf $HERE/build_*
46 changes: 46 additions & 0 deletions tests/project_summary/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e

function EXPECT_ONE_OF()
{
local file=$1
local pattern=$2
local found=$(cat ${file} | grep "${pattern}" | wc -l | xargs)

if [ "$found" != "1" ]; then
echo "File ${file} does not contain exacly one of '$2'"
exit 1
fi
}

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

# --------------------- cleanup ------------------------
$SOURCE/clean.sh

# ----------------- configure project ---------------------

# Options: -DENABLE_MYFEATURE=ON

mkdir -p $HERE/build_1
ecbuild -DENABLE_MYFEATURE=ON $SOURCE/test_project -B $HERE/build_1 | tee $HERE/build_1.log
EXPECT_ONE_OF $HERE/build_1.log "* MYFEATURE, proja(✔): '', projb(✔): ''"

# Options: -DENABLE_MYFEATURE=ON -DPROJB_ENABLE_MYFEATURE=OFF

mkdir -p $HERE/build_2
ecbuild -DENABLE_MYFEATURE=ON -DPROJB_ENABLE_MYFEATURE=OFF $SOURCE/test_project -B $HERE/build_2 | tee $HERE/build_2.log
EXPECT_ONE_OF $HERE/build_2.log "* MYFEATURE, proja(✔): '', projb(✘): ''"

# Options: -DENABLE_MYFEATURE=OFF -DPROJB_ENABLE_MYFEATURE=ON

mkdir -p $HERE/build_3
ecbuild -DENABLE_MYFEATURE=OFF -DPROJB_ENABLE_MYFEATURE=ON $SOURCE/test_project -B $HERE/build_3 | tee $HERE/build_3.log
EXPECT_ONE_OF $HERE/build_3.log "* MYFEATURE, proja(✘): '', projb(✔): ''"
16 changes: 16 additions & 0 deletions tests/project_summary/test_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required( VERSION 3.18.4 FATAL_ERROR )
find_package( ecbuild 3.4 REQUIRED )

project( proja LANGUAGES NONE VERSION 0.2 )
ecbuild_add_option(
FEATURE MYFEATURE
DEFAULT ON
)

project( projb LANGUAGES NONE VERSION 0.1 )
ecbuild_add_option(
FEATURE MYFEATURE
DEFAULT OFF
)

ecbuild_print_summary()

0 comments on commit 662902f

Please sign in to comment.