summaryrefslogtreecommitdiff
path: root/absl/flags/internal
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-06-03 14:03:13 -0700
committerGravatar Gennadiy Rozental <rogeeff@google.com>2020-06-03 18:19:47 -0400
commit1d31b5c365e975d3c8a8f90492c3d9de35ef024f (patch)
treefbc8093e8aad757b8790fb2688c0e4694e082fa4 /absl/flags/internal
parentda3a87690c56f965705b6a233d25ba5a3294067c (diff)
Export of internal Abseil changes
-- 9e8b4a286d70df9487bff080816bd07ae38af5f8 by Evan Brown <ezb@google.com>: Add btree_node::transfer_n/transfer_n_backward and replace usage of uninitialized_move_n and value_destroy_n. PiperOrigin-RevId: 314600027 -- 6c452aa1ee7e46ab941ba7d1fa636da8ea3d7370 by Laramie Leavitt <lar@google.com>: Remove the MockingBitGenBase base class in favor of type-erasure in BitGenRef. In Abseil random, mocking was split across two different classes, MockingBitGenBase and MockingBitGen. This split existed because Google Mock is a test-only library that we don't link into production, so MockingBitGenBase provided a low-overhead scaffold used to lookup mocks when in test code, but which is unused in production code. That has been replaced by type-erasure which looks for a method named CallImpl with the correct signature. Weaken the coupling between MockingBitGen, DistributionCaller, and MockOverloadSet. Rename CallImpl to InvokeMock() Previously, the implementation of DistributionCaller was also split across different files using explicit instantiation of the DistributionCaller struct and some details in the Mocking classes. Now Distribution caller uses the presence of the InvokeMock() method to choose whether to use the mockable call path or the default call path. PiperOrigin-RevId: 314584095 -- 07853c47dc98698d67d65a3b9b662a65ab9def0a by Abseil Team <absl-team@google.com>: Add PC / backtrace / symbolization support for Apple platforms. Full backtrace support requires iOS 9+ PiperOrigin-RevId: 314415072 -- 43889f17a132b31f6558c6482721cbbc776128fd by Gennadiy Rozental <rogeeff@google.com>: Consolidate all reflection interface in the new module 'reflection' and expose interface to locate reflection handle by name. PiperOrigin-RevId: 314390358 GitOrigin-RevId: 9e8b4a286d70df9487bff080816bd07ae38af5f8 Change-Id: I8e0910437740cf9ea9da5000adddfcef127e1158
Diffstat (limited to 'absl/flags/internal')
-rw-r--r--absl/flags/internal/registry.cc349
-rw-r--r--absl/flags/internal/registry.h13
-rw-r--r--absl/flags/internal/type_erased.cc86
-rw-r--r--absl/flags/internal/type_erased.h80
-rw-r--r--absl/flags/internal/type_erased_test.cc156
-rw-r--r--absl/flags/internal/usage_test.cc12
6 files changed, 12 insertions, 684 deletions
diff --git a/absl/flags/internal/registry.cc b/absl/flags/internal/registry.cc
deleted file mode 100644
index e582d79d..00000000
--- a/absl/flags/internal/registry.cc
+++ /dev/null
@@ -1,349 +0,0 @@
-//
-// 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/registry.h"
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include <functional>
-#include <map>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "absl/base/config.h"
-#include "absl/base/internal/raw_logging.h"
-#include "absl/base/thread_annotations.h"
-#include "absl/flags/commandlineflag.h"
-#include "absl/flags/internal/commandlineflag.h"
-#include "absl/flags/internal/private_handle_accessor.h"
-#include "absl/flags/usage_config.h"
-#include "absl/strings/str_cat.h"
-#include "absl/strings/string_view.h"
-#include "absl/synchronization/mutex.h"
-
-// --------------------------------------------------------------------
-// FlagRegistry implementation
-// A FlagRegistry holds all flag objects indexed
-// by their names so that if you know a flag's name you can access or
-// set it.
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-namespace flags_internal {
-
-// --------------------------------------------------------------------
-// FlagRegistry
-// A FlagRegistry singleton object holds all flag objects indexed
-// by their names so that if you know a flag's name (as a C
-// string), you can access or set it. If the function is named
-// FooLocked(), you must own the registry lock before calling
-// the function; otherwise, you should *not* hold the lock, and
-// the function will acquire it itself if needed.
-// --------------------------------------------------------------------
-
-class FlagRegistry {
- public:
- FlagRegistry() = default;
- ~FlagRegistry() = default;
-
- // Store a flag in this registry. Takes ownership of *flag.
- void RegisterFlag(CommandLineFlag& flag);
-
- void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.Lock(); }
- void Unlock() ABSL_UNLOCK_FUNCTION(lock_) { lock_.Unlock(); }
-
- // Returns the flag object for the specified name, or nullptr if not found.
- // Will emit a warning if a 'retired' flag is specified.
- CommandLineFlag* FindFlagLocked(absl::string_view name);
-
- // Returns the retired flag object for the specified name, or nullptr if not
- // found or not retired. Does not emit a warning.
- CommandLineFlag* FindRetiredFlagLocked(absl::string_view name);
-
- static FlagRegistry& GlobalRegistry(); // returns a singleton registry
-
- private:
- friend class FlagSaverImpl; // reads all the flags in order to copy them
- friend void ForEachFlagUnlocked(
- std::function<void(CommandLineFlag&)> visitor);
-
- // The map from name to flag, for FindFlagLocked().
- using FlagMap = std::map<absl::string_view, CommandLineFlag*>;
- using FlagIterator = FlagMap::iterator;
- using FlagConstIterator = FlagMap::const_iterator;
- FlagMap flags_;
-
- absl::Mutex lock_;
-
- // Disallow
- FlagRegistry(const FlagRegistry&);
- FlagRegistry& operator=(const FlagRegistry&);
-};
-
-FlagRegistry& FlagRegistry::GlobalRegistry() {
- static FlagRegistry* global_registry = new FlagRegistry;
- return *global_registry;
-}
-
-namespace {
-
-class FlagRegistryLock {
- public:
- explicit FlagRegistryLock(FlagRegistry& fr) : fr_(fr) { fr_.Lock(); }
- ~FlagRegistryLock() { fr_.Unlock(); }
-
- private:
- FlagRegistry& fr_;
-};
-
-void DestroyRetiredFlag(CommandLineFlag& flag);
-
-} // namespace
-
-void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
- FlagRegistryLock registry_lock(*this);
- std::pair<FlagIterator, bool> ins =
- flags_.insert(FlagMap::value_type(flag.Name(), &flag));
- if (ins.second == false) { // means the name was already in the map
- CommandLineFlag& old_flag = *ins.first->second;
- if (flag.IsRetired() != old_flag.IsRetired()) {
- // All registrations must agree on the 'retired' flag.
- flags_internal::ReportUsageError(
- absl::StrCat(
- "Retired flag '", flag.Name(), "' was defined normally in file '",
- (flag.IsRetired() ? old_flag.Filename() : flag.Filename()), "'."),
- true);
- } else if (flags_internal::PrivateHandleAccessor::TypeId(flag) !=
- flags_internal::PrivateHandleAccessor::TypeId(old_flag)) {
- flags_internal::ReportUsageError(
- absl::StrCat("Flag '", flag.Name(),
- "' was defined more than once but with "
- "differing types. Defined in files '",
- old_flag.Filename(), "' and '", flag.Filename(), "'."),
- true);
- } else if (old_flag.IsRetired()) {
- // Retired flag can just be deleted.
- DestroyRetiredFlag(flag);
- return;
- } else if (old_flag.Filename() != flag.Filename()) {
- flags_internal::ReportUsageError(
- absl::StrCat("Flag '", flag.Name(),
- "' was defined more than once (in files '",
- old_flag.Filename(), "' and '", flag.Filename(), "')."),
- true);
- } else {
- flags_internal::ReportUsageError(
- absl::StrCat(
- "Something wrong with flag '", flag.Name(), "' in file '",
- flag.Filename(), "'. One possibility: file '", flag.Filename(),
- "' is being linked both statically and dynamically into this "
- "executable. e.g. some files listed as srcs to a test and also "
- "listed as srcs of some shared lib deps of the same test."),
- true);
- }
- // All cases above are fatal, except for the retired flags.
- std::exit(1);
- }
-}
-
-CommandLineFlag* FlagRegistry::FindFlagLocked(absl::string_view name) {
- FlagConstIterator i = flags_.find(name);
- if (i == flags_.end()) {
- return nullptr;
- }
-
- if (i->second->IsRetired()) {
- flags_internal::ReportUsageError(
- absl::StrCat("Accessing retired flag '", name, "'"), false);
- }
-
- return i->second;
-}
-
-CommandLineFlag* FlagRegistry::FindRetiredFlagLocked(absl::string_view name) {
- FlagConstIterator i = flags_.find(name);
- if (i == flags_.end() || !i->second->IsRetired()) {
- return nullptr;
- }
-
- return i->second;
-}
-
-// --------------------------------------------------------------------
-// FlagSaver
-// FlagSaverImpl
-// This class stores the states of all flags at construct time,
-// and restores all flags to that state at destruct time.
-// Its major implementation challenge is that it never modifies
-// pointers in the 'main' registry, so global FLAG_* vars always
-// point to the right place.
-// --------------------------------------------------------------------
-
-class FlagSaverImpl {
- public:
- FlagSaverImpl() = default;
- FlagSaverImpl(const FlagSaverImpl&) = delete;
- void operator=(const FlagSaverImpl&) = delete;
-
- // Saves the flag states from the flag registry into this object.
- // It's an error to call this more than once.
- void SaveFromRegistry() {
- assert(backup_registry_.empty()); // call only once!
- flags_internal::ForEachFlag([&](CommandLineFlag& flag) {
- if (auto flag_state =
- flags_internal::PrivateHandleAccessor::SaveState(flag)) {
- backup_registry_.emplace_back(std::move(flag_state));
- }
- });
- }
-
- // Restores the saved flag states into the flag registry.
- void RestoreToRegistry() {
- for (const auto& flag_state : backup_registry_) {
- flag_state->Restore();
- }
- }
-
- private:
- std::vector<std::unique_ptr<flags_internal::FlagStateInterface>>
- backup_registry_;
-};
-
-FlagSaver::FlagSaver() : impl_(new FlagSaverImpl) { impl_->SaveFromRegistry(); }
-
-void FlagSaver::Ignore() {
- delete impl_;
- impl_ = nullptr;
-}
-
-FlagSaver::~FlagSaver() {
- if (!impl_) return;
-
- impl_->RestoreToRegistry();
- delete impl_;
-}
-
-// --------------------------------------------------------------------
-
-CommandLineFlag* FindCommandLineFlag(absl::string_view name) {
- if (name.empty()) return nullptr;
- FlagRegistry& registry = FlagRegistry::GlobalRegistry();
- FlagRegistryLock frl(registry);
-
- return registry.FindFlagLocked(name);
-}
-
-CommandLineFlag* FindRetiredFlag(absl::string_view name) {
- FlagRegistry& registry = FlagRegistry::GlobalRegistry();
- FlagRegistryLock frl(registry);
-
- return registry.FindRetiredFlagLocked(name);
-}
-
-// --------------------------------------------------------------------
-
-void ForEachFlagUnlocked(std::function<void(CommandLineFlag&)> visitor) {
- FlagRegistry& registry = FlagRegistry::GlobalRegistry();
- for (FlagRegistry::FlagConstIterator i = registry.flags_.begin();
- i != registry.flags_.end(); ++i) {
- visitor(*i->second);
- }
-}
-
-void ForEachFlag(std::function<void(CommandLineFlag&)> visitor) {
- FlagRegistry& registry = FlagRegistry::GlobalRegistry();
- FlagRegistryLock frl(registry);
- ForEachFlagUnlocked(visitor);
-}
-
-// --------------------------------------------------------------------
-
-bool RegisterCommandLineFlag(CommandLineFlag& flag) {
- FlagRegistry::GlobalRegistry().RegisterFlag(flag);
- return true;
-}
-
-// --------------------------------------------------------------------
-
-namespace {
-
-class RetiredFlagObj final : public CommandLineFlag {
- public:
- constexpr RetiredFlagObj(const char* name, FlagFastTypeId type_id)
- : name_(name), type_id_(type_id) {}
-
- private:
- absl::string_view Name() const override { return name_; }
- std::string Filename() const override { return "RETIRED"; }
- FlagFastTypeId TypeId() const override { return type_id_; }
- std::string Help() const override { return ""; }
- bool IsRetired() const override { return true; }
- bool IsSpecifiedOnCommandLine() const override { return false; }
- std::string DefaultValue() const override { return ""; }
- std::string CurrentValue() const override { return ""; }
-
- // Any input is valid
- bool ValidateInputValue(absl::string_view) const override { return true; }
-
- std::unique_ptr<flags_internal::FlagStateInterface> SaveState() override {
- return nullptr;
- }
-
- bool ParseFrom(absl::string_view, flags_internal::FlagSettingMode,
- flags_internal::ValueSource, std::string&) override {
- return false;
- }
-
- void CheckDefaultValueParsingRoundtrip() const override {}
-
- void Read(void*) const override {}
-
- // Data members
- const char* const name_;
- const FlagFastTypeId type_id_;
-};
-
-void DestroyRetiredFlag(CommandLineFlag& flag) {
- assert(flag.IsRetired());
- delete static_cast<RetiredFlagObj*>(&flag);
-}
-
-} // namespace
-
-bool Retire(const char* name, FlagFastTypeId type_id) {
- auto* flag = new flags_internal::RetiredFlagObj(name, type_id);
- FlagRegistry::GlobalRegistry().RegisterFlag(*flag);
- return true;
-}
-
-// --------------------------------------------------------------------
-
-bool IsRetiredFlag(absl::string_view name, bool* type_is_bool) {
- assert(!name.empty());
- CommandLineFlag* flag = flags_internal::FindRetiredFlag(name);
- if (flag == nullptr) {
- return false;
- }
- assert(type_is_bool);
- *type_is_bool = flag->IsOfType<bool>();
- return true;
-}
-
-} // namespace flags_internal
-ABSL_NAMESPACE_END
-} // namespace absl
diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h
index d207c225..1e655a3e 100644
--- a/absl/flags/internal/registry.h
+++ b/absl/flags/internal/registry.h
@@ -28,10 +28,14 @@
namespace absl {
ABSL_NAMESPACE_BEGIN
-namespace flags_internal {
+// TODO(rogeeff): remove this declaration
CommandLineFlag* FindCommandLineFlag(absl::string_view name);
-CommandLineFlag* FindRetiredFlag(absl::string_view name);
+
+namespace flags_internal {
+
+// TODO(rogeeff): remove this alias
+using absl::FindCommandLineFlag;
// Executes specified visitor for each non-retired flag in the registry.
// Requires the caller hold the registry lock.
@@ -85,11 +89,6 @@ inline bool RetiredFlag(const char* flag_name) {
return flags_internal::Retire(flag_name, base_internal::FastTypeId<T>());
}
-// If the flag is retired, returns true and indicates in |*type_is_bool|
-// whether the type of the retired flag is a bool.
-// Only to be called by code that needs to explicitly ignore retired flags.
-bool IsRetiredFlag(absl::string_view name, bool* type_is_bool);
-
//-----------------------------------------------------------------------------
// Saves the states (value, default value, whether the user has set
// the flag, registered validators, etc) of all flags, and restores
diff --git a/absl/flags/internal/type_erased.cc b/absl/flags/internal/type_erased.cc
deleted file mode 100644
index b2523b24..00000000
--- a/absl/flags/internal/type_erased.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-//
-// 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/type_erased.h"
-
-#include <assert.h>
-
-#include <string>
-
-#include "absl/base/config.h"
-#include "absl/base/internal/raw_logging.h"
-#include "absl/flags/commandlineflag.h"
-#include "absl/flags/internal/private_handle_accessor.h"
-#include "absl/flags/internal/registry.h"
-#include "absl/flags/usage_config.h"
-#include "absl/strings/string_view.h"
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-namespace flags_internal {
-
-bool GetCommandLineOption(absl::string_view name, std::string* value) {
- if (name.empty()) return false;
- assert(value);
-
- CommandLineFlag* flag = flags_internal::FindCommandLineFlag(name);
- if (flag == nullptr || flag->IsRetired()) {
- return false;
- }
-
- *value = flag->CurrentValue();
- return true;
-}
-
-bool SetCommandLineOption(absl::string_view name, absl::string_view value) {
- return SetCommandLineOptionWithMode(name, value,
- flags_internal::SET_FLAGS_VALUE);
-}
-
-bool SetCommandLineOptionWithMode(absl::string_view name,
- absl::string_view value,
- FlagSettingMode set_mode) {
- CommandLineFlag* flag = flags_internal::FindCommandLineFlag(name);
-
- if (!flag || flag->IsRetired()) return false;
-
- std::string error;
- if (!flags_internal::PrivateHandleAccessor::ParseFrom(
- *flag, value, set_mode, kProgrammaticChange, error)) {
- // Errors here are all of the form: the provided name was a recognized
- // flag, but the value was invalid (bad type, or validation failed).
- flags_internal::ReportUsageError(error, false);
- return false;
- }
-
- return true;
-}
-
-// --------------------------------------------------------------------
-
-bool IsValidFlagValue(absl::string_view name, absl::string_view value) {
- CommandLineFlag* flag = flags_internal::FindCommandLineFlag(name);
-
- return flag != nullptr &&
- (flag->IsRetired() ||
- flags_internal::PrivateHandleAccessor::ValidateInputValue(*flag,
- value));
-}
-
-// --------------------------------------------------------------------
-
-} // namespace flags_internal
-ABSL_NAMESPACE_END
-} // namespace absl
diff --git a/absl/flags/internal/type_erased.h b/absl/flags/internal/type_erased.h
deleted file mode 100644
index 437a8c28..00000000
--- a/absl/flags/internal/type_erased.h
+++ /dev/null
@@ -1,80 +0,0 @@
-//
-// 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.
-
-#ifndef ABSL_FLAGS_INTERNAL_TYPE_ERASED_H_
-#define ABSL_FLAGS_INTERNAL_TYPE_ERASED_H_
-
-#include <string>
-
-#include "absl/base/config.h"
-#include "absl/flags/commandlineflag.h"
-#include "absl/flags/internal/commandlineflag.h"
-#include "absl/flags/internal/registry.h"
-#include "absl/strings/string_view.h"
-
-// --------------------------------------------------------------------
-// Registry interfaces operating on type erased handles.
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-namespace flags_internal {
-
-// If a flag named "name" exists, store its current value in *OUTPUT
-// and return true. Else return false without changing *OUTPUT.
-// Thread-safe.
-bool GetCommandLineOption(absl::string_view name, std::string* value);
-
-// Set the value of the flag named "name" to value. If successful,
-// returns true. If not successful (e.g., the flag was not found or
-// the value is not a valid value), returns false.
-// Thread-safe.
-bool SetCommandLineOption(absl::string_view name, absl::string_view value);
-
-bool SetCommandLineOptionWithMode(absl::string_view name,
- absl::string_view value,
- FlagSettingMode set_mode);
-
-//-----------------------------------------------------------------------------
-
-// Returns true iff all of the following conditions are true:
-// (a) "name" names a registered flag
-// (b) "value" can be parsed succesfully according to the type of the flag
-// (c) parsed value passes any validator associated with the flag
-bool IsValidFlagValue(absl::string_view name, absl::string_view value);
-
-//-----------------------------------------------------------------------------
-
-// If a flag with specified "name" exists and has type T, store
-// its current value in *dst and return true. Else return false
-// without touching *dst. T must obey all of the requirements for
-// types passed to DEFINE_FLAG.
-template <typename T>
-inline bool GetByName(absl::string_view name, T* dst) {
- CommandLineFlag* flag = flags_internal::FindCommandLineFlag(name);
- if (!flag) return false;
-
- if (auto val = flag->TryGet<T>()) {
- *dst = *val;
- return true;
- }
-
- return false;
-}
-
-} // namespace flags_internal
-ABSL_NAMESPACE_END
-} // namespace absl
-
-#endif // ABSL_FLAGS_INTERNAL_TYPE_ERASED_H_
diff --git a/absl/flags/internal/type_erased_test.cc b/absl/flags/internal/type_erased_test.cc
deleted file mode 100644
index 42f374dc..00000000
--- a/absl/flags/internal/type_erased_test.cc
+++ /dev/null
@@ -1,156 +0,0 @@
-//
-// 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/type_erased.h"
-
-#include <memory>
-#include <string>
-
-#include "gtest/gtest.h"
-#include "absl/flags/flag.h"
-#include "absl/flags/internal/commandlineflag.h"
-#include "absl/flags/internal/registry.h"
-#include "absl/memory/memory.h"
-
-ABSL_FLAG(int, int_flag, 1, "int_flag help");
-ABSL_FLAG(std::string, string_flag, "dflt", "string_flag help");
-ABSL_RETIRED_FLAG(bool, bool_retired_flag, false, "bool_retired_flag help");
-
-namespace {
-
-namespace flags = absl::flags_internal;
-
-class TypeErasedTest : public testing::Test {
- protected:
- void SetUp() override { flag_saver_ = absl::make_unique<flags::FlagSaver>(); }
- void TearDown() override { flag_saver_.reset(); }
-
- private:
- std::unique_ptr<flags::FlagSaver> flag_saver_;
-};
-
-// --------------------------------------------------------------------
-
-TEST_F(TypeErasedTest, TestGetCommandLineOption) {
- std::string value;
- EXPECT_TRUE(flags::GetCommandLineOption("int_flag", &value));
- EXPECT_EQ(value, "1");
-
- EXPECT_TRUE(flags::GetCommandLineOption("string_flag", &value));
- EXPECT_EQ(value, "dflt");
-
- EXPECT_FALSE(flags::GetCommandLineOption("bool_retired_flag", &value));
-
- EXPECT_FALSE(flags::GetCommandLineOption("unknown_flag", &value));
-}
-
-// --------------------------------------------------------------------
-
-TEST_F(TypeErasedTest, TestSetCommandLineOption) {
- EXPECT_TRUE(flags::SetCommandLineOption("int_flag", "101"));
- EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 101);
-
- EXPECT_TRUE(flags::SetCommandLineOption("string_flag", "asdfgh"));
- EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "asdfgh");
-
- EXPECT_FALSE(flags::SetCommandLineOption("bool_retired_flag", "true"));
-
- EXPECT_FALSE(flags::SetCommandLineOption("unknown_flag", "true"));
-}
-
-// --------------------------------------------------------------------
-
-TEST_F(TypeErasedTest, TestSetCommandLineOptionWithMode_SET_FLAGS_VALUE) {
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "101",
- flags::SET_FLAGS_VALUE));
- EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 101);
-
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("string_flag", "asdfgh",
- flags::SET_FLAGS_VALUE));
- EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "asdfgh");
-
- EXPECT_FALSE(flags::SetCommandLineOptionWithMode("bool_retired_flag", "true",
- flags::SET_FLAGS_VALUE));
-
- EXPECT_FALSE(flags::SetCommandLineOptionWithMode("unknown_flag", "true",
- flags::SET_FLAGS_VALUE));
-}
-
-// --------------------------------------------------------------------
-
-TEST_F(TypeErasedTest, TestSetCommandLineOptionWithMode_SET_FLAG_IF_DEFAULT) {
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "101",
- flags::SET_FLAG_IF_DEFAULT));
- EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 101);
-
- // This semantic is broken. We return true instead of false. Value is not
- // updated.
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "202",
- flags::SET_FLAG_IF_DEFAULT));
- EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 101);
-
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("string_flag", "asdfgh",
- flags::SET_FLAG_IF_DEFAULT));
- EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "asdfgh");
-
- EXPECT_FALSE(flags::SetCommandLineOptionWithMode("bool_retired_flag", "true",
- flags::SET_FLAG_IF_DEFAULT));
-
- EXPECT_FALSE(flags::SetCommandLineOptionWithMode("unknown_flag", "true",
- flags::SET_FLAG_IF_DEFAULT));
-}
-
-// --------------------------------------------------------------------
-
-TEST_F(TypeErasedTest, TestSetCommandLineOptionWithMode_SET_FLAGS_DEFAULT) {
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "101",
- flags::SET_FLAGS_DEFAULT));
-
- // Set it again to ensure that resetting logic is covered.
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "102",
- flags::SET_FLAGS_DEFAULT));
-
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "103",
- flags::SET_FLAGS_DEFAULT));
-
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("string_flag", "asdfgh",
- flags::SET_FLAGS_DEFAULT));
- EXPECT_EQ(absl::GetFlag(FLAGS_string_flag), "asdfgh");
-
- EXPECT_FALSE(flags::SetCommandLineOptionWithMode("bool_retired_flag", "true",
- flags::SET_FLAGS_DEFAULT));
-
- EXPECT_FALSE(flags::SetCommandLineOptionWithMode("unknown_flag", "true",
- flags::SET_FLAGS_DEFAULT));
-
- // This should be successfull, since flag is still is not set
- EXPECT_TRUE(flags::SetCommandLineOptionWithMode("int_flag", "202",
- flags::SET_FLAG_IF_DEFAULT));
- EXPECT_EQ(absl::GetFlag(FLAGS_int_flag), 202);
-}
-
-// --------------------------------------------------------------------
-
-TEST_F(TypeErasedTest, TestIsValidFlagValue) {
- EXPECT_TRUE(flags::IsValidFlagValue("int_flag", "57"));
- EXPECT_TRUE(flags::IsValidFlagValue("int_flag", "-101"));
- EXPECT_FALSE(flags::IsValidFlagValue("int_flag", "1.1"));
-
- EXPECT_TRUE(flags::IsValidFlagValue("string_flag", "#%^#%^$%DGHDG$W%adsf"));
-
- EXPECT_TRUE(flags::IsValidFlagValue("bool_retired_flag", "true"));
-}
-
-} // namespace
diff --git a/absl/flags/internal/usage_test.cc b/absl/flags/internal/usage_test.cc
index 53b4d983..46f85b55 100644
--- a/absl/flags/internal/usage_test.cc
+++ b/absl/flags/internal/usage_test.cc
@@ -25,7 +25,7 @@
#include "absl/flags/internal/parse.h"
#include "absl/flags/internal/path_util.h"
#include "absl/flags/internal/program_name.h"
-#include "absl/flags/internal/registry.h"
+#include "absl/flags/reflection.h"
#include "absl/flags/usage.h"
#include "absl/flags/usage_config.h"
#include "absl/strings/match.h"
@@ -110,7 +110,7 @@ TEST_F(UsageReportingDeathTest, TestSetProgramUsageMessage) {
// --------------------------------------------------------------------
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_01) {
- const auto* flag = flags::FindCommandLineFlag("usage_reporting_test_flag_01");
+ const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_01");
std::stringstream test_buf;
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
@@ -122,7 +122,7 @@ TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_01) {
}
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_02) {
- const auto* flag = flags::FindCommandLineFlag("usage_reporting_test_flag_02");
+ const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_02");
std::stringstream test_buf;
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
@@ -134,7 +134,7 @@ TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_02) {
}
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_03) {
- const auto* flag = flags::FindCommandLineFlag("usage_reporting_test_flag_03");
+ const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_03");
std::stringstream test_buf;
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
@@ -146,7 +146,7 @@ TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_03) {
}
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_04) {
- const auto* flag = flags::FindCommandLineFlag("usage_reporting_test_flag_04");
+ const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_04");
std::stringstream test_buf;
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
@@ -158,7 +158,7 @@ TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_04) {
}
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_05) {
- const auto* flag = flags::FindCommandLineFlag("usage_reporting_test_flag_05");
+ const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_05");
std::stringstream test_buf;
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);