[CMake] Calling a Python Testing Script from CMake/CTest

George Ryan George.Ryan at geospectrum.ca
Wed Feb 24 09:45:16 EST 2016


Am 24. Februar 2016 15:09:47 MEZ, schrieb George Ryan
<George.Ryan at geospectrum.ca>:
>> Hi,
>>
>> I am having difficulty getting a python script to run a C++ subprocess
>> on Window 7 using VS2013. On Linux, the following code works fine, but
>> on Windows, from the command line I get the following output:
>>
>> Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
>> Copyright (C) Microsoft Corporation.  All rights reserved.
>>
>> Running tests...
>> Test project C:/work/s/sandbox/ctestpy/b
>>    Start 1: sample_test
>> 1/1 Test #1: sample_test ......................***Not Run   0.00 sec
>>
>> 0% tests passed, 1 tests failed out of 1
>>
>> Total Test time (real) =   0.06 sec
>>
>> The following tests FAILED:
>>          1 - sample_test (BAD_COMMAND)
>> Errors while running CTest
>> NMAKE : fatal error U1077: 'echo' : return code '0x8'
>> Stop.
>>
>> No matter what options I supply to ctest, I can't seem to get any
>> additional insight. I am assuming that for some reason the
>> WORKING_DIRECTORY isn't being obeyed on Windows?
>>
>> If I run the python script manually from the command prompt, it works
>> fine. The python executable is in my $PATH.On Linux I am using CMake
>> 3.3.1, and on Windows I have CMake 3.2.3.
>>
>> ----
>>
>> sample.cpp
>>
>> int main()
>> {
>>  return 0;
>> }
>>
>> --------------
>>
>> sample_test.py
>>
>> #!/usr/bin/env python
>> import sys
>> import subprocess
>>
>> sample = subprocess.Popen("./sample")
>> sample.wait()
>> if sample.returncode != 0:
>>    sys.exit(1)
>> else:
>>    sys.exit(0)
>> ~
>> ------------------------
>>
>> CMakeLists.txt
>>
>> cmake_minimum_required(VERSION 3.0)
>> project(sampleprg)
>>
>> enable_testing()
>>
>> add_executable( sample sample.cpp )
>>
>> add_test(NAME sample_test
>>         COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sample_test.py
>>         WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} )
> You have to manuall call python with the script as argument. Shebang lines don't work on Windows.
>
> HS
Do you mean the shebangs don't work from within CMake? Because I
certainly can simply call the python script from the command line
without using "python simple_test.py" and it works fine.



More information about the CMake mailing list