Tests: Move TryCompile check module cases to RunCMake.Check*

The latter already have similar checks for similar modules.
This commit is contained in:
Brad King
2022-10-06 09:46:42 -04:00
parent 64ac01451d
commit 90aa0bb305
14 changed files with 226 additions and 144 deletions

View File

@@ -0,0 +1,27 @@
enable_language (C)
include(CheckCCompilerFlag)
set(C 1) # test that this is tolerated
if(NOT CMAKE_C_COMPILER_ID STREQUAL "PathScale")
set(DD --)
endif()
check_c_compiler_flag("${DD}-_this_is_not_a_flag_" C_BOGUS_FLAG)
if(C_BOGUS_FLAG)
message(SEND_ERROR "CHECK_C_COMPILER_FLAG() succeeded, but should have failed")
endif()
unset(C_BOGUS_FLAG CACHE)
if(DEFINED C_BOGUS_FLAG)
# Verify that CHECK_C_COMPILER_FLAG didn't construct a normal variable
message(SEND_ERROR "CHECK_C_COMPILER_FLAG shouldn't construct C_BOGUS_FLAG as a normal variable")
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "LCC")
unset(C_STRICT_PROTOTYPES CACHE)
CHECK_C_COMPILER_FLAG("-Werror;-Wstrict-prototypes" C_STRICT_PROTOTYPES)
if(NOT C_STRICT_PROTOTYPES)
message(SEND_ERROR "CHECK_C_COMPILER_FLAG failed -Werror -Wstrict-prototypes")
endif()
endif()

View File

@@ -0,0 +1,19 @@
enable_language (CXX)
include(CheckCXXCompilerFlag)
set(CXX 1) # test that this is tolerated
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "PathScale")
set(DD --)
endif()
check_cxx_compiler_flag("${DD}-_this_is_not_a_flag_" CXX_BOGUS_FLAG)
if(CXX_BOGUS_FLAG)
message(SEND_ERROR "CHECK_CXX_COMPILER_FLAG() succeeded, but should have failed")
endif()
unset(CXX_BOGUS_FLAG CACHE)
if(DEFINED CXX_BOGUS_FLAG)
# Verify that CHECK_CXX_COMPILER_FLAG didn't construct a normal variable
message(SEND_ERROR "CHECK_CXX_COMPILER_FLAG shouldn't construct CXX_BOGUS_FLAG as a normal variable")
endif()

View File

@@ -3,6 +3,8 @@ include(RunCMake)
run_cmake(NotEnabledLanguage)
run_cmake(NonExistentLanguage)
run_cmake(CheckCCompilerFlag)
run_cmake(CheckCXXCompilerFlag)
run_cmake(CheckCompilerFlagC)
run_cmake(CheckCompilerFlagCXX)

View File

@@ -0,0 +1,15 @@
enable_language (C)
include(CheckCSourceCompiles)
set(C 1) # test that this is tolerated
check_c_source_compiles("I don't build" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "invalid C source didn't fail.")
endif()
check_c_source_compiles("int main() {return 0;}" SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for valid C source.")
endif()

View File

@@ -0,0 +1,28 @@
enable_language (CXX)
include(CheckCXXSourceCompiles)
set(CXX 1) # test that this is tolerated
check_cxx_source_compiles("I don't build" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "invalid CXX source didn't fail.")
endif()
check_cxx_source_compiles([=[
#include <vector>
int main() {
return 0;
}
]=]
SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for valid CXX source.")
endif()
CHECK_CXX_SOURCE_COMPILES("void l(char const (&x)[2]){}; int main() { l(\"\\\\n\"); return 0;}"
SHOULD_BUILD_COMPLEX)
if(NOT SHOULD_BUILD_COMPLEX)
message(SEND_ERROR "Test fail for valid CXX complex source.")
endif()

View File

@@ -0,0 +1,21 @@
enable_language (OBJC)
include(CheckOBJCSourceCompiles)
set(OBJC 1) # test that this is tolerated
check_objc_source_compiles("I don't build in Objective-C" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "invalid OBJC source didn't fail.")
endif()
check_objc_source_compiles([[
#import <Foundation/Foundation.h>
int main() {
NSObject *foo;
return 0;
}
]] SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for valid OBJC source.")
endif()

View File

@@ -0,0 +1,24 @@
enable_language (OBJCXX)
include(CheckOBJCXXSourceCompiles)
set(OBJCXX 1) # test that this is tolerated
check_objcxx_source_compiles("I don't build in Objective-C++" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "invalid OBJCXX source didn't fail.")
endif()
check_objcxx_source_compiles([[
#include <vector>
#import <Foundation/Foundation.h>
int main() {
std::vector<int> v;
NSObject *foo;
return 0;
}
]] SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for OBJCXX source.")
endif()

View File

@@ -4,10 +4,14 @@ run_cmake(NotEnabledLanguage)
run_cmake(NonExistentLanguage)
run_cmake(UnknownArgument)
run_cmake(CheckCSourceCompiles)
run_cmake(CheckCXXSourceCompiles)
run_cmake(CheckSourceCompilesC)
run_cmake(CheckSourceCompilesCXX)
if (APPLE)
run_cmake(CheckOBJCSourceCompiles)
run_cmake(CheckOBJCXXSourceCompiles)
run_cmake(CheckSourceCompilesOBJC)
run_cmake(CheckSourceCompilesOBJCXX)
endif()

View File

@@ -0,0 +1,15 @@
enable_language (C)
include(CheckCSourceRuns)
set(C 1) # test that this is tolerated
check_c_source_runs("int main() {return 2;}" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "check_c_source_runs succeeded, but should have failed.")
endif()
check_c_source_runs("int main() {return 0;}" SHOULD_RUN)
if(NOT SHOULD_RUN)
message(SEND_ERROR "check_c_source_runs failed for valid C executable.")
endif()

View File

@@ -0,0 +1,22 @@
enable_language (CXX)
include(CheckCXXSourceRuns)
set(CXX 1) # test that this is tolerated
check_cxx_source_runs("int main() {return 2;}" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "check_cxx_source_runs succeeded, but should have failed.")
endif()
check_cxx_source_runs(
[=[
#include <vector>
int main() {
return 0;
}
]=]
SHOULD_RUN)
if(NOT SHOULD_RUN)
message(SEND_ERROR "check_cxx_source_runs failed for valid C executable.")
endif()

View File

@@ -0,0 +1,21 @@
enable_language (OBJC)
include(CheckOBJCSourceRuns)
set(OBJC 1) # test that this is tolerated
check_objc_source_runs("int main() {return 2;}" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "check_objc_source_runs succeeded, but should have failed.")
endif()
check_objc_source_runs([[
#import <Foundation/Foundation.h>
int main() {
NSObject *foo;
return 0;
}
]] SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for valid OBJC source.")
endif()

View File

@@ -0,0 +1,24 @@
enable_language (OBJCXX)
include(CheckOBJCXXSourceRuns)
set(OBJCXX 1) # test that this is tolerated
check_objcxx_source_runs("int main() {return 2;}" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "check_objcxx_source_runs succeeded, but should have failed.")
endif()
check_objcxx_source_runs([[
#include <vector>
#import <Foundation/Foundation.h>
int main() {
std::vector<int> v;
NSObject *foo;
return 0;
}
]] SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for OBJCXX source.")
endif()

View File

@@ -4,10 +4,14 @@ run_cmake(NotEnabledLanguage)
run_cmake(NonExistentLanguage)
run_cmake(UnknownArgument)
run_cmake(CheckCSourceRuns)
run_cmake(CheckCXXSourceRuns)
run_cmake(CheckSourceRunsC)
run_cmake(CheckSourceRunsCXX)
if (APPLE)
run_cmake(CheckOBJCSourceRuns)
run_cmake(CheckOBJCXXSourceRuns)
run_cmake(CheckSourceRunsOBJC)
run_cmake(CheckSourceRunsOBJCXX)
endif()

View File

@@ -34,30 +34,6 @@ macro(TEST_ASSERT value msg)
endif ()
endmacro()
macro(TEST_FAIL value msg)
if (${value})
message (SEND_ERROR "Failing test succeeded:" ${msg} )
endif ()
endmacro()
macro(TEST_EXPECT_EXACT command expected)
if(NOT "x${result}" STREQUAL "x${expected}")
message(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
endif()
endmacro()
macro(TEST_EXPECT_CONTAINS command expected)
if(NOT "${result}" MATCHES "${expected}")
message(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
endif()
endmacro()
if (APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
endif()
# run old signature tests
set(try_compile_bindir_or_SOURCES ${TryCompile_BINARY_DIR})
set(try_compile_redundant_SOURCES SOURCES)
@@ -136,126 +112,6 @@ TEST_ASSERT(TEST_INNER "try_compile project mode failed:\n${output}")
add_executable(TryCompile pass.c)
#######################################################################
#
# also test that the CHECK_C_SOURCE_COMPILES, CHECK_CXX_SOURCE_COMPILES
# CHECK_C_SOURCE_RUNS and CHECK_CXX_SOURCE_RUNS macros work
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckCSourceRuns)
include(CheckCXXSourceRuns)
CHECK_C_SOURCE_COMPILES("I don't build" C_BUILD_SHOULD_FAIL)
CHECK_C_SOURCE_COMPILES("int main() {return 0;}" C_BUILD_SHOULD_WORK)
CHECK_C_SOURCE_RUNS("int main() {return 1;}" C_RUN_SHOULD_FAIL)
CHECK_C_SOURCE_RUNS("int main() {return 0;}" C_RUN_SHOULD_WORK)
TEST_FAIL(C_BUILD_SHOULD_FAIL "CHECK_C_SOURCE_COMPILES() succeeded, but should have failed")
TEST_ASSERT(C_BUILD_SHOULD_WORK "CHECK_C_SOURCE_COMPILES() failed")
TEST_FAIL(C_RUN_SHOULD_FAIL "CHECK_C_SOURCE_RUNS() succeeded, but should have failed")
TEST_ASSERT(C_RUN_SHOULD_WORK "CHECK_C_SOURCE_RUNS() failed")
CHECK_CXX_SOURCE_COMPILES("I don't build" CXX_BUILD_SHOULD_FAIL)
CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}" CXX_BUILD_SHOULD_WORK)
CHECK_CXX_SOURCE_COMPILES("void l(char const (&x)[2]){}; int main() { l(\"\\\\n\"); return 0;}"
CXX_BUILD_SHOULD_WORK_COMPLEX)
CHECK_CXX_SOURCE_RUNS("int main() {return 2;}" CXX_RUN_SHOULD_FAIL)
CHECK_CXX_SOURCE_RUNS("int main() {return 0;}" CXX_RUN_SHOULD_WORK)
TEST_FAIL(CXX_BUILD_SHOULD_FAIL "CHECK_CXX_SOURCE_COMPILES() succeeded, but should have failed")
TEST_ASSERT(CXX_BUILD_SHOULD_WORK "CHECK_CXX_SOURCE_COMPILES() failed")
TEST_ASSERT(CXX_BUILD_SHOULD_WORK_COMPLEX "CHECK_CXX_SOURCE_COMPILES() failed")
TEST_FAIL(CXX_RUN_SHOULD_FAIL "CHECK_CXX_SOURCE_RUNS() succeeded, but should have failed")
TEST_ASSERT(CXX_RUN_SHOULD_WORK "CHECK_CXX_SOURCE_RUNS() failed")
foreach(lang C CXX)
if(NOT CMAKE_${lang}_COMPILER_ID STREQUAL "PathScale")
set(${lang}_DD --)
endif()
endforeach()
unset(C_BOGUS_FLAG CACHE)
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG(${C_DD}-_this_is_not_a_flag_ C_BOGUS_FLAG)
TEST_FAIL(C_BOGUS_FLAG "CHECK_C_COMPILER_FLAG() succeeded, but should have failed")
unset(C_BOGUS_FLAG CACHE)
if(DEFINED C_BOGUS_FLAG)
# Verify that CHECK_C_COMPILER_FLAG didn't construct a normal variable
message(SEND_ERROR "CHECK_C_COMPILER_FLAG shouldn't construct C_BOGUS_FLAG as a normal variable")
endif()
unset(CXX_BOGUS_FLAG CACHE)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(${CXX_DD}-_this_is_not_a_flag_ CXX_BOGUS_FLAG)
TEST_FAIL(CXX_BOGUS_FLAG "CHECK_CXX_COMPILER_FLAG() succeeded, but should have failed")
unset(CXX_BOGUS_FLAG CACHE)
if(DEFINED CXX_BOGUS_FLAG)
# Verify that CHECK_C_COMPILER_FLAG didn't construct a normal variable
message(SEND_ERROR "CHECK_CXX_COMPILER_FLAG shouldn't construct CXX_BOGUS_FLAG as a normal variable")
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "LCC")
unset(C_STRICT_PROTOTYPES CACHE)
CHECK_C_COMPILER_FLAG("-Werror;-Wstrict-prototypes" C_STRICT_PROTOTYPES)
TEST_ASSERT(C_STRICT_PROTOTYPES "CHECK_C_COMPILER_FLAG failed -Werror -Wstrict-prototypes")
endif()
#########################################################################
#
# Test that the CHECK_OBJCC_SOURCE_COMPILES, CHECK_OBJCXX_SOURCE_COMPILES
# CHECK_OBJC_SOURCE_RUNS and CHECK_OBJCXX_SOURCE_RUNS macros work
if (APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
include(CheckOBJCSourceCompiles)
include(CheckOBJCXXSourceCompiles)
include(CheckOBJCSourceRuns)
include(CheckOBJCXXSourceRuns)
CHECK_OBJC_SOURCE_COMPILES("I don't build in Objective-C" OBJC_BUILD_SHOULD_FAIL)
CHECK_OBJC_SOURCE_COMPILES("int main() { return 0; }" SIMPLE_OBJC_BUILD_SHOULD_WORK)
TEST_FAIL(OBJC_BUILD_SHOULD_FAIL "CHECK_OBJC_SOURCE_COMPILES() succeeded, but should have failed")
TEST_ASSERT(SIMPLE_OBJC_BUILD_SHOULD_WORK "CHECK_OBJC_SOURCE_COMPILES() failed, but should have succeeded")
set(CMAKE_REQUIRED_LIBRARIES "-framework Foundation")
CHECK_OBJC_SOURCE_COMPILES("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 0;\n}\n" OBJC_BUILD_SHOULD_WORK)
CHECK_OBJC_SOURCE_RUNS("int main() { return 2; }" SIMPLE_OBJC_RUN_SHOULD_FAIL)
CHECK_OBJC_SOURCE_RUNS("int main() { return 0; }" SIMPLE_OBJC_RUN_SHOULD_WORK)
CHECK_OBJC_SOURCE_RUNS("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 2;\n}\n" OBJC_RUN_SHOULD_FAIL)
CHECK_OBJC_SOURCE_RUNS("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 0;\n}\n" OBJC_RUN_SHOULD_WORK)
TEST_ASSERT(OBJC_BUILD_SHOULD_WORK "CHECK_OBJC_SOURCE_COMPILES() failed, but should have succeeded")
TEST_FAIL(SIMPLE_OBJC_RUN_SHOULD_FAIL "CHECK_OBJC_SOURC_RUNS() succeeds, but should have failed")
TEST_ASSERT(SIMPLE_OBJC_RUN_SHOULD_WORK "CHECK_OBJC_SOURCE_RUNS() failed, but should have succeeded")
TEST_FAIL(OBJC_RUN_SHOULD_FAIL "CHECK_OBJC_SOURCE_RUNS() succeeds, but should have failed")
TEST_ASSERT(OBJC_RUN_SHOULD_WORK "CHECK_OBJC_SOURCE_RUNS() failed, but should have succeeded")
CHECK_OBJCXX_SOURCE_COMPILES("I don't build in Objective-C++" OBJCXX_BUILD_SHOULD_FAIL)
CHECK_OBJCXX_SOURCE_COMPILES("int main() { return 0; }" SIMPLE_OBJCXX_BUILD_SHOULD_WORK)
TEST_FAIL(OBJCXX_BUILD_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_COMPILES() succeeded, but should have failed")
TEST_ASSERT(SIMPLE_OBJCXX_BUILD_SHOULD_WORK "CHECK_OBJCXX_SOURCE_COMPILES() failed, but should have succeeded")
CHECK_OBJCXX_SOURCE_COMPILES("#import <Foundation/Foundation.h>\n#include <iostream>\nint main()\n{\nNSObject *foo;\nstd::cout << \"Hello\" << std::endl;\nreturn 0;\n}\n" OBJCXX_BUILD_SHOULD_WORK)
CHECK_OBJCXX_SOURCE_RUNS("int main() { return 2; }" SIMPLE_OBJCXX_RUN_SHOULD_FAIL)
CHECK_OBJCXX_SOURCE_RUNS("int main() { return 0; }" SIMPLE_OBJCXX_RUN_SHOULD_WORK)
CHECK_OBJCXX_SOURCE_RUNS("#import <Foundation/Foundation.h>\n#include <vector>\nint main()\n{\nNSObject *foo;\nstd::vector<int> bar;\nreturn 2;\n}\n" OBJCXX_RUN_SHOULD_FAIL)
CHECK_OBJCXX_SOURCE_RUNS("#import <Foundation/Foundation.h>\n#include <vector>\nint main()\n{\nNSObject *foo;\nstd::vector<int> bar;\nreturn 0;\n}\n" OBJCXX_RUN_SHOULD_WORK)
TEST_ASSERT(OBJCXX_BUILD_SHOULD_WORK "CHECK_OBJCXX_SOURCE_COMPILES() failed, but should have succeeded")
TEST_FAIL(SIMPLE_OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURC_RUNS() succeeds, but should have failed")
TEST_ASSERT(SIMPLE_OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded")
TEST_FAIL(OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_RUNS() succeeds, but should have failed")
TEST_ASSERT(OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded")
endif()
#######################################################################
#
# also test that the check_prototype_definition macro works