mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 06:09:52 -06:00
Merge topic 'test-tutorial'
2d712a760e Tests: Convert Tutorial tests to RunCMake infrastructure
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10843
This commit is contained in:
@@ -1747,50 +1747,6 @@ if(BUILD_TESTING)
|
||||
add_installmode_test(SYMLINK_OR_COPY)
|
||||
endif()
|
||||
|
||||
|
||||
# do each of the tutorial steps
|
||||
function(add_tutorial_test step_name use_mymath tutorial_arg pass_regex)
|
||||
set(tutorial_test_name Tutorial${step_name})
|
||||
set(tutorial_build_dir "${CMake_BINARY_DIR}/Tests/Tutorial/${step_name}")
|
||||
if(use_mymath)
|
||||
set(tutorial_build_options "")
|
||||
else()
|
||||
set(tutorial_test_name ${tutorial_test_name}_MYMATH)
|
||||
set(tutorial_build_dir "${tutorial_build_dir}_MYMATH")
|
||||
set(tutorial_build_options -DUSE_MYMATH:BOOL=OFF)
|
||||
endif()
|
||||
add_test(${tutorial_test_name} ${CMAKE_CTEST_COMMAND}
|
||||
-C "Release"
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Help/guide/tutorial/${step_name}"
|
||||
${tutorial_build_dir}_Build
|
||||
${build_generator_args}
|
||||
--build-project Tutorial
|
||||
--build-options ${tutorial_build_options}
|
||||
--test-command Tutorial ${tutorial_arg})
|
||||
set_tests_properties(${tutorial_test_name} PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION ${pass_regex})
|
||||
|
||||
list(APPEND TEST_BUILD_DIRS "${tutorial_build_dir}_Build")
|
||||
endfunction()
|
||||
|
||||
if(NOT CMake_TEST_EXTERNAL_CMAKE)
|
||||
foreach(STP RANGE 2 12)
|
||||
if(STP EQUAL 8)
|
||||
set(pass_regex ".*using log and exp")
|
||||
else()
|
||||
set(pass_regex "The square root of 25 is 5")
|
||||
endif()
|
||||
add_tutorial_test(Step${STP} TRUE 25 ${pass_regex})
|
||||
endforeach()
|
||||
set(pass_regex "The square root of 25 is 5")
|
||||
add_tutorial_test(Complete TRUE 25 ${pass_regex})
|
||||
foreach(STP RANGE 3 12)
|
||||
add_tutorial_test(Step${STP} FALSE 25 ${pass_regex})
|
||||
endforeach()
|
||||
add_tutorial_test(Complete FALSE 25 ${pass_regex})
|
||||
endif()
|
||||
|
||||
function(add_importexport_test export_name import_name)
|
||||
set(install_dir
|
||||
"${CMake_BINARY_DIR}/Tests/ImportExport/Install${export_name}")
|
||||
|
||||
@@ -582,6 +582,11 @@ add_RunCMake_test(TargetArtifacts -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
|
||||
add_RunCMake_test(TargetObjects)
|
||||
add_RunCMake_test(TargetProperties)
|
||||
add_RunCMake_test(ToolchainFile)
|
||||
if(NOT CMake_TEST_EXTERNAL_CMAKE)
|
||||
set(Tutorial_ARGS TEST_DIR Tutorial -DTutorial_SOURCE_DIR=${CMake_SOURCE_DIR}/Help/guide/tutorial)
|
||||
add_RunCMake_test(Tutorial-NoMath ${Tutorial_ARGS} -DTutorial_USE_MYMATH=OFF)
|
||||
add_RunCMake_test(Tutorial-MyMath ${Tutorial_ARGS} -DTutorial_USE_MYMATH=ON)
|
||||
endif()
|
||||
add_RunCMake_test(find_dependency)
|
||||
add_RunCMake_test(CompileDefinitions)
|
||||
add_RunCMake_test(CompileWarningAsError
|
||||
|
||||
39
Tests/RunCMake/Tutorial/RunCMakeTest.cmake
Normal file
39
Tests/RunCMake/Tutorial/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,39 @@
|
||||
include(RunCMake)
|
||||
|
||||
function(run_tutorial_step name)
|
||||
set(RunCMake_TEST_SOURCE_DIR ${Tutorial_SOURCE_DIR}/${name})
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build)
|
||||
if(Tutorial_USE_MYMATH)
|
||||
set(math MyMath)
|
||||
else()
|
||||
set(math NoMath)
|
||||
endif()
|
||||
set(config Release)
|
||||
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
|
||||
set(exe ${RunCMake_TEST_BINARY_DIR}/${config}/Tutorial)
|
||||
else()
|
||||
set(exe ${RunCMake_TEST_BINARY_DIR}/Tutorial)
|
||||
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=${config})
|
||||
endif()
|
||||
list(APPEND RunCMake_TEST_OPTIONS -DUSE_MYMATH:BOOL=${Tutorial_USE_MYMATH})
|
||||
run_cmake(${name}-configure)
|
||||
unset(RunCMake_TEST_OPTIONS)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
set(RunCMake_TEST_OUTPUT_MERGE 1)
|
||||
run_cmake_command(${name}-build ${CMAKE_COMMAND} --build . --config ${config})
|
||||
unset(RunCMake_TEST_OUTPUT_MERGE)
|
||||
if(EXISTS ${RunCMake_SOURCE_DIR}/${name}-${math}-run-stdout.txt)
|
||||
set(RunCMake-stdout-file ${name}-${math}-run-stdout.txt)
|
||||
else()
|
||||
set(RunCMake-stdout-file Step-${math}-run-stdout.txt)
|
||||
endif()
|
||||
run_cmake_command(${name}-run ${exe} 25)
|
||||
endfunction()
|
||||
|
||||
if(NOT Tutorial_USE_MYMATH)
|
||||
run_tutorial_step(Step2)
|
||||
endif()
|
||||
foreach(step RANGE 3 12)
|
||||
run_tutorial_step(Step${step})
|
||||
endforeach()
|
||||
run_tutorial_step(Complete)
|
||||
2
Tests/RunCMake/Tutorial/Step-MyMath-run-stdout.txt
Normal file
2
Tests/RunCMake/Tutorial/Step-MyMath-run-stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
^(Computing sqrt of 25 to be [0-9.]+
|
||||
)+The square root of 25 is 5$
|
||||
1
Tests/RunCMake/Tutorial/Step-NoMath-run-stdout.txt
Normal file
1
Tests/RunCMake/Tutorial/Step-NoMath-run-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
^The square root of 25 is 5$
|
||||
2
Tests/RunCMake/Tutorial/Step8-MyMath-run-stdout.txt
Normal file
2
Tests/RunCMake/Tutorial/Step8-MyMath-run-stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
^Computing sqrt of 25 to be 5 using log and exp
|
||||
The square root of 25 is 5$
|
||||
Reference in New Issue
Block a user