Skip to content

Commit 640a03e

Browse files
Add isGitHubActions helper and use in tests
Introduce a cross-platform isGitHubActions() helper (uses _dupenv_s on Windows and getenv elsewhere) and declare it in tests/utils.h. Replace direct getenv usage in tests/unit/test_tray.cpp with the new helper and guard the Windows notification timeout to avoid unnecessary sleeps outside GitHub Actions. Also remove an unused <cstdlib> include.
1 parent 7005558 commit 640a03e

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

tests/unit/test_tray.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <array>
66
#include <atomic>
77
#include <chrono>
8-
#include <cstdlib>
98
#include <ostream>
109
#include <string>
1110
#include <thread>
@@ -251,7 +250,7 @@ class TrayTest: public BaseTest { // NOSONAR(cpp:S3656) - fixture members must
251250
void WaitForNotificationReady() {
252251
WaitForTrayReady();
253252
#if defined(_WIN32)
254-
if (std::getenv("GITHUB_ACTIONS") != nullptr) {
253+
if (isGitHubActions()) {
255254
for (int i = 0; i < 40; i++) {
256255
tray_loop(0);
257256
std::this_thread::sleep_for(std::chrono::milliseconds(50));

tests/utils.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ int setEnv(const std::string &name, const std::string &value) {
4141
#endif
4242
}
4343

44+
bool isGitHubActions() {
45+
#ifdef _WIN32
46+
char *value = nullptr;
47+
size_t value_size = 0;
48+
const bool result = _dupenv_s(&value, &value_size, "GITHUB_ACTIONS") == 0 && value != nullptr && value_size > 0;
49+
std::free(value);
50+
return result;
51+
#else
52+
return std::getenv("GITHUB_ACTIONS") != nullptr;
53+
#endif
54+
}
55+
4456
void dismissNativeNotifications() {
4557
#ifdef __linux__
4658
closeFreedesktopNotifications();
@@ -51,6 +63,9 @@ void dismissNativeNotifications() {
5163

5264
void waitForNativeNotificationTimeout() {
5365
#ifdef _WIN32
66+
if (!isGitHubActions()) {
67+
return;
68+
}
5469
constexpr auto wait_timeout = std::chrono::milliseconds(6000);
5570
std::this_thread::sleep_for(wait_timeout);
5671
#elif defined(__linux__)

tests/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
int setEnv(const std::string &name, const std::string &value);
1111

12+
bool isGitHubActions();
13+
1214
void dismissNativeNotifications();
1315

1416
void waitForNativeNotificationTimeout();

0 commit comments

Comments
 (0)