Search code examples
bashtravis-ciqttest

Travis CI Qt Test Integration


Travis relies on the exit code on an executable to determine if the test passed or failed. Qt Test is designed so that every test class is contained in its own executable so, after the build, I end up with a bunch of tests inside my bin/tests folder.

I don't want to hard code each and every test name in my build script so I'm currently using to execute all of them.

find ./bin/tests/ -type f -perm -a=x -exec '{}' \;

The tests are all executed correctly but, even if one of the tests returns an exit code different from 0, that line itself will be interpreted as exit code 0 and the tests are always passing as much as Travis can tell.

What I'd want is the equivalent of for %a in (bin\tests\*.exe) do %a in windows.

For a small example see https://travis-ci.org/VSRonin/QtModelUtilities/jobs/362301017


Solution

  • Quick solution from the top of my head.

    Make a script like this:

    #!/bin/bash
    
    exit=0
    
    while IFS= read line; do
        "$line" || exit=1
    done <<< "$(find ./bin/tests/ -type f -perm -a=x)"
    
    exit $exit
    

    Considerations:

    • If the names of the files contain spaces, it will not work (Should be fixed with just quoting)
    • It will stop on the first test that fails and will not go on (might be what you need)
    • If there are Dirs aside from files it will attempt to execute them and will fail.