abseil-cpp/absl/flags/internal/program_name_test.cc
Go to the documentation of this file.
1 //
2 // Copyright 2019 The Abseil Authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // https://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #include "absl/flags/internal/program_name.h"
17 
18 #include <string>
19 
20 #include "gtest/gtest.h"
21 #include "absl/strings/match.h"
22 #include "absl/strings/string_view.h"
23 
24 namespace {
25 
26 namespace flags = absl::flags_internal;
27 
28 TEST(FlagsPathUtilTest, TestProgamNameInterfaces) {
29  flags::SetProgramInvocationName("absl/flags/program_name_test");
31  for (char& c : program_name)
32  if (c == '\\') c = '/';
33 
34 #if !defined(__wasm__) && !defined(__asmjs__)
35  const std::string expect_name = "absl/flags/program_name_test";
36  const std::string expect_basename = "program_name_test";
37 #else
38  // For targets that generate javascript or webassembly the invocation name
39  // has the special value below.
40  const std::string expect_name = "this.program";
41  const std::string expect_basename = "this.program";
42 #endif
43 
44  EXPECT_TRUE(absl::EndsWith(program_name, expect_name)) << program_name;
45  EXPECT_EQ(flags::ShortProgramInvocationName(), expect_basename);
46 
48 
51 
52  absl::string_view not_null_terminated("absl/aaa/bbb");
53  not_null_terminated = not_null_terminated.substr(1, 10);
54 
55  flags::SetProgramInvocationName(not_null_terminated);
56 
57  EXPECT_EQ(flags::ProgramInvocationName(), "bsl/aaa/bb");
59 }
60 
61 } // namespace
absl::flags_internal::ProgramInvocationName
std::string ProgramInvocationName()
Definition: abseil-cpp/absl/flags/internal/program_name.cc:36
absl::flags_internal::ShortProgramInvocationName
std::string ShortProgramInvocationName()
Definition: abseil-cpp/absl/flags/internal/program_name.cc:42
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
absl::flags_internal::SetProgramInvocationName
void SetProgramInvocationName(absl::string_view prog_name_str)
Definition: abseil-cpp/absl/flags/internal/program_name.cc:49
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
absl::EndsWith
bool EndsWith(absl::string_view text, absl::string_view suffix) noexcept
Definition: third_party/abseil-cpp/absl/strings/match.h:68


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:46