<br><br><div class="gmail_quote">On Thu, Sep 8, 2011 at 3:39 PM, David Cole <span dir="ltr"><<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Thu, Sep 8, 2011 at 9:30 AM, Delphinus Delphinus wrote:<br>
> Hi all,<br>
><br>
> I am using the Qt module QTestLib to do some tests on my application<br>
> (windows, MSVC 2008) that has been all set up with CMake.<br>
><br>
> A test I have created with QTestLib is executed, all output is sent to the<br>
> command window. Since I want it to a file, I used what Qt suggest to<br>
> redirect all output: -xml -o my_file.xml<br>
> so I do this in my CMake file:<br>
><br>
> add_test ( NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} -xml -o<br>
> log/foo.xml )<br>
><br>
> So now, when I do the "run_test" through visual, my test is run and my file<br>
> is created (so far so good!).<br>
><br>
><br>
> My problem is that I want the name of the file to be time and date dependant<br>
> (log20110908140230.xml - a year, month, day, hour, minute and second<br>
> format).<br>
><br>
> So I have considered the following solution (I did not succeed in<br>
> implementing it so far):<br>
> I want to execute a script, just after the execution of my test that will<br>
> rename the result file generated.<br>
> --> Here I don't know how I can tell CMake to execute my script just when<br>
> the test has been executed ?<br>
><br>
> NB: I do NOT have any problem creating a script that rename a foo.xml file<br>
> to a log20110908140230.xml file (my script.bat file is already ready). The<br>
> problem is how to make this script to be executed just after the test<br>
> execution.<br>
><br>
><br>
> Any insight is welcomed on how to implement my suggestion (or if you have<br>
> another choice, I'm all ears :)! ).<br>
><br>
><br>
</div></div><br>
You can either:<br>
<br>
(1) execute your script as an additional test that depends on the<br>
first one (so that guarantees it to run *after* the test, even in<br>
parallel testing scenarios, although not necessarily *immediately*<br>
after)<br>
<br>
or<br>
<br>
(2) execute a single script as the test itself, and then inside that<br>
script, execute the real test first, followed immediately by the<br>
script your already have...<br>
<br>
I would do option #2 if I were you. :-)<br>
<br>
You can probably find other examples of this by googling around for<br>
"add_test script cmake" ( one of the hits is another reply I made<br>
previously on this list:<br>
<a href="http://www.cmake.org/pipermail/cmake/2011-May/044180.html" target="_blank">http://www.cmake.org/pipermail/cmake/2011-May/044180.html</a> )<br>
<br>
<br>
HTH,<br>
<font color="#888888">David<br>
</font></blockquote></div><br><br>Thanks. And yes, it helped !<br><br>I chose option #2.<br><br>I created a runAndRename.cmake file:<br><<<<<<br>macro(COMMAND_EXEC1 P_COMMAND)<br> execute_process(COMMAND ${P_COMMAND} -xml -o log/foo.xml RESULT_VARIABLE RESULT_VAR_COMMAND)<br>
if(RESULT_VAR_COMMAND)<br> message(FATAL_ERROR "Error ${P_COMMAND}")<br> endif()<br>endmacro()<br><br>macro(COMMAND_EXEC2 P_COMMAND)<br> execute_process(COMMAND ${P_COMMAND} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE RESULT_VAR_COMMAND)<br>
if(RESULT_VAR_COMMAND)<br> message(FATAL_ERROR "Error ${P_COMMAND}")<br> endif()<br>endmacro()<br><br>COMMAND_EXEC1(${COMMAND1})<br>COMMAND_EXEC2(${COMMAND2})<br>>>>>><br><br>And then in my CMakeLists.txt, I have now:<br>
<<<<<<br>add_test( NAME ${PROJECT_NAME} COMMAND "${CMAKE_COMMAND}" -DCOMMAND1=$<TARGET_FILE:${PROJECT_NAME}><br> -DCOMMAND2=renameExe<br>
-P "${CMAKE_CURRENT_SOURCE_DIR}/runAndRename.cmake")<br>>>>>><br><br>It is working for me, even though there is still a lot of room for improvement:<br>
- I did not find the proper way to pass the needed arguments (-xml -o filename) ... so I created two macros :(.<br>- And I spent most of my time figuring out that I should "transform" myScript.BAT to a myScript.EXE to make my second part work !<br>
<br>I'll look into those later...<br><br>