From 0a339a5402010fe388197404c616e18f786ee11c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Nov 2021 22:55:41 +0100 Subject: [PATCH] [libcalamares] Test Runner output-processing --- src/libcalamares/utils/Tests.cpp | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index b20581f4c..9ce09a299 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -74,6 +74,7 @@ private Q_SLOTS: /** @section Test Runner directory-manipulation. */ void testRunnerDirs(); void testCalculateWorkingDirectory(); + void testRunnerOutput(); private: void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth ); @@ -884,6 +885,44 @@ LibCalamaresTests::testCalculateWorkingDirectory() } } +void +LibCalamaresTests::testRunnerOutput() +{ + cDebug() << "Testing ls"; + { + Calamares::Utils::Runner r( { "ls", "-d", "." } ); + QSignalSpy spy( &r, &decltype( r )::output ); + r.enableOutputProcessing( true ); + + auto result = r.run(); + QCOMPARE( result.getExitCode(), 0 ); + QCOMPARE( result.getOutput(), QString() ); + QCOMPARE( spy.count(), 1 ); + } + + cDebug() << "Testing cat"; + { + Calamares::Utils::Runner r( { "cat" } ); + QSignalSpy spy( &r, &decltype( r )::output ); + r.enableOutputProcessing( true ).setInput( QStringLiteral( "hello\nworld\n\n!\n" ) ); + + { + auto result = r.run(); + QCOMPARE( result.getExitCode(), 0 ); + QCOMPARE( result.getOutput(), QString() ); + QCOMPARE( spy.count(), 4 ); + } + + r.setInput( QStringLiteral( "yo\ndogg" ) ); + { + auto result = r.run(); + QCOMPARE( result.getExitCode(), 0 ); + QCOMPARE( result.getOutput(), QString() ); + QCOMPARE( spy.count(), 6 ); // 4 from before, +2 here + } + } +} + QTEST_GUILESS_MAIN( LibCalamaresTests )