1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Tests: Add XCTest cases to cover output directory selection

Fixes: #21800
This commit is contained in:
Yauheni Khnykin
2021-03-08 17:57:35 +01:00
parent ae791686e7
commit 74eda8ab1f
2 changed files with 43 additions and 0 deletions

View File

@@ -387,4 +387,30 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 8)
XcodeRemoveExcessiveISystemSDK(iphoneos)
XcodeRemoveExcessiveISystemSDK(iphonesimulator)
endif()
if (XCODE_VERSION VERSION_GREATER_EQUAL 7.3)
function(xctest_add_bundle_test SystemName SDK BuildSystemVersion ExpectedOutputDir)
set(RunCMake_TEST_BINARY_DIR
${RunCMake_BINARY_DIR}/DeploymentTarget-${SystemName}-${SDK}-${BuildSystemVersion}-build)
set(RunCMake_TEST_OPTIONS
"-DCMAKE_SYSTEM_NAME=${SystemName}"
"-DCMAKE_OSX_SYSROOT=${SDK}"
"-DTEST_EXPECTED_OUTPUT_DIR=${ExpectedOutputDir}")
unset(RunCMake_GENERATOR_TOOLSET)
if(BuildSystemVersion)
set(RunCMake_GENERATOR_TOOLSET "buildsystem=${BuildSystemVersion}")
endif()
run_cmake(XCTestAddBundle)
endfunction()
if(XCODE_VERSION VERSION_GREATER_EQUAL 12)
xctest_add_bundle_test(Darwin macosx "1" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
xctest_add_bundle_test(Darwin macosx "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
xctest_add_bundle_test(iOS iphoneos "1" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
xctest_add_bundle_test(iOS iphoneos "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>")
else()
xctest_add_bundle_test(Darwin macosx "" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
xctest_add_bundle_test(iOS iphoneos "" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
endif()
endif()
# Please add macOS-only tests above before the device-specific tests.

View File

@@ -0,0 +1,17 @@
enable_language(Swift)
find_package(XCTest REQUIRED)
add_executable(TestedApp MACOSX_BUNDLE EXCLUDE_FROM_ALL foo.swift)
xctest_add_bundle(TestingAppBundle TestedApp foo.swift)
get_target_property(_lib_output_dir TestingAppBundle LIBRARY_OUTPUT_DIRECTORY)
if (NOT DEFINED TEST_EXPECTED_OUTPUT_DIR)
message(FATAL_ERROR "Testing variable TEST_EXPECTED_OUTPUT_DIR is not set")
endif()
if (NOT _lib_output_dir STREQUAL TEST_EXPECTED_OUTPUT_DIR)
message(SEND_ERROR "Property LIBRARY_OUTPUT_DIRECTORY is expected to be ${TEST_EXPECTED_OUTPUT_DIR} "
"but was ${_lib_output_dir}")
endif()