Changeset View
Changeset View
Standalone View
Standalone View
autotests/kconfig_compiler/kconfigcompiler_test.cpp
Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 118 | if (!fileRef.open(QIODevice::ReadOnly | QIODevice::Text)) { | |||
---|---|---|---|---|---|
120 | QFAIL("Can't open file for comparison"); | 120 | QFAIL("Can't open file for comparison"); | ||
121 | } | 121 | } | ||
122 | QString content = file.readAll(); | 122 | QString content = file.readAll(); | ||
123 | QString contentRef = fileRef.readAll(); | 123 | QString contentRef = fileRef.readAll(); | ||
124 | 124 | | |||
125 | if (content != contentRef) { | 125 | if (content != contentRef) { | ||
126 | appendFileDiff(fileRef.fileName(), file.fileName()); | 126 | appendFileDiff(fileRef.fileName(), file.fileName()); | ||
127 | } | 127 | } | ||
128 | // use split('\n') to avoid | 128 | | ||
129 | // the whole output shown inline | | |||
dfaure: Why did you remove this? It's just a more user-friendly version of the QVERIFY on the next line… | |||||
the text was really not friendly, it was a big blob of diff content pasted on screen. Considering that the next line will also fail I replaced this by saving the diff file on disk, this way we can actually look at the file that failed and take the time to understand the error. tcanabrava: the text was really not friendly, it was a big blob of diff content pasted on screen. | |||||
OK, this needs a hint for the person debugging regressions then. Something like QVERIFY2(content == contentRef, "Failure, see foo.diff"); dfaure: OK, this needs a hint for the person debugging regressions then. Something like
QVERIFY2… | |||||
tcanabrava: This is done now within the appendFileDiff function. | |||||
130 | QCOMPARE(content.split('\n'), contentRef.split('\n')); | | |||
131 | QVERIFY(content == contentRef); | 129 | QVERIFY(content == contentRef); | ||
132 | } | 130 | } | ||
133 | 131 | | |||
134 | void KConfigCompiler_Test::testRunning_data() | 132 | void KConfigCompiler_Test::testRunning_data() | ||
135 | { | 133 | { | ||
136 | QTest::addColumn<QString>("testName"); | 134 | QTest::addColumn<QString>("testName"); | ||
137 | 135 | | |||
138 | for (const char **it = testCasesToRun; *it; ++it) { | 136 | for (const char **it = testCasesToRun; *it; ++it) { | ||
Show All 22 Lines | |||||
161 | } | 159 | } | ||
162 | 160 | | |||
163 | void KConfigCompiler_Test::appendFileDiff(const QString &oldFile, const QString &newFile) | 161 | void KConfigCompiler_Test::appendFileDiff(const QString &oldFile, const QString &newFile) | ||
164 | { | 162 | { | ||
165 | if (m_diffExe.isEmpty()) { | 163 | if (m_diffExe.isEmpty()) { | ||
166 | return; | 164 | return; | ||
167 | } | 165 | } | ||
168 | 166 | | |||
169 | QStringList args; | 167 | QStringList args({ | ||
170 | args << QStringLiteral("-u"); | 168 | QStringLiteral("-u"), | ||
171 | args << QFileInfo(oldFile).absoluteFilePath(); | 169 | QFileInfo(oldFile).absoluteFilePath(), | ||
172 | args << QFileInfo(newFile).absoluteFilePath(); | 170 | QFileInfo(newFile).absoluteFilePath() }); | ||
173 | 171 | | |||
174 | QProcess process; | 172 | QProcess process; | ||
175 | process.start(m_diffExe, args, QIODevice::ReadOnly); | 173 | process.start(m_diffExe, args, QIODevice::ReadOnly); | ||
176 | process.waitForStarted(); | 174 | process.waitForStarted(); | ||
177 | process.waitForFinished(); | 175 | process.waitForFinished(); | ||
176 | | ||||
178 | if (process.exitCode() == 1) { | 177 | if (process.exitCode() == 1) { | ||
179 | QByteArray out = process.readAllStandardOutput(); | 178 | const QString diffFileName = oldFile + QStringLiteral(".diff"); | ||
180 | qDebug() << '\n' << out; | 179 | QFile diffFile(diffFileName); | ||
180 | QVERIFY2(diffFile.open(QIODevice::WriteOnly), qPrintable(QLatin1String("Could not save diff file for ") + oldFile)); | ||||
dfaure: QVERIFY(...) | |||||
I meant QVERIFY2(diffFile.open(...), ...). dfaure: I meant QVERIFY2(diffFile.open(...), ...).
No need to make a separate call to isOpen(). | |||||
tcanabrava: ups :)
| |||||
181 | diffFile.write(process.readAllStandardOutput()); | ||||
182 | | ||||
183 | // force a failure to print the flename where we stored the diff. | ||||
dfaure: diffFile.write(out); would be simpler than going via QTextStream | |||||
184 | QVERIFY2(false, qPrintable(QLatin1String("This test failed, look at the following file for details: ") + diffFileName)); | ||||
dfaure: not needed, the dtor closes | |||||
181 | } | 185 | } | ||
182 | } | 186 | } |
Why did you remove this? It's just a more user-friendly version of the QVERIFY on the next line, so it can't possibly have failed while the next line passes...