From e113ab11681fa8c7b7b4ab2d8f4a093ef4230d5d Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Fri, 13 Dec 2019 19:53:28 +0100 Subject: trace: Add test for the JSON-v1 trace --- Tests/RunCMake/CMakeLists.txt | 2 +- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 8 +++ .../RunCMake/CommandLine/trace-json-v1-check.cmake | 11 ++++ Tests/RunCMake/CommandLine/trace-json-v1-check.py | 67 ++++++++++++++++++++++ .../CommandLine/trace-json-v1-expand-check.cmake | 11 ++++ .../CommandLine/trace-json-v1-expand.cmake | 1 + Tests/RunCMake/CommandLine/trace-json-v1.cmake | 5 ++ 7 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/CommandLine/trace-json-v1-check.cmake create mode 100755 Tests/RunCMake/CommandLine/trace-json-v1-check.py create mode 100644 Tests/RunCMake/CommandLine/trace-json-v1-expand-check.cmake create mode 100644 Tests/RunCMake/CommandLine/trace-json-v1-expand.cmake create mode 100644 Tests/RunCMake/CommandLine/trace-json-v1.cmake diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 10e4c6f..1939612 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -454,7 +454,7 @@ add_RunCMake_test(target_include_directories) add_RunCMake_test(target_sources) add_RunCMake_test(CheckModules) add_RunCMake_test(CheckIPOSupported) -add_RunCMake_test(CommandLine -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DCYGWIN=${CYGWIN}) +add_RunCMake_test(CommandLine -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DCYGWIN=${CYGWIN} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}) add_RunCMake_test(CommandLineTar) if(CMAKE_PLATFORM_NO_VERSIONED_SONAME OR (NOT CMAKE_SHARED_LIBRARY_SONAME_FLAG AND NOT CMAKE_SHARED_LIBRARY_SONAME_C_FLAG)) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index bd368cb..4bdc759 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -607,6 +607,14 @@ set(RunCMake_TEST_OPTIONS --trace-redirect=/no/such/file.txt) run_cmake(trace-redirect-nofile) unset(RunCMake_TEST_OPTIONS) +set(RunCMake_TEST_OPTIONS --trace --trace-format=json-v1 --trace-redirect=${RunCMake_BINARY_DIR}/json-v1.trace) +run_cmake(trace-json-v1) +unset(RunCMake_TEST_OPTIONS) + +set(RunCMake_TEST_OPTIONS --trace-expand --trace-format=json-v1 --trace-redirect=${RunCMake_BINARY_DIR}/json-v1-expand.trace) +run_cmake(trace-json-v1-expand) +unset(RunCMake_TEST_OPTIONS) + set(RunCMake_TEST_OPTIONS -Wno-deprecated --warn-uninitialized) run_cmake(warn-uninitialized) unset(RunCMake_TEST_OPTIONS) diff --git a/Tests/RunCMake/CommandLine/trace-json-v1-check.cmake b/Tests/RunCMake/CommandLine/trace-json-v1-check.cmake new file mode 100644 index 0000000..66af039 --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-json-v1-check.cmake @@ -0,0 +1,11 @@ +if(PYTHON_EXECUTABLE) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/trace-json-v1-check.py" "${RunCMake_BINARY_DIR}/json-v1.trace" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_VARIABLE output + ) + if(NOT result EQUAL 0) + set(RunCMake_TEST_FAILED "JSON trace validation failed:\n${output}") + endif() +endif() diff --git a/Tests/RunCMake/CommandLine/trace-json-v1-check.py b/Tests/RunCMake/CommandLine/trace-json-v1-check.py new file mode 100755 index 0000000..d69ac8f --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-json-v1-check.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +import argparse +import json +import os +import sys + +if sys.version_info[0] >= 3: + unicode = str + +parser = argparse.ArgumentParser(description='Checks the trace output') +parser.add_argument('-e', '--expand', action='store_true') +parser.add_argument('trace', type=str, help='the trace file to check') + +args = parser.parse_args() + +assert os.path.exists(args.trace) + +if args.expand: + msg_args = ['STATUS', 'fff', 'fff;sss; SPACES !!! ', ' 42 space in string!', ' SPACES !!! '] +else: + msg_args = ['STATUS', 'fff', '${ASDF}', ' ${FOO} ${BAR}', ' SPACES !!! '] + +required_traces = [ + { + 'args': ['STATUS', 'JSON-V1 str', 'spaces'], + 'cmd': 'message', + }, + { + 'args': ['ASDF', 'fff', 'sss', ' SPACES !!! '], + 'cmd': 'set', + }, + { + 'args': ['FOO', '42'], + 'cmd': 'set', + }, + { + 'args': ['BAR', ' space in string!'], + 'cmd': 'set', + }, + { + 'args': msg_args, + 'cmd': 'message', + }, +] + +with open(args.trace, 'r') as fp: + # Check for version (must be the first document) + vers = json.loads(fp.readline()) + assert sorted(vers.keys()) == ['version'] + assert sorted(vers['version'].keys()) == ['major', 'minor'] + assert vers['version']['major'] == 1 + assert vers['version']['minor'] == 0 + + for i in fp.readlines(): + line = json.loads(i) + assert sorted(line.keys()) == ['args', 'cmd', 'file', 'line'] + assert isinstance(line['args'], list) + assert isinstance(line['cmd'], unicode) + assert isinstance(line['file'], unicode) + assert isinstance(line['line'], int) + + for i in required_traces: + if i['cmd'] == line['cmd'] and i['args'] == line['args']: + i['found'] = True + +assert all([x.get('found', False) == True for x in required_traces]) diff --git a/Tests/RunCMake/CommandLine/trace-json-v1-expand-check.cmake b/Tests/RunCMake/CommandLine/trace-json-v1-expand-check.cmake new file mode 100644 index 0000000..7916d2e --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-json-v1-expand-check.cmake @@ -0,0 +1,11 @@ +if(PYTHON_EXECUTABLE) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/trace-json-v1-check.py" --expand "${RunCMake_BINARY_DIR}/json-v1-expand.trace" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_VARIABLE output + ) + if(NOT result EQUAL 0) + set(RunCMake_TEST_FAILED "JSON trace validation failed:\n${output}") + endif() +endif() diff --git a/Tests/RunCMake/CommandLine/trace-json-v1-expand.cmake b/Tests/RunCMake/CommandLine/trace-json-v1-expand.cmake new file mode 100644 index 0000000..5c190e6 --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-json-v1-expand.cmake @@ -0,0 +1 @@ +include(trace-json-v1.cmake) diff --git a/Tests/RunCMake/CommandLine/trace-json-v1.cmake b/Tests/RunCMake/CommandLine/trace-json-v1.cmake new file mode 100644 index 0000000..ed0a0f9 --- /dev/null +++ b/Tests/RunCMake/CommandLine/trace-json-v1.cmake @@ -0,0 +1,5 @@ +message(STATUS "JSON-V1 str" "spaces") +set(ASDF fff sss " SPACES !!! ") +set(FOO 42) +set(BAR " space in string!") +message(STATUS fff ${ASDF} " ${FOO} ${BAR}" " SPACES !!! ") -- cgit v0.12