"Fossies" - the Fresh Open Source Software Archive

Member "qt-creator-opensource-src-4.15.1/src/plugins/autotest/ctest/ctestoutputreader.cpp" (8 Jun 2021, 6331 Bytes) of package /linux/misc/qt-creator-opensource-src-4.15.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ctestoutputreader.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: opensource-src-4.15.0_vs_opensource-src-4.15.1.

    1 /****************************************************************************
    2 **
    3 ** Copyright (C) 2020 The Qt Company Ltd.
    4 **
    5 ** This file is part of Qt Creator.
    6 **
    7 ** Commercial License Usage
    8 ** Licensees holding valid commercial Qt licenses may use this file in
    9 ** accordance with the commercial license agreement provided with the
   10 ** Software or, alternatively, in accordance with the terms contained in
   11 ** a written agreement between you and The Qt Company. For licensing terms
   12 ** and conditions see https://www.qt.io/terms-conditions. For further
   13 ** information use the contact form at https://www.qt.io/contact-us.
   14 **
   15 ** GNU General Public License Usage
   16 ** Alternatively, this file may be used under the terms of the GNU
   17 ** General Public License version 3 as published by the Free Software
   18 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
   19 ** included in the packaging of this file. Please review the following
   20 ** information to ensure the GNU General Public License requirements will
   21 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
   22 **
   23 ****************************************************************************/
   24 
   25 #include "ctestoutputreader.h"
   26 
   27 #include "ctesttreeitem.h"
   28 #include "../testframeworkmanager.h"
   29 #include "../testresult.h"
   30 
   31 #include <cmakeprojectmanager/cmakeprojectconstants.h>
   32 
   33 #include <utils/qtcassert.h>
   34 
   35 #include <QRegularExpression>
   36 
   37 namespace Autotest {
   38 namespace Internal {
   39 
   40 class CTestResult : public TestResult
   41 {
   42 public:
   43     CTestResult(const QString &id, const QString &project, const QString &testCase)
   44         : TestResult(id, project)
   45         , m_testCase(testCase)
   46     {}
   47 
   48     bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const override
   49     {
   50         if (!TestResult::isDirectParentOf(other, needsIntermediate))
   51             return false;
   52         return result() == ResultType::TestStart;
   53     }
   54 
   55     const ITestTreeItem *findTestTreeItem() const override
   56     {
   57         ITestTool *testTool = TestFrameworkManager::testToolForBuildSystemId(
   58                     CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
   59         QTC_ASSERT(testTool, return nullptr);
   60         const ITestTreeItem *rootNode = testTool->rootNode();
   61         if (!rootNode)
   62             return nullptr;
   63 
   64         return rootNode->findFirstLevelChild([this](const ITestTreeItem *item) {
   65             return item && item->name() == m_testCase;
   66         });
   67     }
   68 
   69 private:
   70     QString m_testCase;
   71 };
   72 
   73 CTestOutputReader::CTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
   74                                      QProcess *testApplication, const QString &buildDirectory)
   75     : TestOutputReader(futureInterface, testApplication, buildDirectory)
   76 {
   77 }
   78 
   79 void CTestOutputReader::processOutputLine(const QByteArray &outputLine)
   80 {
   81     static const QRegularExpression testProject("^Test project (.*)$");
   82     static const QRegularExpression testCase("^(test \\d+)|(    Start\\s+\\d+: .*)$");
   83     static const QRegularExpression testResult("^\\s*\\d+/\\d+ Test\\s+#\\d+: (.*) (\\.+)\\s*"
   84                                                "(Passed|\\*\\*\\*Failed|\\*\\*\\*Not Run|"
   85                                                ".*\\*\\*\\*Exception:.*)\\s+(.*) sec$");
   86     static const QRegularExpression summary("^\\d+% tests passed, (\\d+) tests failed "
   87                                             "out of (\\d+)");
   88     static const QRegularExpression summaryTime("^Total Test time .* =\\s+(.*) sec$");
   89 
   90     const QString line = removeCommandlineColors(QString::fromLatin1(outputLine));
   91     if (line.trimmed().isEmpty())
   92         return;
   93 
   94     struct ExactMatch : public QRegularExpressionMatch
   95     {
   96         ExactMatch(const QRegularExpressionMatch &other) : QRegularExpressionMatch(other) {}
   97         operator bool() const { return hasMatch(); }
   98     };
   99 
  100     if (ExactMatch match = testProject.match(line)) {
  101         if (!m_testName.isEmpty()) // possible?
  102             sendCompleteInformation();
  103         m_project = match.captured(1);
  104         TestResultPtr testResult = createDefaultResult();
  105         testResult->setResult(ResultType::TestStart);
  106         testResult->setDescription(tr("Running tests for %1").arg(m_project));
  107         reportResult(testResult);
  108     } else if (ExactMatch match = testCase.match(line)) {
  109         if (!m_testName.isEmpty())
  110             sendCompleteInformation();
  111     } else if (ExactMatch match = testResult.match(line)) {
  112         m_description = match.captured();
  113         m_testName = match.captured(1);
  114         const QString resultType = match.captured(3);
  115         if (resultType == "Passed")
  116             m_result = ResultType::Pass;
  117         else if (resultType == "***Failed" || resultType == "***Not Run")
  118             m_result = ResultType::Fail;
  119         else
  120             m_result = ResultType::MessageFatal;
  121     } else if (ExactMatch match = summary.match(line)) {
  122         if (!m_testName.isEmpty())
  123             sendCompleteInformation();
  124         TestResultPtr testResult = createDefaultResult();
  125         testResult->setResult(ResultType::MessageInfo);
  126         testResult->setDescription(match.captured());
  127         reportResult(testResult);
  128         int failed = match.captured(1).toInt();
  129         int testCount = match.captured(2).toInt();
  130         m_summary.insert(ResultType::Fail, failed);
  131         m_summary.insert(ResultType::Pass, testCount - failed);
  132     } else if (ExactMatch match = summaryTime.match(line)) {
  133         if (!m_testName.isEmpty()) // possible?
  134             sendCompleteInformation();
  135         TestResultPtr testResult = createDefaultResult();
  136         testResult->setResult(ResultType::TestEnd);
  137         testResult->setDescription(match.captured());
  138         reportResult(testResult);
  139     } else {
  140         if (!m_description.isEmpty())
  141             m_description.append('\n');
  142         m_description.append(line);
  143     }
  144 }
  145 
  146 TestResultPtr CTestOutputReader::createDefaultResult() const
  147 {
  148     return TestResultPtr(new CTestResult(id(), m_project, m_testName));
  149 }
  150 
  151 void CTestOutputReader::sendCompleteInformation()
  152 {
  153     TestResultPtr testResult = createDefaultResult();
  154     testResult->setResult(m_result);
  155     testResult->setDescription(m_description);
  156     reportResult(testResult);
  157     m_testName.clear();
  158     m_description.clear();
  159     m_result = ResultType::Invalid;
  160 }
  161 
  162 } // namespace Internal
  163 } // namespace Autotest