diff options
-rw-r--r-- | mkspecs/features/qttest_p4.prf | 36 | ||||
-rw-r--r-- | mkspecs/features/testcase.prf | 65 | ||||
-rw-r--r-- | tests/auto/maketestselftest/checktest/checktest.pro | 7 | ||||
-rw-r--r-- | tests/auto/maketestselftest/checktest/main.cpp | 99 | ||||
-rw-r--r-- | tests/auto/maketestselftest/maketestselftest.pro | 9 | ||||
-rw-r--r-- | tests/auto/maketestselftest/test/test.pro | 18 | ||||
-rw-r--r-- | tests/auto/maketestselftest/tst_maketestselftest.cpp | 76 |
7 files changed, 269 insertions, 41 deletions
diff --git a/mkspecs/features/qttest_p4.prf b/mkspecs/features/qttest_p4.prf index d2011d0..d1c7c2b 100644 --- a/mkspecs/features/qttest_p4.prf +++ b/mkspecs/features/qttest_p4.prf @@ -1,5 +1,5 @@ isEmpty(TEMPLATE):TEMPLATE=app -CONFIG += qt warn_on console depend_includepath +CONFIG += qt warn_on console depend_includepath testcase qtAddLibrary(QtTest) @@ -13,39 +13,5 @@ symbian:{ # prefix test binary with tst_ !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") - -check.files = -check.path = . -!isEmpty(DESTDIR): check.commands = cd ./$(DESTDIR) && -macx: check.commands += ./$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET) -else:unix: check.commands += ./$(QMAKE_TARGET) -else:win32: { - CONFIG(debug, debug|release):check.commands += $(DESTDIR_TARGET) - else:check.commands += $(DESTDIR_TARGET) -} -embedded: check.commands += -qws -QMAKE_EXTRA_TARGETS += check - -!debug_and_release|build_pass { - check.depends = first -} else { - check.CONFIG = recursive - # In debug and release mode, only run the test once. - # Run debug if available, release otherwise. - debug_and_release { - check.target = dummy_check - check.recurse_target = check - debug { - real_check.depends = debug-check - real_check.target = check - QMAKE_EXTRA_TARGETS += real_check - } else { - real_check.depends = release-check - real_check.target = check - QMAKE_EXTRA_TARGETS += real_check - } - } -} - target.path += $$[QT_INSTALL_PREFIX]/tests/qt4 INSTALLS += target diff --git a/mkspecs/features/testcase.prf b/mkspecs/features/testcase.prf new file mode 100644 index 0000000..2a56d7d --- /dev/null +++ b/mkspecs/features/testcase.prf @@ -0,0 +1,65 @@ +!contains(TEMPLATE,subdirs) { + +check.files = +check.path = . + +# If the test ends up in a different directory, we should cd to that directory. +# Note that qmake modifies DESTDIR after this file is processed, +# therefore, testing DESTDIR for emptiness is not sufficient. +# Also note that in debug-and-release mode we don't want to cd into the debug/release +# directory (e.g. if the test goes to foo/release/tst_thing.exe, we want to do +# cd foo && release/tst_thing.exe ). +MUNGED_DESTDIR=$$DESTDIR +MUNGED_TARGET=$$TARGET +win32:debug_and_release { + contains(DESTDIR,^release$)|contains(DESTDIR,^debug$):MUNGED_DESTDIR= + + # In debug-and-release mode, the first ../ in TARGET breaks out of the debug/release + # subdirectory. However, since make's working directory is already outside of the + # debug/release subdirectory, this first ../ should be ignored when deciding if + # we have to change directory before running the test. + MUNGED_TARGET=$$replace(MUNGED_TARGET,^\.\./,) +} +!isEmpty(MUNGED_DESTDIR):!contains(MUNGED_DESTDIR,^\./?):check.commands = cd $(DESTDIR) && +contains(MUNGED_TARGET,.*/.*):check.commands = cd $(DESTDIR) && + +# Allow for a custom test runner script +check.commands += $(TESTRUNNER) + +macx { + app_bundle: check.commands += ./$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET) + else: check.commands += ./$(QMAKE_TARGET) +} +else:unix: check.commands += ./$(QMAKE_TARGET) +else: check.commands += $(DESTDIR_TARGET) + +# For Qt/Embedded, run every test app as a QWS server +embedded: check.commands += -qws + +# Allow for custom arguments to tests +check.commands += $(TESTARGS) +QMAKE_EXTRA_TARGETS *= check + +!debug_and_release|build_pass { + check.depends = first +} else { + check.CONFIG = recursive + # In debug and release mode, only run the test once. + # Run debug if available, release otherwise. + debug_and_release { + check.target = dummy_check + check.recurse_target = check + debug { + real_check.depends = debug-check + real_check.target = check + QMAKE_EXTRA_TARGETS += real_check + } else { + real_check.depends = release-check + real_check.target = check + QMAKE_EXTRA_TARGETS += real_check + } + } +} + +} + diff --git a/tests/auto/maketestselftest/checktest/checktest.pro b/tests/auto/maketestselftest/checktest/checktest.pro new file mode 100644 index 0000000..79c5ca5 --- /dev/null +++ b/tests/auto/maketestselftest/checktest/checktest.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +TARGET = checktest +CONFIG += console +CONFIG -= app_bundle +DESTDIR = ./ +QT = core +SOURCES += main.cpp diff --git a/tests/auto/maketestselftest/checktest/main.cpp b/tests/auto/maketestselftest/checktest/main.cpp new file mode 100644 index 0000000..af98953 --- /dev/null +++ b/tests/auto/maketestselftest/checktest/main.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QCoreApplication> +#include <QDir> +#include <QFile> +#include <QFileInfo> +#include <QStringList> + +#include <stdio.h> +#include <stdlib.h> + +void fail(QString const& message) +{ + printf("CHECKTEST FAIL: %s\n", qPrintable(message)); + exit(0); +} + +void pass(QString const& message) +{ + printf("CHECKTEST PASS: %s\n", qPrintable(message)); + exit(0); +} + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + QStringList args = app.arguments(); + args.removeFirst(); // ourself + + QString args_quoted = QString("'%1'").arg(args.join("','")); + +#ifdef Q_WS_QWS + { + // for QWS we expect tests to be run as the QWS server + QString qws = args.takeLast(); + if (qws != "-qws") { + fail(QString("Expected test to be run with `-qws', but it wasn't; args: %1").arg(args_quoted)); + } + } +#endif + + if (args.count() != 1) { + fail(QString("These arguments are not what I expected: %1").arg(args_quoted)); + } + + QString test = args.at(0); + + QFileInfo testfile(test); + if (!testfile.exists()) { + fail(QString("File %1 does not exist (my working directory is: %2, my args are: %3)") + .arg(test) + .arg(QDir::currentPath()) + .arg(args_quoted) + ); + } + + pass(args_quoted); +} + diff --git a/tests/auto/maketestselftest/maketestselftest.pro b/tests/auto/maketestselftest/maketestselftest.pro index 6cc1744..a27d5d7 100644 --- a/tests/auto/maketestselftest/maketestselftest.pro +++ b/tests/auto/maketestselftest/maketestselftest.pro @@ -1,9 +1,6 @@ -load(qttest_p4) - -SOURCES += tst_maketestselftest.cpp -QT = core - -DEFINES += SRCDIR=\\\"$$PWD/\\\" +TEMPLATE = subdirs +SUBDIRS = checktest test +test.depends = checktest requires(!cross_compile) diff --git a/tests/auto/maketestselftest/test/test.pro b/tests/auto/maketestselftest/test/test.pro new file mode 100644 index 0000000..d9de51e --- /dev/null +++ b/tests/auto/maketestselftest/test/test.pro @@ -0,0 +1,18 @@ +load(qttest_p4) + +TARGET = ../tst_maketestselftest +SOURCES += ../tst_maketestselftest.cpp +QT = core + +DEFINES += SRCDIR=\\\"$$PWD/..\\\" + +requires(!cross_compile) + +win32 { + CONFIG(debug, debug|release) { + TARGET = ../../debug/tst_maketestselftest +} else { + TARGET = ../../release/tst_maketestselftest + } +} + diff --git a/tests/auto/maketestselftest/tst_maketestselftest.cpp b/tests/auto/maketestselftest/tst_maketestselftest.cpp index 437e143..3d1bbed 100644 --- a/tests/auto/maketestselftest/tst_maketestselftest.cpp +++ b/tests/auto/maketestselftest/tst_maketestselftest.cpp @@ -66,6 +66,8 @@ private slots: void naming_convention(); void naming_convention_data(); + void make_check(); + private: QStringList find_subdirs(QString const&, FindSubdirsMode, QString const& = QString()); @@ -446,6 +448,80 @@ QStringList tst_MakeTestSelfTest::find_subdirs(QString const& pro_file, FindSubd return out; } +void tst_MakeTestSelfTest::make_check() +{ + /* + Run `make check' over the whole tests tree with a custom TESTRUNNER, + to verify that the TESTRUNNER mechanism works right. + */ + QString testsDir(SRCDIR "/.."); + QString checktest(SRCDIR "/checktest/checktest"); + +#ifdef Q_OS_WIN32 + if (qgetenv("RUN_SLOW_TESTS").isEmpty()) { + QSKIP("This test is too slow to run by default on Windows. Set RUN_SLOW_TESTS=1 to run it.", SkipAll); + } + checktest.replace("/", "\\"); + checktest += ".exe"; +#endif + + QProcess make; + make.setWorkingDirectory(testsDir); + + QStringList arguments; + arguments << "-k"; + arguments << "check"; + arguments << QString("TESTRUNNER=%1").arg(checktest); + + // find the right make; from externaltests.cpp + static const char makes[] = + "nmake.exe\0" + "mingw32-make.exe\0" + "gmake\0" + "make\0" + ; + + bool ok = false; + for (const char *p = makes; *p; p += strlen(p) + 1) { + make.start(p, arguments); + if (make.waitForStarted()) { + ok = true; + break; + } + } + + if (!ok) { + QFAIL("Could not find the right make tool in PATH"); + } + + QVERIFY(make.waitForFinished(1000 * 60 * 10)); + QCOMPARE(make.exitStatus(), QProcess::NormalExit); + + int pass = 0; + QList<QByteArray> out = make.readAllStandardOutput().split('\n'); + QStringList fails; + foreach (QByteArray line, out) { + while (line.endsWith("\r")) { + line.chop(1); + } + if (line.startsWith("CHECKTEST FAIL")) { + fails << QString::fromLocal8Bit(line); + } + if (line.startsWith("CHECKTEST PASS")) { + ++pass; + } + } + + // We can't check that the exit code of make is 0, because some tests + // may have failed to compile, but that doesn't mean `make check' is broken. + // We do assume there are at least this many unbroken tests, though. + QVERIFY2(fails.count() == 0, + qPrintable(QString("`make check' doesn't work for %1 tests:\n%2") + .arg(fails.count()).arg(fails.join("\n"))) + ); + QVERIFY(pass > 50); +} + QStringList find_test_class(QString const& filename) { QStringList out; |