Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change test runner to work on windows #7

Merged
merged 1 commit into from
Mar 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ament_cmake_test/cmake/ament_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ include(CMakeParseArguments)
# :type testname: string
# :param COMMAND: the command including its arguments to invoke
# :type COMMAND: list of strings
# :param OUTPUT_FILE: the path of the file to pipe the output to
# :type OUTPUT_FILE: string
# :param TIMEOUT: the test timeout in seconds, default: 60
# :type TIMEOUT: integer
# :param WORKING_DIRECTORY: the working directory for invoking the
Expand All @@ -26,7 +28,7 @@ include(CMakeParseArguments)
#
function(ament_add_test testname)
cmake_parse_arguments(ARG "GENERATE_RESULT_FOR_RETURN_CODE_ZERO"
"TIMEOUT;WORKING_DIRECTORY" "COMMAND" ${ARGN})
"OUTPUT_FILE;TIMEOUT;WORKING_DIRECTORY" "COMMAND" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "ament_add_test() called with unused arguments: "
"${ARG_UNPARSED_ARGUMENTS}")
Expand All @@ -47,11 +49,14 @@ function(ament_add_test testname)
endif()

# wrap command with run_test script to ensure test result generation
set(cmd_wrapper ${PYTHON_EXECUTABLE} ${ament_cmake_test_DIR}/run_test.py
set(cmd_wrapper "${PYTHON_EXECUTABLE}" "${ament_cmake_test_DIR}/run_test.py"
"${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${testname}.xml")
if(ARG_GENERATE_RESULT_FOR_RETURN_CODE_ZERO)
list(APPEND cmd_wrapper "--generate-result-on-success")
endif()
if(ARG_OUTPUT_FILE)
list(APPEND cmd_wrapper "--output-file" "${ARG_OUTPUT_FILE}")
endif()
list(APPEND cmd_wrapper "--command" ${ARG_COMMAND})

add_test(
Expand Down
10 changes: 9 additions & 1 deletion ament_cmake_test/cmake/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def main(argv=sys.argv[1:]):
help='The test command to execute. '
'It must be passed after other arguments since it collects all '
'following options.')
parser.add_argument(
'--output-file',
help='The path to the output log file')
parser.add_argument(
'--generate-result-on-success',
action='store_true',
Expand Down Expand Up @@ -62,7 +65,12 @@ def main(argv=sys.argv[1:]):

print("-- run_test.py: invoke following command in '%s':\n - %s" %
(os.getcwd(), ' '.join(args.command)))
rc = subprocess.call(args.command, shell=True)

if args.output_file:
with open(args.output_file, 'w') as h:
rc = subprocess.call(args.command, stdout=h, stderr=subprocess.STDOUT)
else:
rc = subprocess.call(args.command)

print("-- run_test.py: verify result file '%s'" % args.result_file)

Expand Down