From 71b0b4e0a9f2d9080f167c03dcafbd8b1823fb76 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 22 Jan 2024 08:50:11 -0800 Subject: [PATCH] Fix getting env variables on windows (#15518) Fixes https://github.com/protocolbuffers/protobuf/issues/15436 Closes #15518 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15518 from isuruf:win_env 1b1f2cc31cf412c022717c1f23af6047aef9725a PiperOrigin-RevId: 600469988 --- src/google/protobuf/compiler/mock_code_generator.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index c3291603dd..665262d713 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -72,7 +72,13 @@ static constexpr absl::string_view kSecondInsertionPoint = " # @@protoc_insertion_point(second_mock_insertion_point) is here\n"; MockCodeGenerator::MockCodeGenerator(absl::string_view name) : name_(name) { - absl::string_view key = getenv("TEST_CASE"); + const char* c_key = getenv("TEST_CASE"); + if (c_key == NULL) { + // In Windows, setting 'TEST_CASE=' is equivalent to unsetting + // and therefore c_key can be NULL + c_key = ""; + } + absl::string_view key(c_key); if (key == "no_editions") { suppressed_features_ |= CodeGenerator::FEATURE_SUPPORTS_EDITIONS; } else if (key == "invalid_features") {