diff options
Diffstat (limited to 'tests/auto/testlib')
11 files changed, 267 insertions, 15 deletions
diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml b/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml new file mode 100644 index 0000000000..95b932e3c4 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml @@ -0,0 +1,30 @@ +<Environment> + <QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion> + <QtBuild/> + <QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion> +</Environment> +<TestFunction name="initTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="testQPair"> +<Incident type="fail" file="../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="51"> + <Description><![CDATA[Compared values are not the same + Actual (pair1): "QPair(1,1)" + Expected (pair2): "QPair(1,2)"]]></Description> +</Incident> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="testStdPair"> +<Incident type="fail" file="../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="58"> + <Description><![CDATA[Compared values are not the same + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)"]]></Description> +</Incident> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="cleanupTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<Duration msecs="0"/> diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity b/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity new file mode 100644 index 0000000000..06883570ac --- /dev/null +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity @@ -0,0 +1,12 @@ +##teamcity[testSuiteStarted name='tst_PairDiagnostics' flowId='tst_PairDiagnostics'] +##teamcity[testStarted name='initTestCase()' flowId='tst_PairDiagnostics'] +##teamcity[testFinished name='initTestCase()' flowId='tst_PairDiagnostics'] +##teamcity[testStarted name='testQPair()' flowId='tst_PairDiagnostics'] +##teamcity[testFailed name='testQPair()' message='Failure! |[Loc: ../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(51)|]' details='Compared values are not the same|n Actual (pair1): "QPair(1,1)"|n Expected (pair2): "QPair(1,2)"' flowId='tst_PairDiagnostics'] +##teamcity[testFinished name='testQPair()' flowId='tst_PairDiagnostics'] +##teamcity[testStarted name='testStdPair()' flowId='tst_PairDiagnostics'] +##teamcity[testFailed name='testStdPair()' message='Failure! |[Loc: ../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(58)|]' details='Compared values are not the same|n Actual (pair1): "std::pair(1,1)"|n Expected (pair2): "std::pair(1,2)"' flowId='tst_PairDiagnostics'] +##teamcity[testFinished name='testStdPair()' flowId='tst_PairDiagnostics'] +##teamcity[testStarted name='cleanupTestCase()' flowId='tst_PairDiagnostics'] +##teamcity[testFinished name='cleanupTestCase()' flowId='tst_PairDiagnostics'] +##teamcity[testSuiteFinished name='tst_PairDiagnostics' flowId='tst_PairDiagnostics'] diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.txt b/tests/auto/testlib/selftests/expected_pairdiagnostics.txt new file mode 100644 index 0000000000..e09b9a560f --- /dev/null +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.txt @@ -0,0 +1,14 @@ +********* Start testing of tst_PairDiagnostics ********* +Config: Using QtTest library @INSERT_QT_VERSION_HERE@, Qt @INSERT_QT_VERSION_HERE@ +PASS : tst_PairDiagnostics::initTestCase() +FAIL! : tst_PairDiagnostics::testQPair() Compared values are not the same + Actual (pair1): "QPair(1,1)" + Expected (pair2): "QPair(1,2)" + Loc: [../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(51)] +FAIL! : tst_PairDiagnostics::testStdPair() Compared values are not the same + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)" + Loc: [../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(58)] +PASS : tst_PairDiagnostics::cleanupTestCase() +Totals: 2 passed, 2 failed, 0 skipped, 0 blacklisted, 1ms +********* Finished testing of tst_PairDiagnostics ********* diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.xml b/tests/auto/testlib/selftests/expected_pairdiagnostics.xml new file mode 100644 index 0000000000..47921e0b8a --- /dev/null +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<TestCase name="tst_PairDiagnostics"> +<Environment> + <QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion> + <QtBuild/> + <QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion> +</Environment> +<TestFunction name="initTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0.680795"/> +</TestFunction> +<TestFunction name="testQPair"> +<Incident type="fail" file="../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="51"> + <Description><![CDATA[Compared values are not the same + Actual (pair1): "QPair(1,1)" + Expected (pair2): "QPair(1,2)"]]></Description> +</Incident> + <Duration msecs="0.085705"/> +</TestFunction> +<TestFunction name="testStdPair"> +<Incident type="fail" file="../../../qt5/qtbase_fixItemData/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="58"> + <Description><![CDATA[Compared values are not the same + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)"]]></Description> +</Incident> + <Duration msecs="0.030780"/> +</TestFunction> +<TestFunction name="cleanupTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0.039052"/> +</TestFunction> +<Duration msecs="0.995227"/> +</TestCase> diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.xunitxml b/tests/auto/testlib/selftests/expected_pairdiagnostics.xunitxml new file mode 100644 index 0000000000..cf2a30b84a --- /dev/null +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.xunitxml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<testsuite errors="0" failures="2" tests="4" name="tst_PairDiagnostics"> + <properties> + <property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/> + <property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/> + <property value="" name="QtBuild"/> + </properties> + <testcase result="pass" name="initTestCase"/> + <testcase result="fail" name="testQPair"> + <failure message="Compared values are not the same + Actual (pair1): "QPair(1,1)" + Expected (pair2): "QPair(1,2)"" result="fail"/> + </testcase> + <testcase result="fail" name="testStdPair"> + <failure message="Compared values are not the same + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)"" result="fail"/> + </testcase> + <testcase result="pass" name="cleanupTestCase"/> + <system-err/> +</testsuite> diff --git a/tests/auto/testlib/selftests/generate_expected_output.py b/tests/auto/testlib/selftests/generate_expected_output.py index 202c4cc426..a3a66da98b 100755 --- a/tests/auto/testlib/selftests/generate_expected_output.py +++ b/tests/auto/testlib/selftests/generate_expected_output.py @@ -32,9 +32,18 @@ # Usage: cd to the build directory corresponding to this script's # location; invoke this script; optionally pass the names of sub-dirs # to limit which tests to regenerate expected_* files for. +# +# The saved test output is used by ./tst_selftests.cpp, which compares +# it to the output of each test, ignoring various boring changes. +# This script canonicalises the parts that would exhibit those boring +# changes, so as to avoid noise in git (and conflicts in merges) for +# the saved copies of the output. If you add or remove any files, be +# sure to update selftests.qrc to match; the selftest only sees files +# listed there. import os import subprocess +import re class Fail (Exception): pass @@ -55,17 +64,18 @@ class Cleaner (object): def __init__(self, here, command): """Set up the details we need for later cleaning. - Takes two parameters: here is $PWD and command is how this - script was invoked, from which we'll work out where it is; in - a shadow build, the former is the build tree's location - corresponding to this last. Checks $PWD does look as expected - in a build tree - raising Fail() if not - then invokes qmake - to discover Qt version (saved as .version for the benefit of - clients) and prepares the sequence of (regex, replace) pairs - that .clean() needs to do its job.""" - self.version, self.__replace = self.__getPatterns(here, command) - - import re + Takes two parameters: here is os.getcwd() and command is how + this script was invoked, from which we'll work out where it + is; in a shadow build, the former is the build tree's location + corresponding to this last. Saves the directory of this + script as self.sourceDir, so client can find tst_selftests.cpp + there. Checks here does look as expected in a build tree - + raising Fail() if not - then invokes qmake to discover Qt + version (saved as .version for the benefit of clients) and + prepares the sequence of (regex, replace) pairs that .clean() + needs to do its job.""" + self.version, self.sourceDir, self.__replace = self.__getPatterns(here, command) + @staticmethod def __getPatterns(here, command, patterns = ( @@ -80,9 +90,10 @@ class Cleaner (object): (r'( *<QtBuild)>[^<]+</QtBuild>', r'\1/>'), # xml, lightxml (r'(<property value=")[^"]+(" name="QtBuild"/>)', r'\1\2'), # xunitxml # Line numbers in source files: + (r'(ASSERT: ".*" in file .*, line) \d+', r'\1 0'), # lightxml (r'(Loc: \[[^[\]()]+)\(\d+\)', r'\1(0)'), # txt (r'(\[Loc: [^[\]()]+)\(\d+\)', r'\1(0)'), # teamcity - (r'(<Incident.*\bfile=.*\bline=)"\d+"', r'\1"0"'), # lightxml, xml + (r'(<(?:Incident|Message)\b.*\bfile=.*\bline=)"\d+"', r'\1"0"'), # lightxml, xml ), precook = re.compile): """Private implementation details of __init__().""" @@ -131,8 +142,7 @@ class Cleaner (object): patterns += tuple((root.replace('-', '�*2D;'), r'') for root in roots if '-' in root) - return qtver, tuple((precook(p), r) for p, r in patterns) - del re + return qtver, scriptPath, tuple((precook(p), r) for p, r in patterns) def clean(self, data): """Remove volatile details from test output. @@ -145,6 +155,62 @@ class Cleaner (object): line = searchRe.sub(replaceExp, line) yield line +class Scanner (object): + """Knows which subdirectories to generate output for. + + Tell its constructor the name of this source directory (see + Cleaner's .sourceDir) and it'll scan tst_selftests.cpp for the + list. Its .subdirs() can then filter a user-supplied list of + subdirs or generate the full list, when the user supplied + none.""" + def __init__(self, srcDir): + self.__tested = tuple(self.__scan_cpp(os.path.join(srcDir, 'tst_selftests.cpp'))) + + @staticmethod + def __scan_cpp(name, + trimc = re.compile(r'/\*.*?\*/').sub, + trimcpp = re.compile(r'//.*$').sub, + first = re.compile(r'(QStringList|auto)\s+tests\s*=\s*QStringList\(\)').match, + match = re.compile(r'(?:tests\s*)?<<\s*"(\w+)"').match, + last = re.compile(r'\bfor.*\b(LoggerSet|auto)\b.*\ballLoggerSets\(\)').search): + """Scans tst_selftests.cpp to find which subdirs matter. + + There's a list, tests, to which all subdir names get added, if + they're to be tested. Other sub-dirs aren't tested, so + there's no sense in generating output for them.""" + scan = False + with open(name) as src: + for line in src: + line = trimcpp('', trimc('', line.strip())).strip() + if not scan: + got = first(line) + if got: + scan, line = True, line[len(got.group()):] + if scan: + if last(line): break + got = match(line) + while got: + yield got.group(1) + line = line[len(got.group()):].strip() + got = match(line) + + def subdirs(self, given): + if given: + for d in given: + if not os.path.isdir(d): + print('No such directory:', d, '- skipped') + elif d in self.__tested: + yield d + else: + print('Directory', d, 'is not tested by tst_selftests.cpp') + else: + for d in self.__tested: + if os.path.isdir(d): + yield d + else: + print('tst_selftests.cpp names', d, "as a test, but it doesn't exist") +del re + def generateTestData(testname, clean, formats = ('xml', 'txt', 'xunitxml', 'lightxml', 'teamcity'), extraArgs = { @@ -190,7 +256,7 @@ def main(name, *args): herePath = os.getcwd() cleaner = Cleaner(herePath, name) - tests = args if args else [d for d in os.listdir('.') if os.path.isdir(d)] + tests = tuple(Scanner(cleaner.sourceDir).subdirs(args)) print("Generating", len(tests), "test results for", cleaner.version, "in:", herePath) for path in tests: generateTestData(path, cleaner.clean) diff --git a/tests/auto/testlib/selftests/pairdiagnostics/pairdiagnostics.pro b/tests/auto/testlib/selftests/pairdiagnostics/pairdiagnostics.pro new file mode 100644 index 0000000000..1c07c93e9d --- /dev/null +++ b/tests/auto/testlib/selftests/pairdiagnostics/pairdiagnostics.pro @@ -0,0 +1,6 @@ +SOURCES += tst_pairdiagnostics.cpp +QT = core testlib + +CONFIG -= app_bundle debug_and_release_target + +TARGET = pairdiagnostics diff --git a/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp b/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp new file mode 100644 index 0000000000..bbee5334fe --- /dev/null +++ b/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Make sure we get a real Q_ASSERT even in release builds +#ifdef QT_NO_DEBUG +# undef QT_NO_DEBUG +#endif + +#include <QtCore/QCoreApplication> +#include <QtCore/QPair> +#include <QtTest/QtTest> + +class tst_PairDiagnostics: public QObject +{ + Q_OBJECT + +private slots: + void testQPair() const; + void testStdPair() const; +}; + +void tst_PairDiagnostics::testQPair() const +{ + QPair<int, int> pair1 = qMakePair(1, 1); + QPair<int, int> pair2 = qMakePair(1, 2); + QCOMPARE(pair1, pair2); +} + +void tst_PairDiagnostics::testStdPair() const +{ + std::pair<int, int> pair1 = std::make_pair(1, 1); + std::pair<int, int> pair2 = std::make_pair(1, 2); + QCOMPARE(pair1, pair2); +} + +QTEST_MAIN(tst_PairDiagnostics) + +#include "tst_pairdiagnostics.moc" diff --git a/tests/auto/testlib/selftests/selftests.pri b/tests/auto/testlib/selftests/selftests.pri index 66c7e06760..0287e35447 100644 --- a/tests/auto/testlib/selftests/selftests.pri +++ b/tests/auto/testlib/selftests/selftests.pri @@ -28,6 +28,7 @@ SUBPROGRAMS = \ longstring \ maxwarnings \ multiexec \ + pairdiagnostics \ printdatatags \ printdatatagswithglobaltags \ qexecstringlist \ diff --git a/tests/auto/testlib/selftests/selftests.qrc b/tests/auto/testlib/selftests/selftests.qrc index 3c3fef28d9..02e8adb6b4 100644 --- a/tests/auto/testlib/selftests/selftests.qrc +++ b/tests/auto/testlib/selftests/selftests.qrc @@ -115,6 +115,11 @@ <file>expected_maxwarnings.xml</file> <file>expected_maxwarnings.xunitxml</file> <file>expected_multiexec.txt</file> + <file>expected_pairdiagnostics.lightxml</file> + <file>expected_pairdiagnostics.teamcity</file> + <file>expected_pairdiagnostics.txt</file> + <file>expected_pairdiagnostics.xml</file> + <file>expected_pairdiagnostics.xunitxml</file> <file>expected_printdatatags.txt</file> <file>expected_printdatatagswithglobaltags.txt</file> <file>expected_qexecstringlist.txt</file> diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index e7123fc059..64f324e26c 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -395,6 +395,7 @@ void tst_Selftests::runSubTest_data() << "longstring" << "maxwarnings" << "multiexec" + << "pairdiagnostics" << "printdatatags" << "printdatatagswithglobaltags" << "qexecstringlist" |