Skip to content

Commit

Permalink
tests: better test initializing allowing for better printing (#5379)
Browse files Browse the repository at this point in the history
Co-authored-by: Nerixyz <nerixdev@outlook.de>
  • Loading branch information
pajlada and Nerixyz authored May 5, 2024
1 parent a88a2ac commit 401feac
Show file tree
Hide file tree
Showing 41 changed files with 198 additions and 178 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unversioned

- Dev: Add doxygen build target. (#5377)
- Dev: Make printing of strings in tests easier. (#5379)

## 2.5.1

Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ option(CHATTERINO_TEST_USE_PUBLIC_HTTPBIN "Use public httpbin for testing networ
set(test_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
${CMAKE_CURRENT_LIST_DIR}/resources/test-resources.qrc
${CMAKE_CURRENT_LIST_DIR}/src/TestHelpers.hpp
${CMAKE_CURRENT_LIST_DIR}/src/Test.hpp
${CMAKE_CURRENT_LIST_DIR}/src/Test.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ChannelChatters.cpp
${CMAKE_CURRENT_LIST_DIR}/src/AccessGuard.cpp
${CMAKE_CURRENT_LIST_DIR}/src/NetworkCommon.cpp
Expand Down
2 changes: 1 addition & 1 deletion tests/src/AccessGuard.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "common/UniqueAccess.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QDebug>
#include <QString>

Expand Down
2 changes: 1 addition & 1 deletion tests/src/BasicPubSub.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "providers/liveupdates/BasicPubSubClient.hpp"
#include "providers/liveupdates/BasicPubSubManager.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
Expand Down
3 changes: 2 additions & 1 deletion tests/src/BttvLiveUpdates.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "providers/bttv/BttvLiveUpdates.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

#include <QString>

#include <optional>
Expand Down
2 changes: 1 addition & 1 deletion tests/src/ChannelChatters.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "common/ChannelChatters.hpp"

#include "mocks/Channel.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QColor>
#include <QStringList>

Expand Down
3 changes: 2 additions & 1 deletion tests/src/ChatterSet.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common/ChatterSet.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

#include <QStringList>

TEST(ChatterSet, insert)
Expand Down
3 changes: 1 addition & 2 deletions tests/src/Emojis.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "providers/emoji/Emojis.hpp"

#include "common/Literals.hpp"
#include "TestHelpers.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QDebug>
#include <QString>

Expand Down
2 changes: 1 addition & 1 deletion tests/src/ExponentialBackoff.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "util/ExponentialBackoff.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

using namespace chatterino;

Expand Down
43 changes: 19 additions & 24 deletions tests/src/Filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "providers/twitch/TwitchBadge.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Emotes.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QColor>
#include <QVariant>

Expand Down Expand Up @@ -101,7 +101,7 @@ namespace chatterino::filters {

std::ostream &operator<<(std::ostream &os, Type t)
{
os << qUtf8Printable(typeToString(t));
os << typeToString(t);
return os;
}

Expand Down Expand Up @@ -138,8 +138,8 @@ TEST(Filters, Validity)
auto filterResult = Filter::fromString(input);
bool isValid = std::holds_alternative<Filter>(filterResult);
EXPECT_EQ(isValid, expected)
<< "Filter::fromString( " << qUtf8Printable(input)
<< " ) should be " << (expected ? "valid" : "invalid");
<< "Filter::fromString( " << input << " ) should be "
<< (expected ? "valid" : "invalid");
}
}

Expand Down Expand Up @@ -168,15 +168,14 @@ TEST(Filters, TypeSynthesis)
{
auto filterResult = Filter::fromString(input);
bool isValid = std::holds_alternative<Filter>(filterResult);
ASSERT_TRUE(isValid) << "Filter::fromString( " << qUtf8Printable(input)
<< " ) is invalid";
ASSERT_TRUE(isValid)
<< "Filter::fromString( " << input << " ) is invalid";

auto filter = std::move(std::get<Filter>(filterResult));
T type = filter.returnType();
EXPECT_EQ(type, expected)
<< "Filter{ " << qUtf8Printable(input) << " } has type " << type
<< " instead of " << expected << ".\nDebug: "
<< qUtf8Printable(filter.debugString(typingContext));
<< "Filter{ " << input << " } has type " << type << " instead of "
<< expected << ".\nDebug: " << filter.debugString(typingContext);
}
}

Expand Down Expand Up @@ -244,17 +243,16 @@ TEST(Filters, Evaluation)
{
auto filterResult = Filter::fromString(input);
bool isValid = std::holds_alternative<Filter>(filterResult);
ASSERT_TRUE(isValid) << "Filter::fromString( " << qUtf8Printable(input)
<< " ) is invalid";
ASSERT_TRUE(isValid)
<< "Filter::fromString( " << input << " ) is invalid";

auto filter = std::move(std::get<Filter>(filterResult));
auto result = filter.execute(contextMap);

EXPECT_EQ(result, expected)
<< "Filter{ " << qUtf8Printable(input) << " } evaluated to "
<< qUtf8Printable(result.toString()) << " instead of "
<< qUtf8Printable(expected.toString()) << ".\nDebug: "
<< qUtf8Printable(filter.debugString(typingContext));
<< "Filter{ " << input << " } evaluated to " << result.toString()
<< " instead of " << expected.toString()
<< ".\nDebug: " << filter.debugString(typingContext);
}
}

Expand Down Expand Up @@ -354,20 +352,17 @@ TEST_F(FiltersF, ExpressionDebug)
{
const auto filterResult = Filter::fromString(input);
const auto *filter = std::get_if<Filter>(&filterResult);
EXPECT_NE(filter, nullptr)
<< "Filter::fromString(" << qUtf8Printable(input)
<< ") did not build a proper filter";
EXPECT_NE(filter, nullptr) << "Filter::fromString(" << input
<< ") did not build a proper filter";

const auto actualDebugString = filter->debugString(typingContext);
EXPECT_EQ(actualDebugString, debugString)
<< "filter->debugString() on '" << qUtf8Printable(input)
<< "' should be '" << qUtf8Printable(debugString) << "', but got '"
<< qUtf8Printable(actualDebugString) << "'";
<< "filter->debugString() on '" << input << "' should be '"
<< debugString << "', but got '" << actualDebugString << "'";

const auto actualFilterString = filter->filterString();
EXPECT_EQ(actualFilterString, filterString)
<< "filter->filterString() on '" << qUtf8Printable(input)
<< "' should be '" << qUtf8Printable(filterString) << "', but got '"
<< qUtf8Printable(actualFilterString) << "'";
<< "filter->filterString() on '" << input << "' should be '"
<< filterString << "', but got '" << actualFilterString << "'";
}
}
13 changes: 6 additions & 7 deletions tests/src/FormatTime.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "util/FormatTime.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

#include <chrono>

Expand Down Expand Up @@ -62,8 +62,8 @@ TEST(FormatTime, Int)
const auto actual = formatTime(input);

EXPECT_EQ(actual, expected)
<< qUtf8Printable(actual) << " (" << input
<< ") did not match expected value " << qUtf8Printable(expected);
<< actual << " (" << input << ") did not match expected value "
<< expected;
}
}

Expand Down Expand Up @@ -130,8 +130,8 @@ TEST(FormatTime, QString)
const auto actual = formatTime(input);

EXPECT_EQ(actual, expected)
<< qUtf8Printable(actual) << " (" << qUtf8Printable(input)
<< ") did not match expected value " << qUtf8Printable(expected);
<< actual << " (" << input << ") did not match expected value "
<< expected;
}
}

Expand Down Expand Up @@ -202,7 +202,6 @@ TEST(FormatTime, chrono)
const auto actual = formatTime(input);

EXPECT_EQ(actual, expected)
<< qUtf8Printable(actual) << " did not match expected value "
<< qUtf8Printable(expected);
<< actual << " did not match expected value " << expected;
}
}
15 changes: 7 additions & 8 deletions tests/src/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "util/Helpers.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

using namespace chatterino;
using namespace _helpers_internal;
Expand Down Expand Up @@ -275,8 +275,8 @@ TEST(Helpers, skipSpace)
const auto actual = skipSpace(makeView(c.input), c.startIdx);

EXPECT_EQ(actual, c.expected)
<< actual << " (" << qUtf8Printable(c.input)
<< ") did not match expected value " << c.expected;
<< actual << " (" << c.input << ") did not match expected value "
<< c.expected;
}
}

Expand Down Expand Up @@ -418,14 +418,13 @@ TEST(Helpers, findUnitMultiplierToSec)

if (c.expectedMultiplier == bad)
{
EXPECT_FALSE(actual.second) << qUtf8Printable(c.input);
EXPECT_FALSE(actual.second) << c.input;
}
else
{
EXPECT_TRUE(pos == c.expectedEndPos && actual.second &&
actual.first == c.expectedMultiplier)
<< qUtf8Printable(c.input)
<< ": Expected(end: " << c.expectedEndPos
<< c.input << ": Expected(end: " << c.expectedEndPos
<< ", mult: " << c.expectedMultiplier << ") Actual(end: " << pos
<< ", mult: " << actual.first << ")";
}
Expand Down Expand Up @@ -503,7 +502,7 @@ TEST(Helpers, parseDurationToSeconds)
const auto actual = parseDurationToSeconds(c.input, c.noUnitMultiplier);

EXPECT_EQ(actual, c.output)
<< actual << " (" << qUtf8Printable(c.input)
<< ") did not match expected value " << c.output;
<< actual << " (" << c.input << ") did not match expected value "
<< c.output;
}
}
9 changes: 3 additions & 6 deletions tests/src/HighlightController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
#include "providers/twitch/TwitchBadge.hpp" // for Badge
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "Test.hpp"

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <QDebug>
#include <QDir>
#include <QFile>
Expand Down Expand Up @@ -216,11 +215,9 @@ class HighlightControllerTest : public ::testing::Test
input.originalMessage, input.flags);

EXPECT_EQ(isMatch, expected.state)
<< qUtf8Printable(input.senderName) << ": "
<< qUtf8Printable(input.originalMessage);
<< input.senderName << ": " << input.originalMessage;
EXPECT_EQ(matchResult, expected.result)
<< qUtf8Printable(input.senderName) << ": "
<< qUtf8Printable(input.originalMessage);
<< input.senderName << ": " << input.originalMessage;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/HighlightPhrase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "controllers/highlights/HighlightPhrase.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

using namespace chatterino;

Expand Down
3 changes: 1 addition & 2 deletions tests/src/Hotkeys.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "controllers/hotkeys/HotkeyHelpers.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions tests/src/InputCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "singletons/Emotes.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "Test.hpp"
#include "widgets/splits/InputCompletionPopup.hpp"

#include <gtest/gtest.h>
#include <QDir>
#include <QFile>
#include <QModelIndex>
Expand Down Expand Up @@ -224,7 +224,7 @@ void containsRoughly(std::span<EmoteItem> span, std::set<QString> values)
}
}

ASSERT_TRUE(found) << qPrintable(v) << " was not found in the span";
ASSERT_TRUE(found) << v << " was not found in the span";
}
}

Expand Down
7 changes: 4 additions & 3 deletions tests/src/IrcHelpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "util/IrcHelpers.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

#include <QApplication>
#include <QDebug>
#include <QtConcurrent>
Expand Down Expand Up @@ -55,7 +56,7 @@ TEST(IrcHelpers, ParseTagString)
const auto actual = parseTagString(input);

EXPECT_EQ(actual, expected)
<< qUtf8Printable(actual) << " (" << qUtf8Printable(input)
<< ") did not match expected value " << qUtf8Printable(expected);
<< actual << " (" << input << ") did not match expected value "
<< expected;
}
}
2 changes: 1 addition & 1 deletion tests/src/LimitedQueue.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "messages/LimitedQueue.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

#include <vector>

Expand Down
3 changes: 1 addition & 2 deletions tests/src/LinkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include "common/Literals.hpp"
#include "SignalSpy.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

using namespace chatterino;
using namespace literals;
Expand Down
3 changes: 1 addition & 2 deletions tests/src/LinkParser.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "common/LinkParser.hpp"

#include "TestHelpers.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QString>
#include <QStringList>

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Literals.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "common/Literals.hpp"

#include <gtest/gtest.h>
#include "Test.hpp"

using namespace chatterino::literals;

Expand Down
2 changes: 1 addition & 1 deletion tests/src/MessageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
#include "Test.hpp"

#include <gtest/gtest.h>
#include <QDebug>
#include <QString>

Expand Down
Loading

0 comments on commit 401feac

Please sign in to comment.