From 3d6dd1202ab42a2a26ca1f8bdebd18dee1976d61 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 29 Jan 2019 07:31:29 -0500 Subject: [PATCH] [libcalamares] Extend tests to all example config files - Do a `find ../src/ -name *.conf` to get files to load - Load and save all of them to check for correctness --- src/libcalamares/Tests.cpp | 42 ++++++++++++++++++++++++++++++++++++++ src/libcalamares/Tests.h | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/Tests.cpp b/src/libcalamares/Tests.cpp index 3987976dc..102a18409 100644 --- a/src/libcalamares/Tests.cpp +++ b/src/libcalamares/Tests.cpp @@ -66,4 +66,46 @@ LibCalamaresTests::testLoadSaveYaml() auto map = CalamaresUtils::loadYaml( "settings.conf" ); CalamaresUtils::saveYaml( "out.yaml", map ); + + auto other_map = CalamaresUtils::loadYaml( "out.yaml" ); + CalamaresUtils::saveYaml(" out2.yaml", other_map ); + QCOMPARE( map, other_map ); + + QFile::remove( "out.yaml" ); + QFile::remove( "out2.yaml" ); +} + +static QStringList +findConf( const QDir& d ) +{ + QStringList mine; + if ( d.exists() ) + { + QString path = d.absolutePath(); + path.append( d.separator() ); + for ( const auto& confname : d.entryList( { "*.conf" } ) ) + mine.append( path + confname ); + for ( const auto& subdirname : d.entryList( QDir::AllDirs | QDir::NoDotAndDotDot ) ) + { + QDir subdir( d ); + subdir.cd( subdirname ); + mine.append( findConf( subdir ) ); + } + } + return mine; +} + + +void +LibCalamaresTests::testLoadSaveYamlExtended() +{ + for ( const auto& confname : findConf( QDir( "../src" ) ) ) + { + cDebug() << "Testing" << confname; + auto map = CalamaresUtils::loadYaml( confname ); + QVERIFY( CalamaresUtils::saveYaml( "out.yaml", map ) ); + auto othermap = CalamaresUtils::loadYaml( "out.yaml" ); + QCOMPARE( map, othermap ); + } + QFile::remove( "out.yaml" ); } diff --git a/src/libcalamares/Tests.h b/src/libcalamares/Tests.h index 19e5a3f0c..8d0aee1ff 100644 --- a/src/libcalamares/Tests.h +++ b/src/libcalamares/Tests.h @@ -32,7 +32,8 @@ private Q_SLOTS: void initTestCase(); void testDebugLevels(); - void testLoadSaveYaml(); + void testLoadSaveYaml(); // Just settings.conf + void testLoadSaveYamlExtended(); // Do a find() in the src dir }; #endif