Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-10-22 13:00:31 +0200
committerMartin Hořeňovský2022-10-22 22:18:24 +0200
commit3fed2307e756aae3d2908ac71032aa7158a6cbfb (patch)
treef340b97c4c6b66f4a8277775ee2b8b4fbd030c55 /src
parent2d0dcc36e8202504f870a79820ab7d4bb39cf410 (diff)
downloadcatch3-3fed2307e756aae3d2908ac71032aa7158a6cbfb.tar.gz
Add Detail::getEnv wrapper that compiles under UWP
Under UWP it will always return nullptr, so UWP will essentially behave as if the environment was just empty.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/catch2/catch_all.hpp1
-rw-r--r--src/catch2/internal/catch_getenv.cpp36
-rw-r--r--src/catch2/internal/catch_getenv.hpp20
-rw-r--r--src/catch2/meson.build2
5 files changed, 61 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 599a104f..313d57e3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -78,6 +78,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/internal/catch_exception_translator_registry.hpp
${SOURCES_DIR}/internal/catch_fatal_condition_handler.hpp
${SOURCES_DIR}/internal/catch_floating_point_helpers.hpp
+ ${SOURCES_DIR}/internal/catch_getenv.hpp
${SOURCES_DIR}/internal/catch_istream.hpp
${SOURCES_DIR}/internal/catch_unique_name.hpp
${SOURCES_DIR}/internal/catch_sharding.hpp
@@ -184,6 +185,7 @@ set(IMPL_SOURCES
${SOURCES_DIR}/internal/catch_exception_translator_registry.cpp
${SOURCES_DIR}/internal/catch_fatal_condition_handler.cpp
${SOURCES_DIR}/internal/catch_floating_point_helpers.cpp
+ ${SOURCES_DIR}/internal/catch_getenv.cpp
${SOURCES_DIR}/internal/catch_istream.cpp
${SOURCES_DIR}/internal/catch_parse_numbers.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_generatortracker.cpp
diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp
index 3d32ce7f..f7af81fc 100644
--- a/src/catch2/catch_all.hpp
+++ b/src/catch2/catch_all.hpp
@@ -68,6 +68,7 @@
#include <catch2/internal/catch_exception_translator_registry.hpp>
#include <catch2/internal/catch_fatal_condition_handler.hpp>
#include <catch2/internal/catch_floating_point_helpers.hpp>
+#include <catch2/internal/catch_getenv.hpp>
#include <catch2/internal/catch_istream.hpp>
#include <catch2/internal/catch_lazy_expr.hpp>
#include <catch2/internal/catch_leak_detector.hpp>
diff --git a/src/catch2/internal/catch_getenv.cpp b/src/catch2/internal/catch_getenv.cpp
new file mode 100644
index 00000000..e9be6372
--- /dev/null
+++ b/src/catch2/internal/catch_getenv.cpp
@@ -0,0 +1,36 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+#include <catch2/internal/catch_getenv.hpp>
+#include <catch2/internal/catch_platform.hpp>
+
+#include <cstdlib>
+
+namespace Catch {
+ namespace Detail {
+
+#if defined( CATCH_PLATFORM_WINDOWS_UWP )
+ char const* getEnv( char const* ) { return nullptr; }
+#else
+
+ char const* getEnv( char const* varName ) {
+# if defined( _MSC_VER )
+# pragma warning( push )
+# pragma warning( disable : 4996 ) // use getenv_s instead of getenv
+# endif
+
+ return std::getenv( varName );
+
+# if defined( _MSC_VER )
+# pragma warning( pop )
+# endif
+#endif
+ }
+
+} // namespace Detail
+} // namespace Catch
diff --git a/src/catch2/internal/catch_getenv.hpp b/src/catch2/internal/catch_getenv.hpp
new file mode 100644
index 00000000..b419ad9b
--- /dev/null
+++ b/src/catch2/internal/catch_getenv.hpp
@@ -0,0 +1,20 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+#ifndef CATCH_GETENV_HPP_INCLUDED
+#define CATCH_GETENV_HPP_INCLUDED
+
+namespace Catch {
+namespace Detail {
+
+ //! Wrapper over `std::getenv` that compiles on UWP (and always returns nullptr there)
+ char const* getEnv(char const* varName);
+
+}
+}
+
+#endif // CATCH_GETENV_HPP_INCLUDED
diff --git a/src/catch2/meson.build b/src/catch2/meson.build
index 8b9e288a..761b79d9 100644
--- a/src/catch2/meson.build
+++ b/src/catch2/meson.build
@@ -90,6 +90,7 @@ internal_headers = [
'internal/catch_exception_translator_registry.hpp',
'internal/catch_fatal_condition_handler.hpp',
'internal/catch_floating_point_helpers.hpp',
+ 'internal/catch_getenv.hpp',
'internal/catch_istream.hpp',
'internal/catch_lazy_expr.hpp',
'internal/catch_leak_detector.hpp',
@@ -202,6 +203,7 @@ internal_sources = files(
'internal/catch_exception_translator_registry.cpp',
'internal/catch_fatal_condition_handler.cpp',
'internal/catch_floating_point_helpers.cpp',
+ 'internal/catch_getenv.cpp',
'internal/catch_istream.cpp',
'internal/catch_lazy_expr.cpp',
'internal/catch_leak_detector.cpp',