Changeset View
Changeset View
Standalone View
Standalone View
autotests/kconfig_compiler/kconfigcompiler_test.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 30 | static CompilerTestSet testCases = { | |||
---|---|---|---|---|---|
47 | "test13.h", "test13.cpp", | 47 | "test13.h", "test13.cpp", | ||
48 | "test_dpointer.cpp", "test_dpointer.h", | 48 | "test_dpointer.cpp", "test_dpointer.h", | ||
49 | "test_qdebugcategory.cpp", "test_qdebugcategory.h", | 49 | "test_qdebugcategory.cpp", "test_qdebugcategory.h", | ||
50 | "test_signal.cpp", "test_signal.h", | 50 | "test_signal.cpp", "test_signal.h", | ||
51 | "test_notifiers.cpp", "test_notifiers.h", | 51 | "test_notifiers.cpp", "test_notifiers.h", | ||
52 | "test_translation_kde.cpp", "test_translation_kde.h", | 52 | "test_translation_kde.cpp", "test_translation_kde.h", | ||
53 | "test_translation_kde_domain.cpp", "test_translation_kde_domain.h", | 53 | "test_translation_kde_domain.cpp", "test_translation_kde_domain.h", | ||
54 | "test_translation_qt.cpp", "test_translation_qt.h", | 54 | "test_translation_qt.cpp", "test_translation_qt.h", | ||
55 | "test_emptyentries.cpp", "test_emptyentries.h", | ||||
55 | nullptr | 56 | nullptr | ||
56 | }; | 57 | }; | ||
57 | 58 | | |||
58 | static CompilerTestSet testCasesToRun = { | 59 | static CompilerTestSet testCasesToRun = { | ||
59 | "test1", | 60 | "test1", | ||
60 | "test2", | 61 | "test2", | ||
61 | "test3", | 62 | "test3", | ||
62 | "test3a", | 63 | "test3a", | ||
63 | "test4", | 64 | "test4", | ||
64 | "test5", | 65 | "test5", | ||
65 | "test6", | 66 | "test6", | ||
66 | "test7", | 67 | "test7", | ||
67 | "test8", | 68 | "test8", | ||
68 | "test9", | 69 | "test9", | ||
69 | "test10", | 70 | "test10", | ||
70 | "test11", | 71 | "test11", | ||
71 | "test12", | 72 | "test12", | ||
72 | "test13", | 73 | "test13", | ||
73 | "test_dpointer", | 74 | "test_dpointer", | ||
74 | "test_qdebugcategory", | 75 | "test_qdebugcategory", | ||
75 | "test_signal", | 76 | "test_signal", | ||
76 | "test_translation_kde", | 77 | "test_translation_kde", | ||
77 | "test_translation_kde_domain", | 78 | "test_translation_kde_domain", | ||
78 | "test_translation_qt", | 79 | "test_translation_qt", | ||
80 | "test_emptyentries", | ||||
79 | nullptr | 81 | nullptr | ||
80 | }; | 82 | }; | ||
81 | 83 | | |||
82 | #if 0 | 84 | #if 0 | ||
83 | static CompilerTestSet willFailCases = { | 85 | static CompilerTestSet willFailCases = { | ||
84 | // where is that QDir coming from? | 86 | // where is that QDir coming from? | ||
85 | //"test9.cpp", NULL | 87 | //"test9.cpp", NULL | ||
86 | NULL | 88 | NULL | ||
Show All 33 Lines | 120 | if (!fileRef.open(QIODevice::ReadOnly | QIODevice::Text)) { | |||
120 | QFAIL("Can't open file for comparison"); | 122 | QFAIL("Can't open file for comparison"); | ||
121 | } | 123 | } | ||
122 | QString content = file.readAll(); | 124 | QString content = file.readAll(); | ||
123 | QString contentRef = fileRef.readAll(); | 125 | QString contentRef = fileRef.readAll(); | ||
124 | 126 | | |||
125 | if (content != contentRef) { | 127 | if (content != contentRef) { | ||
126 | appendFileDiff(fileRef.fileName(), file.fileName()); | 128 | appendFileDiff(fileRef.fileName(), file.fileName()); | ||
127 | } | 129 | } | ||
128 | // use split('\n') to avoid | 130 | | ||
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); | 131 | QVERIFY(content == contentRef); | ||
132 | } | 132 | } | ||
133 | 133 | | |||
134 | void KConfigCompiler_Test::testRunning_data() | 134 | void KConfigCompiler_Test::testRunning_data() | ||
135 | { | 135 | { | ||
136 | QTest::addColumn<QString>("testName"); | 136 | QTest::addColumn<QString>("testName"); | ||
137 | 137 | | |||
138 | for (const char **it = testCasesToRun; *it; ++it) { | 138 | for (const char **it = testCasesToRun; *it; ++it) { | ||
Show All 22 Lines | |||||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | void KConfigCompiler_Test::appendFileDiff(const QString &oldFile, const QString &newFile) | 163 | void KConfigCompiler_Test::appendFileDiff(const QString &oldFile, const QString &newFile) | ||
164 | { | 164 | { | ||
165 | if (m_diffExe.isEmpty()) { | 165 | if (m_diffExe.isEmpty()) { | ||
166 | return; | 166 | return; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | QStringList args; | 169 | QStringList args({ | ||
170 | args << QStringLiteral("-u"); | 170 | QStringLiteral("-u"), | ||
171 | args << QFileInfo(oldFile).absoluteFilePath(); | 171 | QFileInfo(oldFile).absoluteFilePath(), | ||
172 | args << QFileInfo(newFile).absoluteFilePath(); | 172 | QFileInfo(newFile).absoluteFilePath() }); | ||
173 | 173 | | |||
174 | QProcess process; | 174 | QProcess process; | ||
175 | process.start(m_diffExe, args, QIODevice::ReadOnly); | 175 | process.start(m_diffExe, args, QIODevice::ReadOnly); | ||
176 | process.waitForStarted(); | 176 | process.waitForStarted(); | ||
177 | process.waitForFinished(); | 177 | process.waitForFinished(); | ||
178 | | ||||
178 | if (process.exitCode() == 1) { | 179 | if (process.exitCode() == 1) { | ||
179 | QByteArray out = process.readAllStandardOutput(); | 180 | const QString diffFileName = oldFile + QStringLiteral(".diff"); | ||
180 | qDebug() << '\n' << out; | 181 | QFile diffFile(diffFileName); | ||
182 | 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 :)
| |||||
183 | diffFile.write(process.readAllStandardOutput()); | ||||
184 | | ||||
185 | // force a failure to print the flename where we stored the diff. | ||||
dfaure: diffFile.write(out); would be simpler than going via QTextStream | |||||
186 | QVERIFY2(false, qPrintable(QLatin1String("This test failed, look at the following file for details: ") + diffFileName)); | ||||
dfaure: not needed, the dtor closes | |||||
181 | } | 187 | } | ||
182 | } | 188 | } |
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...