Re: [Qbs] Qt Quick Tests and custom import paths
This is amazing! And it is exactly what I am doing now using a custom module and a custom test runner! Thanks On Thu, 31 May 2018 at 11:23, Christian Kandeler wrote: > On Tue, 15 May 2018 15:19:49 +0200 > Federico Frenguelli wrote: > > > I'm writing a test for a qt quick component and I need to add "qrc:/qml" > to > > the qml import paths. > > One way would be to add custom arguments to the AutotestRunner: > > > > AutotestRunner { > > arguments: ["-import", "qrc:/qml"] > > } > > In qbs 1.13, you will be able to write this in your autotest product: > autotest.arguments: ["-import", "qrc:/qml"] > See https://codereview.qt-project.org/#/c/230726/ > > > Christian > ___ > Qbs mailing list > Qbs@qt-project.org > http://lists.qt-project.org/mailman/listinfo/qbs > -- Federico Frenguelli ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
On Tue, 15 May 2018 15:19:49 +0200 Federico Frenguelli wrote: > I'm writing a test for a qt quick component and I need to add "qrc:/qml" to > the qml import paths. > One way would be to add custom arguments to the AutotestRunner: > > AutotestRunner { > arguments: ["-import", "qrc:/qml"] > } In qbs 1.13, you will be able to write this in your autotest product: autotest.arguments: ["-import", "qrc:/qml"] See https://codereview.qt-project.org/#/c/230726/ Christian ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
On Thu, 17 May 2018 14:59:31 +0200 <resurrect...@centrum.cz> wrote: > It does, I use following quite a lot: > > property var foo: (function (arg1, arg2) { return arg1 + arg2; }) > property var elsewhere: foo() Yes, for the project resolution phase it's fine. But using the function in a rule is a bit more involved (and requires the master branch). Christian > > __ > > Od: Christian Kandeler <christian.kande...@qt.io> > > Komu: qbs@qt-project.org > > Datum: 17.05.2018 10:25 > > Předmět: Re: [Qbs] Qt Quick Tests and custom import paths > > > On Wed, 16 May 2018 18:01:40 +0200 > Federico Frenguelli <synas...@gmail.com> wrote: > > > > 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. > > > > > > > That could be a clear and flexible solution but is it possible to use > > function properties? Or you were thinking of wrapping the function > > definition in a string?? > > I think it can work like this already, using a variant property. > > > Christian > ___ > Qbs mailing list > Qbs@qt-project.org > http://lists.qt-project.org/mailman/listinfo/qbs > <http://lists.qt-project.org/mailman/listinfo/qbs> > ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
It does, I use following quite a lot: property var foo: (function (arg1, arg2) { return arg1 + arg2; }) property var elsewhere: foo() __ Od: Christian Kandeler <christian.kande...@qt.io> Komu: qbs@qt-project.org Datum: 17.05.2018 10:25 Předmět: Re: [Qbs] Qt Quick Tests and custom import paths On Wed, 16 May 2018 18:01:40 +0200 Federico Frenguelli <synas...@gmail.com> wrote: > > 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. > > > > That could be a clear and flexible solution but is it possible to use > function properties? Or you were thinking of wrapping the function > definition in a string?? I think it can work like this already, using a variant property. Christian ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs <http://lists.qt-project.org/mailman/listinfo/qbs> ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
> What do you mean by that? > > > Is it possible to access a product's properties from the artifact? > > Artifact objects have a "product" property, which gives you the product > object. > My idea was to define a custom property in the test Product like the "qmlImportPaths" property that is used by Qt Creator to resolve imports. The problem is that I can't retrieve the value of a custom property from the artifact, even through its "product" property. This is an example: In the test: CppApplication { name: "tst_planets" type: ["application", "autotest"] property stringList arguments: ["-import", "qrc:/qml"] // } and in the test runner: ... Rule { ... prepare: { var commandFilePath; var installed = input.moduleProperty("qbs", "install"); var additionalImportPaths = input.product.arguments; // This one returns undefined! } That would be a more flexible alternative to the one based on a custom module, but I can't find a way to retrieve that value. -- Federico Frenguelli ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
On Thu, 17 May 2018 10:57:31 +0200 Federico Frenguelliwrote: > On Thu, 17 May 2018 at 10:25, Christian Kandeler > wrote: > > > On Wed, 16 May 2018 18:01:40 +0200 > > Federico Frenguelli wrote: > > > > > > 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. > > > > > > > > > > That could be a clear and flexible solution but is it possible to use > > > function properties? Or you were thinking of wrapping the function > > > definition in a string?? > > > > I think it can work like this already, using a variant property. > > > I tried to test your proposal but unfortunately that syntax is not > supported. What do you mean by that? > Is it possible to access a product's properties from the artifact? Artifact objects have a "product" property, which gives you the product object. Christian ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
On Thu, 17 May 2018 at 10:25, Christian Kandelerwrote: > On Wed, 16 May 2018 18:01:40 +0200 > Federico Frenguelli wrote: > > > > 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. > > > > > > > That could be a clear and flexible solution but is it possible to use > > function properties? Or you were thinking of wrapping the function > > definition in a string?? > > I think it can work like this already, using a variant property. > I tried to test your proposal but unfortunately that syntax is not supported. Is it possible to access a product's properties from the artifact? -- Federico Frenguelli ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
On Wed, 16 May 2018 18:01:40 +0200 Federico Frenguelliwrote: > > 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. > > > > That could be a clear and flexible solution but is it possible to use > function properties? Or you were thinking of wrapping the function > definition in a string?? I think it can work like this already, using a variant property. Christian ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
> 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. > That could be a clear and flexible solution but is it possible to use function properties? Or you were thinking of wrapping the function definition in a string?? -- Federico Frenguelli ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
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). On Tue, 15 May 2018 at 16:25, Christian Kandelerwrote: > On Tue, 15 May 2018 15:52:44 +0200 > Federico Frenguelli wrote: > > > I'm not a QtQuick expert, but can't you just use the QML2_IMPORT_PATH > > > variable? > > > > > > AutotestRunner { > > > environment: base.concat("QML2_IMPORT_PATH=qrc:/qml") > > > } > > > > > > > I tried to use environment exactly how you proposed but somehow the value > > of QML2_IMPORT_PATH is processed and qrc:/qml is not added to the list. > > Interesting is that if I set environment to > > > > environment: base.concat("QML2_IMPORT_PATH=qrc:/qml:/home") > > > > this is the resulting list of import paths: > > > > View: QQuickView, import paths: > > > '/home//workspace//debug/tst-components-default.f0fbc580' > > 'qrc:/qt-project.org/imports' > > '/home' > > '/home//Qt/5.9.5/gcc_64/qml' > > > > qrc:/qml has been removed. > > Interesting. If you run qbs with "--command-echo-mode > command-line-with-environment", you can see exactly what environment qbs > passes to the application. > Although now that I think of it, the colon might be the problem, as > QtQuick probably interprets it as a path separator and then throws away the > "qrc" and "/qml" parts, because they are not existing paths. Maybe it's not > possible to provide qrc paths in this variable... > > > Christian > ___ > Qbs mailing list > Qbs@qt-project.org > http://lists.qt-project.org/mailman/listinfo/qbs > -- Federico Frenguelli ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [Qbs] Qt Quick Tests and custom import paths
On Tue, 15 May 2018 15:19:49 +0200 Federico Frenguelliwrote: > I'm writing a test for a qt quick component and I need to add "qrc:/qml" to > the qml import paths. > One way would be to add custom arguments to the AutotestRunner: > > AutotestRunner { > arguments: ["-import", "qrc:/qml"] > } > > but then tests fail when I mix cpp tests with qt quick tests. Yes, the arguments property is rather inflexible in that is applied to all tests. > Do you know of any workaround to make this work? I'm not a QtQuick expert, but can't you just use the QML2_IMPORT_PATH variable? AutotestRunner { environment: base.concat("QML2_IMPORT_PATH=qrc:/qml") } Christian ___ Qbs mailing list Qbs@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs