Files
abseil-cpp/absl/flags/internal/program_name_test.cc
Abseil Team 2eba343b51 Export of internal Abseil changes
--
baf626d27ff1547776745f3b601cc42f703d4bdf by Greg Falcon <gfalcon@google.com>:

Import of CCTZ from GitHub.

PiperOrigin-RevId: 315486679

--
39d4e7f9214c5a74e4ee4b8a7f4af26479925029 by Gennadiy Rozental <rogeeff@google.com>:

Avoid order dependant test cases.

PiperOrigin-RevId: 315327948

--
8feb187703a28bb0c5cfc5dd6091e3faa90a8e61 by Gennadiy Rozental <rogeeff@google.com>:

Avoid order dependant test cases.

PiperOrigin-RevId: 315317018

--
cffd8fddad15908ec9de7f21f65b20528972e3fa by Gennadiy Rozental <rogeeff@google.com>:

Avoid order dependant test cases.

PiperOrigin-RevId: 315311587

--
48997a0ceb231b75c14eb4b1eb3b66af69e49f42 by Tom Manshreck <shreck@google.com>:

Nit: remove extra "the"

PiperOrigin-RevId: 314959763

--
9516f44a4b5d3055427c95e80c8c04a6321e4221 by Gennadiy Rozental <rogeeff@google.com>:

Import of CCTZ from GitHub.

PiperOrigin-RevId: 314925147

--
4f8691d74a4eb42ed03ef29c9588a01b78829941 by Abseil Team <absl-team@google.com>:

Uninclude util/bits/bits.h

PiperOrigin-RevId: 314858384

--
02b42a8ec5e5561b29b4e5f93cc1482c3c72ef2d by Abseil Team <absl-team@google.com>:

Google-internal changes only.

PiperOrigin-RevId: 314855667

--
146013d69dabafbe2030e23ced7b741d9e8d417c by Gennadiy Rozental <rogeeff@google.com>:

Uninclude util/bits/bits.h

PiperOrigin-RevId: 314838927
GitOrigin-RevId: baf626d27ff1547776745f3b601cc42f703d4bdf
Change-Id: I2602286fb13cf35a88bdd80fe0b44974d4388d46
2020-06-09 11:23:39 -04:00

62 lines
2.0 KiB
C++

//
// Copyright 2019 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/flags/internal/program_name.h"
#include <string>
#include "gtest/gtest.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
namespace {
namespace flags = absl::flags_internal;
TEST(FlagsPathUtilTest, TestProgamNameInterfaces) {
flags::SetProgramInvocationName("absl/flags/program_name_test");
std::string program_name = flags::ProgramInvocationName();
for (char& c : program_name)
if (c == '\\') c = '/';
#if !defined(__wasm__) && !defined(__asmjs__)
const std::string expect_name = "absl/flags/program_name_test";
const std::string expect_basename = "program_name_test";
#else
// For targets that generate javascript or webassembly the invocation name
// has the special value below.
const std::string expect_name = "this.program";
const std::string expect_basename = "this.program";
#endif
EXPECT_TRUE(absl::EndsWith(program_name, expect_name)) << program_name;
EXPECT_EQ(flags::ShortProgramInvocationName(), expect_basename);
flags::SetProgramInvocationName("a/my_test");
EXPECT_EQ(flags::ProgramInvocationName(), "a/my_test");
EXPECT_EQ(flags::ShortProgramInvocationName(), "my_test");
absl::string_view not_null_terminated("absl/aaa/bbb");
not_null_terminated = not_null_terminated.substr(1, 10);
flags::SetProgramInvocationName(not_null_terminated);
EXPECT_EQ(flags::ProgramInvocationName(), "bsl/aaa/bb");
EXPECT_EQ(flags::ShortProgramInvocationName(), "bb");
}
} // namespace