[libcalamares] Be far more detailed in comparing maps

- just comparing a==b (both QVariantMap) gives a
  not-so-informative message, so go through the keys looking
  for differences.
This commit is contained in:
Adriaan de Groot 2020-04-08 14:19:11 +02:00
parent 69cd87909b
commit c6463a30ea
2 changed files with 38 additions and 2 deletions

View File

@ -109,16 +109,49 @@ findConf( const QDir& d )
return mine;
}
void LibCalamaresTests::recursiveCompareMap(const QVariantMap& a, const QVariantMap& b, int depth )
{
cDebug() << "Comparing depth" << depth << a.count() << b.count();
QCOMPARE( a.keys(), b.keys() );
for ( const auto& k : a.keys() )
{
cDebug() << Logger::SubEntry << k;
const auto& av = a[k];
const auto& bv = b[k];
if ( av.typeName() != bv.typeName() )
{
cDebug() << Logger::SubEntry << "a type" << av.typeName() << av;
cDebug() << Logger::SubEntry << "b type" << bv.typeName() << bv;
}
QCOMPARE( av.typeName(), bv.typeName() );
if ( av.canConvert<QVariantMap>() )
{
recursiveCompareMap( av.toMap(), bv.toMap(), depth+1 );
}
else
{
QCOMPARE( av, bv );
}
}
}
void
LibCalamaresTests::testLoadSaveYamlExtended()
{
bool loaded_ok;
for ( const auto& confname : findConf( QDir( "../src" ) ) )
{
loaded_ok = true;
cDebug() << "Testing" << confname;
auto map = CalamaresUtils::loadYaml( confname );
auto map = CalamaresUtils::loadYaml( confname, &loaded_ok );
QVERIFY( loaded_ok );
QVERIFY( CalamaresUtils::saveYaml( "out.yaml", map ) );
auto othermap = CalamaresUtils::loadYaml( "out.yaml" );
auto othermap = CalamaresUtils::loadYaml( "out.yaml", &loaded_ok );
QVERIFY( loaded_ok );
QCOMPARE( map.keys(), othermap.keys() );
recursiveCompareMap( map, othermap, 0 );
QCOMPARE( map, othermap );
}
QFile::remove( "out.yaml" );

View File

@ -44,6 +44,9 @@ private Q_SLOTS:
void testEntropy();
void testPrintableEntropy();
void testOddSizedPrintable();
private:
void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth );
};
#endif