Skip to content

Commit d492c84

Browse files
pillo79kartben
authored andcommitted
tests: cmake: run zephyr_get() tests in script mode
Re-run the zephyr_get() testsuite in script mode after the project mode testsuite has been executed. This is to ensure that the zephyr_get() function works correctly in script mode as well. Signed-off-by: Luca Burelli <[email protected]>
1 parent 4e29a35 commit d492c84

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tests/cmake/zephyr_get/CMakeLists.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
cmake_minimum_required(VERSION 3.20.0)
44

5-
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6-
project(zephyr_get_test)
7-
target_sources(app PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c)
5+
if(CMAKE_SCRIPT_MODE_FILE)
6+
# Script mode initialization (re-run)
7+
set(ZEPHYR_BASE ${CMAKE_CURRENT_LIST_DIR}/../../../)
8+
list(APPEND CMAKE_MODULE_PATH "${ZEPHYR_BASE}/cmake/modules")
9+
include(extensions)
10+
else()
11+
# Project mode initialization (main CMake invocation)
12+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
13+
project(zephyr_get_test)
14+
target_sources(app PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c)
15+
endif()
816

917
if(SYSBUILD)
1018
get_property(IMAGE_NAME TARGET sysbuild_cache PROPERTY SYSBUILD_NAME)
@@ -73,6 +81,9 @@ function(assert_equal variable expected_value)
7381
endif()
7482

7583
set(info "${TEST_NAME}: ${variable} == '${actual_value}'")
84+
if(CMAKE_SCRIPT_MODE_FILE)
85+
string(PREPEND info "script mode ")
86+
endif()
7687
if("${actual_value}" STREQUAL "${expected_value}")
7788
message("PASS: ${info}")
7889
else()
@@ -584,3 +595,8 @@ run_suite(
584595
test_merge_reverse
585596
test_snippets_scope
586597
)
598+
599+
if (NOT CMAKE_SCRIPT_MODE_FILE AND NOT SYSBUILD)
600+
# Re-run this testsuite in plain script mode
601+
execute_process(COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_FILE})
602+
endif()

0 commit comments

Comments
 (0)