summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2010-03-19 01:59:07 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2010-03-22 00:27:36 (GMT)
commit3f2485e98ff52505d9277459b0b0403c26fb165f (patch)
tree92c55e93c8fec501bd1fbaad717a741a6022bdd1
parent71dedbee1f5a23411e2c82157a6fe6ee5d48ab6e (diff)
downloadQt-3f2485e98ff52505d9277459b0b0403c26fb165f.zip
Qt-3f2485e98ff52505d9277459b0b0403c26fb165f.tar.gz
Qt-3f2485e98ff52505d9277459b0b0403c26fb165f.tar.bz2
Make maketestselftest more strict.
-rw-r--r--tests/auto/auto.pro3
-rw-r--r--tests/auto/declarative.pro4
-rw-r--r--tests/auto/maketestselftest/tst_maketestselftest.cpp138
3 files changed, 143 insertions, 2 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 497e720..c0004f7 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -18,6 +18,5 @@ contains(QT_CONFIG, webkit): SUBDIRS += webkit.pro
contains(QT_CONFIG, multimedia): SUBDIRS += multimedia.pro
contains(QT_CONFIG, phonon): SUBDIRS += phonon.pro
contains(QT_CONFIG, svg): SUBDIRS += svg.pro
-contains(QT_CONFIG, declarative): SUBDIRS += declarative
-
+contains(QT_CONFIG, declarative): SUBDIRS += declarative.pro
diff --git a/tests/auto/declarative.pro b/tests/auto/declarative.pro
new file mode 100644
index 0000000..f2173f0
--- /dev/null
+++ b/tests/auto/declarative.pro
@@ -0,0 +1,4 @@
+TEMPLATE=subdirs
+SUBDIRS=\
+ declarative \
+
diff --git a/tests/auto/maketestselftest/tst_maketestselftest.cpp b/tests/auto/maketestselftest/tst_maketestselftest.cpp
index 8264e27..638e103 100644
--- a/tests/auto/maketestselftest/tst_maketestselftest.cpp
+++ b/tests/auto/maketestselftest/tst_maketestselftest.cpp
@@ -44,16 +44,53 @@
#include <QRegExp>
#include <QStringList>
#include <QTest>
+#include <QSet>
+#include <QProcess>
+#include <QDebug>
+
+enum FindSubdirsMode {
+ Flat = 0,
+ Recursive
+};
class tst_MakeTestSelfTest: public QObject
{
Q_OBJECT
private slots:
+ void tests_auto_pro();
+
void tests_pro_files();
void tests_pro_files_data();
+
+private:
+ QStringList find_subdirs(QString const&, FindSubdirsMode);
};
+/*
+ Verify that auto.pro only contains other .pro files (and not directories).
+ We enforce this so that we can process every .pro file other than auto.pro
+ independently and get all the tests.
+ If tests were allowed to appear directly in auto.pro, we'd have the problem
+ that we need to somehow run these tests from auto.pro while preventing
+ recursion into the other .pro files.
+*/
+void tst_MakeTestSelfTest::tests_auto_pro()
+{
+ QStringList subdirsList = find_subdirs(SRCDIR "/../auto.pro", Flat);
+ if (QTest::currentTestFailed()) {
+ return;
+ }
+
+ foreach (QString const& subdir, subdirsList) {
+ QVERIFY2(subdir.endsWith(".pro"), qPrintable(QString(
+ "auto.pro contains a subdir `%1'.\n"
+ "auto.pro must _only_ contain other .pro files, not actual subdirs.\n"
+ "Please move `%1' into some other .pro file referenced by auto.pro."
+ ).arg(subdir)));
+ }
+}
+
/* Verify that all tests are listed somewhere in one of the autotest .pro files */
void tst_MakeTestSelfTest::tests_pro_files()
{
@@ -82,6 +119,8 @@ void tst_MakeTestSelfTest::tests_pro_files()
}
}
+
+
QFAIL(qPrintable(QString(
"Subdir `%1' is missing from tests/auto/*.pro\n"
"This means the test won't be compiled or run on any platform.\n"
@@ -106,5 +145,104 @@ void tst_MakeTestSelfTest::tests_pro_files_data()
}
}
+/*
+ Returns a list of all subdirs in a given .pro file
+*/
+QStringList tst_MakeTestSelfTest::find_subdirs(QString const& pro_file, FindSubdirsMode mode)
+{
+ QStringList out;
+
+ QByteArray features = qgetenv("QMAKEFEATURES");
+
+ if (features.isEmpty()) {
+ features = SRCDIR "/features";
+ }
+ else {
+ features.prepend(SRCDIR "/features:");
+ }
+
+ QStringList args;
+ args << pro_file << "-o" << SRCDIR "/dummy_output" << "CONFIG+=dump_subdirs";
+
+ QString cmd_with_args = QString("qmake %1").arg(args.join(" "));
+
+ QProcess proc;
+
+ proc.setProcessChannelMode(QProcess::MergedChannels);
+
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+ env.insert("QMAKEFEATURES", features);
+ proc.setProcessEnvironment(env);
+
+ proc.start("qmake", args);
+ if (!proc.waitForStarted(10000)) {
+ QTest::qFail(qPrintable(QString("Failed to run qmake: %1\nCommand: %2")
+ .arg(proc.errorString())
+ .arg(cmd_with_args)),
+ __FILE__, __LINE__
+ );
+ return out;
+ }
+ if (!proc.waitForFinished(30000)) {
+ QTest::qFail(qPrintable(QString("qmake did not finish within 30 seconds\nCommand: %1\nOutput: %2")
+ .arg(proc.errorString())
+ .arg(cmd_with_args)
+ .arg(QString::fromLocal8Bit(proc.readAll()))),
+ __FILE__, __LINE__
+ );
+ return out;
+ }
+
+ if (proc.exitStatus() != QProcess::NormalExit) {
+ QTest::qFail(qPrintable(QString("qmake crashed\nCommand: %1\nOutput: %2")
+ .arg(cmd_with_args)
+ .arg(QString::fromLocal8Bit(proc.readAll()))),
+ __FILE__, __LINE__
+ );
+ return out;
+ }
+
+ if (proc.exitCode() != 0) {
+ QTest::qFail(qPrintable(QString("qmake exited with code %1\nCommand: %2\nOutput: %3")
+ .arg(proc.exitCode())
+ .arg(cmd_with_args)
+ .arg(QString::fromLocal8Bit(proc.readAll()))),
+ __FILE__, __LINE__
+ );
+ return out;
+ }
+
+ QList<QByteArray> lines = proc.readAll().split('\n');
+ if (!lines.count()) {
+ QTest::qFail(qPrintable(QString("qmake seems to have not output anything\nCommand: %1\n")
+ .arg(cmd_with_args)),
+ __FILE__, __LINE__
+ );
+ return out;
+ }
+
+ foreach (QByteArray const& line, lines) {
+ static const QByteArray marker = "Project MESSAGE: subdir: ";
+ if (line.startsWith(marker)) {
+ QString subdir = QString::fromLocal8Bit(line.mid(marker.size()));
+ out << subdir;
+
+ if (mode == Flat) {
+ continue;
+ }
+
+ // Add subdirs recursively
+ if (subdir.endsWith(".pro")) {
+ // Need full path to .pro file
+ QString subdir_pro = subdir;
+ subdir_pro.prepend(QFileInfo(pro_file).path() + "/");
+ out << find_subdirs(subdir_pro, mode);
+ }
+ }
+ }
+
+ return out;
+}
+
QTEST_MAIN(tst_MakeTestSelfTest)
#include "tst_maketestselftest.moc"