Skip to content

Commit 1ffebb2

Browse files
Merge pull request #16237 from protocolbuffers/windows-getenv-fix
Fix windows-only issue in our compiler unittests.
2 parents 03342ce + a4d2448 commit 1ffebb2

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

.github/workflows/test_cpp.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
config:
2020
- { name: Optimized, flags: --config=opt }
2121
- { name: Debug, flags: --config=dbg }
22-
- { name: ASAN, flags: --config=asan, runner: ubuntu-22-large }
23-
- { name: MSAN, flags: --config=docker-msan, runner: ubuntu-22-large }
24-
- { name: TSAN, flags: --config=tsan }
22+
- { name: ASAN, flags: --config=asan, runner: ubuntu-20-large }
23+
- { name: MSAN, flags: --config=docker-msan, runner: ubuntu-20-large }
24+
- { name: TSAN, flags: --config=tsan, runner: ubuntu-20-large }
2525
- { name: UBSAN, flags: --config=ubsan }
2626
- { name: No-RTTI, flags: --cxxopt=-fno-rtti }
2727
include:

.github/workflows/test_upb.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
- { name: "Bazel 7", bazel_version: "7.0.0" }
2121
- { name: "Fastbuild" }
2222
- { name: "Optimized", flags: "-c opt" }
23-
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/..." }
23+
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/...", runner: ubuntu-20-large }
2424
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." }
2525
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." }
2626
# TODO: Add 32-bit ASAN test
2727
# TODO: Restore the FastTable tests
2828

2929
name: ${{ matrix.config.name }}
30-
runs-on: ubuntu-latest
30+
runs-on: ${{ matrix.config.runner || 'ubuntu-latest' }}
3131

3232
steps:
3333
- name: Checkout pending changes

src/google/protobuf/compiler/mock_code_generator.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
namespace google {
5151
namespace protobuf {
5252
namespace compiler {
53+
namespace {
5354

5455
// Returns the list of the names of files in all_files in the form of a
5556
// comma-separated string.
@@ -71,14 +72,20 @@ static constexpr absl::string_view kFirstInsertionPoint =
7172
static constexpr absl::string_view kSecondInsertionPoint =
7273
" # @@protoc_insertion_point(second_mock_insertion_point) is here\n";
7374

74-
MockCodeGenerator::MockCodeGenerator(absl::string_view name) : name_(name) {
75+
absl::string_view GetTestCase() {
7576
const char* c_key = getenv("TEST_CASE");
76-
if (c_key == NULL) {
77+
if (c_key == nullptr) {
7778
// In Windows, setting 'TEST_CASE=' is equivalent to unsetting
78-
// and therefore c_key can be NULL
79-
c_key = "";
79+
// and therefore c_key can be nullptr
80+
return "";
8081
}
81-
absl::string_view key(c_key);
82+
return c_key;
83+
}
84+
85+
} // namespace
86+
87+
MockCodeGenerator::MockCodeGenerator(absl::string_view name) : name_(name) {
88+
absl::string_view key = GetTestCase();
8289
if (key == "no_editions") {
8390
suppressed_features_ |= CodeGenerator::FEATURE_SUPPORTS_EDITIONS;
8491
} else if (key == "invalid_features") {
@@ -214,7 +221,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file,
214221
std::string* error) const {
215222
// Override minimum/maximum after generating the pool to simulate a plugin
216223
// that "works" but doesn't advertise support of the current edition.
217-
absl::string_view test_case = getenv("TEST_CASE");
224+
absl::string_view test_case = GetTestCase();
218225
if (test_case == "high_minimum") {
219226
minimum_edition_ = Edition::EDITION_99997_TEST_ONLY;
220227
} else if (test_case == "low_maximum") {

0 commit comments

Comments
 (0)