Skip to content

Commit 9ee097e

Browse files
committed
refactor(templates): Consolidate duplicate test project scripts
Replaces test_project_root_containers.sh.in and test_project_stl_containers.sh.in with a single parameterized test_project.sh.in script to eliminate code duplication.
1 parent 676fb3b commit 9ee097e

3 files changed

Lines changed: 37 additions & 74 deletions

File tree

templates/CMakeLists.txt

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11

2-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_project_root_containers.sh.in
3-
${CMAKE_CURRENT_BINARY_DIR}/test_project_root_containers.sh
2+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_project.sh.in
3+
${CMAKE_CURRENT_BINARY_DIR}/test_project.sh
44
@ONLY)
5-
add_test(NAME project_root_containers
6-
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_project_root_containers.sh)
7-
set_tests_properties(project_root_containers PROPERTIES
8-
TIMEOUT "300"
9-
PASS_REGULAR_EXPRESSION "Test successful."
10-
)
11-
add_test(NAME project_root_containers_double
12-
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_project_root_containers.sh --double-configure)
13-
set_tests_properties(project_root_containers_double PROPERTIES
14-
TIMEOUT "300"
15-
PASS_REGULAR_EXPRESSION "Test successful."
16-
)
175

18-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_project_stl_containers.sh.in
19-
${CMAKE_CURRENT_BINARY_DIR}/test_project_stl_containers.sh
20-
@ONLY)
21-
add_test(NAME project_stl_containers
22-
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_project_stl_containers.sh)
23-
set_tests_properties(project_stl_containers PROPERTIES
24-
TIMEOUT "300"
25-
PASS_REGULAR_EXPRESSION "Test successful."
26-
)
27-
add_test(NAME project_stl_containers_double
28-
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_project_stl_containers.sh --double-configure)
29-
set_tests_properties(project_stl_containers_double PROPERTIES
30-
TIMEOUT "300"
31-
PASS_REGULAR_EXPRESSION "Test successful."
32-
)
6+
foreach(container_type IN ITEMS root stl)
7+
add_test(NAME project_${container_type}_containers
8+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_project.sh ${container_type})
9+
set_tests_properties(project_${container_type}_containers PROPERTIES
10+
TIMEOUT "300"
11+
PASS_REGULAR_EXPRESSION "Test successful."
12+
)
13+
14+
add_test(NAME project_${container_type}_containers_double
15+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_project.sh ${container_type} --double-configure)
16+
set_tests_properties(project_${container_type}_containers_double PROPERTIES
17+
TIMEOUT "300"
18+
PASS_REGULAR_EXPRESSION "Test successful."
19+
)
20+
endforeach()

templates/test_project_stl_containers.sh.in renamed to templates/test_project.sh.in

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22

33
set -x -e
44

5+
# Usage: test_project.sh <container_type> [--double-configure]
6+
# where container_type is either 'root' or 'stl'
7+
8+
if [ $# -lt 1 ]; then
9+
echo "Usage: $0 <container_type> [--double-configure]"
10+
echo " container_type: 'root' or 'stl'"
11+
exit 1
12+
fi
13+
14+
CONTAINER_TYPE=$1
15+
DOUBLE_CONFIGURE_FLAG=$2
16+
17+
if [[ "$CONTAINER_TYPE" != "root" && "$CONTAINER_TYPE" != "stl" ]]; then
18+
echo "Error: container_type must be 'root' or 'stl'"
19+
exit 1
20+
fi
21+
522
CURRENT_DIR=`pwd`
623
SOURCE_DIR=@CMAKE_SOURCE_DIR@
724
MYTMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
825

926
cd $MYTMPDIR
10-
cp -a $SOURCE_DIR/templates/project_stl_containers .
11-
cd project_stl_containers
27+
cp -a $SOURCE_DIR/templates/project_${CONTAINER_TYPE}_containers .
28+
cd project_${CONTAINER_TYPE}_containers
1229
./rename.sh TestProj Tst det
1330
mkdir build
1431
cd build
@@ -24,7 +41,7 @@ fi
2441

2542
cmake $parameters ..
2643

27-
if [[ "$1" = "--double-configure" ]]; then
44+
if [[ "$DOUBLE_CONFIGURE_FLAG" = "--double-configure" ]]; then
2845
echo "*** Calling cmake configure again:"
2946
# Check if all the cache variables
3047
# are good for a reconfiguration step
@@ -39,4 +56,3 @@ fi
3956

4057
cd $CURRENT_DIR
4158
rm -rf $MYTMPDIR
42-

templates/test_project_root_containers.sh.in

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)