diff options
Diffstat (limited to 'Tests')
18 files changed, 167 insertions, 47 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 6072711..38ab553 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -773,7 +773,7 @@ add_RunCMake_test(PrecompileHeaders -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION}) add_RunCMake_test("UnityBuild") -add_RunCMake_test(CMakePresets) +add_RunCMake_test(CMakePresets -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DCMake_TEST_JSON_SCHEMA=${CMake_TEST_JSON_SCHEMA}) add_RunCMake_test(TransformDepfile) if(WIN32) diff --git a/Tests/RunCMake/CMakePresets/CMakePresets.json.in b/Tests/RunCMake/CMakePresets/CMakePresets.json.in index 8bfc602..ea7df45 100644 --- a/Tests/RunCMake/CMakePresets/CMakePresets.json.in +++ b/Tests/RunCMake/CMakePresets/CMakePresets.json.in @@ -46,6 +46,22 @@ "type": "BOOL", "value": "OFF" }, + "TEST_BOOL_TRUE": true, + "TEST_BOOL_FALSE": false, + "TEST_TYPED_BOOL_TRUE": { + "type": "STRING", + "value": true + }, + "TEST_TYPED_BOOL_FALSE": { + "type": "STRING", + "value": false + }, + "TEST_UNTYPED_BOOL_TRUE": { + "value": true + }, + "TEST_UNTYPED_BOOL_FALSE": { + "value": false + }, "TEST_PRESET_NAME": { "type": "STRING", "value": "x${presetName}x" @@ -306,16 +322,6 @@ "binaryDir": "${sourceDir}/build" }, { - "name": "UnclosedMacro", - "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${sourceDir" - }, - { - "name": "NoSuchMacro", - "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${noexist}" - }, - { "name": "VendorMacro", "generator": "@RunCMake_GENERATOR@", "binaryDir": "$vendor{unknown.unknownMacro}" @@ -326,31 +332,6 @@ "binaryDir": "${sourceDir}/build" }, { - "name": "EnvCycle", - "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${sourceDir}/build", - "environment": { - "ENV_1": "$env{ENV_2}", - "ENV_2": "$env{ENV_1}" - } - }, - { - "name": "EmptyEnv", - "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "MY_VAR": "$env{}" - } - }, - { - "name": "EmptyPenv", - "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "MY_VAR": "$penv{}" - } - }, - { "name": "UseHiddenPreset", "generator": "@RunCMake_GENERATOR@", "binaryDir": "${sourceDir}/build", diff --git a/Tests/RunCMake/CMakePresets/EmptyEnv-stderr.txt b/Tests/RunCMake/CMakePresets/EmptyEnv-stderr.txt index 9c9c025..723ac21 100644 --- a/Tests/RunCMake/CMakePresets/EmptyEnv-stderr.txt +++ b/Tests/RunCMake/CMakePresets/EmptyEnv-stderr.txt @@ -1 +1,2 @@ -^CMake Error: Could not evaluate preset "EmptyEnv": Invalid macro expansion$ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresets/EmptyEnv: Invalid macro expansion$ diff --git a/Tests/RunCMake/CMakePresets/EmptyEnv.json.in b/Tests/RunCMake/CMakePresets/EmptyEnv.json.in new file mode 100644 index 0000000..ef0d575 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/EmptyEnv.json.in @@ -0,0 +1,13 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "EmptyEnv", + "generator": "@RunCMake_GENERATOR@", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "MY_VAR": "$env{}" + } + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/EmptyPenv-stderr.txt b/Tests/RunCMake/CMakePresets/EmptyPenv-stderr.txt index 395c7b4..880cee6 100644 --- a/Tests/RunCMake/CMakePresets/EmptyPenv-stderr.txt +++ b/Tests/RunCMake/CMakePresets/EmptyPenv-stderr.txt @@ -1 +1,2 @@ -^CMake Error: Could not evaluate preset "EmptyPenv": Invalid macro expansion$ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresets/EmptyPenv: Invalid macro expansion$ diff --git a/Tests/RunCMake/CMakePresets/EmptyPenv.json.in b/Tests/RunCMake/CMakePresets/EmptyPenv.json.in new file mode 100644 index 0000000..9081fe5 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/EmptyPenv.json.in @@ -0,0 +1,13 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "EmptyPenv", + "generator": "@RunCMake_GENERATOR@", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "MY_VAR": "$penv{}" + } + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/EnvCycle-stderr.txt b/Tests/RunCMake/CMakePresets/EnvCycle-stderr.txt index c8568f1..1d22b87 100644 --- a/Tests/RunCMake/CMakePresets/EnvCycle-stderr.txt +++ b/Tests/RunCMake/CMakePresets/EnvCycle-stderr.txt @@ -1 +1,2 @@ -^CMake Error: Could not evaluate preset "EnvCycle": Invalid macro expansion$ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresets/EnvCycle: Invalid macro expansion$ diff --git a/Tests/RunCMake/CMakePresets/EnvCycle.json.in b/Tests/RunCMake/CMakePresets/EnvCycle.json.in new file mode 100644 index 0000000..25a1349 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/EnvCycle.json.in @@ -0,0 +1,14 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "EnvCycle", + "generator": "@RunCMake_GENERATOR@", + "binaryDir": "${sourceDir}/build", + "environment": { + "ENV_1": "$env{ENV_2}", + "ENV_2": "$env{ENV_1}" + } + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/Good-stdout.txt b/Tests/RunCMake/CMakePresets/Good-stdout.txt index ce6189e..7adf1ca 100644 --- a/Tests/RunCMake/CMakePresets/Good-stdout.txt +++ b/Tests/RunCMake/CMakePresets/Good-stdout.txt @@ -1,5 +1,7 @@ Preset CMake variables: + TEST_BOOL_FALSE:BOOL="FALSE" + TEST_BOOL_TRUE:BOOL="TRUE" TEST_DOLLAR="\$" TEST_D_ENV_REF="xEnvironment variablex" TEST_D_ENV_REF_P="" @@ -32,6 +34,10 @@ Preset CMake variables: TEST_TRAILING_DOLLAR="a \$" TEST_TRAILING_UNKNOWN_NAMESPACE="\$unknown{namespace" TEST_TRUE:BOOL="TRUE" + TEST_TYPED_BOOL_FALSE:STRING="FALSE" + TEST_TYPED_BOOL_TRUE:STRING="TRUE" + TEST_UNTYPED_BOOL_FALSE="FALSE" + TEST_UNTYPED_BOOL_TRUE="TRUE" Preset environment variables: diff --git a/Tests/RunCMake/CMakePresets/Good.cmake b/Tests/RunCMake/CMakePresets/Good.cmake index d8e3e2d..55b85da 100644 --- a/Tests/RunCMake/CMakePresets/Good.cmake +++ b/Tests/RunCMake/CMakePresets/Good.cmake @@ -8,6 +8,12 @@ test_variable(TEST_SOURCE_PARENT_DIR "PATH" "${_parent_dir}") test_variable(TEST_SOURCE_LIST "FILEPATH" "${CMAKE_SOURCE_DIR}/CMakeLists.txt") test_variable(TEST_TRUE "BOOL" "TRUE") test_variable(TEST_OFF "BOOL" "OFF") +test_variable(TEST_BOOL_TRUE "BOOL" "TRUE") +test_variable(TEST_BOOL_FALSE "BOOL" "FALSE") +test_variable(TEST_TYPED_BOOL_TRUE "STRING" "TRUE") +test_variable(TEST_TYPED_BOOL_FALSE "STRING" "FALSE") +test_variable(TEST_UNTYPED_BOOL_TRUE "UNINITIALIZED" "TRUE") +test_variable(TEST_UNTYPED_BOOL_FALSE "UNINITIALIZED" "FALSE") test_variable(TEST_PRESET_NAME "STRING" "xGoodx") test_variable(TEST_GENERATOR "UNINITIALIZED" "x${CMAKE_GENERATOR}x") test_variable(TEST_DOLLAR "UNINITIALIZED" "$") diff --git a/Tests/RunCMake/CMakePresets/ListPresets.json.in b/Tests/RunCMake/CMakePresets/ListPresets.json.in index c7646c6..2ef3797 100644 --- a/Tests/RunCMake/CMakePresets/ListPresets.json.in +++ b/Tests/RunCMake/CMakePresets/ListPresets.json.in @@ -26,7 +26,7 @@ { "name": "invalid-macro", "generator": "@RunCMake_GENERATOR@", - "binaryDir": "${noexist}" + "binaryDir": "$vendor{noexist}" }, { "name": "ListPresetsHidden", diff --git a/Tests/RunCMake/CMakePresets/NoSuchMacro-stderr.txt b/Tests/RunCMake/CMakePresets/NoSuchMacro-stderr.txt index 08fa87b..7dafe62 100644 --- a/Tests/RunCMake/CMakePresets/NoSuchMacro-stderr.txt +++ b/Tests/RunCMake/CMakePresets/NoSuchMacro-stderr.txt @@ -1 +1,2 @@ -^CMake Error: Could not evaluate preset "NoSuchMacro": Invalid macro expansion$ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresets/NoSuchMacro: Invalid macro expansion$ diff --git a/Tests/RunCMake/CMakePresets/NoSuchMacro.json.in b/Tests/RunCMake/CMakePresets/NoSuchMacro.json.in new file mode 100644 index 0000000..94d0b76 --- /dev/null +++ b/Tests/RunCMake/CMakePresets/NoSuchMacro.json.in @@ -0,0 +1,10 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "NoSuchMacro", + "generator": "@RunCMake_GENERATOR@", + "binaryDir": "${noexist}" + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake index 18ea093..dddf05f 100644 --- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake @@ -7,6 +7,24 @@ if(RunCMake_GENERATOR MATCHES "^(Visual Studio [0-9]+ [0-9]+) ") set(RunCMake_GENERATOR "${CMAKE_MATCH_1}") endif() +set(RunCMake-check-file check.cmake) + +function(validate_schema file expected_result) + execute_process( + COMMAND "${PYTHON_EXECUTABLE}" "${RunCMake_SOURCE_DIR}/validate_schema.py" "${file}" + RESULT_VARIABLE _result + OUTPUT_VARIABLE _output + ERROR_VARIABLE _error + ) + if(NOT _result STREQUAL expected_result) + string(REPLACE "\n" "\n" _output_p "${_output}") + string(REPLACE "\n" "\n" _error_p "${_error}") + string(APPEND RunCMake_TEST_FAILED "Expected result of validating ${file}: ${expected_result}\nActual result: ${_result}\nOutput:\n${_output_p}\nError:\n${_error_p}") + endif() + + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) +endfunction() + function(run_cmake_presets name) set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/${name}") set(_source_arg "${RunCMake_TEST_SOURCE_DIR}") @@ -57,6 +75,7 @@ function(run_cmake_presets name) endfunction() # Test CMakePresets.json errors +set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_presets(NoCMakePresets) run_cmake_presets(JSONParseError) run_cmake_presets(InvalidRoot) @@ -65,15 +84,21 @@ run_cmake_presets(InvalidVersion) run_cmake_presets(LowVersion) run_cmake_presets(HighVersion) run_cmake_presets(InvalidVendor) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) run_cmake_presets(NoPresets) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_presets(InvalidPresets) run_cmake_presets(PresetNotObject) run_cmake_presets(NoPresetName) run_cmake_presets(InvalidPresetName) run_cmake_presets(EmptyPresetName) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) run_cmake_presets(NoPresetGenerator) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_presets(InvalidPresetGenerator) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) run_cmake_presets(NoPresetBinaryDir) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_presets(InvalidPresetBinaryDir) run_cmake_presets(InvalidVariables) run_cmake_presets(VariableNotObject) @@ -83,6 +108,7 @@ run_cmake_presets(ExtraRootField) run_cmake_presets(ExtraPresetField) run_cmake_presets(ExtraVariableField) run_cmake_presets(InvalidPresetVendor) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) run_cmake_presets(DuplicatePresets) run_cmake_presets(CyclicInheritance0) run_cmake_presets(CyclicInheritance1) @@ -90,13 +116,22 @@ run_cmake_presets(CyclicInheritance2) run_cmake_presets(InvalidInheritance) run_cmake_presets(ErrorNoWarningDev) run_cmake_presets(ErrorNoWarningDeprecated) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_presets(InvalidCMakeGeneratorConfig) run_cmake_presets(UnknownCMakeGeneratorConfig) run_cmake_presets(EmptyCacheKey) run_cmake_presets(EmptyEnvKey) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) +run_cmake_presets(UnclosedMacro) +run_cmake_presets(NoSuchMacro) +run_cmake_presets(EnvCycle) +run_cmake_presets(EmptyEnv) +run_cmake_presets(EmptyPenv) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) # Test cmakeMinimumRequired field run_cmake_presets(MinimumRequiredInvalid) +set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) run_cmake_presets(MinimumRequiredEmpty) run_cmake_presets(MinimumRequiredMajor) run_cmake_presets(MinimumRequiredMinor) @@ -142,13 +177,8 @@ run_cmake_presets(GoodInheritanceMultiSecond) run_cmake_presets(GoodInheritanceMacro) # Test bad preset arguments -run_cmake_presets(UnclosedMacro) -run_cmake_presets(NoSuchMacro) run_cmake_presets(VendorMacro) run_cmake_presets(InvalidGenerator) -run_cmake_presets(EnvCycle) -run_cmake_presets(EmptyEnv) -run_cmake_presets(EmptyPenv) # Test Visual Studio-specific stuff if(RunCMake_GENERATOR MATCHES "^Visual Studio ") diff --git a/Tests/RunCMake/CMakePresets/UnclosedMacro-stderr.txt b/Tests/RunCMake/CMakePresets/UnclosedMacro-stderr.txt index 248510d..f9481f0 100644 --- a/Tests/RunCMake/CMakePresets/UnclosedMacro-stderr.txt +++ b/Tests/RunCMake/CMakePresets/UnclosedMacro-stderr.txt @@ -1 +1,2 @@ -^CMake Error: Could not evaluate preset "UnclosedMacro": Invalid macro expansion$ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresets/UnclosedMacro: Invalid macro expansion$ diff --git a/Tests/RunCMake/CMakePresets/UnclosedMacro.json.in b/Tests/RunCMake/CMakePresets/UnclosedMacro.json.in new file mode 100644 index 0000000..ad6cf7d --- /dev/null +++ b/Tests/RunCMake/CMakePresets/UnclosedMacro.json.in @@ -0,0 +1,10 @@ +{ + "version": 1, + "configurePresets": [ + { + "name": "UnclosedMacro", + "generator": "@RunCMake_GENERATOR@", + "binaryDir": "${sourceDir" + } + ] +} diff --git a/Tests/RunCMake/CMakePresets/check.cmake b/Tests/RunCMake/CMakePresets/check.cmake new file mode 100644 index 0000000..bf43c7e --- /dev/null +++ b/Tests/RunCMake/CMakePresets/check.cmake @@ -0,0 +1,15 @@ +if(PYTHON_EXECUTABLE AND CMake_TEST_JSON_SCHEMA) + if(NOT CMakePresets_SCHEMA_EXPECTED_RESULT) + set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) + endif() + if(EXISTS "${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json") + validate_schema("${RunCMake_TEST_SOURCE_DIR}/CMakePresets.json" "${CMakePresets_SCHEMA_EXPECTED_RESULT}") + endif() + + if(NOT CMakeUserPresets_SCHEMA_EXPECTED_RESULT) + set(CMakeUserPresets_SCHEMA_EXPECTED_RESULT 0) + endif() + if(EXISTS "${RunCMake_TEST_SOURCE_DIR}/CMakeUserPresets.json") + validate_schema("${RunCMake_TEST_SOURCE_DIR}/CMakeUserPresets.json" "${CMakeUserPresets_SCHEMA_EXPECTED_RESULT}") + endif() +endif() diff --git a/Tests/RunCMake/CMakePresets/validate_schema.py b/Tests/RunCMake/CMakePresets/validate_schema.py new file mode 100644 index 0000000..c9f84ee --- /dev/null +++ b/Tests/RunCMake/CMakePresets/validate_schema.py @@ -0,0 +1,17 @@ +import jsmin +import json +import jsonschema +import os.path +import sys + + +with open(sys.argv[1], "rb") as f: + contents = json.loads(jsmin.jsmin(f.read().decode("utf-8-sig"))) + +schema_file = os.path.join( + os.path.dirname(__file__), + "..", "..", "..", "Help", "manual", "presets", "schema.json") +with open(schema_file) as f: + schema = json.load(f) + +jsonschema.validate(contents, schema) |