From f51776c427b268caf348efa524264c5e25e31a18 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 4 Sep 2019 14:11:01 +0200 Subject: Improve QDoc's generatedOutput autotest Streamline the process of adding new tests/files, by adding a helper function to both run QDoc and compare the generated output with expected data. Add a way to pass extra command line parameters to QDoc. Change-Id: I04870c18ae3d31ae07115d3d8f5d3c77d090418a Reviewed-by: Paul Wicking --- .../qdoc/generatedoutput/tst_generatedoutput.cpp | 106 ++++++++++----------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp index ab7c91040..01134517a 100644 --- a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp +++ b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp @@ -44,8 +44,11 @@ private: QScopedPointer m_outputDir; QString m_qdoc; - bool runQDocProcess(const QStringList &arguments); - void compareLineByLine(QString &expectedFilename, QString &actualFilename); + void runQDocProcess(const QStringList &arguments); + void compareLineByLine(const QStringList &expectedFiles); + void testAndCompare(const char *input, + const char *outNames, + const char *extraParams = nullptr); }; void tst_generatedOutput::initTestCase() @@ -66,7 +69,7 @@ void tst_generatedOutput::init() } } -bool tst_generatedOutput::runQDocProcess(const QStringList &arguments) +void tst_generatedOutput::runQDocProcess(const QStringList &arguments) { QProcess qdocProcess; qdocProcess.setProgram(m_qdoc); @@ -75,7 +78,7 @@ bool tst_generatedOutput::runQDocProcess(const QStringList &arguments) qdocProcess.waitForFinished(); if (qdocProcess.exitCode() == 0) - return true; + return; QString output = qdocProcess.readAllStandardOutput(); QString errors = qdocProcess.readAllStandardError(); @@ -85,70 +88,61 @@ bool tst_generatedOutput::runQDocProcess(const QStringList &arguments) qInfo() << "Received output:\n" << output; if (errors.size() > 0) qInfo() << "Received errors:\n" << errors; - return false; + + QFAIL("Running QDoc failed. See output above."); } -void tst_generatedOutput::compareLineByLine(QString &expected, QString &actual) +void tst_generatedOutput::compareLineByLine(const QStringList &expectedFiles) { - QFile expectedFile(expected); - if (!expectedFile.open(QIODevice::ReadOnly)) - QFAIL("Cannot open expected data file!"); - QTextStream expectedIn(&expectedFile); - - QFile actualFile(actual); - if (!actualFile.open(QIODevice::ReadOnly)) - QFAIL("Cannot open actual data file!"); - QTextStream actualIn(&actualFile); - - int lineNumber = 0; - while (!expectedIn.atEnd() && !actualIn.atEnd()) { - lineNumber++; - QString prefix = QString::number(lineNumber) + QLatin1String(": "); - QString expectedLine = prefix + expectedIn.readLine(); - QString actualLine = prefix + actualIn.readLine(); - QCOMPARE(actualLine, expectedLine); + for (const auto &file : expectedFiles) { + QString expected(QFINDTESTDATA("/expected_output/" + file)); + QString actual(m_outputDir->path() + "/" + file); + + QFile expectedFile(expected); + if (!expectedFile.open(QIODevice::ReadOnly)) + QFAIL("Cannot open expected data file!"); + QTextStream expectedIn(&expectedFile); + + QFile actualFile(actual); + if (!actualFile.open(QIODevice::ReadOnly)) + QFAIL("Cannot open actual data file!"); + QTextStream actualIn(&actualFile); + + int lineNumber = 0; + while (!expectedIn.atEnd() && !actualIn.atEnd()) { + lineNumber++; + QString prefix = QString::number(lineNumber) + QLatin1String(": "); + QString expectedLine = prefix + expectedIn.readLine(); + QString actualLine = prefix + actualIn.readLine(); + QCOMPARE(actualLine, expectedLine); + } } } -void tst_generatedOutput::htmlFromQDocFile() +void tst_generatedOutput::testAndCompare(const char *input, + const char *outNames, + const char *extraParams) { - const QStringList arguments = { - "--outputdir", - m_outputDir->path(), - QFINDTESTDATA("test.qdocconf") - }; - - if (!runQDocProcess(arguments)) - QFAIL("Running QDoc failed. See output above."); - - QString expectedFile = QFINDTESTDATA("/expected_output/qdoctests-qdocfileoutput.html"); - QString actualFile = m_outputDir->path() + QLatin1String("/qdoctests-qdocfileoutput.html"); + QStringList args{ "-outputdir", m_outputDir->path(), QFINDTESTDATA(input) }; + if (extraParams) + args << QString(QLatin1String(extraParams)).split(QChar(' ')); + runQDocProcess(args); + if (QTest::currentTestFailed()) + return; + compareLineByLine(QString(QLatin1String(outNames)).split(QChar(' '))); +} - compareLineByLine(expectedFile, actualFile); +void tst_generatedOutput::htmlFromQDocFile() +{ + testAndCompare("test.qdocconf", + "qdoctests-qdocfileoutput.html"); } void tst_generatedOutput::htmlFromQml() { - const QStringList arguments = { - "--outputdir", - m_outputDir->path(), - QFINDTESTDATA("testqml.qdocconf") - }; - - if (!runQDocProcess(arguments)) - QFAIL("Running QDoc failed. See output above."); - - const QStringList files{ - "test-componentset-example.html", - "uicomponents-qmlmodule.html"}; - - for (const auto &file : files) { - QString expectedPath = "/expected_output/" + file; - QString expectedFile(QFINDTESTDATA(expectedPath)); - QString actualFile(m_outputDir->path() + "/" + file); - - compareLineByLine(expectedFile, actualFile); - } + testAndCompare("testqml.qdocconf", + "test-componentset-example.html " + "uicomponents-qmlmodule.html"); } QTEST_APPLESS_MAIN(tst_generatedOutput) -- cgit v1.2.3