Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests more platform agnostic #4650

Merged
merged 10 commits into from
May 26, 2023

Conversation

Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented May 22, 2023

Description

  • Windows systems (one of the supported operating systems) doesn't have a /tmp directory the same way, e.g. Linux has it. So instead, the tests are now using QTemporaryDir - which is cross-platform.
  • Running Docker on Windows or macOS effectively runs an entire VM, which is a lot of overhead to just get an HTTP echo server. I added a CMake option to use the public (but less reliable) httpbin server (CHATTERINO_TEST_LOCAL_HTTPBIN=Off).
  • MSVC (apparently) has a different implementation of a std::unordered_map than the one used when writing the input completion tests. Since unordered_map doesn't guarantee an ordering (the name explicitly says unordered), one can't rely on values being in order in such a map. This map is the underlying data-type for an EmoteMap. For the input completions, this is a bit more tricky, since they do guarantee some amount of ordering (regarding the emote/emoji provider). So, for an emote provider, the completions are now sorted.
  • For some reason, connecting to the PubSub server always took more than 50ms for me, so I increased the delay.

Now, the only program one needs to run next to the tests is the PubSub test-server.

Note: The tests will still fail when using Qt 6 (which is still marked as experimental and thus not tested). I'll make another PR to fix that and add tests there.

CMakeLists.txt Outdated Show resolved Hide resolved
ASSERT_EQ(completion[0].displayName, "FeelsBirthdayMan");
ASSERT_EQ(completion[1].displayName, "FeelsBadMan");
// all these matches are BTTV global emotes
std::sort(completion.begin(), completion.end(), cmpCompletion);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant about this change - I'd rather leave this change out as part of the platform-agnostic PR & discuss it in a separate PR/issue.
Most likely I'd like to see us just change the EmoteMap to be consistently ordered instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the change, but added a note for future visitors.

Most likely I'd like to see us just change the EmoteMap to be consistently ordered instead

Not sure if it's that easy. It should probably be benchmarked to see if it makes a meaningful difference, since working with emotes and checking for emotes in a word is an integral part.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

benchmarks/src/Highlights.cpp Show resolved Hide resolved
benchmarks/src/Highlights.cpp Show resolved Hide resolved
benchmarks/src/main.cpp Show resolved Hide resolved
benchmarks/src/main.cpp Show resolved Hide resolved
Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!
One step closer to running tests on all platforms

@pajlada pajlada changed the title Make Tests (more) Platform Agnostic Make tests more platform agnostic May 26, 2023
@pajlada pajlada enabled auto-merge (squash) May 26, 2023 12:14
@pajlada pajlada merged commit 1bc423d into Chatterino:master May 26, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -66,7 +67,8 @@ class MockApplication : mock::EmptyApplication
static void BM_HighlightTest(benchmark::State &state)
{
MockApplication mockApplication;
Settings settings("/tmp/c2-mock");
QTemporaryDir settingsDir;
Settings settings(settingsDir.path());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'settings' of type 'chatterino::Settings' can be declared 'const' [misc-const-correctness]

Suggested change
Settings settings(settingsDir.path());
Settings const settings(settingsDir.path());

QTemporaryDir settingsDir;
settingsDir.setAutoRemove(false); // we'll remove it manually
qDebug() << "Settings directory:" << settingsDir.path();
chatterino::Settings settings(settingsDir.path());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'settings' of type 'chatterino::Settings' can be declared 'const' [misc-const-correctness]

Suggested change
chatterino::Settings settings(settingsDir.path());
chatterino::Settings const settings(settingsDir.path());

@Nerixyz Nerixyz deleted the fix/tests-platformagnostic branch May 26, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants