From fecbc87608f4b1429721292d3414bde9eb9f073f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 16 Jan 2019 14:08:50 -0500 Subject: Tests: Fix RunCMake.CTestCommandLine to actually check json-v1 Add a file missing from commit 67209a9291 (Tests: Add cases for ctest --show-only=json-v1, 2018-11-01) to actually hook up the content check. --- Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake | 1 + 1 file changed, 1 insertion(+) create mode 100644 Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake diff --git a/Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake b/Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake new file mode 100644 index 0000000..f8bcd2c --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake @@ -0,0 +1 @@ +ShowAsJson_check_python(1) -- cgit v0.12 From 75a7a237465e37215525831f942a3904d20d1380 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Jan 2019 10:57:15 -0500 Subject: Tests: Rename RunCMake.CTestCommandLine show-only test cases The current name was chosen from an earlier design iteration of the command-line option name. Rename the case to match the final name. --- Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 16 ++-- .../RunCMake/CTestCommandLine/ShowAsJson1-check.py | 106 --------------------- .../ShowAsJsonVersionOne-check.cmake | 1 - .../RunCMake/CTestCommandLine/ShowAsJson_check.py | 24 ----- .../CTestCommandLine/show-only_json-v1-check.cmake | 1 + .../CTestCommandLine/show-only_json-v1_check.py | 106 +++++++++++++++++++++ .../CTestCommandLine/show_only_json_check.py | 24 +++++ 7 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 Tests/RunCMake/CTestCommandLine/ShowAsJson1-check.py delete mode 100644 Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake delete mode 100644 Tests/RunCMake/CTestCommandLine/ShowAsJson_check.py create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_json-v1-check.cmake create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_json-v1_check.py create mode 100644 Tests/RunCMake/CTestCommandLine/show_only_json_check.py diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index cae14b1..c8ea3fc 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -174,12 +174,12 @@ function(run_TestStdin) endfunction() run_TestStdin() -function(ShowAsJson_check_python v) +function(show_only_json_check_python v) set(json_file "${RunCMake_TEST_BINARY_DIR}/ctest.json") file(WRITE "${json_file}" "${actual_stdout}") set(actual_stdout "" PARENT_SCOPE) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/ShowAsJson${v}-check.py" "${json_file}" + COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/show-only_json-v${v}_check.py" "${json_file}" RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE output @@ -190,15 +190,15 @@ function(ShowAsJson_check_python v) endif() endfunction() -function(run_ShowAsJson) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ShowAsJson) +function(run_ShowOnly) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ShowOnly) set(RunCMake_TEST_NO_CLEAN 1) file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" " - add_test(ShowAsJson \"${CMAKE_COMMAND}\" -E echo) - set_tests_properties(ShowAsJson PROPERTIES WILL_FAIL true _BACKTRACE_TRIPLES \"file1;1;add_test;file0;;\") + add_test(ShowOnly \"${CMAKE_COMMAND}\" -E echo) + set_tests_properties(ShowOnly PROPERTIES WILL_FAIL true _BACKTRACE_TRIPLES \"file1;1;add_test;file0;;\") ") - run_cmake_command(ShowAsJsonVersionOne ${CMAKE_CTEST_COMMAND} --show-only=json-v1) + run_cmake_command(show-only_json-v1 ${CMAKE_CTEST_COMMAND} --show-only=json-v1) endfunction() -run_ShowAsJson() +run_ShowOnly() diff --git a/Tests/RunCMake/CTestCommandLine/ShowAsJson1-check.py b/Tests/RunCMake/CTestCommandLine/ShowAsJson1-check.py deleted file mode 100644 index d794e7d..0000000 --- a/Tests/RunCMake/CTestCommandLine/ShowAsJson1-check.py +++ /dev/null @@ -1,106 +0,0 @@ -from ShowAsJson_check import * - -def check_kind(k): - assert is_string(k) - assert k == "ctestInfo" - -def check_version(v): - assert is_dict(v) - assert sorted(v.keys()) == ["major", "minor"] - assert is_int(v["major"]) - assert is_int(v["minor"]) - assert v["major"] == 1 - assert v["minor"] == 0 - -def check_backtracegraph(b): - assert is_dict(b) - assert sorted(b.keys()) == ["commands", "files", "nodes"] - check_backtracegraph_commands(b["commands"]) - check_backtracegraph_files(b["files"]) - check_backtracegraph_nodes(b["nodes"]) - -def check_backtracegraph_commands(c): - assert is_list(c) - assert len(c) == 1 - assert is_string(c[0]) - assert c[0] == "add_test" - -def check_backtracegraph_files(f): - assert is_list(f) - assert len(f) == 2 - assert is_string(f[0]) - assert is_string(f[1]) - assert f[0] == "file1" - assert f[1] == "file0" - -def check_backtracegraph_nodes(n): - assert is_list(n) - assert len(n) == 2 - node = n[0] - assert is_dict(node) - assert sorted(node.keys()) == ["file"] - assert is_int(node["file"]) - assert node["file"] == 1 - node = n[1] - assert is_dict(node) - assert sorted(node.keys()) == ["command", "file", "line", "parent"] - assert is_int(node["command"]) - assert is_int(node["file"]) - assert is_int(node["line"]) - assert is_int(node["parent"]) - assert node["command"] == 0 - assert node["file"] == 0 - assert node["line"] == 1 - assert node["parent"] == 0 - -def check_command(c): - assert is_list(c) - assert len(c) == 3 - assert is_string(c[0]) - check_re(c[0], "/cmake(\.exe)?$") - assert is_string(c[1]) - assert c[1] == "-E" - assert is_string(c[2]) - assert c[2] == "echo" - -def check_willfail_property(p): - assert is_dict(p) - assert sorted(p.keys()) == ["name", "value"] - assert is_string(p["name"]) - assert is_bool(p["value"]) - assert p["name"] == "WILL_FAIL" - assert p["value"] == True - -def check_workingdir_property(p): - assert is_dict(p) - assert sorted(p.keys()) == ["name", "value"] - assert is_string(p["name"]) - assert is_string(p["value"]) - assert p["name"] == "WORKING_DIRECTORY" - assert p["value"].endswith("Tests/RunCMake/CTestCommandLine/ShowAsJson") - -def check_properties(p): - assert is_list(p) - assert len(p) == 2 - check_willfail_property(p[0]) - check_workingdir_property(p[1]) - -def check_tests(t): - assert is_list(t) - assert len(t) == 1 - test = t[0] - assert is_dict(test) - assert sorted(test.keys()) == ["backtrace", "command", "name", "properties"] - assert is_int(test["backtrace"]) - assert test["backtrace"] == 1 - check_command(test["command"]) - assert is_string(test["name"]) - assert test["name"] == "ShowAsJson" - check_properties(test["properties"]) - -assert is_dict(ctest_json) -assert sorted(ctest_json.keys()) == ["backtraceGraph", "kind", "tests", "version"] -check_backtracegraph(ctest_json["backtraceGraph"]) -check_kind(ctest_json["kind"]) -check_version(ctest_json["version"]) -check_tests(ctest_json["tests"]) diff --git a/Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake b/Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake deleted file mode 100644 index f8bcd2c..0000000 --- a/Tests/RunCMake/CTestCommandLine/ShowAsJsonVersionOne-check.cmake +++ /dev/null @@ -1 +0,0 @@ -ShowAsJson_check_python(1) diff --git a/Tests/RunCMake/CTestCommandLine/ShowAsJson_check.py b/Tests/RunCMake/CTestCommandLine/ShowAsJson_check.py deleted file mode 100644 index 493c9e5..0000000 --- a/Tests/RunCMake/CTestCommandLine/ShowAsJson_check.py +++ /dev/null @@ -1,24 +0,0 @@ -import sys -import json -import re - -def is_bool(x): - return isinstance(x, bool) - -def is_dict(x): - return isinstance(x, dict) - -def is_list(x): - return isinstance(x, list) - -def is_int(x): - return isinstance(x, int) or isinstance(x, long) - -def is_string(x): - return isinstance(x, str) or isinstance(x, unicode) - -def check_re(x, regex): - assert re.search(regex, x) - -with open(sys.argv[1]) as f: - ctest_json = json.load(f) diff --git a/Tests/RunCMake/CTestCommandLine/show-only_json-v1-check.cmake b/Tests/RunCMake/CTestCommandLine/show-only_json-v1-check.cmake new file mode 100644 index 0000000..f9234f8 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/show-only_json-v1-check.cmake @@ -0,0 +1 @@ +show_only_json_check_python(1) diff --git a/Tests/RunCMake/CTestCommandLine/show-only_json-v1_check.py b/Tests/RunCMake/CTestCommandLine/show-only_json-v1_check.py new file mode 100644 index 0000000..4dff90c --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/show-only_json-v1_check.py @@ -0,0 +1,106 @@ +from show_only_json_check import * + +def check_kind(k): + assert is_string(k) + assert k == "ctestInfo" + +def check_version(v): + assert is_dict(v) + assert sorted(v.keys()) == ["major", "minor"] + assert is_int(v["major"]) + assert is_int(v["minor"]) + assert v["major"] == 1 + assert v["minor"] == 0 + +def check_backtracegraph(b): + assert is_dict(b) + assert sorted(b.keys()) == ["commands", "files", "nodes"] + check_backtracegraph_commands(b["commands"]) + check_backtracegraph_files(b["files"]) + check_backtracegraph_nodes(b["nodes"]) + +def check_backtracegraph_commands(c): + assert is_list(c) + assert len(c) == 1 + assert is_string(c[0]) + assert c[0] == "add_test" + +def check_backtracegraph_files(f): + assert is_list(f) + assert len(f) == 2 + assert is_string(f[0]) + assert is_string(f[1]) + assert f[0] == "file1" + assert f[1] == "file0" + +def check_backtracegraph_nodes(n): + assert is_list(n) + assert len(n) == 2 + node = n[0] + assert is_dict(node) + assert sorted(node.keys()) == ["file"] + assert is_int(node["file"]) + assert node["file"] == 1 + node = n[1] + assert is_dict(node) + assert sorted(node.keys()) == ["command", "file", "line", "parent"] + assert is_int(node["command"]) + assert is_int(node["file"]) + assert is_int(node["line"]) + assert is_int(node["parent"]) + assert node["command"] == 0 + assert node["file"] == 0 + assert node["line"] == 1 + assert node["parent"] == 0 + +def check_command(c): + assert is_list(c) + assert len(c) == 3 + assert is_string(c[0]) + check_re(c[0], "/cmake(\.exe)?$") + assert is_string(c[1]) + assert c[1] == "-E" + assert is_string(c[2]) + assert c[2] == "echo" + +def check_willfail_property(p): + assert is_dict(p) + assert sorted(p.keys()) == ["name", "value"] + assert is_string(p["name"]) + assert is_bool(p["value"]) + assert p["name"] == "WILL_FAIL" + assert p["value"] == True + +def check_workingdir_property(p): + assert is_dict(p) + assert sorted(p.keys()) == ["name", "value"] + assert is_string(p["name"]) + assert is_string(p["value"]) + assert p["name"] == "WORKING_DIRECTORY" + assert p["value"].endswith("Tests/RunCMake/CTestCommandLine/ShowOnly") + +def check_properties(p): + assert is_list(p) + assert len(p) == 2 + check_willfail_property(p[0]) + check_workingdir_property(p[1]) + +def check_tests(t): + assert is_list(t) + assert len(t) == 1 + test = t[0] + assert is_dict(test) + assert sorted(test.keys()) == ["backtrace", "command", "name", "properties"] + assert is_int(test["backtrace"]) + assert test["backtrace"] == 1 + check_command(test["command"]) + assert is_string(test["name"]) + assert test["name"] == "ShowOnly" + check_properties(test["properties"]) + +assert is_dict(ctest_json) +assert sorted(ctest_json.keys()) == ["backtraceGraph", "kind", "tests", "version"] +check_backtracegraph(ctest_json["backtraceGraph"]) +check_kind(ctest_json["kind"]) +check_version(ctest_json["version"]) +check_tests(ctest_json["tests"]) diff --git a/Tests/RunCMake/CTestCommandLine/show_only_json_check.py b/Tests/RunCMake/CTestCommandLine/show_only_json_check.py new file mode 100644 index 0000000..493c9e5 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/show_only_json_check.py @@ -0,0 +1,24 @@ +import sys +import json +import re + +def is_bool(x): + return isinstance(x, bool) + +def is_dict(x): + return isinstance(x, dict) + +def is_list(x): + return isinstance(x, list) + +def is_int(x): + return isinstance(x, int) or isinstance(x, long) + +def is_string(x): + return isinstance(x, str) or isinstance(x, unicode) + +def check_re(x, regex): + assert re.search(regex, x) + +with open(sys.argv[1]) as f: + ctest_json = json.load(f) -- cgit v0.12 From 62fec84ad7b44b7c54130e9eb3686f4fbc22672e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Jan 2019 11:59:20 -0500 Subject: Tests: Fix RunCMake.CTestCommandLine case when no python is found Do not try to run the python checks if the python executable is not available. --- Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index c8ea3fc..52002ce 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -175,6 +175,9 @@ endfunction() run_TestStdin() function(show_only_json_check_python v) + if(RunCMake_TEST_FAILED OR NOT PYTHON_EXECUTABLE) + return() + endif() set(json_file "${RunCMake_TEST_BINARY_DIR}/ctest.json") file(WRITE "${json_file}" "${actual_stdout}") set(actual_stdout "" PARENT_SCOPE) -- cgit v0.12 From 7370b02c36b45bcd92b6c5bb7cc65ecff75b9b2b Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 16 Jan 2019 14:18:42 -0500 Subject: CTest: Teach --show-only=json-v1 to filter out not-available tests Avoid exposing the internal special value that we use to track tests not available in the tested configuration. This also prevents clients from having to do the filtering themselves. --- Source/CTest/cmCTestMultiProcessHandler.cxx | 5 +++++ Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 1 + 2 files changed, 6 insertions(+) diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 8867323..320647a 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -1039,6 +1039,11 @@ void cmCTestMultiProcessHandler::PrintOutputAsJson() testRun.SetTestProperties(&p); testRun.ComputeArguments(); + // Skip tests not available in this configuration. + if (p.Args.size() >= 2 && p.Args[1] == "NOT_AVAILABLE") { + continue; + } + Json::Value testInfo = DumpCTestInfo(testRun, p, backtraceGraph); tests.append(testInfo); } diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index 52002ce..82bd963 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -201,6 +201,7 @@ function(run_ShowOnly) file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" " add_test(ShowOnly \"${CMAKE_COMMAND}\" -E echo) set_tests_properties(ShowOnly PROPERTIES WILL_FAIL true _BACKTRACE_TRIPLES \"file1;1;add_test;file0;;\") + add_test(ShowOnlyNotAvailable NOT_AVAILABLE) ") run_cmake_command(show-only_json-v1 ${CMAKE_CTEST_COMMAND} --show-only=json-v1) endfunction() -- cgit v0.12 From cae9d2a61afea3948c8dfaf1f7dbc39ebaa71055 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 16 Jan 2019 14:32:29 -0500 Subject: CTest: Teach --show-only= to reject unknown values --- Source/cmCTest.cxx | 3 +++ Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 2 ++ Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt | 1 + Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt | 1 + Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt | 1 + 5 files changed, 8 insertions(+) create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt create mode 100644 Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 65c0d91..ccd74c0 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1944,6 +1944,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, this->Quiet = true; this->OutputAsJson = true; this->OutputAsJsonVersion = 1; + } else if (format != "human") { + errormsg = "'--show-only=' given unknown value '" + format + "'"; + return false; } } diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index 82bd963..d524f41 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -203,6 +203,8 @@ function(run_ShowOnly) set_tests_properties(ShowOnly PROPERTIES WILL_FAIL true _BACKTRACE_TRIPLES \"file1;1;add_test;file0;;\") add_test(ShowOnlyNotAvailable NOT_AVAILABLE) ") + run_cmake_command(show-only_human ${CMAKE_CTEST_COMMAND} --show-only=human) + run_cmake_command(show-only_bad ${CMAKE_CTEST_COMMAND} --show-only=bad) run_cmake_command(show-only_json-v1 ${CMAKE_CTEST_COMMAND} --show-only=json-v1) endfunction() run_ShowOnly() diff --git a/Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt b/Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/show-only_bad-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt b/Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt new file mode 100644 index 0000000..cc55ab3 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/show-only_bad-stderr.txt @@ -0,0 +1 @@ +^CMake Error: '--show-only=' given unknown value 'bad'$ diff --git a/Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt b/Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt new file mode 100644 index 0000000..1332149 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/show-only_human-stdout.txt @@ -0,0 +1 @@ +Test #1: ShowOnly -- cgit v0.12