Skip to content

Commit

Permalink
chore: remove LogSilencers from tests
Browse files Browse the repository at this point in the history
Change-Id: I413f05fa409294978b470afd393eb6fa02867fba
  • Loading branch information
narnaud committed Jun 7, 2024
1 parent 2350058 commit 2cde028
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 72 deletions.
10 changes: 0 additions & 10 deletions docs/contributing/unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ Tests written using the QtTest module.
There are some utility classes you can use:

- `Test::testDataPath()`: returns the test data folder path
- `Test::LogSilencers`: silence logs during the tests
```cpp
// Silence multiple logs
auto ls = Test::LogSilencers {"cpp_client", "cpp_server", "cpp_messages"};

// Silence the default log
Test::LogSilencers ls;
```
- `Test::FileTester`: create an original file based on the original one, and compare the result with an expected one

```cpp
Expand Down
45 changes: 1 addition & 44 deletions tests/common/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,50 +131,7 @@ class LogCounter
std::shared_ptr<spdlog::sinks::callback_sink_mt> m_sink;
};

class LogSilencer
{
public:
inline static std::string Default = "";

LogSilencer(const std::string &name = Default)
{
if (name.empty())
m_logger = spdlog::default_logger();
else
m_logger = spdlog::get(name);
if (m_logger) {
m_level = m_logger->level();
m_logger->set_level(spdlog::level::off);
}
}
~LogSilencer()
{
if (m_logger) {
m_logger->set_level(m_level);
}
}

LogSilencer(LogSilencer &&) noexcept = default;
LogSilencer &operator=(LogSilencer &&) noexcept = default;

private:
spdlog::level::level_enum m_level = spdlog::level::off;
std::shared_ptr<spdlog::logger> m_logger;
};

class LogSilencers
{
public:
LogSilencers(std::initializer_list<std::string> names)
{
m_logs.reserve(names.size());
for (const auto &name : names)
m_logs.emplace_back(name);
}

private:
std::vector<LogSilencer> m_logs;
};
// *****************************************************************************

constexpr inline bool noClangd()
{
Expand Down
3 changes: 0 additions & 3 deletions tests/tst_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private slots:
CHECK_CLANGD;

Lsp::Client client("cpp", "clangd", {"--log=verbose", "--pretty"});
auto logs = Test::LogSilencers {"cpp_client", "cpp_server", "cpp_messages"};

QVERIFY(client.initialize(Test::testDataPath()));
QCOMPARE(client.state(), Lsp::Client::Initialized);
Expand All @@ -40,7 +39,6 @@ private slots:
CHECK_CLANGD;

Lsp::Client client("cpp", "clangd", {"--log=verbose", "--pretty"});
auto logs = Test::LogSilencers {"cpp_client", "cpp_server", "cpp_messages"};

client.initialize(Test::testDataPath() + "/tst_client");

Expand All @@ -63,7 +61,6 @@ private slots:
CHECK_CLANGD;

Lsp::Client client("cpp", "clangd", {"--log=verbose", "--pretty"});
auto logs = Test::LogSilencers {"cpp_client", "cpp_server", "cpp_messages"};

client.initialize(Test::testDataPath() + "/tst_client");

Expand Down
2 changes: 0 additions & 2 deletions tests/tst_clientbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ private slots:
CHECK_CLANGD;

Lsp::ClientBackend client("cpp", "clangd", {});
// auto logs = Test::LogSilencers {"cpp_server", "cpp_messages"};

QSignalSpy errorOccured(&client, &Lsp::ClientBackend::errorOccured);
QSignalSpy finished(&client, &Lsp::ClientBackend::finished);
Expand Down Expand Up @@ -59,7 +58,6 @@ private slots:
CHECK_CLANGD;

Lsp::ClientBackend client("cpp", "clangd", {});
auto logs = Test::LogSilencers {"cpp_server", "cpp_messages"};

QSignalSpy errorOccured(&client, &Lsp::ClientBackend::errorOccured);
QSignalSpy finished(&client, &Lsp::ClientBackend::finished);
Expand Down
6 changes: 0 additions & 6 deletions tests/tst_rcparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TestRcParser : public QObject
private slots:
void testDialog()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/dialog/dialog.rc");

QCOMPARE(rcFile.isValid, true);
Expand Down Expand Up @@ -60,7 +59,6 @@ private slots:

void testAccelerator()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/accelerators/Accelerators.rc");

QCOMPARE(rcFile.isValid, true);
Expand All @@ -80,7 +78,6 @@ private slots:

void testLuaDebugger()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/luaDebugger/LuaDebugger.rc");

QCOMPARE(rcFile.isValid, true);
Expand Down Expand Up @@ -135,21 +132,18 @@ private slots:

void test2048Game()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/2048Game/2048Game.rc");
QCOMPARE(rcFile.isValid, true);
}

void testCryEdit()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/cryEdit/CryEdit.rc");
QCOMPARE(rcFile.isValid, true);
}

void testRibbon()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/ribbonexample/RibbonExample.rc");
QCOMPARE(rcFile.isValid, true);

Expand Down
4 changes: 0 additions & 4 deletions tests/tst_rcwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private slots:

void testQrc()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/2048Game/2048Game.rc");
auto data = rcFile.data.value("LANG_ENGLISH;SUBLANG_ENGLISH_US");

Expand Down Expand Up @@ -65,7 +64,6 @@ private slots:

void testConvertDialog()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/2048Game/2048Game.rc");
auto usData = rcFile.data.value("LANG_ENGLISH;SUBLANG_ENGLISH_US");
auto result = convertDialog(usData, usData.dialogs.first(), RcCore::Widget::AllFlags);
Expand All @@ -90,7 +88,6 @@ private slots:

void testWriteDialog()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/cryEdit/CryEdit.rc");
auto data = rcFile.data.value("LANG_ENGLISH;SUBLANG_ENGLISH_US");

Expand Down Expand Up @@ -125,7 +122,6 @@ private slots:

void testConvertAction()
{
Test::LogSilencer ls;
RcFile rcFile = parse(Test::testDataPath() + "/rcfiles/2048Game/2048Game.rc");
auto data = rcFile.data.value("LANG_ENGLISH;SUBLANG_ENGLISH_US");

Expand Down
3 changes: 0 additions & 3 deletions tests/tst_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private slots:

void load()
{
Test::LogSilencer ls;
SettingsFixture settings;

// Default values
Expand All @@ -62,7 +61,6 @@ private slots:

void getValue()
{
Test::LogSilencer ls;
SettingsFixture settings;

settings.loadProjectSettings(Test::testDataPath() + "/tst_settings");
Expand All @@ -87,7 +85,6 @@ private slots:
void setValue()
{
Test::FileTester file(Test::testDataPath() + "/tst_settings/setValue/knut.json");
Test::LogSilencer ls;
SettingsFixture settings;
QSignalSpy settingsSaved(&settings, &Core::Settings::settingsSaved);

Expand Down

0 comments on commit 2cde028

Please sign in to comment.