diff --git a/tests/fixtures/fixtures.cpp b/tests/fixtures/fixtures.cpp index 6a2fb90..82ba067 100644 --- a/tests/fixtures/fixtures.cpp +++ b/tests/fixtures/fixtures.cpp @@ -1,9 +1,6 @@ // header include #include "fixtures.h" -// system includes -#include - // local includes #include "displaydevice/logging.h" @@ -92,7 +89,7 @@ BaseTest::skipTest() const { if (isSystemTest()) { const static bool is_system_test_skippable { []() { - const std::string value { std::getenv("SKIP_SYSTEM_TESTS") }; + const auto value { getEnv("SKIP_SYSTEM_TESTS") }; return value == "1"; }() }; diff --git a/tests/fixtures/testutils.cpp b/tests/fixtures/testutils.cpp index 503dc45..1947562 100644 --- a/tests/fixtures/testutils.cpp +++ b/tests/fixtures/testutils.cpp @@ -1,6 +1,9 @@ // header include #include "testutils.h" +// system includes +#include + // system includes #include #include @@ -26,3 +29,11 @@ setEnv(const std::string &name, const std::string &value) { return setenv(name.c_str(), value.c_str(), 1); #endif } + +std::optional +getEnv(const std::string &name) { + if (const auto value { std::getenv(name.c_str()) }; value) { + return std::string { value }; + } + return std::nullopt; +} diff --git a/tests/fixtures/testutils.h b/tests/fixtures/testutils.h index f49271b..a73de6a 100644 --- a/tests/fixtures/testutils.h +++ b/tests/fixtures/testutils.h @@ -1,20 +1,29 @@ #pragma once // system includes +#include #include /** * @brief Test regular expression against string. - * @return True if string matches the regex, false otherwise + * @return True if string matches the regex, false otherwise. */ bool testRegex(const std::string &test_pattern, const std::string ®ex_pattern); /** * @brief Set an environment variable. - * @param name Name of the environment variable - * @param value Value of the environment variable - * @return 0 on success, non-zero error code on failure + * @param name Name of the environment variable. + * @param value Value of the environment variable. + * @return 0 on success, non-zero error code on failure. */ int setEnv(const std::string &name, const std::string &value); + +/** + * @brief Get an environment variable. + * @param name Name of the environment variable. + * @return String value of the variable or an empty optional otherwise. + */ +std::optional +getEnv(const std::string &name);