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

Hendrik Sattler post at hendrik-sattler.de
Wed Feb 24 14:55:33 EST 2016


It actually should be used using find_package()

HS


Am 24. Februar 2016 16:10:49 MEZ, schrieb George Ryan <George.Ryan at geospectrum.ca>:
>Thanks, Matthew. That worked.
>
>I had tried something similar using find(PythonInterp REQUIRED), but
>that didn't work. The include() worked perfectly!
>
>Thanks!
>George
>
>
>On 02/24/2016 10:51 AM, Matthew Keeler wrote:
>My guess is that the command prompt is seeing the .py extension and
>automatically invoking the python interpreter for you. On other
>platforms it looks for the #!/usr/bin/env python which won’t work on
>windows.What you should do is use the FindPythonInterp cmake module to
>find your python executable and specify the interpreter to execute in
>your add test line.
>https://cmake.org/cmake/help/v3.3/module/FindPythonInterp.html
>
>Something like the following should work (I have not tested so the
>syntax might need some slight tweaks).
>
>include(FindPythonInterp)
>add_test(NAME sample_test COMMAND ${PYTHON_EXECUTABLE}
>${CMAKE_CURRENT_SOURCE_DIR}/sample_test.py WORKING_DIRECTORY
>${EXECUTABLE_OUTPUT_PATH} )
>
>--
>Matthew Keeler
>
>On February 24, 2016 at 09:15:10, George Ryan
>(george.ryan at geospectrum.ca<mailto:george.ryan at geospectrum.ca>) wrote:
>
>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} )
>
>
>
>
>--
>
>Powered by www.kitware.com<http://www.kitware.com>
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For
>more information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake
>
>
>--
>Senior Software Architect
>GeoSpectrum Technologies Inc.
>Dartmouth, Nova Scotia, Canada
>
>
>------------------------------------------------------------------------
>
>-- 
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For
>more information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160224/37e6e62f/attachment.html>


More information about the CMake mailing list