Commit b5fdfe46 authored by Marco Bubke's avatar Marco Bubke

UnitTests: Cleanup Diagnostic test

Change-Id: Idf7d50ad15862508c2d57167f2147389e3bacba4
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 17080d70
......@@ -25,6 +25,7 @@
#include "googletest.h"
#include "diagnosticcontainer-matcher.h"
#include "rundocumentparse-utility.h"
#include "testenvironment.h"
#include <diagnostic.h>
......@@ -78,24 +79,14 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset,
return true;
}
struct DiagnosticData {
DiagnosticData(Document &document)
: diagnosticSet{document.translationUnit().diagnostics()}
, diagnostic{diagnosticSet.front()}
{
}
DiagnosticSet diagnosticSet;
::Diagnostic diagnostic;
};
class Diagnostic : public ::testing::Test
{
protected:
enum ChildMode { WithChild, WithoutChild };
struct Data {
Data()
{
document.parse();
d.reset(new DiagnosticData(document));
}
DiagnosticContainer expectedDiagnostic(ChildMode childMode) const;
protected:
ProjectPart projectPart{Utf8StringLiteral("projectPartId"),
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++11")})};
ClangBackEnd::ProjectParts projects;
......@@ -105,84 +96,72 @@ struct Data {
projectPart,
Utf8StringVector(),
documents};
std::unique_ptr<DiagnosticData> d;
};
class Diagnostic : public ::testing::Test
{
protected:
void SetUp() override;
void TearDown() override;
protected:
Data *d;
protected:
enum ChildMode { WithChild, WithoutChild };
DiagnosticContainer expectedDiagnostic(ChildMode childMode) const;
UnitTest::RunDocumentParse _1{document};
DiagnosticSet diagnosticSet{document.translationUnit().diagnostics()};
::Diagnostic diagnostic{diagnosticSet.front()};
};
using DiagnosticSlowTest = Diagnostic;
TEST_F(DiagnosticSlowTest, MoveContructor)
{
const auto diagnostic2 = std::move(d->d->diagnostic);
const auto diagnostic2 = std::move(diagnostic);
ASSERT_TRUE(d->d->diagnostic.isNull());
ASSERT_TRUE(diagnostic.isNull());
ASSERT_FALSE(diagnostic2.isNull());
}
TEST_F(DiagnosticSlowTest, MoveAssigment)
{
auto diagnostic2 = std::move(d->d->diagnostic);
d->d->diagnostic = std::move(diagnostic2);
auto diagnostic2 = std::move(diagnostic);
diagnostic = std::move(diagnostic2);
ASSERT_TRUE(diagnostic2.isNull());
ASSERT_FALSE(d->d->diagnostic.isNull());
ASSERT_FALSE(diagnostic.isNull());
}
TEST_F(DiagnosticSlowTest, MoveSelfAssigment)
{
d->d->diagnostic = std::move(d->d->diagnostic);
diagnostic = std::move(diagnostic);
ASSERT_FALSE(d->d->diagnostic.isNull());
ASSERT_FALSE(diagnostic.isNull());
}
TEST_F(DiagnosticSlowTest, Text)
{
ASSERT_THAT(d->d->diagnostic.text(), Utf8StringLiteral("warning: control reaches end of non-void function"));
ASSERT_THAT(diagnostic.text(), Utf8StringLiteral("warning: control reaches end of non-void function"));
}
TEST_F(DiagnosticSlowTest, Category)
{
ASSERT_THAT(d->d->diagnostic.category(), Utf8StringLiteral("Semantic Issue"));
ASSERT_THAT(diagnostic.category(), Utf8StringLiteral("Semantic Issue"));
}
TEST_F(DiagnosticSlowTest, EnableOption)
{
ASSERT_THAT(d->d->diagnostic.options().first, Utf8StringLiteral("-Wreturn-type"));
ASSERT_THAT(diagnostic.options().first, Utf8StringLiteral("-Wreturn-type"));
}
TEST_F(DiagnosticSlowTest, DisableOption)
{
ASSERT_THAT(d->d->diagnostic.options().second, Utf8StringLiteral("-Wno-return-type"));
ASSERT_THAT(diagnostic.options().second, Utf8StringLiteral("-Wno-return-type"));
}
TEST_F(DiagnosticSlowTest, Severity)
{
ASSERT_THAT(d->d->diagnostic.severity(), DiagnosticSeverity::Warning);
ASSERT_THAT(diagnostic.severity(), DiagnosticSeverity::Warning);
}
TEST_F(DiagnosticSlowTest, ChildDiagnosticsSize)
{
auto diagnostic = d->d->diagnosticSet.back();
auto diagnostic = diagnosticSet.back();
ASSERT_THAT(diagnostic.childDiagnostics().size(), 1);
}
TEST_F(DiagnosticSlowTest, ChildDiagnosticsText)
{
auto childDiagnostic = d->d->diagnosticSet.back().childDiagnostics().front();
auto childDiagnostic = diagnosticSet.back().childDiagnostics().front();
ASSERT_THAT(childDiagnostic.text(), Utf8StringLiteral("note: candidate function not viable: requires 1 argument, but 0 were provided"));
}
......@@ -191,22 +170,11 @@ TEST_F(DiagnosticSlowTest, toDiagnosticContainerLetChildrenThroughByDefault)
{
const auto diagnosticWithChild = expectedDiagnostic(WithChild);
const auto diagnostic = d->d->diagnosticSet.back().toDiagnosticContainer();
const auto diagnostic = diagnosticSet.back().toDiagnosticContainer();
ASSERT_THAT(diagnostic, IsDiagnosticContainer(diagnosticWithChild));
}
void Diagnostic::SetUp()
{
d = new Data;
}
void Diagnostic::TearDown()
{
delete d;
d = nullptr;
}
DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMode) const
{
QVector<DiagnosticContainer> children;
......@@ -216,7 +184,7 @@ DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMo
Utf8StringLiteral("Semantic Issue"),
{Utf8String(), Utf8String()},
ClangBackEnd::DiagnosticSeverity::Note,
SourceLocationContainer(d->document.filePath(), 5, 6),
SourceLocationContainer(document.filePath(), 5, 6),
{},
{},
{}
......@@ -230,7 +198,7 @@ DiagnosticContainer Diagnostic::expectedDiagnostic(Diagnostic::ChildMode childMo
Utf8StringLiteral("Semantic Issue"),
{Utf8String(), Utf8String()},
ClangBackEnd::DiagnosticSeverity::Error,
SourceLocationContainer(d->document.filePath(), 7, 5),
SourceLocationContainer(document.filePath(), 7, 5),
{},
{},
children
......
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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.
**
****************************************************************************/
#pragma once
#include <clangdocument.h>
namespace UnitTest {
struct RunDocumentParse {
RunDocumentParse(ClangBackEnd::Document &document)
{
document.parse();
}
};
} // namespace UnitTest
......@@ -220,7 +220,8 @@ HEADERS += \
mocksqlitestatement.h \
unittest-utility-functions.h \
mocksymbolquery.h \
runprojectcreateorupdate-utility.h
runprojectcreateorupdate-utility.h \
rundocumentparse-utility.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \
chunksreportedmonitor.h \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment