[packagechooser] Fix tests when run from in-source build

This commit is contained in:
Adriaan de Groot 2019-08-07 12:54:03 +02:00
parent e2cb2690bd
commit 8636689cea

View File

@ -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." );