From 8636689ceacefd940cbc4f8ab75eea3bba7870e9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 7 Aug 2019 12:54:03 +0200 Subject: [PATCH] [packagechooser] Fix tests when run from in-source build --- src/modules/packagechooser/Tests.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/modules/packagechooser/Tests.cpp b/src/modules/packagechooser/Tests.cpp index 7e2552c28..537ecbd3c 100644 --- a/src/modules/packagechooser/Tests.cpp +++ b/src/modules/packagechooser/Tests.cpp @@ -45,21 +45,23 @@ PackageChooserTests::testBogus() void PackageChooserTests::testAppData() { - // Path from the build-dir - QString appdataName( "../io.calamares.calamares.appdata.xml" ); - if ( !QFile::exists( appdataName ) ) + // Path from the build-dir and from the running-the-test varies, + // for in-source build, for build/, and for tests-in-build/, + // so look in multiple places. + QString appdataName( "io.calamares.calamares.appdata.xml" ); + for ( const auto& prefix : QStringList { "", "../", "../../../", "../../../../" } ) { - // Running the tests by hand from the build-dir uses the - // path above, but ctest, used by "make test", runs them in - // the module build dir (e.g. build/src/modules/packagechooser) - // so we need to adjust the path some. - appdataName.prepend( "../../../" ); + if ( QFile::exists( prefix + appdataName ) ) + { + appdataName = prefix + appdataName; + break; + } } QVERIFY( QFile::exists( appdataName ) ); QVariantMap m; m.insert( "appdata", appdataName ); - + PackageItem p1 = PackageItem::fromAppData( m ); #ifdef HAVE_XML QVERIFY( p1.isValid() ); @@ -71,10 +73,10 @@ PackageChooserTests::testAppData() QCOMPARE( p1.description.get( QLocale( "en_GB" ) ), "Calamares Linux Installer" ); QCOMPARE( p1.description.get( QLocale( "nl" ) ), "Calamares is een installatieprogramma voor Linux distributies." ); QVERIFY( p1.screenshot.isNull() ); - + m.insert( "id", "calamares" ); m.insert( "screenshot", ":/images/calamares.png" ); - PackageItem p2= PackageItem::fromAppData( m ); + PackageItem p2 = PackageItem::fromAppData( m ); QVERIFY( p2.isValid() ); QCOMPARE( p2.id, "calamares" ); QCOMPARE( p2.description.get( QLocale( "nl" ) ), "Calamares is een installatieprogramma voor Linux distributies." );