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 
17 
18 #include "gtest/gtest.h"
19 #include "absl/strings/match.h"
20 
21 namespace {
22 
23 namespace flags = absl::flags_internal;
24 
25 TEST(FlagsPathUtilTest, TestInitialProgamName) {
26  flags::SetProgramInvocationName("absl/flags/program_name_test");
27  std::string program_name = flags::ProgramInvocationName();
28  for (char& c : program_name)
29  if (c == '\\') c = '/';
30 
31 #if !defined(__wasm__) && !defined(__asmjs__)
32  const std::string expect_name = "absl/flags/program_name_test";
33  const std::string expect_basename = "program_name_test";
34 #else
35  // For targets that generate javascript or webassembly the invocation name
36  // has the special value below.
37  const std::string expect_name = "this.program";
38  const std::string expect_basename = "this.program";
39 #endif
40 
41  EXPECT_TRUE(absl::EndsWith(program_name, expect_name)) << program_name;
42  EXPECT_EQ(flags::ShortProgramInvocationName(), expect_basename);
43 }
44 
45 TEST(FlagsPathUtilTest, TestProgamNameInterfaces) {
47 
48  EXPECT_EQ(flags::ProgramInvocationName(), "a/my_test");
49  EXPECT_EQ(flags::ShortProgramInvocationName(), "my_test");
50 
51  absl::string_view not_null_terminated("absl/aaa/bbb");
52  not_null_terminated = not_null_terminated.substr(1, 10);
53 
54  flags::SetProgramInvocationName(not_null_terminated);
55 
56  EXPECT_EQ(flags::ProgramInvocationName(), "bsl/aaa/bb");
57  EXPECT_EQ(flags::ShortProgramInvocationName(), "bb");
58 }
59 
60 } // namespace
std::string ProgramInvocationName()
Definition: program_name.cc:30
bool EndsWith(absl::string_view text, absl::string_view suffix)
Definition: match.h:61
std::string ShortProgramInvocationName()
Definition: program_name.cc:36
void SetProgramInvocationName(absl::string_view prog_name_str)
Definition: program_name.cc:43
TEST(Symbolize, Unimplemented)


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:37