[Qbs] Qt Quick Tests and custom import paths

Christian Kandeler christian.kandeler at qt.io
Wed May 16 17:39:20 CEST 2018


On Wed, 16 May 2018 16:43:32 +0200
Federico Frenguelli <synasius at gmail.com> wrote:

> I finally found a solution which I want to report here, so that we can
> start a discussion and maybe improve the state of Qt Quick tests in QBS.
> 
> This is a toy project that shows what I did:
> 
> https://github.com/synasius/prefect-qtquick-tests
> 
> If you checkout the first commit and run "qbs build -p autotest-runner" it
> should fail because it's not able to resolve an import since the needed
> import path is missing.
> Then you can move to the latest commit and run the same command again and
> now the tests should pass.
> 
> Basically I wrote a custom module that provides a property where one can
> add the needed import paths. Then I wrote a custom testrunner (copied and
> pasted from the original AutotestRunner)
> that takes into account the property of the module so it can run the tests
> with the additional import paths.
> 
> I'd like some feedback. Maybe a similar approach can be provided by QBS out
> of the box using one of the existing module (Qt.qmltest for example).

If functions were properly supported as properties, there'd be a simple generic solution:

AutotestRunner {
    additionalArgsFunc: function(testArtifact)  {
        var myArgs = [];
        var additionalImportPaths = testArtifact.quickpaths.additionalImportPaths;
        for (var i in additionalImportPaths)
             myArgs.push("-import", additionalImportPaths[i]);
        return myArgs;
    })
}

In fact, I think this is already possible, though the implementation (on the AutotestRunner side) would look rather awful, involving eval().
So maybe that's the way to go? Higher-level concepts might not be flexible enough. For instance, the approach sketched above also allows you to get the necessary information from product or project properties, or even from the environment.


Christian



More information about the Qbs mailing list