diff options
author | Topi Reinio <topi.reinio@qt.io> | 2020-04-15 00:24:17 +0200 |
---|---|---|
committer | Topi Reinio <topi.reinio@qt.io> | 2020-04-21 20:44:54 +0200 |
commit | 6f74a799af2c3c9c99dd425218f12fd010b5dd4b (patch) | |
tree | b47ba1d744ede99b82e945a2ad2ff2ef17959d0c | |
parent | d53af222939321fb816d44f86588c3eb8c255e10 (diff) |
qdoc: tst_generatedoutput: Add option to regenerate expected data
Replace the use of QTEST_APPLESS_MAIN with a main() that accepts a
command line option -regenerate. When set, all tests are skipped and
the expected data directory is re-populated from the output generated
by QDoc.
Fixes: QTBUG-81210
Change-Id: If362338570fca2f7348bf25e452b02a91a96ff14
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r-- | tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp index 40fcdfcac..f8abee1b4 100644 --- a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp +++ b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp @@ -34,6 +34,9 @@ class tst_generatedOutput : public QObject { Q_OBJECT +public: + void setRegenerate() { m_regen = true; } + private slots: void initTestCase(); void init(); @@ -73,6 +76,8 @@ private slots: private: QScopedPointer<QTemporaryDir> m_outputDir; QString m_qdoc; + QDir m_expectedDir; + bool m_regen = false; void runQDocProcess(const QStringList &arguments); void compareLineByLine(const QStringList &expectedFiles); @@ -87,6 +92,7 @@ void tst_generatedOutput::initTestCase() const auto binpath = QLibraryInfo::location(QLibraryInfo::BinariesPath); const auto extension = QSysInfo::productType() == "windows" ? ".exe" : ""; m_qdoc = binpath + QLatin1String("/qdoc") + extension; + m_expectedDir.setPath(QFINDTESTDATA(".") + QLatin1String("/expected_output")); } void tst_generatedOutput::init() @@ -125,8 +131,8 @@ void tst_generatedOutput::runQDocProcess(const QStringList &arguments) void tst_generatedOutput::compareLineByLine(const QStringList &expectedFiles) { for (const auto &file : expectedFiles) { - QString expected(QFINDTESTDATA("/expected_output/" + file)); - QString actual(m_outputDir->path() + "/" + file); + QString expected(m_expectedDir.filePath(file)); + QString actual(m_outputDir->filePath(file)); QFile expectedFile(expected); if (!expectedFile.open(QIODevice::ReadOnly)) @@ -168,6 +174,19 @@ void tst_generatedOutput::testAndCompare(const char *input, const char *outNames for (auto &expectedOut : expectedOuts) expectedOut = QString(outputPathPrefix) + "/" + expectedOut; + if (m_regen) { + QVERIFY(m_expectedDir.mkpath(m_expectedDir.path())); + for (const auto &file : qAsConst(expectedOuts)) { + QFileInfo fileInfo(m_expectedDir.filePath(file)); + fileInfo.dir().remove(fileInfo.fileName()); // Allowed to fail + QVERIFY(m_expectedDir.mkpath(fileInfo.dir().path())); + QVERIFY(QFile::copy(m_outputDir->filePath(file), + fileInfo.filePath())); + } + QSKIP("Regenerated expected output only."); + return; + } + compareLineByLine(expectedOuts); } @@ -400,6 +419,15 @@ void tst_generatedOutput::nestedMacro() "nestedmacro/testcpp-module.html"); } -QTEST_APPLESS_MAIN(tst_generatedOutput) +int main(int argc, char *argv[]) +{ + tst_generatedOutput tc; + // Re-populate expected data and skip tests if option -regenerate is set + if (argc == 2 && QByteArray(argv[1]) == "-regenerate") { + tc.setRegenerate(); + --argc; + } + return QTest::qExec(&tc, argc, argv); +} #include "tst_generatedoutput.moc" |