QMAKE_POST_LINK process run



  • Hi everyone.
    I have a project with unit tests (G-test). During building all project (solution), I want to interrupt project build if unit tests failed. How I can achive such behavior?

    I use START_COMMAND, which is "start /B "
    If use QMAKE_POST_LINK += $$START_COMMAND$$DESTDIR/$$TARGET $$PWD/TestFiles

    it build test, but if it fails, solution build don't stop.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    That's a rather unusual setup. The standard way of developing is to build everything and then run the tests. If you would like to do things more sequentially you should rather have a separated script that builds your various modules one after the other and run the tests after each module build.



  • As @SGaist said, that's a bit of an unusual pattern, which might indicate that you're going about something in a non-recommended way.

    But, if you do really want to break the build if an external command fails, then you need to add an additional qmake target.

    For example, here's how I break a build if doxygen fails to generate docs:

    doc.pro

    TEMPLATE = aux
    first.commands += doxygen all.dox && doxygen api.dox
    QMAKE_EXTRA_TARGETS += first
    

    The, my top-level (solution) .pro would look something like:

    TEMPLATE = subdirs
    SUBDIRS += src doc
    CONFIG += ordered
    doc.depends = src
    

    Out if curiosity, how are you building your G-test tests? via qmake or some other build tool?



  • @Paul-Colby said:

    Out if curiosity, how are you building your G-test tests? via qmake or some other build tool?

    via qmake
    build:
    int main(int argc, char* argv[])
    {
    QApplication a(argc, argv);

    ::testing::InitGoogleTest(&argc, argv);  //gtest.h function
    return RUN_ALL_TESTS();
    

    }

    Solution for my problem was find.
    I use START_COMMAND, which is "start /b /wait "

    and added command for process return value
    EXIT_RESULT_COMMAND = "EXIT /B %ERRORLEVEL%"

    use - add to test pro file command
    QMAKE_POST_LINK += $START_COMMAND$DESTDIR/$TARGET $PWD/TestFiles & $$EXIT_RESULT_COMMAND

    This will fail solution build (root pro file) if one of unit test fails


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.