Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- weight/_dep/abseil-cpp/absl/cleanup/CMakeLists.txt +56 -0
- weight/_dep/abseil-cpp/absl/copts/GENERATED_AbseilCopts.cmake +229 -0
- weight/_dep/abseil-cpp/absl/flags/internal/commandlineflag.cc +26 -0
- weight/_dep/abseil-cpp/absl/flags/internal/flag.cc +615 -0
- weight/_dep/abseil-cpp/absl/flags/internal/parse.h +70 -0
- weight/_dep/abseil-cpp/absl/flags/internal/path_util.h +62 -0
- weight/_dep/abseil-cpp/absl/flags/internal/path_util_test.cc +46 -0
- weight/_dep/abseil-cpp/absl/flags/internal/private_handle_accessor.cc +65 -0
- weight/_dep/abseil-cpp/absl/flags/internal/private_handle_accessor.h +61 -0
- weight/_dep/abseil-cpp/absl/flags/internal/program_name.cc +60 -0
- weight/_dep/abseil-cpp/absl/flags/internal/program_name.h +50 -0
- weight/_dep/abseil-cpp/absl/flags/internal/program_name_test.cc +61 -0
- weight/_dep/abseil-cpp/absl/flags/internal/registry.h +97 -0
- weight/_dep/abseil-cpp/absl/flags/internal/sequence_lock.h +187 -0
- weight/_dep/abseil-cpp/absl/flags/internal/sequence_lock_test.cc +169 -0
- weight/_dep/abseil-cpp/absl/flags/internal/usage.cc +555 -0
- weight/_dep/abseil-cpp/absl/flags/internal/usage.h +106 -0
- weight/_dep/abseil-cpp/absl/flags/internal/usage_test.cc +544 -0
- weight/_dep/abseil-cpp/absl/flags/marshalling.h +361 -0
- weight/_dep/abseil-cpp/absl/flags/marshalling_test.cc +1220 -0
- weight/_dep/abseil-cpp/absl/flags/reflection.cc +355 -0
- weight/_dep/abseil-cpp/absl/flags/usage.h +43 -0
- weight/_dep/abseil-cpp/absl/log/BUILD.bazel +676 -0
- weight/_dep/abseil-cpp/absl/log/CMakeLists.txt +1144 -0
- weight/_dep/abseil-cpp/absl/log/check.h +209 -0
- weight/_dep/abseil-cpp/absl/log/check_test.cc +58 -0
- weight/_dep/abseil-cpp/absl/log/check_test_impl.inc +528 -0
- weight/_dep/abseil-cpp/absl/log/die_if_null.cc +32 -0
- weight/_dep/abseil-cpp/absl/log/die_if_null.h +76 -0
- weight/_dep/abseil-cpp/absl/log/die_if_null_test.cc +107 -0
- weight/_dep/abseil-cpp/absl/log/flags.cc +143 -0
- weight/_dep/abseil-cpp/absl/log/flags.h +43 -0
- weight/_dep/abseil-cpp/absl/log/flags_test.cc +188 -0
- weight/_dep/abseil-cpp/absl/log/globals.cc +178 -0
- weight/_dep/abseil-cpp/absl/log/globals.h +218 -0
- weight/_dep/abseil-cpp/absl/log/globals_test.cc +147 -0
- weight/_dep/abseil-cpp/absl/log/initialize.cc +38 -0
- weight/_dep/abseil-cpp/absl/log/initialize.h +45 -0
- weight/_dep/abseil-cpp/absl/log/internal/check_op.h +420 -0
- weight/_dep/abseil-cpp/absl/log/log.h +361 -0
- weight/_dep/abseil-cpp/absl/log/log_basic_test.cc +21 -0
- weight/_dep/abseil-cpp/absl/log/log_basic_test_impl.inc +545 -0
- weight/_dep/abseil-cpp/absl/log/log_benchmark.cc +97 -0
- weight/_dep/abseil-cpp/absl/log/log_entry.cc +41 -0
- weight/_dep/abseil-cpp/absl/log/log_entry.h +221 -0
- weight/_dep/abseil-cpp/absl/log/log_entry_test.cc +468 -0
- weight/_dep/abseil-cpp/absl/log/log_format_test.cc +1872 -0
- weight/_dep/abseil-cpp/absl/log/log_macro_hygiene_test.cc +187 -0
- weight/_dep/abseil-cpp/absl/log/log_modifier_methods_test.cc +233 -0
- weight/_dep/abseil-cpp/absl/log/log_sink.cc +23 -0
weight/_dep/abseil-cpp/absl/cleanup/CMakeLists.txt
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 The Abseil Authors.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
# Internal-only target, do not depend on directly.
|
| 16 |
+
absl_cc_library(
|
| 17 |
+
NAME
|
| 18 |
+
cleanup_internal
|
| 19 |
+
HDRS
|
| 20 |
+
"internal/cleanup.h"
|
| 21 |
+
COPTS
|
| 22 |
+
${ABSL_DEFAULT_COPTS}
|
| 23 |
+
DEPS
|
| 24 |
+
absl::base_internal
|
| 25 |
+
absl::core_headers
|
| 26 |
+
absl::utility
|
| 27 |
+
PUBLIC
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
absl_cc_library(
|
| 31 |
+
NAME
|
| 32 |
+
cleanup
|
| 33 |
+
HDRS
|
| 34 |
+
"cleanup.h"
|
| 35 |
+
COPTS
|
| 36 |
+
${ABSL_DEFAULT_COPTS}
|
| 37 |
+
DEPS
|
| 38 |
+
absl::cleanup_internal
|
| 39 |
+
absl::config
|
| 40 |
+
absl::core_headers
|
| 41 |
+
PUBLIC
|
|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14 |
+
|
| 15 |
+
list(APPEND ABSL_CLANG_CL_TEST_FLAGS
|
| 16 |
+
"/W3"
|
| 17 |
+
"/DNOMINMAX"
|
| 18 |
+
"/DWIN32_LEAN_AND_MEAN"
|
| 19 |
+
"/D_CRT_SECURE_NO_WARNINGS"
|
| 20 |
+
"/D_SCL_SECURE_NO_WARNINGS"
|
| 21 |
+
"/D_ENABLE_EXTENDED_ALIGNED_STORAGE"
|
| 22 |
+
"-Wno-deprecated-declarations"
|
| 23 |
+
"-Wno-implicit-int-conversion"
|
| 24 |
+
"-Wno-missing-prototypes"
|
| 25 |
+
"-Wno-missing-variable-declarations"
|
| 26 |
+
"-Wno-shadow"
|
| 27 |
+
"-Wno-shorten-64-to-32"
|
| 28 |
+
"-Wno-sign-compare"
|
| 29 |
+
"-Wno-sign-conversion"
|
| 30 |
+
"-Wno-unreachable-code-loop-increment"
|
| 31 |
+
"-Wno-unused-function"
|
| 32 |
+
"-Wno-unused-member-function"
|
| 33 |
+
"-Wno-unused-parameter"
|
| 34 |
+
"-Wno-unused-private-field"
|
| 35 |
+
"-Wno-unused-template"
|
| 36 |
+
"-Wno-used-but-marked-unused"
|
| 37 |
+
"-Wno-gnu-zero-variadic-macro-arguments"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
list(APPEND ABSL_GCC_FLAGS
|
| 41 |
+
"-Wall"
|
| 42 |
+
"-Wextra"
|
| 43 |
+
"-Wcast-qual"
|
| 44 |
+
"-Wconversion-null"
|
| 45 |
+
"-Wformat-security"
|
| 46 |
+
"-Wmissing-declarations"
|
| 47 |
+
"-Woverlength-strings"
|
| 48 |
+
"-Wpointer-arith"
|
| 49 |
+
"-Wundef"
|
| 50 |
+
"-Wunused-local-typedefs"
|
| 51 |
+
"-Wunused-result"
|
| 52 |
+
"-Wvarargs"
|
| 53 |
+
"-Wvla"
|
| 54 |
+
"-Wwrite-strings"
|
| 55 |
+
"-DNOMINMAX"
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
list(APPEND ABSL_GCC_TEST_FLAGS
|
| 59 |
+
"-Wall"
|
| 60 |
+
"-Wextra"
|
| 61 |
+
"-Wcast-qual"
|
| 62 |
+
"-Wconversion-null"
|
| 63 |
+
"-Wformat-security"
|
| 64 |
+
"-Woverlength-strings"
|
| 65 |
+
"-Wpointer-arith"
|
| 66 |
+
"-Wundef"
|
| 67 |
+
"-Wunused-local-typedefs"
|
| 68 |
+
"-Wunused-result"
|
| 69 |
+
"-Wvarargs"
|
| 70 |
+
"-Wvla"
|
| 71 |
+
"-Wwrite-strings"
|
| 72 |
+
"-DNOMINMAX"
|
| 73 |
+
"-Wno-deprecated-declarations"
|
| 74 |
+
"-Wno-missing-declarations"
|
| 75 |
+
"-Wno-self-move"
|
| 76 |
+
"-Wno-sign-compare"
|
| 77 |
+
"-Wno-unused-function"
|
| 78 |
+
"-Wno-unused-parameter"
|
| 79 |
+
"-Wno-unused-private-field"
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
list(APPEND ABSL_LLVM_FLAGS
|
| 83 |
+
"-Wall"
|
| 84 |
+
"-Wextra"
|
| 85 |
+
"-Wcast-qual"
|
| 86 |
+
"-Wconversion"
|
| 87 |
+
"-Wfloat-overflow-conversion"
|
| 88 |
+
"-Wfloat-zero-conversion"
|
| 89 |
+
"-Wfor-loop-analysis"
|
| 90 |
+
"-Wformat-security"
|
| 91 |
+
"-Wgnu-redeclared-enum"
|
| 92 |
+
"-Winfinite-recursion"
|
| 93 |
+
"-Winvalid-constexpr"
|
| 94 |
+
"-Wliteral-conversion"
|
| 95 |
+
"-Wmissing-declarations"
|
| 96 |
+
"-Woverlength-strings"
|
| 97 |
+
"-Wpointer-arith"
|
| 98 |
+
"-Wself-assign"
|
| 99 |
+
"-Wshadow-all"
|
| 100 |
+
"-Wshorten-64-to-32"
|
| 101 |
+
"-Wsign-conversion"
|
| 102 |
+
"-Wstring-conversion"
|
| 103 |
+
"-Wtautological-overlap-compare"
|
| 104 |
+
"-Wtautological-unsigned-zero-compare"
|
| 105 |
+
"-Wundef"
|
| 106 |
+
"-Wuninitialized"
|
| 107 |
+
"-Wunreachable-code"
|
| 108 |
+
"-Wunused-comparison"
|
| 109 |
+
"-Wunused-local-typedefs"
|
| 110 |
+
"-Wunused-result"
|
| 111 |
+
"-Wvla"
|
| 112 |
+
"-Wwrite-strings"
|
| 113 |
+
"-Wno-float-conversion"
|
| 114 |
+
"-Wno-implicit-float-conversion"
|
| 115 |
+
"-Wno-implicit-int-float-conversion"
|
| 116 |
+
"-Wno-unknown-warning-option"
|
| 117 |
+
"-DNOMINMAX"
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
list(APPEND ABSL_LLVM_TEST_FLAGS
|
| 121 |
+
"-Wall"
|
| 122 |
+
"-Wextra"
|
| 123 |
+
"-Wcast-qual"
|
| 124 |
+
"-Wconversion"
|
| 125 |
+
"-Wfloat-overflow-conversion"
|
| 126 |
+
"-Wfloat-zero-conversion"
|
| 127 |
+
"-Wfor-loop-analysis"
|
| 128 |
+
"-Wformat-security"
|
| 129 |
+
"-Wgnu-redeclared-enum"
|
| 130 |
+
"-Winfinite-recursion"
|
| 131 |
+
"-Winvalid-constexpr"
|
| 132 |
+
"-Wliteral-conversion"
|
| 133 |
+
"-Wmissing-declarations"
|
| 134 |
+
"-Woverlength-strings"
|
| 135 |
+
"-Wpointer-arith"
|
| 136 |
+
"-Wself-assign"
|
| 137 |
+
"-Wshadow-all"
|
| 138 |
+
"-Wstring-conversion"
|
| 139 |
+
"-Wtautological-overlap-compare"
|
| 140 |
+
"-Wtautological-unsigned-zero-compare"
|
| 141 |
+
"-Wundef"
|
| 142 |
+
"-Wuninitialized"
|
| 143 |
+
"-Wunreachable-code"
|
| 144 |
+
"-Wunused-comparison"
|
| 145 |
+
"-Wunused-local-typedefs"
|
| 146 |
+
"-Wunused-result"
|
| 147 |
+
"-Wvla"
|
| 148 |
+
"-Wwrite-strings"
|
| 149 |
+
"-Wno-float-conversion"
|
| 150 |
+
"-Wno-implicit-float-conversion"
|
| 151 |
+
"-Wno-implicit-int-float-conversion"
|
| 152 |
+
"-Wno-unknown-warning-option"
|
| 153 |
+
"-DNOMINMAX"
|
| 154 |
+
"-Wno-deprecated-declarations"
|
| 155 |
+
"-Wno-implicit-int-conversion"
|
| 156 |
+
"-Wno-missing-prototypes"
|
| 157 |
+
"-Wno-missing-variable-declarations"
|
| 158 |
+
"-Wno-shadow"
|
| 159 |
+
"-Wno-shorten-64-to-32"
|
| 160 |
+
"-Wno-sign-compare"
|
| 161 |
+
"-Wno-sign-conversion"
|
| 162 |
+
"-Wno-unreachable-code-loop-increment"
|
| 163 |
+
"-Wno-unused-function"
|
| 164 |
+
"-Wno-unused-member-function"
|
| 165 |
+
"-Wno-unused-parameter"
|
| 166 |
+
"-Wno-unused-private-field"
|
| 167 |
+
"-Wno-unused-template"
|
| 168 |
+
"-Wno-used-but-marked-unused"
|
| 169 |
+
"-Wno-gnu-zero-variadic-macro-arguments"
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
list(APPEND ABSL_MSVC_FLAGS
|
| 173 |
+
"/W3"
|
| 174 |
+
"/bigobj"
|
| 175 |
+
"/wd4005"
|
| 176 |
+
"/wd4068"
|
| 177 |
+
"/wd4180"
|
| 178 |
+
"/wd4244"
|
| 179 |
+
"/wd4267"
|
| 180 |
+
"/wd4503"
|
| 181 |
+
"/wd4800"
|
| 182 |
+
"/DNOMINMAX"
|
| 183 |
+
"/DWIN32_LEAN_AND_MEAN"
|
| 184 |
+
"/D_CRT_SECURE_NO_WARNINGS"
|
| 185 |
+
"/D_SCL_SECURE_NO_WARNINGS"
|
| 186 |
+
"/D_ENABLE_EXTENDED_ALIGNED_STORAGE"
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
list(APPEND ABSL_MSVC_LINKOPTS
|
| 190 |
+
"-ignore:4221"
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
list(APPEND ABSL_MSVC_TEST_FLAGS
|
| 194 |
+
"/W3"
|
| 195 |
+
"/bigobj"
|
| 196 |
+
"/wd4005"
|
| 197 |
+
"/wd4068"
|
| 198 |
+
"/wd4180"
|
| 199 |
+
"/wd4244"
|
| 200 |
+
"/wd4267"
|
| 201 |
+
"/wd4503"
|
| 202 |
+
"/wd4800"
|
| 203 |
+
"/DNOMINMAX"
|
| 204 |
+
"/DWIN32_LEAN_AND_MEAN"
|
| 205 |
+
"/D_CRT_SECURE_NO_WARNINGS"
|
| 206 |
+
"/D_SCL_SECURE_NO_WARNINGS"
|
| 207 |
+
"/D_ENABLE_EXTENDED_ALIGNED_STORAGE"
|
| 208 |
+
"/wd4018"
|
| 209 |
+
"/wd4101"
|
| 210 |
+
"/wd4503"
|
| 211 |
+
"/wd4996"
|
| 212 |
+
"/DNOMINMAX"
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
list(APPEND ABSL_RANDOM_HWAES_ARM32_FLAGS
|
| 216 |
+
"-mfpu=neon"
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
list(APPEND ABSL_RANDOM_HWAES_ARM64_FLAGS
|
| 220 |
+
"-march=armv8-a+crypto"
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
list(APPEND ABSL_RANDOM_HWAES_MSVC_X64_FLAGS
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
list(APPEND ABSL_RANDOM_HWAES_X64_FLAGS
|
| 227 |
+
"-maes"
|
| 228 |
+
"-msse4.1"
|
| 229 |
+
)
|
weight/_dep/abseil-cpp/absl/flags/internal/commandlineflag.cc
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2020 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/commandlineflag.h"
|
| 17 |
+
|
| 18 |
+
namespace absl {
|
| 19 |
+
ABSL_NAMESPACE_BEGIN
|
| 20 |
+
namespace flags_internal {
|
| 21 |
+
|
| 22 |
+
FlagStateInterface::~FlagStateInterface() = default;
|
| 23 |
+
|
| 24 |
+
} // namespace flags_internal
|
| 25 |
+
ABSL_NAMESPACE_END
|
| 26 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/flags/internal/flag.cc
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/flag.h"
|
| 17 |
+
|
| 18 |
+
#include <assert.h>
|
| 19 |
+
#include <stddef.h>
|
| 20 |
+
#include <stdint.h>
|
| 21 |
+
#include <string.h>
|
| 22 |
+
|
| 23 |
+
#include <array>
|
| 24 |
+
#include <atomic>
|
| 25 |
+
#include <memory>
|
| 26 |
+
#include <new>
|
| 27 |
+
#include <string>
|
| 28 |
+
#include <typeinfo>
|
| 29 |
+
|
| 30 |
+
#include "absl/base/call_once.h"
|
| 31 |
+
#include "absl/base/casts.h"
|
| 32 |
+
#include "absl/base/config.h"
|
| 33 |
+
#include "absl/base/dynamic_annotations.h"
|
| 34 |
+
#include "absl/base/optimization.h"
|
| 35 |
+
#include "absl/flags/config.h"
|
| 36 |
+
#include "absl/flags/internal/commandlineflag.h"
|
| 37 |
+
#include "absl/flags/usage_config.h"
|
| 38 |
+
#include "absl/memory/memory.h"
|
| 39 |
+
#include "absl/strings/str_cat.h"
|
| 40 |
+
#include "absl/strings/string_view.h"
|
| 41 |
+
#include "absl/synchronization/mutex.h"
|
| 42 |
+
|
| 43 |
+
namespace absl {
|
| 44 |
+
ABSL_NAMESPACE_BEGIN
|
| 45 |
+
namespace flags_internal {
|
| 46 |
+
|
| 47 |
+
// The help message indicating that the commandline flag has been
|
| 48 |
+
// 'stripped'. It will not show up when doing "-help" and its
|
| 49 |
+
// variants. The flag is stripped if ABSL_FLAGS_STRIP_HELP is set to 1
|
| 50 |
+
// before including absl/flags/flag.h
|
| 51 |
+
const char kStrippedFlagHelp[] = "\001\002\003\004 (unknown) \004\003\002\001";
|
| 52 |
+
|
| 53 |
+
namespace {
|
| 54 |
+
|
| 55 |
+
// Currently we only validate flag values for user-defined flag types.
|
| 56 |
+
bool ShouldValidateFlagValue(FlagFastTypeId flag_type_id) {
|
| 57 |
+
#define DONT_VALIDATE(T, _) \
|
| 58 |
+
if (flag_type_id == base_internal::FastTypeId<T>()) return false;
|
| 59 |
+
ABSL_FLAGS_INTERNAL_SUPPORTED_TYPES(DONT_VALIDATE)
|
| 60 |
+
#undef DONT_VALIDATE
|
| 61 |
+
|
| 62 |
+
return true;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// RAII helper used to temporarily unlock and relock `absl::Mutex`.
|
| 66 |
+
// This is used when we need to ensure that locks are released while
|
| 67 |
+
// invoking user supplied callbacks and then reacquired, since callbacks may
|
| 68 |
+
// need to acquire these locks themselves.
|
| 69 |
+
class MutexRelock {
|
| 70 |
+
public:
|
| 71 |
+
explicit MutexRelock(absl::Mutex& mu) : mu_(mu) { mu_.Unlock(); }
|
| 72 |
+
~MutexRelock() { mu_.Lock(); }
|
| 73 |
+
|
| 74 |
+
MutexRelock(const MutexRelock&) = delete;
|
| 75 |
+
MutexRelock& operator=(const MutexRelock&) = delete;
|
| 76 |
+
|
| 77 |
+
private:
|
| 78 |
+
absl::Mutex& mu_;
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
} // namespace
|
| 82 |
+
|
| 83 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 84 |
+
// Persistent state of the flag data.
|
| 85 |
+
|
| 86 |
+
class FlagImpl;
|
| 87 |
+
|
| 88 |
+
class FlagState : public flags_internal::FlagStateInterface {
|
| 89 |
+
public:
|
| 90 |
+
template <typename V>
|
| 91 |
+
FlagState(FlagImpl& flag_impl, const V& v, bool modified,
|
| 92 |
+
bool on_command_line, int64_t counter)
|
| 93 |
+
: flag_impl_(flag_impl),
|
| 94 |
+
value_(v),
|
| 95 |
+
modified_(modified),
|
| 96 |
+
on_command_line_(on_command_line),
|
| 97 |
+
counter_(counter) {}
|
| 98 |
+
|
| 99 |
+
~FlagState() override {
|
| 100 |
+
if (flag_impl_.ValueStorageKind() != FlagValueStorageKind::kAlignedBuffer &&
|
| 101 |
+
flag_impl_.ValueStorageKind() != FlagValueStorageKind::kSequenceLocked)
|
| 102 |
+
return;
|
| 103 |
+
flags_internal::Delete(flag_impl_.op_, value_.heap_allocated);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
private:
|
| 107 |
+
friend class FlagImpl;
|
| 108 |
+
|
| 109 |
+
// Restores the flag to the saved state.
|
| 110 |
+
void Restore() const override {
|
| 111 |
+
if (!flag_impl_.RestoreState(*this)) return;
|
| 112 |
+
|
| 113 |
+
ABSL_INTERNAL_LOG(INFO,
|
| 114 |
+
absl::StrCat("Restore saved value of ", flag_impl_.Name(),
|
| 115 |
+
" to: ", flag_impl_.CurrentValue()));
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// Flag and saved flag data.
|
| 119 |
+
FlagImpl& flag_impl_;
|
| 120 |
+
union SavedValue {
|
| 121 |
+
explicit SavedValue(void* v) : heap_allocated(v) {}
|
| 122 |
+
explicit SavedValue(int64_t v) : one_word(v) {}
|
| 123 |
+
|
| 124 |
+
void* heap_allocated;
|
| 125 |
+
int64_t one_word;
|
| 126 |
+
} value_;
|
| 127 |
+
bool modified_;
|
| 128 |
+
bool on_command_line_;
|
| 129 |
+
int64_t counter_;
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 133 |
+
// Flag implementation, which does not depend on flag value type.
|
| 134 |
+
|
| 135 |
+
DynValueDeleter::DynValueDeleter(FlagOpFn op_arg) : op(op_arg) {}
|
| 136 |
+
|
| 137 |
+
void DynValueDeleter::operator()(void* ptr) const {
|
| 138 |
+
if (op == nullptr) return;
|
| 139 |
+
|
| 140 |
+
Delete(op, ptr);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
void FlagImpl::Init() {
|
| 144 |
+
new (&data_guard_) absl::Mutex;
|
| 145 |
+
|
| 146 |
+
auto def_kind = static_cast<FlagDefaultKind>(def_kind_);
|
| 147 |
+
|
| 148 |
+
switch (ValueStorageKind()) {
|
| 149 |
+
case FlagValueStorageKind::kValueAndInitBit:
|
| 150 |
+
case FlagValueStorageKind::kOneWordAtomic: {
|
| 151 |
+
alignas(int64_t) std::array<char, sizeof(int64_t)> buf{};
|
| 152 |
+
if (def_kind == FlagDefaultKind::kGenFunc) {
|
| 153 |
+
(*default_value_.gen_func)(buf.data());
|
| 154 |
+
} else {
|
| 155 |
+
assert(def_kind != FlagDefaultKind::kDynamicValue);
|
| 156 |
+
std::memcpy(buf.data(), &default_value_, Sizeof(op_));
|
| 157 |
+
}
|
| 158 |
+
if (ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit) {
|
| 159 |
+
// We presume here the memory layout of FlagValueAndInitBit struct.
|
| 160 |
+
uint8_t initialized = 1;
|
| 161 |
+
std::memcpy(buf.data() + Sizeof(op_), &initialized,
|
| 162 |
+
sizeof(initialized));
|
| 163 |
+
}
|
| 164 |
+
// Type can contain valid uninitialized bits, e.g. padding.
|
| 165 |
+
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(buf.data(), buf.size());
|
| 166 |
+
OneWordValue().store(absl::bit_cast<int64_t>(buf),
|
| 167 |
+
std::memory_order_release);
|
| 168 |
+
break;
|
| 169 |
+
}
|
| 170 |
+
case FlagValueStorageKind::kSequenceLocked: {
|
| 171 |
+
// For this storage kind the default_value_ always points to gen_func
|
| 172 |
+
// during initialization.
|
| 173 |
+
assert(def_kind == FlagDefaultKind::kGenFunc);
|
| 174 |
+
(*default_value_.gen_func)(AtomicBufferValue());
|
| 175 |
+
break;
|
| 176 |
+
}
|
| 177 |
+
case FlagValueStorageKind::kAlignedBuffer:
|
| 178 |
+
// For this storage kind the default_value_ always points to gen_func
|
| 179 |
+
// during initialization.
|
| 180 |
+
assert(def_kind == FlagDefaultKind::kGenFunc);
|
| 181 |
+
(*default_value_.gen_func)(AlignedBufferValue());
|
| 182 |
+
break;
|
| 183 |
+
}
|
| 184 |
+
seq_lock_.MarkInitialized();
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
absl::Mutex* FlagImpl::DataGuard() const {
|
| 188 |
+
absl::call_once(const_cast<FlagImpl*>(this)->init_control_, &FlagImpl::Init,
|
| 189 |
+
const_cast<FlagImpl*>(this));
|
| 190 |
+
|
| 191 |
+
// data_guard_ is initialized inside Init.
|
| 192 |
+
return reinterpret_cast<absl::Mutex*>(&data_guard_);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
void FlagImpl::AssertValidType(FlagFastTypeId rhs_type_id,
|
| 196 |
+
const std::type_info* (*gen_rtti)()) const {
|
| 197 |
+
FlagFastTypeId lhs_type_id = flags_internal::FastTypeId(op_);
|
| 198 |
+
|
| 199 |
+
// `rhs_type_id` is the fast type id corresponding to the declaration
|
| 200 |
+
// visible at the call site. `lhs_type_id` is the fast type id
|
| 201 |
+
// corresponding to the type specified in flag definition. They must match
|
| 202 |
+
// for this operation to be well-defined.
|
| 203 |
+
if (ABSL_PREDICT_TRUE(lhs_type_id == rhs_type_id)) return;
|
| 204 |
+
|
| 205 |
+
const std::type_info* lhs_runtime_type_id =
|
| 206 |
+
flags_internal::RuntimeTypeId(op_);
|
| 207 |
+
const std::type_info* rhs_runtime_type_id = (*gen_rtti)();
|
| 208 |
+
|
| 209 |
+
if (lhs_runtime_type_id == rhs_runtime_type_id) return;
|
| 210 |
+
|
| 211 |
+
#ifdef ABSL_INTERNAL_HAS_RTTI
|
| 212 |
+
if (*lhs_runtime_type_id == *rhs_runtime_type_id) return;
|
| 213 |
+
#endif
|
| 214 |
+
|
| 215 |
+
ABSL_INTERNAL_LOG(
|
| 216 |
+
FATAL, absl::StrCat("Flag '", Name(),
|
| 217 |
+
"' is defined as one type and declared as another"));
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
std::unique_ptr<void, DynValueDeleter> FlagImpl::MakeInitValue() const {
|
| 221 |
+
void* res = nullptr;
|
| 222 |
+
switch (DefaultKind()) {
|
| 223 |
+
case FlagDefaultKind::kDynamicValue:
|
| 224 |
+
res = flags_internal::Clone(op_, default_value_.dynamic_value);
|
| 225 |
+
break;
|
| 226 |
+
case FlagDefaultKind::kGenFunc:
|
| 227 |
+
res = flags_internal::Alloc(op_);
|
| 228 |
+
(*default_value_.gen_func)(res);
|
| 229 |
+
break;
|
| 230 |
+
default:
|
| 231 |
+
res = flags_internal::Clone(op_, &default_value_);
|
| 232 |
+
break;
|
| 233 |
+
}
|
| 234 |
+
return {res, DynValueDeleter{op_}};
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
void FlagImpl::StoreValue(const void* src) {
|
| 238 |
+
switch (ValueStorageKind()) {
|
| 239 |
+
case FlagValueStorageKind::kValueAndInitBit:
|
| 240 |
+
case FlagValueStorageKind::kOneWordAtomic: {
|
| 241 |
+
// Load the current value to avoid setting 'init' bit manually.
|
| 242 |
+
int64_t one_word_val = OneWordValue().load(std::memory_order_acquire);
|
| 243 |
+
std::memcpy(&one_word_val, src, Sizeof(op_));
|
| 244 |
+
OneWordValue().store(one_word_val, std::memory_order_release);
|
| 245 |
+
seq_lock_.IncrementModificationCount();
|
| 246 |
+
break;
|
| 247 |
+
}
|
| 248 |
+
case FlagValueStorageKind::kSequenceLocked: {
|
| 249 |
+
seq_lock_.Write(AtomicBufferValue(), src, Sizeof(op_));
|
| 250 |
+
break;
|
| 251 |
+
}
|
| 252 |
+
case FlagValueStorageKind::kAlignedBuffer:
|
| 253 |
+
Copy(op_, src, AlignedBufferValue());
|
| 254 |
+
seq_lock_.IncrementModificationCount();
|
| 255 |
+
break;
|
| 256 |
+
}
|
| 257 |
+
modified_ = true;
|
| 258 |
+
InvokeCallback();
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
absl::string_view FlagImpl::Name() const { return name_; }
|
| 262 |
+
|
| 263 |
+
std::string FlagImpl::Filename() const {
|
| 264 |
+
return flags_internal::GetUsageConfig().normalize_filename(filename_);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
std::string FlagImpl::Help() const {
|
| 268 |
+
return HelpSourceKind() == FlagHelpKind::kLiteral ? help_.literal
|
| 269 |
+
: help_.gen_func();
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
FlagFastTypeId FlagImpl::TypeId() const {
|
| 273 |
+
return flags_internal::FastTypeId(op_);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
int64_t FlagImpl::ModificationCount() const {
|
| 277 |
+
return seq_lock_.ModificationCount();
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
bool FlagImpl::IsSpecifiedOnCommandLine() const {
|
| 281 |
+
absl::MutexLock l(DataGuard());
|
| 282 |
+
return on_command_line_;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
std::string FlagImpl::DefaultValue() const {
|
| 286 |
+
absl::MutexLock l(DataGuard());
|
| 287 |
+
|
| 288 |
+
auto obj = MakeInitValue();
|
| 289 |
+
return flags_internal::Unparse(op_, obj.get());
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
std::string FlagImpl::CurrentValue() const {
|
| 293 |
+
auto* guard = DataGuard(); // Make sure flag initialized
|
| 294 |
+
switch (ValueStorageKind()) {
|
| 295 |
+
case FlagValueStorageKind::kValueAndInitBit:
|
| 296 |
+
case FlagValueStorageKind::kOneWordAtomic: {
|
| 297 |
+
const auto one_word_val =
|
| 298 |
+
absl::bit_cast<std::array<char, sizeof(int64_t)>>(
|
| 299 |
+
OneWordValue().load(std::memory_order_acquire));
|
| 300 |
+
return flags_internal::Unparse(op_, one_word_val.data());
|
| 301 |
+
}
|
| 302 |
+
case FlagValueStorageKind::kSequenceLocked: {
|
| 303 |
+
std::unique_ptr<void, DynValueDeleter> cloned(flags_internal::Alloc(op_),
|
| 304 |
+
DynValueDeleter{op_});
|
| 305 |
+
ReadSequenceLockedData(cloned.get());
|
| 306 |
+
return flags_internal::Unparse(op_, cloned.get());
|
| 307 |
+
}
|
| 308 |
+
case FlagValueStorageKind::kAlignedBuffer: {
|
| 309 |
+
absl::MutexLock l(guard);
|
| 310 |
+
return flags_internal::Unparse(op_, AlignedBufferValue());
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
return "";
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
void FlagImpl::SetCallback(const FlagCallbackFunc mutation_callback) {
|
| 318 |
+
absl::MutexLock l(DataGuard());
|
| 319 |
+
|
| 320 |
+
if (callback_ == nullptr) {
|
| 321 |
+
callback_ = new FlagCallback;
|
| 322 |
+
}
|
| 323 |
+
callback_->func = mutation_callback;
|
| 324 |
+
|
| 325 |
+
InvokeCallback();
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
void FlagImpl::InvokeCallback() const {
|
| 329 |
+
if (!callback_) return;
|
| 330 |
+
|
| 331 |
+
// Make a copy of the C-style function pointer that we are about to invoke
|
| 332 |
+
// before we release the lock guarding it.
|
| 333 |
+
FlagCallbackFunc cb = callback_->func;
|
| 334 |
+
|
| 335 |
+
// If the flag has a mutation callback this function invokes it. While the
|
| 336 |
+
// callback is being invoked the primary flag's mutex is unlocked and it is
|
| 337 |
+
// re-locked back after call to callback is completed. Callback invocation is
|
| 338 |
+
// guarded by flag's secondary mutex instead which prevents concurrent
|
| 339 |
+
// callback invocation. Note that it is possible for other thread to grab the
|
| 340 |
+
// primary lock and update flag's value at any time during the callback
|
| 341 |
+
// invocation. This is by design. Callback can get a value of the flag if
|
| 342 |
+
// necessary, but it might be different from the value initiated the callback
|
| 343 |
+
// and it also can be different by the time the callback invocation is
|
| 344 |
+
// completed. Requires that *primary_lock be held in exclusive mode; it may be
|
| 345 |
+
// released and reacquired by the implementation.
|
| 346 |
+
MutexRelock relock(*DataGuard());
|
| 347 |
+
absl::MutexLock lock(&callback_->guard);
|
| 348 |
+
cb();
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
std::unique_ptr<FlagStateInterface> FlagImpl::SaveState() {
|
| 352 |
+
absl::MutexLock l(DataGuard());
|
| 353 |
+
|
| 354 |
+
bool modified = modified_;
|
| 355 |
+
bool on_command_line = on_command_line_;
|
| 356 |
+
switch (ValueStorageKind()) {
|
| 357 |
+
case FlagValueStorageKind::kValueAndInitBit:
|
| 358 |
+
case FlagValueStorageKind::kOneWordAtomic: {
|
| 359 |
+
return absl::make_unique<FlagState>(
|
| 360 |
+
*this, OneWordValue().load(std::memory_order_acquire), modified,
|
| 361 |
+
on_command_line, ModificationCount());
|
| 362 |
+
}
|
| 363 |
+
case FlagValueStorageKind::kSequenceLocked: {
|
| 364 |
+
void* cloned = flags_internal::Alloc(op_);
|
| 365 |
+
// Read is guaranteed to be successful because we hold the lock.
|
| 366 |
+
bool success =
|
| 367 |
+
seq_lock_.TryRead(cloned, AtomicBufferValue(), Sizeof(op_));
|
| 368 |
+
assert(success);
|
| 369 |
+
static_cast<void>(success);
|
| 370 |
+
return absl::make_unique<FlagState>(*this, cloned, modified,
|
| 371 |
+
on_command_line, ModificationCount());
|
| 372 |
+
}
|
| 373 |
+
case FlagValueStorageKind::kAlignedBuffer: {
|
| 374 |
+
return absl::make_unique<FlagState>(
|
| 375 |
+
*this, flags_internal::Clone(op_, AlignedBufferValue()), modified,
|
| 376 |
+
on_command_line, ModificationCount());
|
| 377 |
+
}
|
| 378 |
+
}
|
| 379 |
+
return nullptr;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
bool FlagImpl::RestoreState(const FlagState& flag_state) {
|
| 383 |
+
absl::MutexLock l(DataGuard());
|
| 384 |
+
if (flag_state.counter_ == ModificationCount()) {
|
| 385 |
+
return false;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
switch (ValueStorageKind()) {
|
| 389 |
+
case FlagValueStorageKind::kValueAndInitBit:
|
| 390 |
+
case FlagValueStorageKind::kOneWordAtomic:
|
| 391 |
+
StoreValue(&flag_state.value_.one_word);
|
| 392 |
+
break;
|
| 393 |
+
case FlagValueStorageKind::kSequenceLocked:
|
| 394 |
+
case FlagValueStorageKind::kAlignedBuffer:
|
| 395 |
+
StoreValue(flag_state.value_.heap_allocated);
|
| 396 |
+
break;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
modified_ = flag_state.modified_;
|
| 400 |
+
on_command_line_ = flag_state.on_command_line_;
|
| 401 |
+
|
| 402 |
+
return true;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
template <typename StorageT>
|
| 406 |
+
StorageT* FlagImpl::OffsetValue() const {
|
| 407 |
+
char* p = reinterpret_cast<char*>(const_cast<FlagImpl*>(this));
|
| 408 |
+
// The offset is deduced via Flag value type specific op_.
|
| 409 |
+
ptrdiff_t offset = flags_internal::ValueOffset(op_);
|
| 410 |
+
|
| 411 |
+
return reinterpret_cast<StorageT*>(p + offset);
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
void* FlagImpl::AlignedBufferValue() const {
|
| 415 |
+
assert(ValueStorageKind() == FlagValueStorageKind::kAlignedBuffer);
|
| 416 |
+
return OffsetValue<void>();
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
std::atomic<uint64_t>* FlagImpl::AtomicBufferValue() const {
|
| 420 |
+
assert(ValueStorageKind() == FlagValueStorageKind::kSequenceLocked);
|
| 421 |
+
return OffsetValue<std::atomic<uint64_t>>();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
std::atomic<int64_t>& FlagImpl::OneWordValue() const {
|
| 425 |
+
assert(ValueStorageKind() == FlagValueStorageKind::kOneWordAtomic ||
|
| 426 |
+
ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit);
|
| 427 |
+
return OffsetValue<FlagOneWordValue>()->value;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
// Attempts to parse supplied `value` string using parsing routine in the `flag`
|
| 431 |
+
// argument. If parsing successful, this function replaces the dst with newly
|
| 432 |
+
// parsed value. In case if any error is encountered in either step, the error
|
| 433 |
+
// message is stored in 'err'
|
| 434 |
+
std::unique_ptr<void, DynValueDeleter> FlagImpl::TryParse(
|
| 435 |
+
absl::string_view value, std::string& err) const {
|
| 436 |
+
std::unique_ptr<void, DynValueDeleter> tentative_value = MakeInitValue();
|
| 437 |
+
|
| 438 |
+
std::string parse_err;
|
| 439 |
+
if (!flags_internal::Parse(op_, value, tentative_value.get(), &parse_err)) {
|
| 440 |
+
absl::string_view err_sep = parse_err.empty() ? "" : "; ";
|
| 441 |
+
err = absl::StrCat("Illegal value '", value, "' specified for flag '",
|
| 442 |
+
Name(), "'", err_sep, parse_err);
|
| 443 |
+
return nullptr;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
return tentative_value;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
void FlagImpl::Read(void* dst) const {
|
| 450 |
+
auto* guard = DataGuard(); // Make sure flag initialized
|
| 451 |
+
switch (ValueStorageKind()) {
|
| 452 |
+
case FlagValueStorageKind::kValueAndInitBit:
|
| 453 |
+
case FlagValueStorageKind::kOneWordAtomic: {
|
| 454 |
+
const int64_t one_word_val =
|
| 455 |
+
OneWordValue().load(std::memory_order_acquire);
|
| 456 |
+
std::memcpy(dst, &one_word_val, Sizeof(op_));
|
| 457 |
+
break;
|
| 458 |
+
}
|
| 459 |
+
case FlagValueStorageKind::kSequenceLocked: {
|
| 460 |
+
ReadSequenceLockedData(dst);
|
| 461 |
+
break;
|
| 462 |
+
}
|
| 463 |
+
case FlagValueStorageKind::kAlignedBuffer: {
|
| 464 |
+
absl::MutexLock l(guard);
|
| 465 |
+
flags_internal::CopyConstruct(op_, AlignedBufferValue(), dst);
|
| 466 |
+
break;
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
int64_t FlagImpl::ReadOneWord() const {
|
| 472 |
+
assert(ValueStorageKind() == FlagValueStorageKind::kOneWordAtomic ||
|
| 473 |
+
ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit);
|
| 474 |
+
auto* guard = DataGuard(); // Make sure flag initialized
|
| 475 |
+
(void)guard;
|
| 476 |
+
return OneWordValue().load(std::memory_order_acquire);
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
bool FlagImpl::ReadOneBool() const {
|
| 480 |
+
assert(ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit);
|
| 481 |
+
auto* guard = DataGuard(); // Make sure flag initialized
|
| 482 |
+
(void)guard;
|
| 483 |
+
return absl::bit_cast<FlagValueAndInitBit<bool>>(
|
| 484 |
+
OneWordValue().load(std::memory_order_acquire))
|
| 485 |
+
.value;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
void FlagImpl::ReadSequenceLockedData(void* dst) const {
|
| 489 |
+
size_t size = Sizeof(op_);
|
| 490 |
+
// Attempt to read using the sequence lock.
|
| 491 |
+
if (ABSL_PREDICT_TRUE(seq_lock_.TryRead(dst, AtomicBufferValue(), size))) {
|
| 492 |
+
return;
|
| 493 |
+
}
|
| 494 |
+
// We failed due to contention. Acquire the lock to prevent contention
|
| 495 |
+
// and try again.
|
| 496 |
+
absl::ReaderMutexLock l(DataGuard());
|
| 497 |
+
bool success = seq_lock_.TryRead(dst, AtomicBufferValue(), size);
|
| 498 |
+
assert(success);
|
| 499 |
+
static_cast<void>(success);
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
void FlagImpl::Write(const void* src) {
|
| 503 |
+
absl::MutexLock l(DataGuard());
|
| 504 |
+
|
| 505 |
+
if (ShouldValidateFlagValue(flags_internal::FastTypeId(op_))) {
|
| 506 |
+
std::unique_ptr<void, DynValueDeleter> obj{flags_internal::Clone(op_, src),
|
| 507 |
+
DynValueDeleter{op_}};
|
| 508 |
+
std::string ignored_error;
|
| 509 |
+
std::string src_as_str = flags_internal::Unparse(op_, src);
|
| 510 |
+
if (!flags_internal::Parse(op_, src_as_str, obj.get(), &ignored_error)) {
|
| 511 |
+
ABSL_INTERNAL_LOG(ERROR, absl::StrCat("Attempt to set flag '", Name(),
|
| 512 |
+
"' to invalid value ", src_as_str));
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
StoreValue(src);
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
// Sets the value of the flag based on specified string `value`. If the flag
|
| 520 |
+
// was successfully set to new value, it returns true. Otherwise, sets `err`
|
| 521 |
+
// to indicate the error, leaves the flag unchanged, and returns false. There
|
| 522 |
+
// are three ways to set the flag's value:
|
| 523 |
+
// * Update the current flag value
|
| 524 |
+
// * Update the flag's default value
|
| 525 |
+
// * Update the current flag value if it was never set before
|
| 526 |
+
// The mode is selected based on 'set_mode' parameter.
|
| 527 |
+
bool FlagImpl::ParseFrom(absl::string_view value, FlagSettingMode set_mode,
|
| 528 |
+
ValueSource source, std::string& err) {
|
| 529 |
+
absl::MutexLock l(DataGuard());
|
| 530 |
+
|
| 531 |
+
switch (set_mode) {
|
| 532 |
+
case SET_FLAGS_VALUE: {
|
| 533 |
+
// set or modify the flag's value
|
| 534 |
+
auto tentative_value = TryParse(value, err);
|
| 535 |
+
if (!tentative_value) return false;
|
| 536 |
+
|
| 537 |
+
StoreValue(tentative_value.get());
|
| 538 |
+
|
| 539 |
+
if (source == kCommandLine) {
|
| 540 |
+
on_command_line_ = true;
|
| 541 |
+
}
|
| 542 |
+
break;
|
| 543 |
+
}
|
| 544 |
+
case SET_FLAG_IF_DEFAULT: {
|
| 545 |
+
// set the flag's value, but only if it hasn't been set by someone else
|
| 546 |
+
if (modified_) {
|
| 547 |
+
// TODO(rogeeff): review and fix this semantic. Currently we do not fail
|
| 548 |
+
// in this case if flag is modified. This is misleading since the flag's
|
| 549 |
+
// value is not updated even though we return true.
|
| 550 |
+
// *err = absl::StrCat(Name(), " is already set to ",
|
| 551 |
+
// CurrentValue(), "\n");
|
| 552 |
+
// return false;
|
| 553 |
+
return true;
|
| 554 |
+
}
|
| 555 |
+
auto tentative_value = TryParse(value, err);
|
| 556 |
+
if (!tentative_value) return false;
|
| 557 |
+
|
| 558 |
+
StoreValue(tentative_value.get());
|
| 559 |
+
break;
|
| 560 |
+
}
|
| 561 |
+
case SET_FLAGS_DEFAULT: {
|
| 562 |
+
auto tentative_value = TryParse(value, err);
|
| 563 |
+
if (!tentative_value) return false;
|
| 564 |
+
|
| 565 |
+
if (DefaultKind() == FlagDefaultKind::kDynamicValue) {
|
| 566 |
+
void* old_value = default_value_.dynamic_value;
|
| 567 |
+
default_value_.dynamic_value = tentative_value.release();
|
| 568 |
+
tentative_value.reset(old_value);
|
| 569 |
+
} else {
|
| 570 |
+
default_value_.dynamic_value = tentative_value.release();
|
| 571 |
+
def_kind_ = static_cast<uint8_t>(FlagDefaultKind::kDynamicValue);
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
if (!modified_) {
|
| 575 |
+
// Need to set both default value *and* current, in this case.
|
| 576 |
+
StoreValue(default_value_.dynamic_value);
|
| 577 |
+
modified_ = false;
|
| 578 |
+
}
|
| 579 |
+
break;
|
| 580 |
+
}
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
return true;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
void FlagImpl::CheckDefaultValueParsingRoundtrip() const {
|
| 587 |
+
std::string v = DefaultValue();
|
| 588 |
+
|
| 589 |
+
absl::MutexLock lock(DataGuard());
|
| 590 |
+
|
| 591 |
+
auto dst = MakeInitValue();
|
| 592 |
+
std::string error;
|
| 593 |
+
if (!flags_internal::Parse(op_, v, dst.get(), &error)) {
|
| 594 |
+
ABSL_INTERNAL_LOG(
|
| 595 |
+
FATAL,
|
| 596 |
+
absl::StrCat("Flag ", Name(), " (from ", Filename(),
|
| 597 |
+
"): string form of default value '", v,
|
| 598 |
+
"' could not be parsed; error=", error));
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
// We do not compare dst to def since parsing/unparsing may make
|
| 602 |
+
// small changes, e.g., precision loss for floating point types.
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
bool FlagImpl::ValidateInputValue(absl::string_view value) const {
|
| 606 |
+
absl::MutexLock l(DataGuard());
|
| 607 |
+
|
| 608 |
+
auto obj = MakeInitValue();
|
| 609 |
+
std::string ignored_error;
|
| 610 |
+
return flags_internal::Parse(op_, value, obj.get(), &ignored_error);
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
} // namespace flags_internal
|
| 614 |
+
ABSL_NAMESPACE_END
|
| 615 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/flags/internal/parse.h
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_PARSE_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_PARSE_H_
|
| 18 |
+
|
| 19 |
+
#include <iostream>
|
| 20 |
+
#include <ostream>
|
| 21 |
+
#include <string>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "absl/base/config.h"
|
| 25 |
+
#include "absl/flags/declare.h"
|
| 26 |
+
#include "absl/flags/internal/usage.h"
|
| 27 |
+
#include "absl/strings/string_view.h"
|
| 28 |
+
|
| 29 |
+
ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile);
|
| 30 |
+
ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv);
|
| 31 |
+
ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv);
|
| 32 |
+
ABSL_DECLARE_FLAG(std::vector<std::string>, undefok);
|
| 33 |
+
|
| 34 |
+
namespace absl {
|
| 35 |
+
ABSL_NAMESPACE_BEGIN
|
| 36 |
+
namespace flags_internal {
|
| 37 |
+
|
| 38 |
+
enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage };
|
| 39 |
+
enum class OnUndefinedFlag {
|
| 40 |
+
kIgnoreUndefined,
|
| 41 |
+
kReportUndefined,
|
| 42 |
+
kAbortIfUndefined
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
// This is not a public interface. This interface exists to expose the ability
|
| 46 |
+
// to change help output stream in case of parsing errors. This is used by
|
| 47 |
+
// internal unit tests to validate expected outputs.
|
| 48 |
+
// When this was written, `EXPECT_EXIT` only supported matchers on stderr,
|
| 49 |
+
// but not on stdout.
|
| 50 |
+
std::vector<char*> ParseCommandLineImpl(
|
| 51 |
+
int argc, char* argv[], UsageFlagsAction usage_flag_action,
|
| 52 |
+
OnUndefinedFlag undef_flag_action,
|
| 53 |
+
std::ostream& error_help_output = std::cout);
|
| 54 |
+
|
| 55 |
+
// --------------------------------------------------------------------
|
| 56 |
+
// Inspect original command line
|
| 57 |
+
|
| 58 |
+
// Returns true if flag with specified name was either present on the original
|
| 59 |
+
// command line or specified in flag file present on the original command line.
|
| 60 |
+
bool WasPresentOnCommandLine(absl::string_view flag_name);
|
| 61 |
+
|
| 62 |
+
// Return existing flags similar to the parameter, in order to help in case of
|
| 63 |
+
// misspellings.
|
| 64 |
+
std::vector<std::string> GetMisspellingHints(absl::string_view flag);
|
| 65 |
+
|
| 66 |
+
} // namespace flags_internal
|
| 67 |
+
ABSL_NAMESPACE_END
|
| 68 |
+
} // namespace absl
|
| 69 |
+
|
| 70 |
+
#endif // ABSL_FLAGS_INTERNAL_PARSE_H_
|
weight/_dep/abseil-cpp/absl/flags/internal/path_util.h
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_PATH_UTIL_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_PATH_UTIL_H_
|
| 18 |
+
|
| 19 |
+
#include "absl/base/config.h"
|
| 20 |
+
#include "absl/strings/string_view.h"
|
| 21 |
+
|
| 22 |
+
namespace absl {
|
| 23 |
+
ABSL_NAMESPACE_BEGIN
|
| 24 |
+
namespace flags_internal {
|
| 25 |
+
|
| 26 |
+
// A portable interface that returns the basename of the filename passed as an
|
| 27 |
+
// argument. It is similar to basename(3)
|
| 28 |
+
// <https://linux.die.net/man/3/basename>.
|
| 29 |
+
// For example:
|
| 30 |
+
// flags_internal::Basename("a/b/prog/file.cc")
|
| 31 |
+
// returns "file.cc"
|
| 32 |
+
// flags_internal::Basename("file.cc")
|
| 33 |
+
// returns "file.cc"
|
| 34 |
+
inline absl::string_view Basename(absl::string_view filename) {
|
| 35 |
+
auto last_slash_pos = filename.find_last_of("/\\");
|
| 36 |
+
|
| 37 |
+
return last_slash_pos == absl::string_view::npos
|
| 38 |
+
? filename
|
| 39 |
+
: filename.substr(last_slash_pos + 1);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// A portable interface that returns the directory name of the filename
|
| 43 |
+
// passed as an argument, including the trailing slash.
|
| 44 |
+
// Returns the empty string if a slash is not found in the input file name.
|
| 45 |
+
// For example:
|
| 46 |
+
// flags_internal::Package("a/b/prog/file.cc")
|
| 47 |
+
// returns "a/b/prog/"
|
| 48 |
+
// flags_internal::Package("file.cc")
|
| 49 |
+
// returns ""
|
| 50 |
+
inline absl::string_view Package(absl::string_view filename) {
|
| 51 |
+
auto last_slash_pos = filename.find_last_of("/\\");
|
| 52 |
+
|
| 53 |
+
return last_slash_pos == absl::string_view::npos
|
| 54 |
+
? absl::string_view()
|
| 55 |
+
: filename.substr(0, last_slash_pos + 1);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
} // namespace flags_internal
|
| 59 |
+
ABSL_NAMESPACE_END
|
| 60 |
+
} // namespace absl
|
| 61 |
+
|
| 62 |
+
#endif // ABSL_FLAGS_INTERNAL_PATH_UTIL_H_
|
weight/_dep/abseil-cpp/absl/flags/internal/path_util_test.cc
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/path_util.h"
|
| 17 |
+
|
| 18 |
+
#include "gtest/gtest.h"
|
| 19 |
+
|
| 20 |
+
namespace {
|
| 21 |
+
|
| 22 |
+
namespace flags = absl::flags_internal;
|
| 23 |
+
|
| 24 |
+
TEST(FlagsPathUtilTest, TestBasename) {
|
| 25 |
+
EXPECT_EQ(flags::Basename(""), "");
|
| 26 |
+
EXPECT_EQ(flags::Basename("a.cc"), "a.cc");
|
| 27 |
+
EXPECT_EQ(flags::Basename("dir/a.cc"), "a.cc");
|
| 28 |
+
EXPECT_EQ(flags::Basename("dir1/dir2/a.cc"), "a.cc");
|
| 29 |
+
EXPECT_EQ(flags::Basename("../dir1/dir2/a.cc"), "a.cc");
|
| 30 |
+
EXPECT_EQ(flags::Basename("/dir1/dir2/a.cc"), "a.cc");
|
| 31 |
+
EXPECT_EQ(flags::Basename("/dir1/dir2/../dir3/a.cc"), "a.cc");
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// --------------------------------------------------------------------
|
| 35 |
+
|
| 36 |
+
TEST(FlagsPathUtilTest, TestPackage) {
|
| 37 |
+
EXPECT_EQ(flags::Package(""), "");
|
| 38 |
+
EXPECT_EQ(flags::Package("a.cc"), "");
|
| 39 |
+
EXPECT_EQ(flags::Package("dir/a.cc"), "dir/");
|
| 40 |
+
EXPECT_EQ(flags::Package("dir1/dir2/a.cc"), "dir1/dir2/");
|
| 41 |
+
EXPECT_EQ(flags::Package("../dir1/dir2/a.cc"), "../dir1/dir2/");
|
| 42 |
+
EXPECT_EQ(flags::Package("/dir1/dir2/a.cc"), "/dir1/dir2/");
|
| 43 |
+
EXPECT_EQ(flags::Package("/dir1/dir2/../dir3/a.cc"), "/dir1/dir2/../dir3/");
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/flags/internal/private_handle_accessor.cc
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2020 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/private_handle_accessor.h"
|
| 17 |
+
|
| 18 |
+
#include <memory>
|
| 19 |
+
#include <string>
|
| 20 |
+
|
| 21 |
+
#include "absl/base/config.h"
|
| 22 |
+
#include "absl/flags/commandlineflag.h"
|
| 23 |
+
#include "absl/flags/internal/commandlineflag.h"
|
| 24 |
+
#include "absl/strings/string_view.h"
|
| 25 |
+
|
| 26 |
+
namespace absl {
|
| 27 |
+
ABSL_NAMESPACE_BEGIN
|
| 28 |
+
namespace flags_internal {
|
| 29 |
+
|
| 30 |
+
FlagFastTypeId PrivateHandleAccessor::TypeId(const CommandLineFlag& flag) {
|
| 31 |
+
return flag.TypeId();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
std::unique_ptr<FlagStateInterface> PrivateHandleAccessor::SaveState(
|
| 35 |
+
CommandLineFlag& flag) {
|
| 36 |
+
return flag.SaveState();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
bool PrivateHandleAccessor::IsSpecifiedOnCommandLine(
|
| 40 |
+
const CommandLineFlag& flag) {
|
| 41 |
+
return flag.IsSpecifiedOnCommandLine();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
bool PrivateHandleAccessor::ValidateInputValue(const CommandLineFlag& flag,
|
| 45 |
+
absl::string_view value) {
|
| 46 |
+
return flag.ValidateInputValue(value);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void PrivateHandleAccessor::CheckDefaultValueParsingRoundtrip(
|
| 50 |
+
const CommandLineFlag& flag) {
|
| 51 |
+
flag.CheckDefaultValueParsingRoundtrip();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
bool PrivateHandleAccessor::ParseFrom(CommandLineFlag& flag,
|
| 55 |
+
absl::string_view value,
|
| 56 |
+
flags_internal::FlagSettingMode set_mode,
|
| 57 |
+
flags_internal::ValueSource source,
|
| 58 |
+
std::string& error) {
|
| 59 |
+
return flag.ParseFrom(value, set_mode, source, error);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
} // namespace flags_internal
|
| 63 |
+
ABSL_NAMESPACE_END
|
| 64 |
+
} // namespace absl
|
| 65 |
+
|
weight/_dep/abseil-cpp/absl/flags/internal/private_handle_accessor.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2020 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
|
| 18 |
+
|
| 19 |
+
#include <memory>
|
| 20 |
+
#include <string>
|
| 21 |
+
|
| 22 |
+
#include "absl/base/config.h"
|
| 23 |
+
#include "absl/flags/commandlineflag.h"
|
| 24 |
+
#include "absl/flags/internal/commandlineflag.h"
|
| 25 |
+
#include "absl/strings/string_view.h"
|
| 26 |
+
|
| 27 |
+
namespace absl {
|
| 28 |
+
ABSL_NAMESPACE_BEGIN
|
| 29 |
+
namespace flags_internal {
|
| 30 |
+
|
| 31 |
+
// This class serves as a trampoline to access private methods of
|
| 32 |
+
// CommandLineFlag. This class is intended for use exclusively internally inside
|
| 33 |
+
// of the Abseil Flags implementation.
|
| 34 |
+
class PrivateHandleAccessor {
|
| 35 |
+
public:
|
| 36 |
+
// Access to CommandLineFlag::TypeId.
|
| 37 |
+
static FlagFastTypeId TypeId(const CommandLineFlag& flag);
|
| 38 |
+
|
| 39 |
+
// Access to CommandLineFlag::SaveState.
|
| 40 |
+
static std::unique_ptr<FlagStateInterface> SaveState(CommandLineFlag& flag);
|
| 41 |
+
|
| 42 |
+
// Access to CommandLineFlag::IsSpecifiedOnCommandLine.
|
| 43 |
+
static bool IsSpecifiedOnCommandLine(const CommandLineFlag& flag);
|
| 44 |
+
|
| 45 |
+
// Access to CommandLineFlag::ValidateInputValue.
|
| 46 |
+
static bool ValidateInputValue(const CommandLineFlag& flag,
|
| 47 |
+
absl::string_view value);
|
| 48 |
+
|
| 49 |
+
// Access to CommandLineFlag::CheckDefaultValueParsingRoundtrip.
|
| 50 |
+
static void CheckDefaultValueParsingRoundtrip(const CommandLineFlag& flag);
|
| 51 |
+
|
| 52 |
+
static bool ParseFrom(CommandLineFlag& flag, absl::string_view value,
|
| 53 |
+
flags_internal::FlagSettingMode set_mode,
|
| 54 |
+
flags_internal::ValueSource source, std::string& error);
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
} // namespace flags_internal
|
| 58 |
+
ABSL_NAMESPACE_END
|
| 59 |
+
} // namespace absl
|
| 60 |
+
|
| 61 |
+
#endif // ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
|
weight/_dep/abseil-cpp/absl/flags/internal/program_name.cc
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "absl/base/attributes.h"
|
| 21 |
+
#include "absl/base/config.h"
|
| 22 |
+
#include "absl/base/const_init.h"
|
| 23 |
+
#include "absl/base/thread_annotations.h"
|
| 24 |
+
#include "absl/flags/internal/path_util.h"
|
| 25 |
+
#include "absl/strings/string_view.h"
|
| 26 |
+
#include "absl/synchronization/mutex.h"
|
| 27 |
+
|
| 28 |
+
namespace absl {
|
| 29 |
+
ABSL_NAMESPACE_BEGIN
|
| 30 |
+
namespace flags_internal {
|
| 31 |
+
|
| 32 |
+
ABSL_CONST_INIT static absl::Mutex program_name_guard(absl::kConstInit);
|
| 33 |
+
ABSL_CONST_INIT static std::string* program_name
|
| 34 |
+
ABSL_GUARDED_BY(program_name_guard) = nullptr;
|
| 35 |
+
|
| 36 |
+
std::string ProgramInvocationName() {
|
| 37 |
+
absl::MutexLock l(&program_name_guard);
|
| 38 |
+
|
| 39 |
+
return program_name ? *program_name : "UNKNOWN";
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
std::string ShortProgramInvocationName() {
|
| 43 |
+
absl::MutexLock l(&program_name_guard);
|
| 44 |
+
|
| 45 |
+
return program_name ? std::string(flags_internal::Basename(*program_name))
|
| 46 |
+
: "UNKNOWN";
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void SetProgramInvocationName(absl::string_view prog_name_str) {
|
| 50 |
+
absl::MutexLock l(&program_name_guard);
|
| 51 |
+
|
| 52 |
+
if (!program_name)
|
| 53 |
+
program_name = new std::string(prog_name_str);
|
| 54 |
+
else
|
| 55 |
+
program_name->assign(prog_name_str.data(), prog_name_str.size());
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
} // namespace flags_internal
|
| 59 |
+
ABSL_NAMESPACE_END
|
| 60 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/flags/internal/program_name.h
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_
|
| 18 |
+
|
| 19 |
+
#include <string>
|
| 20 |
+
|
| 21 |
+
#include "absl/base/config.h"
|
| 22 |
+
#include "absl/strings/string_view.h"
|
| 23 |
+
|
| 24 |
+
// --------------------------------------------------------------------
|
| 25 |
+
// Program name
|
| 26 |
+
|
| 27 |
+
namespace absl {
|
| 28 |
+
ABSL_NAMESPACE_BEGIN
|
| 29 |
+
namespace flags_internal {
|
| 30 |
+
|
| 31 |
+
// Returns program invocation name or "UNKNOWN" if `SetProgramInvocationName()`
|
| 32 |
+
// is never called. At the moment this is always set to argv[0] as part of
|
| 33 |
+
// library initialization.
|
| 34 |
+
std::string ProgramInvocationName();
|
| 35 |
+
|
| 36 |
+
// Returns base name for program invocation name. For example, if
|
| 37 |
+
// ProgramInvocationName() == "a/b/mybinary"
|
| 38 |
+
// then
|
| 39 |
+
// ShortProgramInvocationName() == "mybinary"
|
| 40 |
+
std::string ShortProgramInvocationName();
|
| 41 |
+
|
| 42 |
+
// Sets program invocation name to a new value. Should only be called once
|
| 43 |
+
// during program initialization, before any threads are spawned.
|
| 44 |
+
void SetProgramInvocationName(absl::string_view prog_name_str);
|
| 45 |
+
|
| 46 |
+
} // namespace flags_internal
|
| 47 |
+
ABSL_NAMESPACE_END
|
| 48 |
+
} // namespace absl
|
| 49 |
+
|
| 50 |
+
#endif // ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_
|
weight/_dep/abseil-cpp/absl/flags/internal/program_name_test.cc
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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");
|
| 30 |
+
std::string program_name = flags::ProgramInvocationName();
|
| 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 |
+
|
| 47 |
+
flags::SetProgramInvocationName("a/my_test");
|
| 48 |
+
|
| 49 |
+
EXPECT_EQ(flags::ProgramInvocationName(), "a/my_test");
|
| 50 |
+
EXPECT_EQ(flags::ShortProgramInvocationName(), "my_test");
|
| 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");
|
| 58 |
+
EXPECT_EQ(flags::ShortProgramInvocationName(), "bb");
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/flags/internal/registry.h
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_REGISTRY_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_REGISTRY_H_
|
| 18 |
+
|
| 19 |
+
#include <functional>
|
| 20 |
+
|
| 21 |
+
#include "absl/base/config.h"
|
| 22 |
+
#include "absl/flags/commandlineflag.h"
|
| 23 |
+
#include "absl/flags/internal/commandlineflag.h"
|
| 24 |
+
#include "absl/strings/string_view.h"
|
| 25 |
+
|
| 26 |
+
// --------------------------------------------------------------------
|
| 27 |
+
// Global flags registry API.
|
| 28 |
+
|
| 29 |
+
namespace absl {
|
| 30 |
+
ABSL_NAMESPACE_BEGIN
|
| 31 |
+
namespace flags_internal {
|
| 32 |
+
|
| 33 |
+
// Executes specified visitor for each non-retired flag in the registry. While
|
| 34 |
+
// callback are executed, the registry is locked and can't be changed.
|
| 35 |
+
void ForEachFlag(std::function<void(CommandLineFlag&)> visitor);
|
| 36 |
+
|
| 37 |
+
//-----------------------------------------------------------------------------
|
| 38 |
+
|
| 39 |
+
bool RegisterCommandLineFlag(CommandLineFlag&, const char* filename);
|
| 40 |
+
|
| 41 |
+
void FinalizeRegistry();
|
| 42 |
+
|
| 43 |
+
//-----------------------------------------------------------------------------
|
| 44 |
+
// Retired registrations:
|
| 45 |
+
//
|
| 46 |
+
// Retired flag registrations are treated specially. A 'retired' flag is
|
| 47 |
+
// provided only for compatibility with automated invocations that still
|
| 48 |
+
// name it. A 'retired' flag:
|
| 49 |
+
// - is not bound to a C++ FLAGS_ reference.
|
| 50 |
+
// - has a type and a value, but that value is intentionally inaccessible.
|
| 51 |
+
// - does not appear in --help messages.
|
| 52 |
+
// - is fully supported by _all_ flag parsing routines.
|
| 53 |
+
// - consumes args normally, and complains about type mismatches in its
|
| 54 |
+
// argument.
|
| 55 |
+
// - emits a complaint but does not die (e.g. LOG(ERROR)) if it is
|
| 56 |
+
// accessed by name through the flags API for parsing or otherwise.
|
| 57 |
+
//
|
| 58 |
+
// The registrations for a flag happen in an unspecified order as the
|
| 59 |
+
// initializers for the namespace-scope objects of a program are run.
|
| 60 |
+
// Any number of weak registrations for a flag can weakly define the flag.
|
| 61 |
+
// One non-weak registration will upgrade the flag from weak to non-weak.
|
| 62 |
+
// Further weak registrations of a non-weak flag are ignored.
|
| 63 |
+
//
|
| 64 |
+
// This mechanism is designed to support moving dead flags into a
|
| 65 |
+
// 'graveyard' library. An example migration:
|
| 66 |
+
//
|
| 67 |
+
// 0: Remove references to this FLAGS_flagname in the C++ codebase.
|
| 68 |
+
// 1: Register as 'retired' in old_lib.
|
| 69 |
+
// 2: Make old_lib depend on graveyard.
|
| 70 |
+
// 3: Add a redundant 'retired' registration to graveyard.
|
| 71 |
+
// 4: Remove the old_lib 'retired' registration.
|
| 72 |
+
// 5: Eventually delete the graveyard registration entirely.
|
| 73 |
+
//
|
| 74 |
+
|
| 75 |
+
// Retire flag with name "name" and type indicated by ops.
|
| 76 |
+
void Retire(const char* name, FlagFastTypeId type_id, char* buf);
|
| 77 |
+
|
| 78 |
+
constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*);
|
| 79 |
+
constexpr size_t kRetiredFlagObjAlignment = alignof(void*);
|
| 80 |
+
|
| 81 |
+
// Registered a retired flag with name 'flag_name' and type 'T'.
|
| 82 |
+
template <typename T>
|
| 83 |
+
class RetiredFlag {
|
| 84 |
+
public:
|
| 85 |
+
void Retire(const char* flag_name) {
|
| 86 |
+
flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
private:
|
| 90 |
+
alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize];
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
} // namespace flags_internal
|
| 94 |
+
ABSL_NAMESPACE_END
|
| 95 |
+
} // namespace absl
|
| 96 |
+
|
| 97 |
+
#endif // ABSL_FLAGS_INTERNAL_REGISTRY_H_
|
weight/_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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2020 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_SEQUENCE_LOCK_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_SEQUENCE_LOCK_H_
|
| 18 |
+
|
| 19 |
+
#include <stddef.h>
|
| 20 |
+
#include <stdint.h>
|
| 21 |
+
|
| 22 |
+
#include <atomic>
|
| 23 |
+
#include <cassert>
|
| 24 |
+
#include <cstring>
|
| 25 |
+
|
| 26 |
+
#include "absl/base/optimization.h"
|
| 27 |
+
|
| 28 |
+
namespace absl {
|
| 29 |
+
ABSL_NAMESPACE_BEGIN
|
| 30 |
+
namespace flags_internal {
|
| 31 |
+
|
| 32 |
+
// Align 'x' up to the nearest 'align' bytes.
|
| 33 |
+
inline constexpr size_t AlignUp(size_t x, size_t align) {
|
| 34 |
+
return align * ((x + align - 1) / align);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// A SequenceLock implements lock-free reads. A sequence counter is incremented
|
| 38 |
+
// before and after each write, and readers access the counter before and after
|
| 39 |
+
// accessing the protected data. If the counter is verified to not change during
|
| 40 |
+
// the access, and the sequence counter value was even, then the reader knows
|
| 41 |
+
// that the read was race-free and valid. Otherwise, the reader must fall back
|
| 42 |
+
// to a Mutex-based code path.
|
| 43 |
+
//
|
| 44 |
+
// This particular SequenceLock starts in an "uninitialized" state in which
|
| 45 |
+
// TryRead() returns false. It must be enabled by calling MarkInitialized().
|
| 46 |
+
// This serves as a marker that the associated flag value has not yet been
|
| 47 |
+
// initialized and a slow path needs to be taken.
|
| 48 |
+
//
|
| 49 |
+
// The memory reads and writes protected by this lock must use the provided
|
| 50 |
+
// `TryRead()` and `Write()` functions. These functions behave similarly to
|
| 51 |
+
// `memcpy()`, with one oddity: the protected data must be an array of
|
| 52 |
+
// `std::atomic<uint64>`. This is to comply with the C++ standard, which
|
| 53 |
+
// considers data races on non-atomic objects to be undefined behavior. See "Can
|
| 54 |
+
// Seqlocks Get Along With Programming Language Memory Models?"[1] by Hans J.
|
| 55 |
+
// Boehm for more details.
|
| 56 |
+
//
|
| 57 |
+
// [1] https://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf
|
| 58 |
+
class SequenceLock {
|
| 59 |
+
public:
|
| 60 |
+
constexpr SequenceLock() : lock_(kUninitialized) {}
|
| 61 |
+
|
| 62 |
+
// Mark that this lock is ready for use.
|
| 63 |
+
void MarkInitialized() {
|
| 64 |
+
assert(lock_.load(std::memory_order_relaxed) == kUninitialized);
|
| 65 |
+
lock_.store(0, std::memory_order_release);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
// Copy "size" bytes of data from "src" to "dst", protected as a read-side
|
| 69 |
+
// critical section of the sequence lock.
|
| 70 |
+
//
|
| 71 |
+
// Unlike traditional sequence lock implementations which loop until getting a
|
| 72 |
+
// clean read, this implementation returns false in the case of concurrent
|
| 73 |
+
// calls to `Write`. In such a case, the caller should fall back to a
|
| 74 |
+
// locking-based slow path.
|
| 75 |
+
//
|
| 76 |
+
// Returns false if the sequence lock was not yet marked as initialized.
|
| 77 |
+
//
|
| 78 |
+
// NOTE: If this returns false, "dst" may be overwritten with undefined
|
| 79 |
+
// (potentially uninitialized) data.
|
| 80 |
+
bool TryRead(void* dst, const std::atomic<uint64_t>* src, size_t size) const {
|
| 81 |
+
// Acquire barrier ensures that no loads done by f() are reordered
|
| 82 |
+
// above the first load of the sequence counter.
|
| 83 |
+
int64_t seq_before = lock_.load(std::memory_order_acquire);
|
| 84 |
+
if (ABSL_PREDICT_FALSE(seq_before & 1) == 1) return false;
|
| 85 |
+
RelaxedCopyFromAtomic(dst, src, size);
|
| 86 |
+
// Another acquire fence ensures that the load of 'lock_' below is
|
| 87 |
+
// strictly ordered after the RelaxedCopyToAtomic call above.
|
| 88 |
+
std::atomic_thread_fence(std::memory_order_acquire);
|
| 89 |
+
int64_t seq_after = lock_.load(std::memory_order_relaxed);
|
| 90 |
+
return ABSL_PREDICT_TRUE(seq_before == seq_after);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// Copy "size" bytes from "src" to "dst" as a write-side critical section
|
| 94 |
+
// of the sequence lock. Any concurrent readers will be forced to retry
|
| 95 |
+
// until they get a read that does not conflict with this write.
|
| 96 |
+
//
|
| 97 |
+
// This call must be externally synchronized against other calls to Write,
|
| 98 |
+
// but may proceed concurrently with reads.
|
| 99 |
+
void Write(std::atomic<uint64_t>* dst, const void* src, size_t size) {
|
| 100 |
+
// We can use relaxed instructions to increment the counter since we
|
| 101 |
+
// are extenally synchronized. The std::atomic_thread_fence below
|
| 102 |
+
// ensures that the counter updates don't get interleaved with the
|
| 103 |
+
// copy to the data.
|
| 104 |
+
int64_t orig_seq = lock_.load(std::memory_order_relaxed);
|
| 105 |
+
assert((orig_seq & 1) == 0); // Must be initially unlocked.
|
| 106 |
+
lock_.store(orig_seq + 1, std::memory_order_relaxed);
|
| 107 |
+
|
| 108 |
+
// We put a release fence between update to lock_ and writes to shared data.
|
| 109 |
+
// Thus all stores to shared data are effectively release operations and
|
| 110 |
+
// update to lock_ above cannot be re-ordered past any of them. Note that
|
| 111 |
+
// this barrier is not for the fetch_add above. A release barrier for the
|
| 112 |
+
// fetch_add would be before it, not after.
|
| 113 |
+
std::atomic_thread_fence(std::memory_order_release);
|
| 114 |
+
RelaxedCopyToAtomic(dst, src, size);
|
| 115 |
+
// "Release" semantics ensure that none of the writes done by
|
| 116 |
+
// RelaxedCopyToAtomic() can be reordered after the following modification.
|
| 117 |
+
lock_.store(orig_seq + 2, std::memory_order_release);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// Return the number of times that Write() has been called.
|
| 121 |
+
//
|
| 122 |
+
// REQUIRES: This must be externally synchronized against concurrent calls to
|
| 123 |
+
// `Write()` or `IncrementModificationCount()`.
|
| 124 |
+
// REQUIRES: `MarkInitialized()` must have been previously called.
|
| 125 |
+
int64_t ModificationCount() const {
|
| 126 |
+
int64_t val = lock_.load(std::memory_order_relaxed);
|
| 127 |
+
assert(val != kUninitialized && (val & 1) == 0);
|
| 128 |
+
return val / 2;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// REQUIRES: This must be externally synchronized against concurrent calls to
|
| 132 |
+
// `Write()` or `ModificationCount()`.
|
| 133 |
+
// REQUIRES: `MarkInitialized()` must have been previously called.
|
| 134 |
+
void IncrementModificationCount() {
|
| 135 |
+
int64_t val = lock_.load(std::memory_order_relaxed);
|
| 136 |
+
assert(val != kUninitialized);
|
| 137 |
+
lock_.store(val + 2, std::memory_order_relaxed);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
private:
|
| 141 |
+
// Perform the equivalent of "memcpy(dst, src, size)", but using relaxed
|
| 142 |
+
// atomics.
|
| 143 |
+
static void RelaxedCopyFromAtomic(void* dst, const std::atomic<uint64_t>* src,
|
| 144 |
+
size_t size) {
|
| 145 |
+
char* dst_byte = static_cast<char*>(dst);
|
| 146 |
+
while (size >= sizeof(uint64_t)) {
|
| 147 |
+
uint64_t word = src->load(std::memory_order_relaxed);
|
| 148 |
+
std::memcpy(dst_byte, &word, sizeof(word));
|
| 149 |
+
dst_byte += sizeof(word);
|
| 150 |
+
src++;
|
| 151 |
+
size -= sizeof(word);
|
| 152 |
+
}
|
| 153 |
+
if (size > 0) {
|
| 154 |
+
uint64_t word = src->load(std::memory_order_relaxed);
|
| 155 |
+
std::memcpy(dst_byte, &word, size);
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// Perform the equivalent of "memcpy(dst, src, size)", but using relaxed
|
| 160 |
+
// atomics.
|
| 161 |
+
static void RelaxedCopyToAtomic(std::atomic<uint64_t>* dst, const void* src,
|
| 162 |
+
size_t size) {
|
| 163 |
+
const char* src_byte = static_cast<const char*>(src);
|
| 164 |
+
while (size >= sizeof(uint64_t)) {
|
| 165 |
+
uint64_t word;
|
| 166 |
+
std::memcpy(&word, src_byte, sizeof(word));
|
| 167 |
+
dst->store(word, std::memory_order_relaxed);
|
| 168 |
+
src_byte += sizeof(word);
|
| 169 |
+
dst++;
|
| 170 |
+
size -= sizeof(word);
|
| 171 |
+
}
|
| 172 |
+
if (size > 0) {
|
| 173 |
+
uint64_t word = 0;
|
| 174 |
+
std::memcpy(&word, src_byte, size);
|
| 175 |
+
dst->store(word, std::memory_order_relaxed);
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
static constexpr int64_t kUninitialized = -1;
|
| 180 |
+
std::atomic<int64_t> lock_;
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
} // namespace flags_internal
|
| 184 |
+
ABSL_NAMESPACE_END
|
| 185 |
+
} // namespace absl
|
| 186 |
+
|
| 187 |
+
#endif // ABSL_FLAGS_INTERNAL_SEQUENCE_LOCK_H_
|
weight/_dep/abseil-cpp/absl/flags/internal/sequence_lock_test.cc
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
#include "absl/flags/internal/sequence_lock.h"
|
| 15 |
+
|
| 16 |
+
#include <algorithm>
|
| 17 |
+
#include <atomic>
|
| 18 |
+
#include <thread> // NOLINT(build/c++11)
|
| 19 |
+
#include <tuple>
|
| 20 |
+
#include <vector>
|
| 21 |
+
|
| 22 |
+
#include "gtest/gtest.h"
|
| 23 |
+
#include "absl/base/internal/sysinfo.h"
|
| 24 |
+
#include "absl/container/fixed_array.h"
|
| 25 |
+
#include "absl/time/clock.h"
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
|
| 29 |
+
namespace flags = absl::flags_internal;
|
| 30 |
+
|
| 31 |
+
class ConcurrentSequenceLockTest
|
| 32 |
+
: public testing::TestWithParam<std::tuple<int, int>> {
|
| 33 |
+
public:
|
| 34 |
+
ConcurrentSequenceLockTest()
|
| 35 |
+
: buf_bytes_(std::get<0>(GetParam())),
|
| 36 |
+
num_threads_(std::get<1>(GetParam())) {}
|
| 37 |
+
|
| 38 |
+
protected:
|
| 39 |
+
const int buf_bytes_;
|
| 40 |
+
const int num_threads_;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
TEST_P(ConcurrentSequenceLockTest, ReadAndWrite) {
|
| 44 |
+
const int buf_words =
|
| 45 |
+
flags::AlignUp(buf_bytes_, sizeof(uint64_t)) / sizeof(uint64_t);
|
| 46 |
+
|
| 47 |
+
// The buffer that will be protected by the SequenceLock.
|
| 48 |
+
absl::FixedArray<std::atomic<uint64_t>> protected_buf(buf_words);
|
| 49 |
+
for (auto& v : protected_buf) v = -1;
|
| 50 |
+
|
| 51 |
+
flags::SequenceLock seq_lock;
|
| 52 |
+
std::atomic<bool> stop{false};
|
| 53 |
+
std::atomic<int64_t> bad_reads{0};
|
| 54 |
+
std::atomic<int64_t> good_reads{0};
|
| 55 |
+
std::atomic<int64_t> unsuccessful_reads{0};
|
| 56 |
+
|
| 57 |
+
// Start a bunch of threads which read 'protected_buf' under the sequence
|
| 58 |
+
// lock. The main thread will concurrently update 'protected_buf'. The updates
|
| 59 |
+
// always consist of an array of identical integers. The reader ensures that
|
| 60 |
+
// any data it reads matches that pattern (i.e. the reads are not "torn").
|
| 61 |
+
std::vector<std::thread> threads;
|
| 62 |
+
for (int i = 0; i < num_threads_; i++) {
|
| 63 |
+
threads.emplace_back([&]() {
|
| 64 |
+
absl::FixedArray<char> local_buf(buf_bytes_);
|
| 65 |
+
while (!stop.load(std::memory_order_relaxed)) {
|
| 66 |
+
if (seq_lock.TryRead(local_buf.data(), protected_buf.data(),
|
| 67 |
+
buf_bytes_)) {
|
| 68 |
+
bool good = true;
|
| 69 |
+
for (const auto& v : local_buf) {
|
| 70 |
+
if (v != local_buf[0]) good = false;
|
| 71 |
+
}
|
| 72 |
+
if (good) {
|
| 73 |
+
good_reads.fetch_add(1, std::memory_order_relaxed);
|
| 74 |
+
} else {
|
| 75 |
+
bad_reads.fetch_add(1, std::memory_order_relaxed);
|
| 76 |
+
}
|
| 77 |
+
} else {
|
| 78 |
+
unsuccessful_reads.fetch_add(1, std::memory_order_relaxed);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
while (unsuccessful_reads.load(std::memory_order_relaxed) < num_threads_) {
|
| 84 |
+
absl::SleepFor(absl::Milliseconds(1));
|
| 85 |
+
}
|
| 86 |
+
seq_lock.MarkInitialized();
|
| 87 |
+
|
| 88 |
+
// Run a maximum of 5 seconds. On Windows, the scheduler behavior seems
|
| 89 |
+
// somewhat unfair and without an explicit timeout for this loop, the tests
|
| 90 |
+
// can run a long time.
|
| 91 |
+
absl::Time deadline = absl::Now() + absl::Seconds(5);
|
| 92 |
+
for (int i = 0; i < 100 && absl::Now() < deadline; i++) {
|
| 93 |
+
absl::FixedArray<char> writer_buf(buf_bytes_);
|
| 94 |
+
for (auto& v : writer_buf) v = i;
|
| 95 |
+
seq_lock.Write(protected_buf.data(), writer_buf.data(), buf_bytes_);
|
| 96 |
+
absl::SleepFor(absl::Microseconds(10));
|
| 97 |
+
}
|
| 98 |
+
stop.store(true, std::memory_order_relaxed);
|
| 99 |
+
for (auto& t : threads) t.join();
|
| 100 |
+
ASSERT_GE(good_reads, 0);
|
| 101 |
+
ASSERT_EQ(bad_reads, 0);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// Simple helper for generating a range of thread counts.
|
| 105 |
+
// Generates [low, low*scale, low*scale^2, ...high)
|
| 106 |
+
// (even if high is between low*scale^k and low*scale^(k+1)).
|
| 107 |
+
std::vector<int> MultiplicativeRange(int low, int high, int scale) {
|
| 108 |
+
std::vector<int> result;
|
| 109 |
+
for (int current = low; current < high; current *= scale) {
|
| 110 |
+
result.push_back(current);
|
| 111 |
+
}
|
| 112 |
+
result.push_back(high);
|
| 113 |
+
return result;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
#ifndef ABSL_HAVE_THREAD_SANITIZER
|
| 117 |
+
const int kMaxThreads = absl::base_internal::NumCPUs();
|
| 118 |
+
#else
|
| 119 |
+
// With TSAN, a lot of threads contending for atomic access on the sequence
|
| 120 |
+
// lock make this test run too slowly.
|
| 121 |
+
const int kMaxThreads = std::min(absl::base_internal::NumCPUs(), 4);
|
| 122 |
+
#endif
|
| 123 |
+
|
| 124 |
+
// Return all of the interesting buffer sizes worth testing:
|
| 125 |
+
// powers of two and adjacent values.
|
| 126 |
+
std::vector<int> InterestingBufferSizes() {
|
| 127 |
+
std::vector<int> ret;
|
| 128 |
+
for (int v : MultiplicativeRange(1, 128, 2)) {
|
| 129 |
+
ret.push_back(v);
|
| 130 |
+
if (v > 1) {
|
| 131 |
+
ret.push_back(v - 1);
|
| 132 |
+
}
|
| 133 |
+
ret.push_back(v + 1);
|
| 134 |
+
}
|
| 135 |
+
return ret;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
INSTANTIATE_TEST_SUITE_P(
|
| 139 |
+
TestManyByteSizes, ConcurrentSequenceLockTest,
|
| 140 |
+
testing::Combine(
|
| 141 |
+
// Buffer size (bytes).
|
| 142 |
+
testing::ValuesIn(InterestingBufferSizes()),
|
| 143 |
+
// Number of reader threads.
|
| 144 |
+
testing::ValuesIn(MultiplicativeRange(1, kMaxThreads, 2))));
|
| 145 |
+
|
| 146 |
+
// Simple single-threaded test, parameterized by the size of the buffer to be
|
| 147 |
+
// protected.
|
| 148 |
+
class SequenceLockTest : public testing::TestWithParam<int> {};
|
| 149 |
+
|
| 150 |
+
TEST_P(SequenceLockTest, SingleThreaded) {
|
| 151 |
+
const int size = GetParam();
|
| 152 |
+
absl::FixedArray<std::atomic<uint64_t>> protected_buf(
|
| 153 |
+
flags::AlignUp(size, sizeof(uint64_t)) / sizeof(uint64_t));
|
| 154 |
+
|
| 155 |
+
flags::SequenceLock seq_lock;
|
| 156 |
+
seq_lock.MarkInitialized();
|
| 157 |
+
|
| 158 |
+
std::vector<char> src_buf(size, 'x');
|
| 159 |
+
seq_lock.Write(protected_buf.data(), src_buf.data(), size);
|
| 160 |
+
|
| 161 |
+
std::vector<char> dst_buf(size, '0');
|
| 162 |
+
ASSERT_TRUE(seq_lock.TryRead(dst_buf.data(), protected_buf.data(), size));
|
| 163 |
+
ASSERT_EQ(src_buf, dst_buf);
|
| 164 |
+
}
|
| 165 |
+
INSTANTIATE_TEST_SUITE_P(TestManyByteSizes, SequenceLockTest,
|
| 166 |
+
// Buffer size (bytes).
|
| 167 |
+
testing::Range(1, 128));
|
| 168 |
+
|
| 169 |
+
} // namespace
|
weight/_dep/abseil-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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/usage.h"
|
| 17 |
+
|
| 18 |
+
#include <stdint.h>
|
| 19 |
+
|
| 20 |
+
#include <algorithm>
|
| 21 |
+
#include <cstdlib>
|
| 22 |
+
#include <functional>
|
| 23 |
+
#include <iterator>
|
| 24 |
+
#include <map>
|
| 25 |
+
#include <ostream>
|
| 26 |
+
#include <string>
|
| 27 |
+
#include <utility>
|
| 28 |
+
#include <vector>
|
| 29 |
+
|
| 30 |
+
#include "absl/base/attributes.h"
|
| 31 |
+
#include "absl/base/config.h"
|
| 32 |
+
#include "absl/base/const_init.h"
|
| 33 |
+
#include "absl/base/thread_annotations.h"
|
| 34 |
+
#include "absl/flags/commandlineflag.h"
|
| 35 |
+
#include "absl/flags/flag.h"
|
| 36 |
+
#include "absl/flags/internal/flag.h"
|
| 37 |
+
#include "absl/flags/internal/path_util.h"
|
| 38 |
+
#include "absl/flags/internal/private_handle_accessor.h"
|
| 39 |
+
#include "absl/flags/internal/program_name.h"
|
| 40 |
+
#include "absl/flags/internal/registry.h"
|
| 41 |
+
#include "absl/flags/usage_config.h"
|
| 42 |
+
#include "absl/strings/match.h"
|
| 43 |
+
#include "absl/strings/str_cat.h"
|
| 44 |
+
#include "absl/strings/str_split.h"
|
| 45 |
+
#include "absl/strings/string_view.h"
|
| 46 |
+
#include "absl/strings/strip.h"
|
| 47 |
+
#include "absl/synchronization/mutex.h"
|
| 48 |
+
|
| 49 |
+
// Dummy global variables to prevent anyone else defining these.
|
| 50 |
+
bool FLAGS_help = false;
|
| 51 |
+
bool FLAGS_helpfull = false;
|
| 52 |
+
bool FLAGS_helpshort = false;
|
| 53 |
+
bool FLAGS_helppackage = false;
|
| 54 |
+
bool FLAGS_version = false;
|
| 55 |
+
bool FLAGS_only_check_args = false;
|
| 56 |
+
bool FLAGS_helpon = false;
|
| 57 |
+
bool FLAGS_helpmatch = false;
|
| 58 |
+
|
| 59 |
+
namespace absl {
|
| 60 |
+
ABSL_NAMESPACE_BEGIN
|
| 61 |
+
namespace flags_internal {
|
| 62 |
+
namespace {
|
| 63 |
+
|
| 64 |
+
using PerFlagFilter = std::function<bool(const absl::CommandLineFlag&)>;
|
| 65 |
+
|
| 66 |
+
// Maximum length size in a human readable format.
|
| 67 |
+
constexpr size_t kHrfMaxLineLength = 80;
|
| 68 |
+
|
| 69 |
+
// This class is used to emit an XML element with `tag` and `text`.
|
| 70 |
+
// It adds opening and closing tags and escapes special characters in the text.
|
| 71 |
+
// For example:
|
| 72 |
+
// std::cout << XMLElement("title", "Milk & Cookies");
|
| 73 |
+
// prints "<title>Milk & Cookies</title>"
|
| 74 |
+
class XMLElement {
|
| 75 |
+
public:
|
| 76 |
+
XMLElement(absl::string_view tag, absl::string_view txt)
|
| 77 |
+
: tag_(tag), txt_(txt) {}
|
| 78 |
+
|
| 79 |
+
friend std::ostream& operator<<(std::ostream& out,
|
| 80 |
+
const XMLElement& xml_elem) {
|
| 81 |
+
out << "<" << xml_elem.tag_ << ">";
|
| 82 |
+
|
| 83 |
+
for (auto c : xml_elem.txt_) {
|
| 84 |
+
switch (c) {
|
| 85 |
+
case '"':
|
| 86 |
+
out << """;
|
| 87 |
+
break;
|
| 88 |
+
case '\'':
|
| 89 |
+
out << "'";
|
| 90 |
+
break;
|
| 91 |
+
case '&':
|
| 92 |
+
out << "&";
|
| 93 |
+
break;
|
| 94 |
+
case '<':
|
| 95 |
+
out << "<";
|
| 96 |
+
break;
|
| 97 |
+
case '>':
|
| 98 |
+
out << ">";
|
| 99 |
+
break;
|
| 100 |
+
case '\n':
|
| 101 |
+
case '\v':
|
| 102 |
+
case '\f':
|
| 103 |
+
case '\t':
|
| 104 |
+
out << " ";
|
| 105 |
+
break;
|
| 106 |
+
default:
|
| 107 |
+
if (IsValidXmlCharacter(static_cast<unsigned char>(c))) {
|
| 108 |
+
out << c;
|
| 109 |
+
}
|
| 110 |
+
break;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
return out << "</" << xml_elem.tag_ << ">";
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
private:
|
| 118 |
+
static bool IsValidXmlCharacter(unsigned char c) { return c >= 0x20; }
|
| 119 |
+
absl::string_view tag_;
|
| 120 |
+
absl::string_view txt_;
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
// --------------------------------------------------------------------
|
| 124 |
+
// Helper class to pretty-print info about a flag.
|
| 125 |
+
|
| 126 |
+
class FlagHelpPrettyPrinter {
|
| 127 |
+
public:
|
| 128 |
+
// Pretty printer holds on to the std::ostream& reference to direct an output
|
| 129 |
+
// to that stream.
|
| 130 |
+
FlagHelpPrettyPrinter(size_t max_line_len, size_t min_line_len,
|
| 131 |
+
size_t wrapped_line_indent, std::ostream& out)
|
| 132 |
+
: out_(out),
|
| 133 |
+
max_line_len_(max_line_len),
|
| 134 |
+
min_line_len_(min_line_len),
|
| 135 |
+
wrapped_line_indent_(wrapped_line_indent),
|
| 136 |
+
line_len_(0),
|
| 137 |
+
first_line_(true) {}
|
| 138 |
+
|
| 139 |
+
void Write(absl::string_view str, bool wrap_line = false) {
|
| 140 |
+
// Empty string - do nothing.
|
| 141 |
+
if (str.empty()) return;
|
| 142 |
+
|
| 143 |
+
std::vector<absl::string_view> tokens;
|
| 144 |
+
if (wrap_line) {
|
| 145 |
+
for (auto line : absl::StrSplit(str, absl::ByAnyChar("\n\r"))) {
|
| 146 |
+
if (!tokens.empty()) {
|
| 147 |
+
// Keep line separators in the input string.
|
| 148 |
+
tokens.emplace_back("\n");
|
| 149 |
+
}
|
| 150 |
+
for (auto token :
|
| 151 |
+
absl::StrSplit(line, absl::ByAnyChar(" \t"), absl::SkipEmpty())) {
|
| 152 |
+
tokens.push_back(token);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
} else {
|
| 156 |
+
tokens.push_back(str);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
for (auto token : tokens) {
|
| 160 |
+
bool new_line = (line_len_ == 0);
|
| 161 |
+
|
| 162 |
+
// Respect line separators in the input string.
|
| 163 |
+
if (token == "\n") {
|
| 164 |
+
EndLine();
|
| 165 |
+
continue;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
// Write the token, ending the string first if necessary/possible.
|
| 169 |
+
if (!new_line && (line_len_ + token.size() >= max_line_len_)) {
|
| 170 |
+
EndLine();
|
| 171 |
+
new_line = true;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if (new_line) {
|
| 175 |
+
StartLine();
|
| 176 |
+
} else {
|
| 177 |
+
out_ << ' ';
|
| 178 |
+
++line_len_;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
out_ << token;
|
| 182 |
+
line_len_ += token.size();
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
void StartLine() {
|
| 187 |
+
if (first_line_) {
|
| 188 |
+
line_len_ = min_line_len_;
|
| 189 |
+
first_line_ = false;
|
| 190 |
+
} else {
|
| 191 |
+
line_len_ = min_line_len_ + wrapped_line_indent_;
|
| 192 |
+
}
|
| 193 |
+
out_ << std::string(line_len_, ' ');
|
| 194 |
+
}
|
| 195 |
+
void EndLine() {
|
| 196 |
+
out_ << '\n';
|
| 197 |
+
line_len_ = 0;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
private:
|
| 201 |
+
std::ostream& out_;
|
| 202 |
+
const size_t max_line_len_;
|
| 203 |
+
const size_t min_line_len_;
|
| 204 |
+
const size_t wrapped_line_indent_;
|
| 205 |
+
size_t line_len_;
|
| 206 |
+
bool first_line_;
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
void FlagHelpHumanReadable(const CommandLineFlag& flag, std::ostream& out) {
|
| 210 |
+
FlagHelpPrettyPrinter printer(kHrfMaxLineLength, 4, 2, out);
|
| 211 |
+
|
| 212 |
+
// Flag name.
|
| 213 |
+
printer.Write(absl::StrCat("--", flag.Name()));
|
| 214 |
+
|
| 215 |
+
// Flag help.
|
| 216 |
+
printer.Write(absl::StrCat("(", flag.Help(), ");"), /*wrap_line=*/true);
|
| 217 |
+
|
| 218 |
+
// The listed default value will be the actual default from the flag
|
| 219 |
+
// definition in the originating source file, unless the value has
|
| 220 |
+
// subsequently been modified using SetCommandLineOption() with mode
|
| 221 |
+
// SET_FLAGS_DEFAULT.
|
| 222 |
+
std::string dflt_val = flag.DefaultValue();
|
| 223 |
+
std::string curr_val = flag.CurrentValue();
|
| 224 |
+
bool is_modified = curr_val != dflt_val;
|
| 225 |
+
|
| 226 |
+
if (flag.IsOfType<std::string>()) {
|
| 227 |
+
dflt_val = absl::StrCat("\"", dflt_val, "\"");
|
| 228 |
+
}
|
| 229 |
+
printer.Write(absl::StrCat("default: ", dflt_val, ";"));
|
| 230 |
+
|
| 231 |
+
if (is_modified) {
|
| 232 |
+
if (flag.IsOfType<std::string>()) {
|
| 233 |
+
curr_val = absl::StrCat("\"", curr_val, "\"");
|
| 234 |
+
}
|
| 235 |
+
printer.Write(absl::StrCat("currently: ", curr_val, ";"));
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
printer.EndLine();
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// Shows help for every filename which matches any of the filters
|
| 242 |
+
// If filters are empty, shows help for every file.
|
| 243 |
+
// If a flag's help message has been stripped (e.g. by adding '#define
|
| 244 |
+
// STRIP_FLAG_HELP 1' then this flag will not be displayed by '--help'
|
| 245 |
+
// and its variants.
|
| 246 |
+
void FlagsHelpImpl(std::ostream& out, PerFlagFilter filter_cb,
|
| 247 |
+
HelpFormat format, absl::string_view program_usage_message) {
|
| 248 |
+
if (format == HelpFormat::kHumanReadable) {
|
| 249 |
+
out << flags_internal::ShortProgramInvocationName() << ": "
|
| 250 |
+
<< program_usage_message << "\n\n";
|
| 251 |
+
} else {
|
| 252 |
+
// XML schema is not a part of our public API for now.
|
| 253 |
+
out << "<?xml version=\"1.0\"?>\n"
|
| 254 |
+
<< "<!-- This output should be used with care. We do not report type "
|
| 255 |
+
"names for flags with user defined types -->\n"
|
| 256 |
+
<< "<!-- Prefer flag only_check_args for validating flag inputs -->\n"
|
| 257 |
+
// The document.
|
| 258 |
+
<< "<AllFlags>\n"
|
| 259 |
+
// The program name and usage.
|
| 260 |
+
<< XMLElement("program", flags_internal::ShortProgramInvocationName())
|
| 261 |
+
<< '\n'
|
| 262 |
+
<< XMLElement("usage", program_usage_message) << '\n';
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
// Ordered map of package name to
|
| 266 |
+
// map of file name to
|
| 267 |
+
// vector of flags in the file.
|
| 268 |
+
// This map is used to output matching flags grouped by package and file
|
| 269 |
+
// name.
|
| 270 |
+
std::map<std::string,
|
| 271 |
+
std::map<std::string, std::vector<const absl::CommandLineFlag*>>>
|
| 272 |
+
matching_flags;
|
| 273 |
+
|
| 274 |
+
flags_internal::ForEachFlag([&](absl::CommandLineFlag& flag) {
|
| 275 |
+
// Ignore retired flags.
|
| 276 |
+
if (flag.IsRetired()) return;
|
| 277 |
+
|
| 278 |
+
// If the flag has been stripped, pretend that it doesn't exist.
|
| 279 |
+
if (flag.Help() == flags_internal::kStrippedFlagHelp) return;
|
| 280 |
+
|
| 281 |
+
// Make sure flag satisfies the filter
|
| 282 |
+
if (!filter_cb(flag)) return;
|
| 283 |
+
|
| 284 |
+
std::string flag_filename = flag.Filename();
|
| 285 |
+
|
| 286 |
+
matching_flags[std::string(flags_internal::Package(flag_filename))]
|
| 287 |
+
[flag_filename]
|
| 288 |
+
.push_back(&flag);
|
| 289 |
+
});
|
| 290 |
+
|
| 291 |
+
absl::string_view package_separator; // controls blank lines between packages
|
| 292 |
+
absl::string_view file_separator; // controls blank lines between files
|
| 293 |
+
for (auto& package : matching_flags) {
|
| 294 |
+
if (format == HelpFormat::kHumanReadable) {
|
| 295 |
+
out << package_separator;
|
| 296 |
+
package_separator = "\n\n";
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
file_separator = "";
|
| 300 |
+
for (auto& flags_in_file : package.second) {
|
| 301 |
+
if (format == HelpFormat::kHumanReadable) {
|
| 302 |
+
out << file_separator << " Flags from " << flags_in_file.first
|
| 303 |
+
<< ":\n";
|
| 304 |
+
file_separator = "\n";
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
std::sort(std::begin(flags_in_file.second),
|
| 308 |
+
std::end(flags_in_file.second),
|
| 309 |
+
[](const CommandLineFlag* lhs, const CommandLineFlag* rhs) {
|
| 310 |
+
return lhs->Name() < rhs->Name();
|
| 311 |
+
});
|
| 312 |
+
|
| 313 |
+
for (const auto* flag : flags_in_file.second) {
|
| 314 |
+
flags_internal::FlagHelp(out, *flag, format);
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
if (format == HelpFormat::kHumanReadable) {
|
| 320 |
+
FlagHelpPrettyPrinter printer(kHrfMaxLineLength, 0, 0, out);
|
| 321 |
+
|
| 322 |
+
if (filter_cb && matching_flags.empty()) {
|
| 323 |
+
printer.Write("No flags matched.\n", true);
|
| 324 |
+
}
|
| 325 |
+
printer.EndLine();
|
| 326 |
+
printer.Write(
|
| 327 |
+
"Try --helpfull to get a list of all flags or --help=substring "
|
| 328 |
+
"shows help for flags which include specified substring in either "
|
| 329 |
+
"in the name, or description or path.\n",
|
| 330 |
+
true);
|
| 331 |
+
} else {
|
| 332 |
+
// The end of the document.
|
| 333 |
+
out << "</AllFlags>\n";
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
void FlagsHelpImpl(std::ostream& out,
|
| 338 |
+
flags_internal::FlagKindFilter filename_filter_cb,
|
| 339 |
+
HelpFormat format, absl::string_view program_usage_message) {
|
| 340 |
+
FlagsHelpImpl(
|
| 341 |
+
out,
|
| 342 |
+
[&](const absl::CommandLineFlag& flag) {
|
| 343 |
+
return filename_filter_cb && filename_filter_cb(flag.Filename());
|
| 344 |
+
},
|
| 345 |
+
format, program_usage_message);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
} // namespace
|
| 349 |
+
|
| 350 |
+
// --------------------------------------------------------------------
|
| 351 |
+
// Produces the help message describing specific flag.
|
| 352 |
+
void FlagHelp(std::ostream& out, const CommandLineFlag& flag,
|
| 353 |
+
HelpFormat format) {
|
| 354 |
+
if (format == HelpFormat::kHumanReadable)
|
| 355 |
+
flags_internal::FlagHelpHumanReadable(flag, out);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
// --------------------------------------------------------------------
|
| 359 |
+
// Produces the help messages for all flags matching the filename filter.
|
| 360 |
+
// If filter is empty produces help messages for all flags.
|
| 361 |
+
void FlagsHelp(std::ostream& out, absl::string_view filter, HelpFormat format,
|
| 362 |
+
absl::string_view program_usage_message) {
|
| 363 |
+
flags_internal::FlagKindFilter filter_cb = [&](absl::string_view filename) {
|
| 364 |
+
return filter.empty() || absl::StrContains(filename, filter);
|
| 365 |
+
};
|
| 366 |
+
flags_internal::FlagsHelpImpl(out, filter_cb, format, program_usage_message);
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
// --------------------------------------------------------------------
|
| 370 |
+
// Checks all the 'usage' command line flags to see if any have been set.
|
| 371 |
+
// If so, handles them appropriately.
|
| 372 |
+
HelpMode HandleUsageFlags(std::ostream& out,
|
| 373 |
+
absl::string_view program_usage_message) {
|
| 374 |
+
switch (GetFlagsHelpMode()) {
|
| 375 |
+
case HelpMode::kNone:
|
| 376 |
+
break;
|
| 377 |
+
case HelpMode::kImportant:
|
| 378 |
+
flags_internal::FlagsHelpImpl(
|
| 379 |
+
out, flags_internal::GetUsageConfig().contains_help_flags,
|
| 380 |
+
GetFlagsHelpFormat(), program_usage_message);
|
| 381 |
+
break;
|
| 382 |
+
|
| 383 |
+
case HelpMode::kShort:
|
| 384 |
+
flags_internal::FlagsHelpImpl(
|
| 385 |
+
out, flags_internal::GetUsageConfig().contains_helpshort_flags,
|
| 386 |
+
GetFlagsHelpFormat(), program_usage_message);
|
| 387 |
+
break;
|
| 388 |
+
|
| 389 |
+
case HelpMode::kFull:
|
| 390 |
+
flags_internal::FlagsHelp(out, "", GetFlagsHelpFormat(),
|
| 391 |
+
program_usage_message);
|
| 392 |
+
break;
|
| 393 |
+
|
| 394 |
+
case HelpMode::kPackage:
|
| 395 |
+
flags_internal::FlagsHelpImpl(
|
| 396 |
+
out, flags_internal::GetUsageConfig().contains_helppackage_flags,
|
| 397 |
+
GetFlagsHelpFormat(), program_usage_message);
|
| 398 |
+
break;
|
| 399 |
+
|
| 400 |
+
case HelpMode::kMatch: {
|
| 401 |
+
std::string substr = GetFlagsHelpMatchSubstr();
|
| 402 |
+
if (substr.empty()) {
|
| 403 |
+
// show all options
|
| 404 |
+
flags_internal::FlagsHelp(out, substr, GetFlagsHelpFormat(),
|
| 405 |
+
program_usage_message);
|
| 406 |
+
} else {
|
| 407 |
+
auto filter_cb = [&substr](const absl::CommandLineFlag& flag) {
|
| 408 |
+
if (absl::StrContains(flag.Name(), substr)) return true;
|
| 409 |
+
if (absl::StrContains(flag.Filename(), substr)) return true;
|
| 410 |
+
if (absl::StrContains(flag.Help(), substr)) return true;
|
| 411 |
+
|
| 412 |
+
return false;
|
| 413 |
+
};
|
| 414 |
+
flags_internal::FlagsHelpImpl(
|
| 415 |
+
out, filter_cb, HelpFormat::kHumanReadable, program_usage_message);
|
| 416 |
+
}
|
| 417 |
+
break;
|
| 418 |
+
}
|
| 419 |
+
case HelpMode::kVersion:
|
| 420 |
+
if (flags_internal::GetUsageConfig().version_string)
|
| 421 |
+
out << flags_internal::GetUsageConfig().version_string();
|
| 422 |
+
// Unlike help, we may be asking for version in a script, so return 0
|
| 423 |
+
break;
|
| 424 |
+
|
| 425 |
+
case HelpMode::kOnlyCheckArgs:
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
return GetFlagsHelpMode();
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
// --------------------------------------------------------------------
|
| 433 |
+
// Globals representing usage reporting flags
|
| 434 |
+
|
| 435 |
+
namespace {
|
| 436 |
+
|
| 437 |
+
ABSL_CONST_INIT absl::Mutex help_attributes_guard(absl::kConstInit);
|
| 438 |
+
ABSL_CONST_INIT std::string* match_substr
|
| 439 |
+
ABSL_GUARDED_BY(help_attributes_guard) = nullptr;
|
| 440 |
+
ABSL_CONST_INIT HelpMode help_mode ABSL_GUARDED_BY(help_attributes_guard) =
|
| 441 |
+
HelpMode::kNone;
|
| 442 |
+
ABSL_CONST_INIT HelpFormat help_format ABSL_GUARDED_BY(help_attributes_guard) =
|
| 443 |
+
HelpFormat::kHumanReadable;
|
| 444 |
+
|
| 445 |
+
} // namespace
|
| 446 |
+
|
| 447 |
+
std::string GetFlagsHelpMatchSubstr() {
|
| 448 |
+
absl::MutexLock l(&help_attributes_guard);
|
| 449 |
+
if (match_substr == nullptr) return "";
|
| 450 |
+
return *match_substr;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
void SetFlagsHelpMatchSubstr(absl::string_view substr) {
|
| 454 |
+
absl::MutexLock l(&help_attributes_guard);
|
| 455 |
+
if (match_substr == nullptr) match_substr = new std::string;
|
| 456 |
+
match_substr->assign(substr.data(), substr.size());
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
HelpMode GetFlagsHelpMode() {
|
| 460 |
+
absl::MutexLock l(&help_attributes_guard);
|
| 461 |
+
return help_mode;
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
void SetFlagsHelpMode(HelpMode mode) {
|
| 465 |
+
absl::MutexLock l(&help_attributes_guard);
|
| 466 |
+
help_mode = mode;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
HelpFormat GetFlagsHelpFormat() {
|
| 470 |
+
absl::MutexLock l(&help_attributes_guard);
|
| 471 |
+
return help_format;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
void SetFlagsHelpFormat(HelpFormat format) {
|
| 475 |
+
absl::MutexLock l(&help_attributes_guard);
|
| 476 |
+
help_format = format;
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
// Deduces usage flags from the input argument in a form --name=value or
|
| 480 |
+
// --name. argument is already split into name and value before we call this
|
| 481 |
+
// function.
|
| 482 |
+
bool DeduceUsageFlags(absl::string_view name, absl::string_view value) {
|
| 483 |
+
if (absl::ConsumePrefix(&name, "help")) {
|
| 484 |
+
if (name.empty()) {
|
| 485 |
+
if (value.empty()) {
|
| 486 |
+
SetFlagsHelpMode(HelpMode::kImportant);
|
| 487 |
+
} else {
|
| 488 |
+
SetFlagsHelpMode(HelpMode::kMatch);
|
| 489 |
+
SetFlagsHelpMatchSubstr(value);
|
| 490 |
+
}
|
| 491 |
+
return true;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
if (name == "match") {
|
| 495 |
+
SetFlagsHelpMode(HelpMode::kMatch);
|
| 496 |
+
SetFlagsHelpMatchSubstr(value);
|
| 497 |
+
return true;
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
if (name == "on") {
|
| 501 |
+
SetFlagsHelpMode(HelpMode::kMatch);
|
| 502 |
+
SetFlagsHelpMatchSubstr(absl::StrCat("/", value, "."));
|
| 503 |
+
return true;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
if (name == "full") {
|
| 507 |
+
SetFlagsHelpMode(HelpMode::kFull);
|
| 508 |
+
return true;
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
if (name == "short") {
|
| 512 |
+
SetFlagsHelpMode(HelpMode::kShort);
|
| 513 |
+
return true;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
if (name == "package") {
|
| 517 |
+
SetFlagsHelpMode(HelpMode::kPackage);
|
| 518 |
+
return true;
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
return false;
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
if (name == "version") {
|
| 525 |
+
SetFlagsHelpMode(HelpMode::kVersion);
|
| 526 |
+
return true;
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
if (name == "only_check_args") {
|
| 530 |
+
SetFlagsHelpMode(HelpMode::kOnlyCheckArgs);
|
| 531 |
+
return true;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
return false;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
// --------------------------------------------------------------------
|
| 538 |
+
|
| 539 |
+
void MaybeExit(HelpMode mode) {
|
| 540 |
+
switch (mode) {
|
| 541 |
+
case flags_internal::HelpMode::kNone:
|
| 542 |
+
return;
|
| 543 |
+
case flags_internal::HelpMode::kOnlyCheckArgs:
|
| 544 |
+
case flags_internal::HelpMode::kVersion:
|
| 545 |
+
std::exit(0);
|
| 546 |
+
default: // For all the other modes we exit with 1
|
| 547 |
+
std::exit(1);
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
// --------------------------------------------------------------------
|
| 552 |
+
|
| 553 |
+
} // namespace flags_internal
|
| 554 |
+
ABSL_NAMESPACE_END
|
| 555 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/flags/internal/usage.h
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#ifndef ABSL_FLAGS_INTERNAL_USAGE_H_
|
| 17 |
+
#define ABSL_FLAGS_INTERNAL_USAGE_H_
|
| 18 |
+
|
| 19 |
+
#include <iosfwd>
|
| 20 |
+
#include <ostream>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/config.h"
|
| 24 |
+
#include "absl/flags/commandlineflag.h"
|
| 25 |
+
#include "absl/strings/string_view.h"
|
| 26 |
+
|
| 27 |
+
// --------------------------------------------------------------------
|
| 28 |
+
// Usage reporting interfaces
|
| 29 |
+
|
| 30 |
+
namespace absl {
|
| 31 |
+
ABSL_NAMESPACE_BEGIN
|
| 32 |
+
namespace flags_internal {
|
| 33 |
+
|
| 34 |
+
// The format to report the help messages in.
|
| 35 |
+
enum class HelpFormat {
|
| 36 |
+
kHumanReadable,
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
// The kind of usage help requested.
|
| 40 |
+
enum class HelpMode {
|
| 41 |
+
kNone,
|
| 42 |
+
kImportant,
|
| 43 |
+
kShort,
|
| 44 |
+
kFull,
|
| 45 |
+
kPackage,
|
| 46 |
+
kMatch,
|
| 47 |
+
kVersion,
|
| 48 |
+
kOnlyCheckArgs
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
// Streams the help message describing `flag` to `out`.
|
| 52 |
+
// The default value for `flag` is included in the output.
|
| 53 |
+
void FlagHelp(std::ostream& out, const CommandLineFlag& flag,
|
| 54 |
+
HelpFormat format = HelpFormat::kHumanReadable);
|
| 55 |
+
|
| 56 |
+
// Produces the help messages for all flags matching the filter. A flag matches
|
| 57 |
+
// the filter if it is defined in a file with a filename which includes
|
| 58 |
+
// filter string as a substring. You can use '/' and '.' to restrict the
|
| 59 |
+
// matching to a specific file names. For example:
|
| 60 |
+
// FlagsHelp(out, "/path/to/file.");
|
| 61 |
+
// restricts help to only flags which resides in files named like:
|
| 62 |
+
// .../path/to/file.<ext>
|
| 63 |
+
// for any extension 'ext'. If the filter is empty this function produces help
|
| 64 |
+
// messages for all flags.
|
| 65 |
+
void FlagsHelp(std::ostream& out, absl::string_view filter,
|
| 66 |
+
HelpFormat format, absl::string_view program_usage_message);
|
| 67 |
+
|
| 68 |
+
// --------------------------------------------------------------------
|
| 69 |
+
|
| 70 |
+
// If any of the 'usage' related command line flags (listed on the bottom of
|
| 71 |
+
// this file) has been set this routine produces corresponding help message in
|
| 72 |
+
// the specified output stream and returns HelpMode that was handled. Otherwise
|
| 73 |
+
// it returns HelpMode::kNone.
|
| 74 |
+
HelpMode HandleUsageFlags(std::ostream& out,
|
| 75 |
+
absl::string_view program_usage_message);
|
| 76 |
+
|
| 77 |
+
// --------------------------------------------------------------------
|
| 78 |
+
// Encapsulates the logic of exiting the binary depending on handled help mode.
|
| 79 |
+
|
| 80 |
+
void MaybeExit(HelpMode mode);
|
| 81 |
+
|
| 82 |
+
// --------------------------------------------------------------------
|
| 83 |
+
// Globals representing usage reporting flags
|
| 84 |
+
|
| 85 |
+
// Returns substring to filter help output (--help=substr argument)
|
| 86 |
+
std::string GetFlagsHelpMatchSubstr();
|
| 87 |
+
// Returns the requested help mode.
|
| 88 |
+
HelpMode GetFlagsHelpMode();
|
| 89 |
+
// Returns the requested help format.
|
| 90 |
+
HelpFormat GetFlagsHelpFormat();
|
| 91 |
+
|
| 92 |
+
// These are corresponding setters to the attributes above.
|
| 93 |
+
void SetFlagsHelpMatchSubstr(absl::string_view);
|
| 94 |
+
void SetFlagsHelpMode(HelpMode);
|
| 95 |
+
void SetFlagsHelpFormat(HelpFormat);
|
| 96 |
+
|
| 97 |
+
// Deduces usage flags from the input argument in a form --name=value or
|
| 98 |
+
// --name. argument is already split into name and value before we call this
|
| 99 |
+
// function.
|
| 100 |
+
bool DeduceUsageFlags(absl::string_view name, absl::string_view value);
|
| 101 |
+
|
| 102 |
+
} // namespace flags_internal
|
| 103 |
+
ABSL_NAMESPACE_END
|
| 104 |
+
} // namespace absl
|
| 105 |
+
|
| 106 |
+
#endif // ABSL_FLAGS_INTERNAL_USAGE_H_
|
weight/_dep/abseil-cpp/absl/flags/internal/usage_test.cc
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/usage.h"
|
| 17 |
+
|
| 18 |
+
#include <stdint.h>
|
| 19 |
+
|
| 20 |
+
#include <sstream>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
#include "gmock/gmock.h"
|
| 24 |
+
#include "gtest/gtest.h"
|
| 25 |
+
#include "absl/flags/flag.h"
|
| 26 |
+
#include "absl/flags/internal/parse.h"
|
| 27 |
+
#include "absl/flags/internal/program_name.h"
|
| 28 |
+
#include "absl/flags/reflection.h"
|
| 29 |
+
#include "absl/flags/usage.h"
|
| 30 |
+
#include "absl/flags/usage_config.h"
|
| 31 |
+
#include "absl/strings/match.h"
|
| 32 |
+
#include "absl/strings/string_view.h"
|
| 33 |
+
|
| 34 |
+
ABSL_FLAG(int, usage_reporting_test_flag_01, 101,
|
| 35 |
+
"usage_reporting_test_flag_01 help message");
|
| 36 |
+
ABSL_FLAG(bool, usage_reporting_test_flag_02, false,
|
| 37 |
+
"usage_reporting_test_flag_02 help message");
|
| 38 |
+
ABSL_FLAG(double, usage_reporting_test_flag_03, 1.03,
|
| 39 |
+
"usage_reporting_test_flag_03 help message");
|
| 40 |
+
ABSL_FLAG(int64_t, usage_reporting_test_flag_04, 1000000000000004L,
|
| 41 |
+
"usage_reporting_test_flag_04 help message");
|
| 42 |
+
ABSL_FLAG(std::string, usage_reporting_test_flag_07, "\r\n\f\v\a\b\t ",
|
| 43 |
+
"usage_reporting_test_flag_07 help \r\n\f\v\a\b\t ");
|
| 44 |
+
|
| 45 |
+
static const char kTestUsageMessage[] = "Custom usage message";
|
| 46 |
+
|
| 47 |
+
struct UDT {
|
| 48 |
+
UDT() = default;
|
| 49 |
+
UDT(const UDT&) = default;
|
| 50 |
+
UDT& operator=(const UDT&) = default;
|
| 51 |
+
};
|
| 52 |
+
static bool AbslParseFlag(absl::string_view, UDT*, std::string*) {
|
| 53 |
+
return true;
|
| 54 |
+
}
|
| 55 |
+
static std::string AbslUnparseFlag(const UDT&) { return "UDT{}"; }
|
| 56 |
+
|
| 57 |
+
ABSL_FLAG(UDT, usage_reporting_test_flag_05, {},
|
| 58 |
+
"usage_reporting_test_flag_05 help message");
|
| 59 |
+
|
| 60 |
+
ABSL_FLAG(
|
| 61 |
+
std::string, usage_reporting_test_flag_06, {},
|
| 62 |
+
"usage_reporting_test_flag_06 help message.\n"
|
| 63 |
+
"\n"
|
| 64 |
+
"Some more help.\n"
|
| 65 |
+
"Even more long long long long long long long long long long long long "
|
| 66 |
+
"help message.");
|
| 67 |
+
|
| 68 |
+
namespace {
|
| 69 |
+
|
| 70 |
+
namespace flags = absl::flags_internal;
|
| 71 |
+
|
| 72 |
+
static std::string NormalizeFileName(absl::string_view fname) {
|
| 73 |
+
#ifdef _WIN32
|
| 74 |
+
std::string normalized(fname);
|
| 75 |
+
std::replace(normalized.begin(), normalized.end(), '\\', '/');
|
| 76 |
+
fname = normalized;
|
| 77 |
+
#endif
|
| 78 |
+
|
| 79 |
+
auto absl_pos = fname.rfind("absl/");
|
| 80 |
+
if (absl_pos != absl::string_view::npos) {
|
| 81 |
+
fname = fname.substr(absl_pos);
|
| 82 |
+
}
|
| 83 |
+
return std::string(fname);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
class UsageReportingTest : public testing::Test {
|
| 87 |
+
protected:
|
| 88 |
+
UsageReportingTest() {
|
| 89 |
+
// Install default config for the use on this unit test.
|
| 90 |
+
// Binary may install a custom config before tests are run.
|
| 91 |
+
absl::FlagsUsageConfig default_config;
|
| 92 |
+
default_config.normalize_filename = &NormalizeFileName;
|
| 93 |
+
absl::SetFlagsUsageConfig(default_config);
|
| 94 |
+
}
|
| 95 |
+
~UsageReportingTest() override {
|
| 96 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kNone);
|
| 97 |
+
flags::SetFlagsHelpMatchSubstr("");
|
| 98 |
+
flags::SetFlagsHelpFormat(flags::HelpFormat::kHumanReadable);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
private:
|
| 102 |
+
absl::FlagSaver flag_saver_;
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
// --------------------------------------------------------------------
|
| 106 |
+
|
| 107 |
+
using UsageReportingDeathTest = UsageReportingTest;
|
| 108 |
+
|
| 109 |
+
TEST_F(UsageReportingDeathTest, TestSetProgramUsageMessage) {
|
| 110 |
+
#if !defined(GTEST_HAS_ABSL) || !GTEST_HAS_ABSL
|
| 111 |
+
// Check for kTestUsageMessage set in main() below.
|
| 112 |
+
EXPECT_EQ(absl::ProgramUsageMessage(), kTestUsageMessage);
|
| 113 |
+
#else
|
| 114 |
+
// Check for part of the usage message set by GoogleTest.
|
| 115 |
+
EXPECT_THAT(absl::ProgramUsageMessage(),
|
| 116 |
+
::testing::HasSubstr(
|
| 117 |
+
"This program contains tests written using Google Test"));
|
| 118 |
+
#endif
|
| 119 |
+
|
| 120 |
+
EXPECT_DEATH_IF_SUPPORTED(
|
| 121 |
+
absl::SetProgramUsageMessage("custom usage message"),
|
| 122 |
+
::testing::HasSubstr("SetProgramUsageMessage() called twice"));
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// --------------------------------------------------------------------
|
| 126 |
+
|
| 127 |
+
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_01) {
|
| 128 |
+
const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_01");
|
| 129 |
+
std::stringstream test_buf;
|
| 130 |
+
|
| 131 |
+
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
|
| 132 |
+
EXPECT_EQ(
|
| 133 |
+
test_buf.str(),
|
| 134 |
+
R"( --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 135 |
+
default: 101;
|
| 136 |
+
)");
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_02) {
|
| 140 |
+
const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_02");
|
| 141 |
+
std::stringstream test_buf;
|
| 142 |
+
|
| 143 |
+
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
|
| 144 |
+
EXPECT_EQ(
|
| 145 |
+
test_buf.str(),
|
| 146 |
+
R"( --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 147 |
+
default: false;
|
| 148 |
+
)");
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_03) {
|
| 152 |
+
const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_03");
|
| 153 |
+
std::stringstream test_buf;
|
| 154 |
+
|
| 155 |
+
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
|
| 156 |
+
EXPECT_EQ(
|
| 157 |
+
test_buf.str(),
|
| 158 |
+
R"( --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 159 |
+
default: 1.03;
|
| 160 |
+
)");
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_04) {
|
| 164 |
+
const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_04");
|
| 165 |
+
std::stringstream test_buf;
|
| 166 |
+
|
| 167 |
+
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
|
| 168 |
+
EXPECT_EQ(
|
| 169 |
+
test_buf.str(),
|
| 170 |
+
R"( --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 171 |
+
default: 1000000000000004;
|
| 172 |
+
)");
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_05) {
|
| 176 |
+
const auto* flag = absl::FindCommandLineFlag("usage_reporting_test_flag_05");
|
| 177 |
+
std::stringstream test_buf;
|
| 178 |
+
|
| 179 |
+
flags::FlagHelp(test_buf, *flag, flags::HelpFormat::kHumanReadable);
|
| 180 |
+
EXPECT_EQ(
|
| 181 |
+
test_buf.str(),
|
| 182 |
+
R"( --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 183 |
+
default: UDT{};
|
| 184 |
+
)");
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
// --------------------------------------------------------------------
|
| 188 |
+
|
| 189 |
+
TEST_F(UsageReportingTest, TestFlagsHelpHRF) {
|
| 190 |
+
std::string usage_test_flags_out =
|
| 191 |
+
R"(usage_test: Custom usage message
|
| 192 |
+
|
| 193 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 194 |
+
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 195 |
+
default: 101;
|
| 196 |
+
--usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 197 |
+
default: false;
|
| 198 |
+
--usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 199 |
+
default: 1.03;
|
| 200 |
+
--usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 201 |
+
default: 1000000000000004;
|
| 202 |
+
--usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 203 |
+
default: UDT{};
|
| 204 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 205 |
+
|
| 206 |
+
Some more help.
|
| 207 |
+
Even more long long long long long long long long long long long long help
|
| 208 |
+
message.); default: "";)"
|
| 209 |
+
|
| 210 |
+
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
|
| 211 |
+
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
|
| 212 |
+
|
| 213 |
+
R"(
|
| 214 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 215 |
+
flags which include specified substring in either in the name, or description or
|
| 216 |
+
path.
|
| 217 |
+
)";
|
| 218 |
+
|
| 219 |
+
std::stringstream test_buf_01;
|
| 220 |
+
flags::FlagsHelp(test_buf_01, "usage_test.cc",
|
| 221 |
+
flags::HelpFormat::kHumanReadable, kTestUsageMessage);
|
| 222 |
+
EXPECT_EQ(test_buf_01.str(), usage_test_flags_out);
|
| 223 |
+
|
| 224 |
+
std::stringstream test_buf_02;
|
| 225 |
+
flags::FlagsHelp(test_buf_02, "flags/internal/usage_test.cc",
|
| 226 |
+
flags::HelpFormat::kHumanReadable, kTestUsageMessage);
|
| 227 |
+
EXPECT_EQ(test_buf_02.str(), usage_test_flags_out);
|
| 228 |
+
|
| 229 |
+
std::stringstream test_buf_03;
|
| 230 |
+
flags::FlagsHelp(test_buf_03, "usage_test", flags::HelpFormat::kHumanReadable,
|
| 231 |
+
kTestUsageMessage);
|
| 232 |
+
EXPECT_EQ(test_buf_03.str(), usage_test_flags_out);
|
| 233 |
+
|
| 234 |
+
std::stringstream test_buf_04;
|
| 235 |
+
flags::FlagsHelp(test_buf_04, "flags/invalid_file_name.cc",
|
| 236 |
+
flags::HelpFormat::kHumanReadable, kTestUsageMessage);
|
| 237 |
+
EXPECT_EQ(test_buf_04.str(),
|
| 238 |
+
R"(usage_test: Custom usage message
|
| 239 |
+
|
| 240 |
+
No flags matched.
|
| 241 |
+
|
| 242 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 243 |
+
flags which include specified substring in either in the name, or description or
|
| 244 |
+
path.
|
| 245 |
+
)");
|
| 246 |
+
|
| 247 |
+
std::stringstream test_buf_05;
|
| 248 |
+
flags::FlagsHelp(test_buf_05, "", flags::HelpFormat::kHumanReadable,
|
| 249 |
+
kTestUsageMessage);
|
| 250 |
+
std::string test_out = test_buf_05.str();
|
| 251 |
+
absl::string_view test_out_str(test_out);
|
| 252 |
+
EXPECT_TRUE(
|
| 253 |
+
absl::StartsWith(test_out_str, "usage_test: Custom usage message"));
|
| 254 |
+
EXPECT_TRUE(absl::StrContains(
|
| 255 |
+
test_out_str, "Flags from absl/flags/internal/usage_test.cc:"));
|
| 256 |
+
EXPECT_TRUE(
|
| 257 |
+
absl::StrContains(test_out_str, "-usage_reporting_test_flag_01 "));
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// --------------------------------------------------------------------
|
| 261 |
+
|
| 262 |
+
TEST_F(UsageReportingTest, TestNoUsageFlags) {
|
| 263 |
+
std::stringstream test_buf;
|
| 264 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 265 |
+
flags::HelpMode::kNone);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
// --------------------------------------------------------------------
|
| 269 |
+
|
| 270 |
+
TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
|
| 271 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kShort);
|
| 272 |
+
|
| 273 |
+
std::stringstream test_buf;
|
| 274 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 275 |
+
flags::HelpMode::kShort);
|
| 276 |
+
EXPECT_EQ(
|
| 277 |
+
test_buf.str(),
|
| 278 |
+
R"(usage_test: Custom usage message
|
| 279 |
+
|
| 280 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 281 |
+
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 282 |
+
default: 101;
|
| 283 |
+
--usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 284 |
+
default: false;
|
| 285 |
+
--usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 286 |
+
default: 1.03;
|
| 287 |
+
--usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 288 |
+
default: 1000000000000004;
|
| 289 |
+
--usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 290 |
+
default: UDT{};
|
| 291 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 292 |
+
|
| 293 |
+
Some more help.
|
| 294 |
+
Even more long long long long long long long long long long long long help
|
| 295 |
+
message.); default: "";)"
|
| 296 |
+
|
| 297 |
+
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
|
| 298 |
+
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
|
| 299 |
+
|
| 300 |
+
R"(
|
| 301 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 302 |
+
flags which include specified substring in either in the name, or description or
|
| 303 |
+
path.
|
| 304 |
+
)");
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
// --------------------------------------------------------------------
|
| 308 |
+
|
| 309 |
+
TEST_F(UsageReportingTest, TestUsageFlag_help_simple) {
|
| 310 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kImportant);
|
| 311 |
+
|
| 312 |
+
std::stringstream test_buf;
|
| 313 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 314 |
+
flags::HelpMode::kImportant);
|
| 315 |
+
EXPECT_EQ(
|
| 316 |
+
test_buf.str(),
|
| 317 |
+
R"(usage_test: Custom usage message
|
| 318 |
+
|
| 319 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 320 |
+
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 321 |
+
default: 101;
|
| 322 |
+
--usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 323 |
+
default: false;
|
| 324 |
+
--usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 325 |
+
default: 1.03;
|
| 326 |
+
--usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 327 |
+
default: 1000000000000004;
|
| 328 |
+
--usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 329 |
+
default: UDT{};
|
| 330 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 331 |
+
|
| 332 |
+
Some more help.
|
| 333 |
+
Even more long long long long long long long long long long long long help
|
| 334 |
+
message.); default: "";)"
|
| 335 |
+
|
| 336 |
+
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
|
| 337 |
+
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
|
| 338 |
+
|
| 339 |
+
R"(
|
| 340 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 341 |
+
flags which include specified substring in either in the name, or description or
|
| 342 |
+
path.
|
| 343 |
+
)");
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
// --------------------------------------------------------------------
|
| 347 |
+
|
| 348 |
+
TEST_F(UsageReportingTest, TestUsageFlag_help_one_flag) {
|
| 349 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kMatch);
|
| 350 |
+
flags::SetFlagsHelpMatchSubstr("usage_reporting_test_flag_06");
|
| 351 |
+
|
| 352 |
+
std::stringstream test_buf;
|
| 353 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 354 |
+
flags::HelpMode::kMatch);
|
| 355 |
+
EXPECT_EQ(test_buf.str(),
|
| 356 |
+
R"(usage_test: Custom usage message
|
| 357 |
+
|
| 358 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 359 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 360 |
+
|
| 361 |
+
Some more help.
|
| 362 |
+
Even more long long long long long long long long long long long long help
|
| 363 |
+
message.); default: "";
|
| 364 |
+
|
| 365 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 366 |
+
flags which include specified substring in either in the name, or description or
|
| 367 |
+
path.
|
| 368 |
+
)");
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
// --------------------------------------------------------------------
|
| 372 |
+
|
| 373 |
+
TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) {
|
| 374 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kMatch);
|
| 375 |
+
flags::SetFlagsHelpMatchSubstr("test_flag");
|
| 376 |
+
|
| 377 |
+
std::stringstream test_buf;
|
| 378 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 379 |
+
flags::HelpMode::kMatch);
|
| 380 |
+
EXPECT_EQ(
|
| 381 |
+
test_buf.str(),
|
| 382 |
+
R"(usage_test: Custom usage message
|
| 383 |
+
|
| 384 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 385 |
+
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 386 |
+
default: 101;
|
| 387 |
+
--usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 388 |
+
default: false;
|
| 389 |
+
--usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 390 |
+
default: 1.03;
|
| 391 |
+
--usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 392 |
+
default: 1000000000000004;
|
| 393 |
+
--usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 394 |
+
default: UDT{};
|
| 395 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 396 |
+
|
| 397 |
+
Some more help.
|
| 398 |
+
Even more long long long long long long long long long long long long help
|
| 399 |
+
message.); default: "";)"
|
| 400 |
+
|
| 401 |
+
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
|
| 402 |
+
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
|
| 403 |
+
|
| 404 |
+
R"(
|
| 405 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 406 |
+
flags which include specified substring in either in the name, or description or
|
| 407 |
+
path.
|
| 408 |
+
)");
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
// --------------------------------------------------------------------
|
| 412 |
+
|
| 413 |
+
TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
|
| 414 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kPackage);
|
| 415 |
+
|
| 416 |
+
std::stringstream test_buf;
|
| 417 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 418 |
+
flags::HelpMode::kPackage);
|
| 419 |
+
EXPECT_EQ(
|
| 420 |
+
test_buf.str(),
|
| 421 |
+
R"(usage_test: Custom usage message
|
| 422 |
+
|
| 423 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 424 |
+
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 425 |
+
default: 101;
|
| 426 |
+
--usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 427 |
+
default: false;
|
| 428 |
+
--usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 429 |
+
default: 1.03;
|
| 430 |
+
--usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 431 |
+
default: 1000000000000004;
|
| 432 |
+
--usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 433 |
+
default: UDT{};
|
| 434 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 435 |
+
|
| 436 |
+
Some more help.
|
| 437 |
+
Even more long long long long long long long long long long long long help
|
| 438 |
+
message.); default: "";)"
|
| 439 |
+
|
| 440 |
+
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
|
| 441 |
+
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
|
| 442 |
+
|
| 443 |
+
R"(
|
| 444 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 445 |
+
flags which include specified substring in either in the name, or description or
|
| 446 |
+
path.
|
| 447 |
+
)");
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
// --------------------------------------------------------------------
|
| 451 |
+
|
| 452 |
+
TEST_F(UsageReportingTest, TestUsageFlag_version) {
|
| 453 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kVersion);
|
| 454 |
+
|
| 455 |
+
std::stringstream test_buf;
|
| 456 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 457 |
+
flags::HelpMode::kVersion);
|
| 458 |
+
#ifndef NDEBUG
|
| 459 |
+
EXPECT_EQ(test_buf.str(), "usage_test\nDebug build (NDEBUG not #defined)\n");
|
| 460 |
+
#else
|
| 461 |
+
EXPECT_EQ(test_buf.str(), "usage_test\n");
|
| 462 |
+
#endif
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
// --------------------------------------------------------------------
|
| 466 |
+
|
| 467 |
+
TEST_F(UsageReportingTest, TestUsageFlag_only_check_args) {
|
| 468 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kOnlyCheckArgs);
|
| 469 |
+
|
| 470 |
+
std::stringstream test_buf;
|
| 471 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
|
| 472 |
+
flags::HelpMode::kOnlyCheckArgs);
|
| 473 |
+
EXPECT_EQ(test_buf.str(), "");
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// --------------------------------------------------------------------
|
| 477 |
+
|
| 478 |
+
TEST_F(UsageReportingTest, TestUsageFlag_helpon) {
|
| 479 |
+
flags::SetFlagsHelpMode(flags::HelpMode::kMatch);
|
| 480 |
+
flags::SetFlagsHelpMatchSubstr("/bla-bla.");
|
| 481 |
+
|
| 482 |
+
std::stringstream test_buf_01;
|
| 483 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf_01, kTestUsageMessage),
|
| 484 |
+
flags::HelpMode::kMatch);
|
| 485 |
+
EXPECT_EQ(test_buf_01.str(),
|
| 486 |
+
R"(usage_test: Custom usage message
|
| 487 |
+
|
| 488 |
+
No flags matched.
|
| 489 |
+
|
| 490 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 491 |
+
flags which include specified substring in either in the name, or description or
|
| 492 |
+
path.
|
| 493 |
+
)");
|
| 494 |
+
|
| 495 |
+
flags::SetFlagsHelpMatchSubstr("/usage_test.");
|
| 496 |
+
|
| 497 |
+
std::stringstream test_buf_02;
|
| 498 |
+
EXPECT_EQ(flags::HandleUsageFlags(test_buf_02, kTestUsageMessage),
|
| 499 |
+
flags::HelpMode::kMatch);
|
| 500 |
+
EXPECT_EQ(
|
| 501 |
+
test_buf_02.str(),
|
| 502 |
+
R"(usage_test: Custom usage message
|
| 503 |
+
|
| 504 |
+
Flags from absl/flags/internal/usage_test.cc:
|
| 505 |
+
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
|
| 506 |
+
default: 101;
|
| 507 |
+
--usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
|
| 508 |
+
default: false;
|
| 509 |
+
--usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
|
| 510 |
+
default: 1.03;
|
| 511 |
+
--usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
|
| 512 |
+
default: 1000000000000004;
|
| 513 |
+
--usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
|
| 514 |
+
default: UDT{};
|
| 515 |
+
--usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
|
| 516 |
+
|
| 517 |
+
Some more help.
|
| 518 |
+
Even more long long long long long long long long long long long long help
|
| 519 |
+
message.); default: "";)"
|
| 520 |
+
|
| 521 |
+
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
|
| 522 |
+
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
|
| 523 |
+
|
| 524 |
+
R"(
|
| 525 |
+
Try --helpfull to get a list of all flags or --help=substring shows help for
|
| 526 |
+
flags which include specified substring in either in the name, or description or
|
| 527 |
+
path.
|
| 528 |
+
)");
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
// --------------------------------------------------------------------
|
| 532 |
+
|
| 533 |
+
} // namespace
|
| 534 |
+
|
| 535 |
+
int main(int argc, char* argv[]) {
|
| 536 |
+
(void)absl::GetFlag(FLAGS_undefok); // Force linking of parse.cc
|
| 537 |
+
flags::SetProgramInvocationName("usage_test");
|
| 538 |
+
#if !defined(GTEST_HAS_ABSL) || !GTEST_HAS_ABSL
|
| 539 |
+
// GoogleTest calls absl::SetProgramUsageMessage() already.
|
| 540 |
+
absl::SetProgramUsageMessage(kTestUsageMessage);
|
| 541 |
+
#endif
|
| 542 |
+
::testing::InitGoogleTest(&argc, argv);
|
| 543 |
+
return RUN_ALL_TESTS();
|
| 544 |
+
}
|
weight/_dep/abseil-cpp/absl/flags/marshalling.h
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 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 |
+
// -----------------------------------------------------------------------------
|
| 17 |
+
// File: marshalling.h
|
| 18 |
+
// -----------------------------------------------------------------------------
|
| 19 |
+
//
|
| 20 |
+
// This header file defines the API for extending Abseil flag support to
|
| 21 |
+
// custom types, and defines the set of overloads for fundamental types.
|
| 22 |
+
//
|
| 23 |
+
// Out of the box, the Abseil flags library supports the following types:
|
| 24 |
+
//
|
| 25 |
+
// * `bool`
|
| 26 |
+
// * `int16_t`
|
| 27 |
+
// * `uint16_t`
|
| 28 |
+
// * `int32_t`
|
| 29 |
+
// * `uint32_t`
|
| 30 |
+
// * `int64_t`
|
| 31 |
+
// * `uint64_t`
|
| 32 |
+
// * `float`
|
| 33 |
+
// * `double`
|
| 34 |
+
// * `std::string`
|
| 35 |
+
// * `std::vector<std::string>`
|
| 36 |
+
// * `std::optional<T>`
|
| 37 |
+
// * `absl::LogSeverity` (provided natively for layering reasons)
|
| 38 |
+
//
|
| 39 |
+
// Note that support for integral types is implemented using overloads for
|
| 40 |
+
// variable-width fundamental types (`short`, `int`, `long`, etc.). However,
|
| 41 |
+
// you should prefer the fixed-width integral types (`int32_t`, `uint64_t`,
|
| 42 |
+
// etc.) we've noted above within flag definitions.
|
| 43 |
+
//
|
| 44 |
+
// In addition, several Abseil libraries provide their own custom support for
|
| 45 |
+
// Abseil flags. Documentation for these formats is provided in the type's
|
| 46 |
+
// `AbslParseFlag()` definition.
|
| 47 |
+
//
|
| 48 |
+
// The Abseil time library provides the following support for civil time values:
|
| 49 |
+
//
|
| 50 |
+
// * `absl::CivilSecond`
|
| 51 |
+
// * `absl::CivilMinute`
|
| 52 |
+
// * `absl::CivilHour`
|
| 53 |
+
// * `absl::CivilDay`
|
| 54 |
+
// * `absl::CivilMonth`
|
| 55 |
+
// * `absl::CivilYear`
|
| 56 |
+
//
|
| 57 |
+
// and also provides support for the following absolute time values:
|
| 58 |
+
//
|
| 59 |
+
// * `absl::Duration`
|
| 60 |
+
// * `absl::Time`
|
| 61 |
+
//
|
| 62 |
+
// Additional support for Abseil types will be noted here as it is added.
|
| 63 |
+
//
|
| 64 |
+
// You can also provide your own custom flags by adding overloads for
|
| 65 |
+
// `AbslParseFlag()` and `AbslUnparseFlag()` to your type definitions. (See
|
| 66 |
+
// below.)
|
| 67 |
+
//
|
| 68 |
+
// -----------------------------------------------------------------------------
|
| 69 |
+
// Optional Flags
|
| 70 |
+
// -----------------------------------------------------------------------------
|
| 71 |
+
//
|
| 72 |
+
// The Abseil flags library supports flags of type `std::optional<T>` where
|
| 73 |
+
// `T` is a type of one of the supported flags. We refer to this flag type as
|
| 74 |
+
// an "optional flag." An optional flag is either "valueless", holding no value
|
| 75 |
+
// of type `T` (indicating that the flag has not been set) or a value of type
|
| 76 |
+
// `T`. The valueless state in C++ code is represented by a value of
|
| 77 |
+
// `std::nullopt` for the optional flag.
|
| 78 |
+
//
|
| 79 |
+
// Using `std::nullopt` as an optional flag's default value allows you to check
|
| 80 |
+
// whether such a flag was ever specified on the command line:
|
| 81 |
+
//
|
| 82 |
+
// if (absl::GetFlag(FLAGS_foo).has_value()) {
|
| 83 |
+
// // flag was set on command line
|
| 84 |
+
// } else {
|
| 85 |
+
// // flag was not passed on command line
|
| 86 |
+
// }
|
| 87 |
+
//
|
| 88 |
+
// Using an optional flag in this manner avoids common workarounds for
|
| 89 |
+
// indicating such an unset flag (such as using sentinel values to indicate this
|
| 90 |
+
// state).
|
| 91 |
+
//
|
| 92 |
+
// An optional flag also allows a developer to pass a flag in an "unset"
|
| 93 |
+
// valueless state on the command line, allowing the flag to later be set in
|
| 94 |
+
// binary logic. An optional flag's valueless state is indicated by the special
|
| 95 |
+
// notation of passing the value as an empty string through the syntax `--flag=`
|
| 96 |
+
// or `--flag ""`.
|
| 97 |
+
//
|
| 98 |
+
// $ binary_with_optional --flag_in_unset_state=
|
| 99 |
+
// $ binary_with_optional --flag_in_unset_state ""
|
| 100 |
+
//
|
| 101 |
+
// Note: as a result of the above syntax requirements, an optional flag cannot
|
| 102 |
+
// be set to a `T` of any value which unparses to the empty string.
|
| 103 |
+
//
|
| 104 |
+
// -----------------------------------------------------------------------------
|
| 105 |
+
// Adding Type Support for Abseil Flags
|
| 106 |
+
// -----------------------------------------------------------------------------
|
| 107 |
+
//
|
| 108 |
+
// To add support for your user-defined type, add overloads of `AbslParseFlag()`
|
| 109 |
+
// and `AbslUnparseFlag()` as free (non-member) functions to your type. If `T`
|
| 110 |
+
// is a class type, these functions can be friend function definitions. These
|
| 111 |
+
// overloads must be added to the same namespace where the type is defined, so
|
| 112 |
+
// that they can be discovered by Argument-Dependent Lookup (ADL).
|
| 113 |
+
//
|
| 114 |
+
// Example:
|
| 115 |
+
//
|
| 116 |
+
// namespace foo {
|
| 117 |
+
//
|
| 118 |
+
// enum OutputMode { kPlainText, kHtml };
|
| 119 |
+
//
|
| 120 |
+
// // AbslParseFlag converts from a string to OutputMode.
|
| 121 |
+
// // Must be in same namespace as OutputMode.
|
| 122 |
+
//
|
| 123 |
+
// // Parses an OutputMode from the command line flag value `text`. Returns
|
| 124 |
+
// // `true` and sets `*mode` on success; returns `false` and sets `*error`
|
| 125 |
+
// // on failure.
|
| 126 |
+
// bool AbslParseFlag(absl::string_view text,
|
| 127 |
+
// OutputMode* mode,
|
| 128 |
+
// std::string* error) {
|
| 129 |
+
// if (text == "plaintext") {
|
| 130 |
+
// *mode = kPlainText;
|
| 131 |
+
// return true;
|
| 132 |
+
// }
|
| 133 |
+
// if (text == "html") {
|
| 134 |
+
// *mode = kHtml;
|
| 135 |
+
// return true;
|
| 136 |
+
// }
|
| 137 |
+
// *error = "unknown value for enumeration";
|
| 138 |
+
// return false;
|
| 139 |
+
// }
|
| 140 |
+
//
|
| 141 |
+
// // AbslUnparseFlag converts from an OutputMode to a string.
|
| 142 |
+
// // Must be in same namespace as OutputMode.
|
| 143 |
+
//
|
| 144 |
+
// // Returns a textual flag value corresponding to the OutputMode `mode`.
|
| 145 |
+
// std::string AbslUnparseFlag(OutputMode mode) {
|
| 146 |
+
// switch (mode) {
|
| 147 |
+
// case kPlainText: return "plaintext";
|
| 148 |
+
// case kHtml: return "html";
|
| 149 |
+
// }
|
| 150 |
+
// return absl::StrCat(mode);
|
| 151 |
+
// }
|
| 152 |
+
//
|
| 153 |
+
// Notice that neither `AbslParseFlag()` nor `AbslUnparseFlag()` are class
|
| 154 |
+
// members, but free functions. `AbslParseFlag/AbslUnparseFlag()` overloads
|
| 155 |
+
// for a type should only be declared in the same file and namespace as said
|
| 156 |
+
// type. The proper `AbslParseFlag/AbslUnparseFlag()` implementations for a
|
| 157 |
+
// given type will be discovered via Argument-Dependent Lookup (ADL).
|
| 158 |
+
//
|
| 159 |
+
// `AbslParseFlag()` may need, in turn, to parse simpler constituent types
|
| 160 |
+
// using `absl::ParseFlag()`. For example, a custom struct `MyFlagType`
|
| 161 |
+
// consisting of a `std::pair<int, std::string>` would add an `AbslParseFlag()`
|
| 162 |
+
// overload for its `MyFlagType` like so:
|
| 163 |
+
//
|
| 164 |
+
// Example:
|
| 165 |
+
//
|
| 166 |
+
// namespace my_flag_type {
|
| 167 |
+
//
|
| 168 |
+
// struct MyFlagType {
|
| 169 |
+
// std::pair<int, std::string> my_flag_data;
|
| 170 |
+
// };
|
| 171 |
+
//
|
| 172 |
+
// bool AbslParseFlag(absl::string_view text, MyFlagType* flag,
|
| 173 |
+
// std::string* err);
|
| 174 |
+
//
|
| 175 |
+
// std::string AbslUnparseFlag(const MyFlagType&);
|
| 176 |
+
//
|
| 177 |
+
// // Within the implementation, `AbslParseFlag()` will, in turn invoke
|
| 178 |
+
// // `absl::ParseFlag()` on its constituent `int` and `std::string` types
|
| 179 |
+
// // (which have built-in Abseil flag support).
|
| 180 |
+
//
|
| 181 |
+
// bool AbslParseFlag(absl::string_view text, MyFlagType* flag,
|
| 182 |
+
// std::string* err) {
|
| 183 |
+
// std::pair<absl::string_view, absl::string_view> tokens =
|
| 184 |
+
// absl::StrSplit(text, ',');
|
| 185 |
+
// if (!absl::ParseFlag(tokens.first, &flag->my_flag_data.first, err))
|
| 186 |
+
// return false;
|
| 187 |
+
// if (!absl::ParseFlag(tokens.second, &flag->my_flag_data.second, err))
|
| 188 |
+
// return false;
|
| 189 |
+
// return true;
|
| 190 |
+
// }
|
| 191 |
+
//
|
| 192 |
+
// // Similarly, for unparsing, we can simply invoke `absl::UnparseFlag()` on
|
| 193 |
+
// // the constituent types.
|
| 194 |
+
// std::string AbslUnparseFlag(const MyFlagType& flag) {
|
| 195 |
+
// return absl::StrCat(absl::UnparseFlag(flag.my_flag_data.first),
|
| 196 |
+
// ",",
|
| 197 |
+
// absl::UnparseFlag(flag.my_flag_data.second));
|
| 198 |
+
// }
|
| 199 |
+
#ifndef ABSL_FLAGS_MARSHALLING_H_
|
| 200 |
+
#define ABSL_FLAGS_MARSHALLING_H_
|
| 201 |
+
|
| 202 |
+
#include "absl/base/config.h"
|
| 203 |
+
#include "absl/numeric/int128.h"
|
| 204 |
+
|
| 205 |
+
#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL)
|
| 206 |
+
#include <optional>
|
| 207 |
+
#endif
|
| 208 |
+
#include <string>
|
| 209 |
+
#include <vector>
|
| 210 |
+
|
| 211 |
+
#include "absl/strings/string_view.h"
|
| 212 |
+
#include "absl/types/optional.h"
|
| 213 |
+
|
| 214 |
+
namespace absl {
|
| 215 |
+
ABSL_NAMESPACE_BEGIN
|
| 216 |
+
|
| 217 |
+
// Forward declaration to be used inside composable flag parse/unparse
|
| 218 |
+
// implementations
|
| 219 |
+
template <typename T>
|
| 220 |
+
inline bool ParseFlag(absl::string_view input, T* dst, std::string* error);
|
| 221 |
+
template <typename T>
|
| 222 |
+
inline std::string UnparseFlag(const T& v);
|
| 223 |
+
|
| 224 |
+
namespace flags_internal {
|
| 225 |
+
|
| 226 |
+
// Overloads of `AbslParseFlag()` and `AbslUnparseFlag()` for fundamental types.
|
| 227 |
+
bool AbslParseFlag(absl::string_view, bool*, std::string*);
|
| 228 |
+
bool AbslParseFlag(absl::string_view, short*, std::string*); // NOLINT
|
| 229 |
+
bool AbslParseFlag(absl::string_view, unsigned short*, std::string*); // NOLINT
|
| 230 |
+
bool AbslParseFlag(absl::string_view, int*, std::string*); // NOLINT
|
| 231 |
+
bool AbslParseFlag(absl::string_view, unsigned int*, std::string*); // NOLINT
|
| 232 |
+
bool AbslParseFlag(absl::string_view, long*, std::string*); // NOLINT
|
| 233 |
+
bool AbslParseFlag(absl::string_view, unsigned long*, std::string*); // NOLINT
|
| 234 |
+
bool AbslParseFlag(absl::string_view, long long*, std::string*); // NOLINT
|
| 235 |
+
bool AbslParseFlag(absl::string_view, unsigned long long*, // NOLINT
|
| 236 |
+
std::string*);
|
| 237 |
+
bool AbslParseFlag(absl::string_view, absl::int128*, std::string*); // NOLINT
|
| 238 |
+
bool AbslParseFlag(absl::string_view, absl::uint128*, std::string*); // NOLINT
|
| 239 |
+
bool AbslParseFlag(absl::string_view, float*, std::string*);
|
| 240 |
+
bool AbslParseFlag(absl::string_view, double*, std::string*);
|
| 241 |
+
bool AbslParseFlag(absl::string_view, std::string*, std::string*);
|
| 242 |
+
bool AbslParseFlag(absl::string_view, std::vector<std::string>*, std::string*);
|
| 243 |
+
|
| 244 |
+
template <typename T>
|
| 245 |
+
bool AbslParseFlag(absl::string_view text, absl::optional<T>* f,
|
| 246 |
+
std::string* err) {
|
| 247 |
+
if (text.empty()) {
|
| 248 |
+
*f = absl::nullopt;
|
| 249 |
+
return true;
|
| 250 |
+
}
|
| 251 |
+
T value;
|
| 252 |
+
if (!absl::ParseFlag(text, &value, err)) return false;
|
| 253 |
+
|
| 254 |
+
*f = std::move(value);
|
| 255 |
+
return true;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL)
|
| 259 |
+
template <typename T>
|
| 260 |
+
bool AbslParseFlag(absl::string_view text, std::optional<T>* f,
|
| 261 |
+
std::string* err) {
|
| 262 |
+
if (text.empty()) {
|
| 263 |
+
*f = std::nullopt;
|
| 264 |
+
return true;
|
| 265 |
+
}
|
| 266 |
+
T value;
|
| 267 |
+
if (!absl::ParseFlag(text, &value, err)) return false;
|
| 268 |
+
|
| 269 |
+
*f = std::move(value);
|
| 270 |
+
return true;
|
| 271 |
+
}
|
| 272 |
+
#endif
|
| 273 |
+
|
| 274 |
+
template <typename T>
|
| 275 |
+
bool InvokeParseFlag(absl::string_view input, T* dst, std::string* err) {
|
| 276 |
+
// Comment on next line provides a good compiler error message if T
|
| 277 |
+
// does not have AbslParseFlag(absl::string_view, T*, std::string*).
|
| 278 |
+
return AbslParseFlag(input, dst, err); // Is T missing AbslParseFlag?
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
// Strings and std:: containers do not have the same overload resolution
|
| 282 |
+
// considerations as fundamental types. Naming these 'AbslUnparseFlag' means we
|
| 283 |
+
// can avoid the need for additional specializations of Unparse (below).
|
| 284 |
+
std::string AbslUnparseFlag(absl::string_view v);
|
| 285 |
+
std::string AbslUnparseFlag(const std::vector<std::string>&);
|
| 286 |
+
|
| 287 |
+
template <typename T>
|
| 288 |
+
std::string AbslUnparseFlag(const absl::optional<T>& f) {
|
| 289 |
+
return f.has_value() ? absl::UnparseFlag(*f) : "";
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL)
|
| 293 |
+
template <typename T>
|
| 294 |
+
std::string AbslUnparseFlag(const std::optional<T>& f) {
|
| 295 |
+
return f.has_value() ? absl::UnparseFlag(*f) : "";
|
| 296 |
+
}
|
| 297 |
+
#endif
|
| 298 |
+
|
| 299 |
+
template <typename T>
|
| 300 |
+
std::string Unparse(const T& v) {
|
| 301 |
+
// Comment on next line provides a good compiler error message if T does not
|
| 302 |
+
// have UnparseFlag.
|
| 303 |
+
return AbslUnparseFlag(v); // Is T missing AbslUnparseFlag?
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
// Overloads for builtin types.
|
| 307 |
+
std::string Unparse(bool v);
|
| 308 |
+
std::string Unparse(short v); // NOLINT
|
| 309 |
+
std::string Unparse(unsigned short v); // NOLINT
|
| 310 |
+
std::string Unparse(int v); // NOLINT
|
| 311 |
+
std::string Unparse(unsigned int v); // NOLINT
|
| 312 |
+
std::string Unparse(long v); // NOLINT
|
| 313 |
+
std::string Unparse(unsigned long v); // NOLINT
|
| 314 |
+
std::string Unparse(long long v); // NOLINT
|
| 315 |
+
std::string Unparse(unsigned long long v); // NOLINT
|
| 316 |
+
std::string Unparse(absl::int128 v);
|
| 317 |
+
std::string Unparse(absl::uint128 v);
|
| 318 |
+
std::string Unparse(float v);
|
| 319 |
+
std::string Unparse(double v);
|
| 320 |
+
|
| 321 |
+
} // namespace flags_internal
|
| 322 |
+
|
| 323 |
+
// ParseFlag()
|
| 324 |
+
//
|
| 325 |
+
// Parses a string value into a flag value of type `T`. Do not add overloads of
|
| 326 |
+
// this function for your type directly; instead, add an `AbslParseFlag()`
|
| 327 |
+
// free function as documented above.
|
| 328 |
+
//
|
| 329 |
+
// Some implementations of `AbslParseFlag()` for types which consist of other,
|
| 330 |
+
// constituent types which already have Abseil flag support, may need to call
|
| 331 |
+
// `absl::ParseFlag()` on those consituent string values. (See above.)
|
| 332 |
+
template <typename T>
|
| 333 |
+
inline bool ParseFlag(absl::string_view input, T* dst, std::string* error) {
|
| 334 |
+
return flags_internal::InvokeParseFlag(input, dst, error);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// UnparseFlag()
|
| 338 |
+
//
|
| 339 |
+
// Unparses a flag value of type `T` into a string value. Do not add overloads
|
| 340 |
+
// of this function for your type directly; instead, add an `AbslUnparseFlag()`
|
| 341 |
+
// free function as documented above.
|
| 342 |
+
//
|
| 343 |
+
// Some implementations of `AbslUnparseFlag()` for types which consist of other,
|
| 344 |
+
// constituent types which already have Abseil flag support, may want to call
|
| 345 |
+
// `absl::UnparseFlag()` on those constituent types. (See above.)
|
| 346 |
+
template <typename T>
|
| 347 |
+
inline std::string UnparseFlag(const T& v) {
|
| 348 |
+
return flags_internal::Unparse(v);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// Overloads for `absl::LogSeverity` can't (easily) appear alongside that type's
|
| 352 |
+
// definition because it is layered below flags. See proper documentation in
|
| 353 |
+
// base/log_severity.h.
|
| 354 |
+
enum class LogSeverity : int;
|
| 355 |
+
bool AbslParseFlag(absl::string_view, absl::LogSeverity*, std::string*);
|
| 356 |
+
std::string AbslUnparseFlag(absl::LogSeverity);
|
| 357 |
+
|
| 358 |
+
ABSL_NAMESPACE_END
|
| 359 |
+
} // namespace absl
|
| 360 |
+
|
| 361 |
+
#endif // ABSL_FLAGS_MARSHALLING_H_
|
weight/_dep/abseil-cpp/absl/flags/marshalling_test.cc
ADDED
|
@@ -0,0 +1,1220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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/marshalling.h"
|
| 17 |
+
|
| 18 |
+
#include <stdint.h>
|
| 19 |
+
|
| 20 |
+
#include <cmath>
|
| 21 |
+
#include <limits>
|
| 22 |
+
#include <string>
|
| 23 |
+
#include <vector>
|
| 24 |
+
|
| 25 |
+
#include "gtest/gtest.h"
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
|
| 29 |
+
TEST(MarshallingTest, TestBoolParsing) {
|
| 30 |
+
std::string err;
|
| 31 |
+
bool value;
|
| 32 |
+
|
| 33 |
+
// True values.
|
| 34 |
+
EXPECT_TRUE(absl::ParseFlag("True", &value, &err));
|
| 35 |
+
EXPECT_TRUE(value);
|
| 36 |
+
EXPECT_TRUE(absl::ParseFlag("true", &value, &err));
|
| 37 |
+
EXPECT_TRUE(value);
|
| 38 |
+
EXPECT_TRUE(absl::ParseFlag("TRUE", &value, &err));
|
| 39 |
+
EXPECT_TRUE(value);
|
| 40 |
+
|
| 41 |
+
EXPECT_TRUE(absl::ParseFlag("Yes", &value, &err));
|
| 42 |
+
EXPECT_TRUE(value);
|
| 43 |
+
EXPECT_TRUE(absl::ParseFlag("yes", &value, &err));
|
| 44 |
+
EXPECT_TRUE(value);
|
| 45 |
+
EXPECT_TRUE(absl::ParseFlag("YES", &value, &err));
|
| 46 |
+
EXPECT_TRUE(value);
|
| 47 |
+
|
| 48 |
+
EXPECT_TRUE(absl::ParseFlag("t", &value, &err));
|
| 49 |
+
EXPECT_TRUE(value);
|
| 50 |
+
EXPECT_TRUE(absl::ParseFlag("T", &value, &err));
|
| 51 |
+
EXPECT_TRUE(value);
|
| 52 |
+
|
| 53 |
+
EXPECT_TRUE(absl::ParseFlag("y", &value, &err));
|
| 54 |
+
EXPECT_TRUE(value);
|
| 55 |
+
EXPECT_TRUE(absl::ParseFlag("Y", &value, &err));
|
| 56 |
+
EXPECT_TRUE(value);
|
| 57 |
+
|
| 58 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 59 |
+
EXPECT_TRUE(value);
|
| 60 |
+
|
| 61 |
+
// False values.
|
| 62 |
+
EXPECT_TRUE(absl::ParseFlag("False", &value, &err));
|
| 63 |
+
EXPECT_FALSE(value);
|
| 64 |
+
EXPECT_TRUE(absl::ParseFlag("false", &value, &err));
|
| 65 |
+
EXPECT_FALSE(value);
|
| 66 |
+
EXPECT_TRUE(absl::ParseFlag("FALSE", &value, &err));
|
| 67 |
+
EXPECT_FALSE(value);
|
| 68 |
+
|
| 69 |
+
EXPECT_TRUE(absl::ParseFlag("No", &value, &err));
|
| 70 |
+
EXPECT_FALSE(value);
|
| 71 |
+
EXPECT_TRUE(absl::ParseFlag("no", &value, &err));
|
| 72 |
+
EXPECT_FALSE(value);
|
| 73 |
+
EXPECT_TRUE(absl::ParseFlag("NO", &value, &err));
|
| 74 |
+
EXPECT_FALSE(value);
|
| 75 |
+
|
| 76 |
+
EXPECT_TRUE(absl::ParseFlag("f", &value, &err));
|
| 77 |
+
EXPECT_FALSE(value);
|
| 78 |
+
EXPECT_TRUE(absl::ParseFlag("F", &value, &err));
|
| 79 |
+
EXPECT_FALSE(value);
|
| 80 |
+
|
| 81 |
+
EXPECT_TRUE(absl::ParseFlag("n", &value, &err));
|
| 82 |
+
EXPECT_FALSE(value);
|
| 83 |
+
EXPECT_TRUE(absl::ParseFlag("N", &value, &err));
|
| 84 |
+
EXPECT_FALSE(value);
|
| 85 |
+
|
| 86 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 87 |
+
EXPECT_FALSE(value);
|
| 88 |
+
|
| 89 |
+
// Whitespace handling.
|
| 90 |
+
EXPECT_TRUE(absl::ParseFlag(" true", &value, &err));
|
| 91 |
+
EXPECT_TRUE(value);
|
| 92 |
+
EXPECT_TRUE(absl::ParseFlag("true ", &value, &err));
|
| 93 |
+
EXPECT_TRUE(value);
|
| 94 |
+
EXPECT_TRUE(absl::ParseFlag(" true ", &value, &err));
|
| 95 |
+
EXPECT_TRUE(value);
|
| 96 |
+
|
| 97 |
+
// Invalid input.
|
| 98 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 99 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 100 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 101 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 102 |
+
EXPECT_FALSE(absl::ParseFlag("2", &value, &err));
|
| 103 |
+
EXPECT_FALSE(absl::ParseFlag("11", &value, &err));
|
| 104 |
+
EXPECT_FALSE(absl::ParseFlag("tt", &value, &err));
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// --------------------------------------------------------------------
|
| 108 |
+
|
| 109 |
+
TEST(MarshallingTest, TestInt16Parsing) {
|
| 110 |
+
std::string err;
|
| 111 |
+
int16_t value;
|
| 112 |
+
|
| 113 |
+
// Decimal values.
|
| 114 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 115 |
+
EXPECT_EQ(value, 1);
|
| 116 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 117 |
+
EXPECT_EQ(value, 0);
|
| 118 |
+
EXPECT_TRUE(absl::ParseFlag("-1", &value, &err));
|
| 119 |
+
EXPECT_EQ(value, -1);
|
| 120 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 121 |
+
EXPECT_EQ(value, 123);
|
| 122 |
+
EXPECT_TRUE(absl::ParseFlag("-18765", &value, &err));
|
| 123 |
+
EXPECT_EQ(value, -18765);
|
| 124 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 125 |
+
EXPECT_EQ(value, 3);
|
| 126 |
+
|
| 127 |
+
// Leading zero values.
|
| 128 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 129 |
+
EXPECT_EQ(value, 1);
|
| 130 |
+
EXPECT_TRUE(absl::ParseFlag("-001", &value, &err));
|
| 131 |
+
EXPECT_EQ(value, -1);
|
| 132 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 133 |
+
EXPECT_EQ(value, 100);
|
| 134 |
+
|
| 135 |
+
// Hex values.
|
| 136 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 137 |
+
EXPECT_EQ(value, 16);
|
| 138 |
+
EXPECT_TRUE(absl::ParseFlag("0X234", &value, &err));
|
| 139 |
+
EXPECT_EQ(value, 564);
|
| 140 |
+
EXPECT_TRUE(absl::ParseFlag("-0x7FFD", &value, &err));
|
| 141 |
+
EXPECT_EQ(value, -32765);
|
| 142 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 143 |
+
EXPECT_EQ(value, 49);
|
| 144 |
+
|
| 145 |
+
// Whitespace handling
|
| 146 |
+
EXPECT_TRUE(absl::ParseFlag("10 ", &value, &err));
|
| 147 |
+
EXPECT_EQ(value, 10);
|
| 148 |
+
EXPECT_TRUE(absl::ParseFlag(" 11", &value, &err));
|
| 149 |
+
EXPECT_EQ(value, 11);
|
| 150 |
+
EXPECT_TRUE(absl::ParseFlag(" 012 ", &value, &err));
|
| 151 |
+
EXPECT_EQ(value, 12);
|
| 152 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x22 ", &value, &err));
|
| 153 |
+
EXPECT_EQ(value, 34);
|
| 154 |
+
|
| 155 |
+
// Invalid values.
|
| 156 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 157 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 158 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 159 |
+
EXPECT_FALSE(absl::ParseFlag("40000", &value, &err));
|
| 160 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 161 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 162 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 163 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 164 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// --------------------------------------------------------------------
|
| 168 |
+
|
| 169 |
+
TEST(MarshallingTest, TestUint16Parsing) {
|
| 170 |
+
std::string err;
|
| 171 |
+
uint16_t value;
|
| 172 |
+
|
| 173 |
+
// Decimal values.
|
| 174 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 175 |
+
EXPECT_EQ(value, 1);
|
| 176 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 177 |
+
EXPECT_EQ(value, 0);
|
| 178 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 179 |
+
EXPECT_EQ(value, 123);
|
| 180 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 181 |
+
EXPECT_EQ(value, 3);
|
| 182 |
+
|
| 183 |
+
// Leading zero values.
|
| 184 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 185 |
+
EXPECT_EQ(value, 1);
|
| 186 |
+
EXPECT_TRUE(absl::ParseFlag("001", &value, &err));
|
| 187 |
+
EXPECT_EQ(value, 1);
|
| 188 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 189 |
+
EXPECT_EQ(value, 100);
|
| 190 |
+
|
| 191 |
+
// Hex values.
|
| 192 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 193 |
+
EXPECT_EQ(value, 16);
|
| 194 |
+
EXPECT_TRUE(absl::ParseFlag("0X234", &value, &err));
|
| 195 |
+
EXPECT_EQ(value, 564);
|
| 196 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 197 |
+
EXPECT_EQ(value, 49);
|
| 198 |
+
|
| 199 |
+
// Whitespace handling
|
| 200 |
+
EXPECT_TRUE(absl::ParseFlag("10 ", &value, &err));
|
| 201 |
+
EXPECT_EQ(value, 10);
|
| 202 |
+
EXPECT_TRUE(absl::ParseFlag(" 11", &value, &err));
|
| 203 |
+
EXPECT_EQ(value, 11);
|
| 204 |
+
EXPECT_TRUE(absl::ParseFlag(" 012 ", &value, &err));
|
| 205 |
+
EXPECT_EQ(value, 12);
|
| 206 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x22 ", &value, &err));
|
| 207 |
+
EXPECT_EQ(value, 34);
|
| 208 |
+
|
| 209 |
+
// Invalid values.
|
| 210 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 211 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 212 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 213 |
+
EXPECT_FALSE(absl::ParseFlag("70000", &value, &err));
|
| 214 |
+
EXPECT_FALSE(absl::ParseFlag("-1", &value, &err));
|
| 215 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 216 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 217 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 218 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 219 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
// --------------------------------------------------------------------
|
| 223 |
+
|
| 224 |
+
TEST(MarshallingTest, TestInt32Parsing) {
|
| 225 |
+
std::string err;
|
| 226 |
+
int32_t value;
|
| 227 |
+
|
| 228 |
+
// Decimal values.
|
| 229 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 230 |
+
EXPECT_EQ(value, 1);
|
| 231 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 232 |
+
EXPECT_EQ(value, 0);
|
| 233 |
+
EXPECT_TRUE(absl::ParseFlag("-1", &value, &err));
|
| 234 |
+
EXPECT_EQ(value, -1);
|
| 235 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 236 |
+
EXPECT_EQ(value, 123);
|
| 237 |
+
EXPECT_TRUE(absl::ParseFlag("-98765", &value, &err));
|
| 238 |
+
EXPECT_EQ(value, -98765);
|
| 239 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 240 |
+
EXPECT_EQ(value, 3);
|
| 241 |
+
|
| 242 |
+
// Leading zero values.
|
| 243 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 244 |
+
EXPECT_EQ(value, 1);
|
| 245 |
+
EXPECT_TRUE(absl::ParseFlag("-001", &value, &err));
|
| 246 |
+
EXPECT_EQ(value, -1);
|
| 247 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 248 |
+
EXPECT_EQ(value, 100);
|
| 249 |
+
|
| 250 |
+
// Hex values.
|
| 251 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 252 |
+
EXPECT_EQ(value, 16);
|
| 253 |
+
EXPECT_TRUE(absl::ParseFlag("0X234", &value, &err));
|
| 254 |
+
EXPECT_EQ(value, 564);
|
| 255 |
+
|
| 256 |
+
EXPECT_TRUE(absl::ParseFlag("-0x7FFFFFFD", &value, &err));
|
| 257 |
+
EXPECT_EQ(value, -2147483645);
|
| 258 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 259 |
+
EXPECT_EQ(value, 49);
|
| 260 |
+
|
| 261 |
+
// Whitespace handling
|
| 262 |
+
EXPECT_TRUE(absl::ParseFlag("10 ", &value, &err));
|
| 263 |
+
EXPECT_EQ(value, 10);
|
| 264 |
+
EXPECT_TRUE(absl::ParseFlag(" 11", &value, &err));
|
| 265 |
+
EXPECT_EQ(value, 11);
|
| 266 |
+
EXPECT_TRUE(absl::ParseFlag(" 012 ", &value, &err));
|
| 267 |
+
EXPECT_EQ(value, 12);
|
| 268 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x22 ", &value, &err));
|
| 269 |
+
EXPECT_EQ(value, 34);
|
| 270 |
+
|
| 271 |
+
// Invalid values.
|
| 272 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 273 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 274 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 275 |
+
EXPECT_FALSE(absl::ParseFlag("70000000000", &value, &err));
|
| 276 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 277 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 278 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 279 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 280 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
// --------------------------------------------------------------------
|
| 284 |
+
|
| 285 |
+
TEST(MarshallingTest, TestUint32Parsing) {
|
| 286 |
+
std::string err;
|
| 287 |
+
uint32_t value;
|
| 288 |
+
|
| 289 |
+
// Decimal values.
|
| 290 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 291 |
+
EXPECT_EQ(value, 1);
|
| 292 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 293 |
+
EXPECT_EQ(value, 0);
|
| 294 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 295 |
+
EXPECT_EQ(value, 123);
|
| 296 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 297 |
+
EXPECT_EQ(value, 3);
|
| 298 |
+
|
| 299 |
+
// Leading zero values.
|
| 300 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 301 |
+
EXPECT_EQ(value, 1);
|
| 302 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 303 |
+
EXPECT_EQ(value, 100);
|
| 304 |
+
|
| 305 |
+
// Hex values.
|
| 306 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 307 |
+
EXPECT_EQ(value, 16);
|
| 308 |
+
EXPECT_TRUE(absl::ParseFlag("0X234", &value, &err));
|
| 309 |
+
EXPECT_EQ(value, 564);
|
| 310 |
+
EXPECT_TRUE(absl::ParseFlag("0xFFFFFFFD", &value, &err));
|
| 311 |
+
EXPECT_EQ(value, 4294967293);
|
| 312 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 313 |
+
EXPECT_EQ(value, 49);
|
| 314 |
+
|
| 315 |
+
// Whitespace handling
|
| 316 |
+
EXPECT_TRUE(absl::ParseFlag("10 ", &value, &err));
|
| 317 |
+
EXPECT_EQ(value, 10);
|
| 318 |
+
EXPECT_TRUE(absl::ParseFlag(" 11", &value, &err));
|
| 319 |
+
EXPECT_EQ(value, 11);
|
| 320 |
+
EXPECT_TRUE(absl::ParseFlag(" 012 ", &value, &err));
|
| 321 |
+
EXPECT_EQ(value, 12);
|
| 322 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x22 ", &value, &err));
|
| 323 |
+
EXPECT_EQ(value, 34);
|
| 324 |
+
|
| 325 |
+
// Invalid values.
|
| 326 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 327 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 328 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 329 |
+
EXPECT_FALSE(absl::ParseFlag("140000000000", &value, &err));
|
| 330 |
+
EXPECT_FALSE(absl::ParseFlag("-1", &value, &err));
|
| 331 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 332 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 333 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 334 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 335 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
// --------------------------------------------------------------------
|
| 339 |
+
|
| 340 |
+
TEST(MarshallingTest, TestInt64Parsing) {
|
| 341 |
+
std::string err;
|
| 342 |
+
int64_t value;
|
| 343 |
+
|
| 344 |
+
// Decimal values.
|
| 345 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 346 |
+
EXPECT_EQ(value, 1);
|
| 347 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 348 |
+
EXPECT_EQ(value, 0);
|
| 349 |
+
EXPECT_TRUE(absl::ParseFlag("-1", &value, &err));
|
| 350 |
+
EXPECT_EQ(value, -1);
|
| 351 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 352 |
+
EXPECT_EQ(value, 123);
|
| 353 |
+
EXPECT_TRUE(absl::ParseFlag("-98765", &value, &err));
|
| 354 |
+
EXPECT_EQ(value, -98765);
|
| 355 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 356 |
+
EXPECT_EQ(value, 3);
|
| 357 |
+
|
| 358 |
+
// Leading zero values.
|
| 359 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 360 |
+
EXPECT_EQ(value, 1);
|
| 361 |
+
EXPECT_TRUE(absl::ParseFlag("001", &value, &err));
|
| 362 |
+
EXPECT_EQ(value, 1);
|
| 363 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 364 |
+
EXPECT_EQ(value, 100);
|
| 365 |
+
|
| 366 |
+
// Hex values.
|
| 367 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 368 |
+
EXPECT_EQ(value, 16);
|
| 369 |
+
EXPECT_TRUE(absl::ParseFlag("0XFFFAAABBBCCCDDD", &value, &err));
|
| 370 |
+
EXPECT_EQ(value, 1152827684197027293);
|
| 371 |
+
EXPECT_TRUE(absl::ParseFlag("-0x7FFFFFFFFFFFFFFE", &value, &err));
|
| 372 |
+
EXPECT_EQ(value, -9223372036854775806);
|
| 373 |
+
EXPECT_TRUE(absl::ParseFlag("-0x02", &value, &err));
|
| 374 |
+
EXPECT_EQ(value, -2);
|
| 375 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 376 |
+
EXPECT_EQ(value, 49);
|
| 377 |
+
|
| 378 |
+
// Whitespace handling
|
| 379 |
+
EXPECT_TRUE(absl::ParseFlag("10 ", &value, &err));
|
| 380 |
+
EXPECT_EQ(value, 10);
|
| 381 |
+
EXPECT_TRUE(absl::ParseFlag(" 11", &value, &err));
|
| 382 |
+
EXPECT_EQ(value, 11);
|
| 383 |
+
EXPECT_TRUE(absl::ParseFlag(" 012 ", &value, &err));
|
| 384 |
+
EXPECT_EQ(value, 12);
|
| 385 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x7F ", &value, &err));
|
| 386 |
+
EXPECT_EQ(value, 127);
|
| 387 |
+
|
| 388 |
+
// Invalid values.
|
| 389 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 390 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 391 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 392 |
+
EXPECT_FALSE(absl::ParseFlag("0xFFFFFFFFFFFFFFFFFF", &value, &err));
|
| 393 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 394 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 395 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 396 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 397 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
// --------------------------------------------------------------------
|
| 401 |
+
|
| 402 |
+
TEST(MarshallingTest, TestUInt64Parsing) {
|
| 403 |
+
std::string err;
|
| 404 |
+
uint64_t value;
|
| 405 |
+
|
| 406 |
+
// Decimal values.
|
| 407 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 408 |
+
EXPECT_EQ(value, 1);
|
| 409 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 410 |
+
EXPECT_EQ(value, 0);
|
| 411 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 412 |
+
EXPECT_EQ(value, 123);
|
| 413 |
+
EXPECT_TRUE(absl::ParseFlag("+13", &value, &err));
|
| 414 |
+
EXPECT_EQ(value, 13);
|
| 415 |
+
|
| 416 |
+
// Leading zero values.
|
| 417 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 418 |
+
EXPECT_EQ(value, 1);
|
| 419 |
+
EXPECT_TRUE(absl::ParseFlag("001", &value, &err));
|
| 420 |
+
EXPECT_EQ(value, 1);
|
| 421 |
+
EXPECT_TRUE(absl::ParseFlag("0000300", &value, &err));
|
| 422 |
+
EXPECT_EQ(value, 300);
|
| 423 |
+
|
| 424 |
+
// Hex values.
|
| 425 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 426 |
+
EXPECT_EQ(value, 16);
|
| 427 |
+
EXPECT_TRUE(absl::ParseFlag("0XFFFF", &value, &err));
|
| 428 |
+
EXPECT_EQ(value, 65535);
|
| 429 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 430 |
+
EXPECT_EQ(value, 49);
|
| 431 |
+
|
| 432 |
+
// Whitespace handling
|
| 433 |
+
EXPECT_TRUE(absl::ParseFlag("10 ", &value, &err));
|
| 434 |
+
EXPECT_EQ(value, 10);
|
| 435 |
+
EXPECT_TRUE(absl::ParseFlag(" 11", &value, &err));
|
| 436 |
+
EXPECT_EQ(value, 11);
|
| 437 |
+
EXPECT_TRUE(absl::ParseFlag(" 012 ", &value, &err));
|
| 438 |
+
EXPECT_EQ(value, 12);
|
| 439 |
+
|
| 440 |
+
// Invalid values.
|
| 441 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 442 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 443 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 444 |
+
EXPECT_FALSE(absl::ParseFlag("0xFFFFFFFFFFFFFFFFFF", &value, &err));
|
| 445 |
+
EXPECT_FALSE(absl::ParseFlag("-1", &value, &err));
|
| 446 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 447 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 448 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 449 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 450 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
// --------------------------------------------------------------------
|
| 454 |
+
|
| 455 |
+
TEST(MarshallingTest, TestInt128Parsing) {
|
| 456 |
+
std::string err;
|
| 457 |
+
absl::int128 value;
|
| 458 |
+
|
| 459 |
+
// Decimal values.
|
| 460 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 461 |
+
EXPECT_EQ(value, 0);
|
| 462 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 463 |
+
EXPECT_EQ(value, 1);
|
| 464 |
+
EXPECT_TRUE(absl::ParseFlag("-1", &value, &err));
|
| 465 |
+
EXPECT_EQ(value, -1);
|
| 466 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 467 |
+
EXPECT_EQ(value, 123);
|
| 468 |
+
EXPECT_TRUE(absl::ParseFlag("-98765", &value, &err));
|
| 469 |
+
EXPECT_EQ(value, -98765);
|
| 470 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 471 |
+
EXPECT_EQ(value, 3);
|
| 472 |
+
|
| 473 |
+
// Leading zero values.
|
| 474 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 475 |
+
EXPECT_EQ(value, 1);
|
| 476 |
+
EXPECT_TRUE(absl::ParseFlag("001", &value, &err));
|
| 477 |
+
EXPECT_EQ(value, 1);
|
| 478 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 479 |
+
EXPECT_EQ(value, 100);
|
| 480 |
+
|
| 481 |
+
// Hex values.
|
| 482 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 483 |
+
EXPECT_EQ(value, 16);
|
| 484 |
+
EXPECT_TRUE(absl::ParseFlag("0xFFFAAABBBCCCDDD", &value, &err));
|
| 485 |
+
EXPECT_EQ(value, 1152827684197027293);
|
| 486 |
+
EXPECT_TRUE(absl::ParseFlag("0xFFF0FFFFFFFFFFFFFFF", &value, &err));
|
| 487 |
+
EXPECT_EQ(value, absl::MakeInt128(0x000000000000fff, 0xFFFFFFFFFFFFFFF));
|
| 488 |
+
|
| 489 |
+
EXPECT_TRUE(absl::ParseFlag("-0x10000000000000000", &value, &err));
|
| 490 |
+
EXPECT_EQ(value, absl::MakeInt128(-1, 0));
|
| 491 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 492 |
+
EXPECT_EQ(value, 49);
|
| 493 |
+
|
| 494 |
+
// Whitespace handling
|
| 495 |
+
EXPECT_TRUE(absl::ParseFlag("16 ", &value, &err));
|
| 496 |
+
EXPECT_EQ(value, 16);
|
| 497 |
+
EXPECT_TRUE(absl::ParseFlag(" 16", &value, &err));
|
| 498 |
+
EXPECT_EQ(value, 16);
|
| 499 |
+
EXPECT_TRUE(absl::ParseFlag(" 0100 ", &value, &err));
|
| 500 |
+
EXPECT_EQ(value, 100);
|
| 501 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x7B ", &value, &err));
|
| 502 |
+
EXPECT_EQ(value, 123);
|
| 503 |
+
|
| 504 |
+
// Invalid values.
|
| 505 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 506 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 507 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 508 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 509 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 510 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 511 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 512 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
// --------------------------------------------------------------------
|
| 516 |
+
|
| 517 |
+
TEST(MarshallingTest, TestUint128Parsing) {
|
| 518 |
+
std::string err;
|
| 519 |
+
absl::uint128 value;
|
| 520 |
+
|
| 521 |
+
// Decimal values.
|
| 522 |
+
EXPECT_TRUE(absl::ParseFlag("0", &value, &err));
|
| 523 |
+
EXPECT_EQ(value, 0);
|
| 524 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 525 |
+
EXPECT_EQ(value, 1);
|
| 526 |
+
EXPECT_TRUE(absl::ParseFlag("123", &value, &err));
|
| 527 |
+
EXPECT_EQ(value, 123);
|
| 528 |
+
EXPECT_TRUE(absl::ParseFlag("+3", &value, &err));
|
| 529 |
+
EXPECT_EQ(value, 3);
|
| 530 |
+
|
| 531 |
+
// Leading zero values.
|
| 532 |
+
EXPECT_TRUE(absl::ParseFlag("01", &value, &err));
|
| 533 |
+
EXPECT_EQ(value, 1);
|
| 534 |
+
EXPECT_TRUE(absl::ParseFlag("001", &value, &err));
|
| 535 |
+
EXPECT_EQ(value, 1);
|
| 536 |
+
EXPECT_TRUE(absl::ParseFlag("0000100", &value, &err));
|
| 537 |
+
EXPECT_EQ(value, 100);
|
| 538 |
+
|
| 539 |
+
// Hex values.
|
| 540 |
+
EXPECT_TRUE(absl::ParseFlag("0x10", &value, &err));
|
| 541 |
+
EXPECT_EQ(value, 16);
|
| 542 |
+
EXPECT_TRUE(absl::ParseFlag("0xFFFAAABBBCCCDDD", &value, &err));
|
| 543 |
+
EXPECT_EQ(value, 1152827684197027293);
|
| 544 |
+
EXPECT_TRUE(absl::ParseFlag("0xFFF0FFFFFFFFFFFFFFF", &value, &err));
|
| 545 |
+
EXPECT_EQ(value, absl::MakeInt128(0x000000000000fff, 0xFFFFFFFFFFFFFFF));
|
| 546 |
+
EXPECT_TRUE(absl::ParseFlag("+0x31", &value, &err));
|
| 547 |
+
EXPECT_EQ(value, 49);
|
| 548 |
+
|
| 549 |
+
// Whitespace handling
|
| 550 |
+
EXPECT_TRUE(absl::ParseFlag("16 ", &value, &err));
|
| 551 |
+
EXPECT_EQ(value, 16);
|
| 552 |
+
EXPECT_TRUE(absl::ParseFlag(" 16", &value, &err));
|
| 553 |
+
EXPECT_EQ(value, 16);
|
| 554 |
+
EXPECT_TRUE(absl::ParseFlag(" 0100 ", &value, &err));
|
| 555 |
+
EXPECT_EQ(value, 100);
|
| 556 |
+
EXPECT_TRUE(absl::ParseFlag(" 0x7B ", &value, &err));
|
| 557 |
+
EXPECT_EQ(value, 123);
|
| 558 |
+
|
| 559 |
+
// Invalid values.
|
| 560 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 561 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 562 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 563 |
+
EXPECT_FALSE(absl::ParseFlag("-1", &value, &err));
|
| 564 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 565 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 566 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 567 |
+
EXPECT_FALSE(absl::ParseFlag("2U", &value, &err));
|
| 568 |
+
EXPECT_FALSE(absl::ParseFlag("FFF", &value, &err));
|
| 569 |
+
EXPECT_FALSE(absl::ParseFlag("-0x10000000000000000", &value, &err));
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
// --------------------------------------------------------------------
|
| 573 |
+
|
| 574 |
+
TEST(MarshallingTest, TestFloatParsing) {
|
| 575 |
+
std::string err;
|
| 576 |
+
float value;
|
| 577 |
+
|
| 578 |
+
// Ordinary values.
|
| 579 |
+
EXPECT_TRUE(absl::ParseFlag("1.3", &value, &err));
|
| 580 |
+
EXPECT_FLOAT_EQ(value, 1.3f);
|
| 581 |
+
EXPECT_TRUE(absl::ParseFlag("-0.1", &value, &err));
|
| 582 |
+
EXPECT_DOUBLE_EQ(value, -0.1f);
|
| 583 |
+
EXPECT_TRUE(absl::ParseFlag("+0.01", &value, &err));
|
| 584 |
+
EXPECT_DOUBLE_EQ(value, 0.01f);
|
| 585 |
+
|
| 586 |
+
// Scientific values.
|
| 587 |
+
EXPECT_TRUE(absl::ParseFlag("1.2e3", &value, &err));
|
| 588 |
+
EXPECT_DOUBLE_EQ(value, 1.2e3f);
|
| 589 |
+
EXPECT_TRUE(absl::ParseFlag("9.8765402e-37", &value, &err));
|
| 590 |
+
EXPECT_DOUBLE_EQ(value, 9.8765402e-37f);
|
| 591 |
+
EXPECT_TRUE(absl::ParseFlag("0.11e+3", &value, &err));
|
| 592 |
+
EXPECT_DOUBLE_EQ(value, 0.11e+3f);
|
| 593 |
+
EXPECT_TRUE(absl::ParseFlag("1.e-2300", &value, &err));
|
| 594 |
+
EXPECT_DOUBLE_EQ(value, 0.f);
|
| 595 |
+
EXPECT_TRUE(absl::ParseFlag("1.e+2300", &value, &err));
|
| 596 |
+
EXPECT_TRUE(std::isinf(value));
|
| 597 |
+
|
| 598 |
+
// Leading zero values.
|
| 599 |
+
EXPECT_TRUE(absl::ParseFlag("01.6", &value, &err));
|
| 600 |
+
EXPECT_DOUBLE_EQ(value, 1.6f);
|
| 601 |
+
EXPECT_TRUE(absl::ParseFlag("000.0001", &value, &err));
|
| 602 |
+
EXPECT_DOUBLE_EQ(value, 0.0001f);
|
| 603 |
+
|
| 604 |
+
// Trailing zero values.
|
| 605 |
+
EXPECT_TRUE(absl::ParseFlag("-5.1000", &value, &err));
|
| 606 |
+
EXPECT_DOUBLE_EQ(value, -5.1f);
|
| 607 |
+
|
| 608 |
+
// Exceptional values.
|
| 609 |
+
EXPECT_TRUE(absl::ParseFlag("NaN", &value, &err));
|
| 610 |
+
EXPECT_TRUE(std::isnan(value));
|
| 611 |
+
EXPECT_TRUE(absl::ParseFlag("Inf", &value, &err));
|
| 612 |
+
EXPECT_TRUE(std::isinf(value));
|
| 613 |
+
|
| 614 |
+
// Hex values
|
| 615 |
+
EXPECT_TRUE(absl::ParseFlag("0x10.23p12", &value, &err));
|
| 616 |
+
EXPECT_DOUBLE_EQ(value, 66096.f);
|
| 617 |
+
EXPECT_TRUE(absl::ParseFlag("-0xF1.A3p-2", &value, &err));
|
| 618 |
+
EXPECT_NEAR(value, -60.4092f, 5e-5f);
|
| 619 |
+
EXPECT_TRUE(absl::ParseFlag("+0x0.0AAp-12", &value, &err));
|
| 620 |
+
EXPECT_NEAR(value, 1.01328e-05f, 5e-11f);
|
| 621 |
+
EXPECT_TRUE(absl::ParseFlag("0x.01p1", &value, &err));
|
| 622 |
+
EXPECT_NEAR(value, 0.0078125f, 5e-8f);
|
| 623 |
+
|
| 624 |
+
// Whitespace handling
|
| 625 |
+
EXPECT_TRUE(absl::ParseFlag("10.1 ", &value, &err));
|
| 626 |
+
EXPECT_DOUBLE_EQ(value, 10.1f);
|
| 627 |
+
EXPECT_TRUE(absl::ParseFlag(" 2.34", &value, &err));
|
| 628 |
+
EXPECT_DOUBLE_EQ(value, 2.34f);
|
| 629 |
+
EXPECT_TRUE(absl::ParseFlag(" 5.7 ", &value, &err));
|
| 630 |
+
EXPECT_DOUBLE_EQ(value, 5.7f);
|
| 631 |
+
EXPECT_TRUE(absl::ParseFlag(" -0xE0.F3p01 ", &value, &err));
|
| 632 |
+
EXPECT_NEAR(value, -449.8984375f, 5e-8f);
|
| 633 |
+
|
| 634 |
+
// Invalid values.
|
| 635 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 636 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 637 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 638 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 639 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 640 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 641 |
+
EXPECT_FALSE(absl::ParseFlag("2.3xxx", &value, &err));
|
| 642 |
+
EXPECT_FALSE(absl::ParseFlag("0x0.1pAA", &value, &err));
|
| 643 |
+
// TODO(rogeeff): below assertion should fail
|
| 644 |
+
EXPECT_TRUE(absl::ParseFlag("0x0.1", &value, &err));
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
// --------------------------------------------------------------------
|
| 648 |
+
|
| 649 |
+
TEST(MarshallingTest, TestDoubleParsing) {
|
| 650 |
+
std::string err;
|
| 651 |
+
double value;
|
| 652 |
+
|
| 653 |
+
// Ordinary values.
|
| 654 |
+
EXPECT_TRUE(absl::ParseFlag("1.3", &value, &err));
|
| 655 |
+
EXPECT_DOUBLE_EQ(value, 1.3);
|
| 656 |
+
EXPECT_TRUE(absl::ParseFlag("-0.1", &value, &err));
|
| 657 |
+
EXPECT_DOUBLE_EQ(value, -0.1);
|
| 658 |
+
EXPECT_TRUE(absl::ParseFlag("+0.01", &value, &err));
|
| 659 |
+
EXPECT_DOUBLE_EQ(value, 0.01);
|
| 660 |
+
|
| 661 |
+
// Scientific values.
|
| 662 |
+
EXPECT_TRUE(absl::ParseFlag("1.2e3", &value, &err));
|
| 663 |
+
EXPECT_DOUBLE_EQ(value, 1.2e3);
|
| 664 |
+
EXPECT_TRUE(absl::ParseFlag("9.00000002e-123", &value, &err));
|
| 665 |
+
EXPECT_DOUBLE_EQ(value, 9.00000002e-123);
|
| 666 |
+
EXPECT_TRUE(absl::ParseFlag("0.11e+3", &value, &err));
|
| 667 |
+
EXPECT_DOUBLE_EQ(value, 0.11e+3);
|
| 668 |
+
EXPECT_TRUE(absl::ParseFlag("1.e-2300", &value, &err));
|
| 669 |
+
EXPECT_DOUBLE_EQ(value, 0);
|
| 670 |
+
EXPECT_TRUE(absl::ParseFlag("1.e+2300", &value, &err));
|
| 671 |
+
EXPECT_TRUE(std::isinf(value));
|
| 672 |
+
|
| 673 |
+
// Leading zero values.
|
| 674 |
+
EXPECT_TRUE(absl::ParseFlag("01.6", &value, &err));
|
| 675 |
+
EXPECT_DOUBLE_EQ(value, 1.6);
|
| 676 |
+
EXPECT_TRUE(absl::ParseFlag("000.0001", &value, &err));
|
| 677 |
+
EXPECT_DOUBLE_EQ(value, 0.0001);
|
| 678 |
+
|
| 679 |
+
// Trailing zero values.
|
| 680 |
+
EXPECT_TRUE(absl::ParseFlag("-5.1000", &value, &err));
|
| 681 |
+
EXPECT_DOUBLE_EQ(value, -5.1);
|
| 682 |
+
|
| 683 |
+
// Exceptional values.
|
| 684 |
+
EXPECT_TRUE(absl::ParseFlag("NaN", &value, &err));
|
| 685 |
+
EXPECT_TRUE(std::isnan(value));
|
| 686 |
+
EXPECT_TRUE(absl::ParseFlag("nan", &value, &err));
|
| 687 |
+
EXPECT_TRUE(std::isnan(value));
|
| 688 |
+
EXPECT_TRUE(absl::ParseFlag("Inf", &value, &err));
|
| 689 |
+
EXPECT_TRUE(std::isinf(value));
|
| 690 |
+
EXPECT_TRUE(absl::ParseFlag("inf", &value, &err));
|
| 691 |
+
EXPECT_TRUE(std::isinf(value));
|
| 692 |
+
|
| 693 |
+
// Hex values
|
| 694 |
+
EXPECT_TRUE(absl::ParseFlag("0x10.23p12", &value, &err));
|
| 695 |
+
EXPECT_DOUBLE_EQ(value, 66096);
|
| 696 |
+
EXPECT_TRUE(absl::ParseFlag("-0xF1.A3p-2", &value, &err));
|
| 697 |
+
EXPECT_NEAR(value, -60.4092, 5e-5);
|
| 698 |
+
EXPECT_TRUE(absl::ParseFlag("+0x0.0AAp-12", &value, &err));
|
| 699 |
+
EXPECT_NEAR(value, 1.01328e-05, 5e-11);
|
| 700 |
+
EXPECT_TRUE(absl::ParseFlag("0x.01p1", &value, &err));
|
| 701 |
+
EXPECT_NEAR(value, 0.0078125, 5e-8);
|
| 702 |
+
|
| 703 |
+
// Whitespace handling
|
| 704 |
+
EXPECT_TRUE(absl::ParseFlag("10.1 ", &value, &err));
|
| 705 |
+
EXPECT_DOUBLE_EQ(value, 10.1);
|
| 706 |
+
EXPECT_TRUE(absl::ParseFlag(" 2.34", &value, &err));
|
| 707 |
+
EXPECT_DOUBLE_EQ(value, 2.34);
|
| 708 |
+
EXPECT_TRUE(absl::ParseFlag(" 5.7 ", &value, &err));
|
| 709 |
+
EXPECT_DOUBLE_EQ(value, 5.7);
|
| 710 |
+
EXPECT_TRUE(absl::ParseFlag(" -0xE0.F3p01 ", &value, &err));
|
| 711 |
+
EXPECT_NEAR(value, -449.8984375, 5e-8);
|
| 712 |
+
|
| 713 |
+
// Invalid values.
|
| 714 |
+
EXPECT_FALSE(absl::ParseFlag("", &value, &err));
|
| 715 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 716 |
+
EXPECT_FALSE(absl::ParseFlag(" ", &value, &err));
|
| 717 |
+
EXPECT_FALSE(absl::ParseFlag("--1", &value, &err));
|
| 718 |
+
EXPECT_FALSE(absl::ParseFlag("\n", &value, &err));
|
| 719 |
+
EXPECT_FALSE(absl::ParseFlag("\t", &value, &err));
|
| 720 |
+
EXPECT_FALSE(absl::ParseFlag("2.3xxx", &value, &err));
|
| 721 |
+
EXPECT_FALSE(absl::ParseFlag("0x0.1pAA", &value, &err));
|
| 722 |
+
// TODO(rogeeff): below assertion should fail
|
| 723 |
+
EXPECT_TRUE(absl::ParseFlag("0x0.1", &value, &err));
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
// --------------------------------------------------------------------
|
| 727 |
+
|
| 728 |
+
TEST(MarshallingTest, TestStringParsing) {
|
| 729 |
+
std::string err;
|
| 730 |
+
std::string value;
|
| 731 |
+
|
| 732 |
+
EXPECT_TRUE(absl::ParseFlag("", &value, &err));
|
| 733 |
+
EXPECT_EQ(value, "");
|
| 734 |
+
EXPECT_TRUE(absl::ParseFlag(" ", &value, &err));
|
| 735 |
+
EXPECT_EQ(value, " ");
|
| 736 |
+
EXPECT_TRUE(absl::ParseFlag(" ", &value, &err));
|
| 737 |
+
EXPECT_EQ(value, " ");
|
| 738 |
+
EXPECT_TRUE(absl::ParseFlag("\n", &value, &err));
|
| 739 |
+
EXPECT_EQ(value, "\n");
|
| 740 |
+
EXPECT_TRUE(absl::ParseFlag("\t", &value, &err));
|
| 741 |
+
EXPECT_EQ(value, "\t");
|
| 742 |
+
EXPECT_TRUE(absl::ParseFlag("asdfg", &value, &err));
|
| 743 |
+
EXPECT_EQ(value, "asdfg");
|
| 744 |
+
EXPECT_TRUE(absl::ParseFlag("asdf ghjk", &value, &err));
|
| 745 |
+
EXPECT_EQ(value, "asdf ghjk");
|
| 746 |
+
EXPECT_TRUE(absl::ParseFlag("a\nb\nc", &value, &err));
|
| 747 |
+
EXPECT_EQ(value, "a\nb\nc");
|
| 748 |
+
EXPECT_TRUE(absl::ParseFlag("asd\0fgh", &value, &err));
|
| 749 |
+
EXPECT_EQ(value, "asd");
|
| 750 |
+
EXPECT_TRUE(absl::ParseFlag("\\\\", &value, &err));
|
| 751 |
+
EXPECT_EQ(value, "\\\\");
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
// --------------------------------------------------------------------
|
| 755 |
+
|
| 756 |
+
TEST(MarshallingTest, TestVectorOfStringParsing) {
|
| 757 |
+
std::string err;
|
| 758 |
+
std::vector<std::string> value;
|
| 759 |
+
|
| 760 |
+
EXPECT_TRUE(absl::ParseFlag("", &value, &err));
|
| 761 |
+
EXPECT_EQ(value, std::vector<std::string>{});
|
| 762 |
+
EXPECT_TRUE(absl::ParseFlag("1", &value, &err));
|
| 763 |
+
EXPECT_EQ(value, std::vector<std::string>({"1"}));
|
| 764 |
+
EXPECT_TRUE(absl::ParseFlag("a,b", &value, &err));
|
| 765 |
+
EXPECT_EQ(value, std::vector<std::string>({"a", "b"}));
|
| 766 |
+
EXPECT_TRUE(absl::ParseFlag("a,b,c,", &value, &err));
|
| 767 |
+
EXPECT_EQ(value, std::vector<std::string>({"a", "b", "c", ""}));
|
| 768 |
+
EXPECT_TRUE(absl::ParseFlag("a,,", &value, &err));
|
| 769 |
+
EXPECT_EQ(value, std::vector<std::string>({"a", "", ""}));
|
| 770 |
+
EXPECT_TRUE(absl::ParseFlag(",", &value, &err));
|
| 771 |
+
EXPECT_EQ(value, std::vector<std::string>({"", ""}));
|
| 772 |
+
EXPECT_TRUE(absl::ParseFlag("a, b,c ", &value, &err));
|
| 773 |
+
EXPECT_EQ(value, std::vector<std::string>({"a", " b", "c "}));
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
// --------------------------------------------------------------------
|
| 777 |
+
|
| 778 |
+
TEST(MarshallingTest, TestOptionalBoolParsing) {
|
| 779 |
+
std::string err;
|
| 780 |
+
absl::optional<bool> value;
|
| 781 |
+
|
| 782 |
+
EXPECT_TRUE(absl::ParseFlag("", &value, &err));
|
| 783 |
+
EXPECT_FALSE(value.has_value());
|
| 784 |
+
|
| 785 |
+
EXPECT_TRUE(absl::ParseFlag("true", &value, &err));
|
| 786 |
+
EXPECT_TRUE(value.has_value());
|
| 787 |
+
EXPECT_TRUE(*value);
|
| 788 |
+
|
| 789 |
+
EXPECT_TRUE(absl::ParseFlag("false", &value, &err));
|
| 790 |
+
EXPECT_TRUE(value.has_value());
|
| 791 |
+
EXPECT_FALSE(*value);
|
| 792 |
+
|
| 793 |
+
EXPECT_FALSE(absl::ParseFlag("nullopt", &value, &err));
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
// --------------------------------------------------------------------
|
| 797 |
+
|
| 798 |
+
TEST(MarshallingTest, TestOptionalIntParsing) {
|
| 799 |
+
std::string err;
|
| 800 |
+
absl::optional<int> value;
|
| 801 |
+
|
| 802 |
+
EXPECT_TRUE(absl::ParseFlag("", &value, &err));
|
| 803 |
+
EXPECT_FALSE(value.has_value());
|
| 804 |
+
|
| 805 |
+
EXPECT_TRUE(absl::ParseFlag("10", &value, &err));
|
| 806 |
+
EXPECT_TRUE(value.has_value());
|
| 807 |
+
EXPECT_EQ(*value, 10);
|
| 808 |
+
|
| 809 |
+
EXPECT_TRUE(absl::ParseFlag("0x1F", &value, &err));
|
| 810 |
+
EXPECT_TRUE(value.has_value());
|
| 811 |
+
EXPECT_EQ(*value, 31);
|
| 812 |
+
|
| 813 |
+
EXPECT_FALSE(absl::ParseFlag("nullopt", &value, &err));
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
// --------------------------------------------------------------------
|
| 817 |
+
|
| 818 |
+
TEST(MarshallingTest, TestOptionalDoubleParsing) {
|
| 819 |
+
std::string err;
|
| 820 |
+
absl::optional<double> value;
|
| 821 |
+
|
| 822 |
+
EXPECT_TRUE(absl::ParseFlag("", &value, &err));
|
| 823 |
+
EXPECT_FALSE(value.has_value());
|
| 824 |
+
|
| 825 |
+
EXPECT_TRUE(absl::ParseFlag("1.11", &value, &err));
|
| 826 |
+
EXPECT_TRUE(value.has_value());
|
| 827 |
+
EXPECT_EQ(*value, 1.11);
|
| 828 |
+
|
| 829 |
+
EXPECT_TRUE(absl::ParseFlag("-0.12", &value, &err));
|
| 830 |
+
EXPECT_TRUE(value.has_value());
|
| 831 |
+
EXPECT_EQ(*value, -0.12);
|
| 832 |
+
|
| 833 |
+
EXPECT_FALSE(absl::ParseFlag("nullopt", &value, &err));
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
// --------------------------------------------------------------------
|
| 837 |
+
|
| 838 |
+
TEST(MarshallingTest, TestOptionalStringParsing) {
|
| 839 |
+
std::string err;
|
| 840 |
+
absl::optional<std::string> value;
|
| 841 |
+
|
| 842 |
+
EXPECT_TRUE(absl::ParseFlag("", &value, &err));
|
| 843 |
+
EXPECT_FALSE(value.has_value());
|
| 844 |
+
|
| 845 |
+
EXPECT_TRUE(absl::ParseFlag(" ", &value, &err));
|
| 846 |
+
EXPECT_TRUE(value.has_value());
|
| 847 |
+
EXPECT_EQ(*value, " ");
|
| 848 |
+
|
| 849 |
+
EXPECT_TRUE(absl::ParseFlag("aqswde", &value, &err));
|
| 850 |
+
EXPECT_TRUE(value.has_value());
|
| 851 |
+
EXPECT_EQ(*value, "aqswde");
|
| 852 |
+
|
| 853 |
+
EXPECT_TRUE(absl::ParseFlag("nullopt", &value, &err));
|
| 854 |
+
EXPECT_TRUE(value.has_value());
|
| 855 |
+
EXPECT_EQ(*value, "nullopt");
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
// --------------------------------------------------------------------
|
| 859 |
+
|
| 860 |
+
TEST(MarshallingTest, TestBoolUnparsing) {
|
| 861 |
+
EXPECT_EQ(absl::UnparseFlag(true), "true");
|
| 862 |
+
EXPECT_EQ(absl::UnparseFlag(false), "false");
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
// --------------------------------------------------------------------
|
| 866 |
+
|
| 867 |
+
TEST(MarshallingTest, TestInt16Unparsing) {
|
| 868 |
+
int16_t value;
|
| 869 |
+
|
| 870 |
+
value = 1;
|
| 871 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 872 |
+
value = 0;
|
| 873 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 874 |
+
value = -1;
|
| 875 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-1");
|
| 876 |
+
value = 9876;
|
| 877 |
+
EXPECT_EQ(absl::UnparseFlag(value), "9876");
|
| 878 |
+
value = -987;
|
| 879 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-987");
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
// --------------------------------------------------------------------
|
| 883 |
+
|
| 884 |
+
TEST(MarshallingTest, TestUint16Unparsing) {
|
| 885 |
+
uint16_t value;
|
| 886 |
+
|
| 887 |
+
value = 1;
|
| 888 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 889 |
+
value = 0;
|
| 890 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 891 |
+
value = 19876;
|
| 892 |
+
EXPECT_EQ(absl::UnparseFlag(value), "19876");
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
// --------------------------------------------------------------------
|
| 896 |
+
|
| 897 |
+
TEST(MarshallingTest, TestInt32Unparsing) {
|
| 898 |
+
int32_t value;
|
| 899 |
+
|
| 900 |
+
value = 1;
|
| 901 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 902 |
+
value = 0;
|
| 903 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 904 |
+
value = -1;
|
| 905 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-1");
|
| 906 |
+
value = 12345;
|
| 907 |
+
EXPECT_EQ(absl::UnparseFlag(value), "12345");
|
| 908 |
+
value = -987;
|
| 909 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-987");
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
// --------------------------------------------------------------------
|
| 913 |
+
|
| 914 |
+
TEST(MarshallingTest, TestUint32Unparsing) {
|
| 915 |
+
uint32_t value;
|
| 916 |
+
|
| 917 |
+
value = 1;
|
| 918 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 919 |
+
value = 0;
|
| 920 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 921 |
+
value = 1234500;
|
| 922 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1234500");
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
// --------------------------------------------------------------------
|
| 926 |
+
|
| 927 |
+
TEST(MarshallingTest, TestInt64Unparsing) {
|
| 928 |
+
int64_t value;
|
| 929 |
+
|
| 930 |
+
value = 1;
|
| 931 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 932 |
+
value = 0;
|
| 933 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 934 |
+
value = -1;
|
| 935 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-1");
|
| 936 |
+
value = 123456789L;
|
| 937 |
+
EXPECT_EQ(absl::UnparseFlag(value), "123456789");
|
| 938 |
+
value = -987654321L;
|
| 939 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-987654321");
|
| 940 |
+
value = 0x7FFFFFFFFFFFFFFF;
|
| 941 |
+
EXPECT_EQ(absl::UnparseFlag(value), "9223372036854775807");
|
| 942 |
+
value = 0xFFFFFFFFFFFFFFFF;
|
| 943 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-1");
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
// --------------------------------------------------------------------
|
| 947 |
+
|
| 948 |
+
TEST(MarshallingTest, TestUint64Unparsing) {
|
| 949 |
+
uint64_t value;
|
| 950 |
+
|
| 951 |
+
value = 1;
|
| 952 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 953 |
+
value = 0;
|
| 954 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 955 |
+
value = 123456789L;
|
| 956 |
+
EXPECT_EQ(absl::UnparseFlag(value), "123456789");
|
| 957 |
+
value = 0xFFFFFFFFFFFFFFFF;
|
| 958 |
+
EXPECT_EQ(absl::UnparseFlag(value), "18446744073709551615");
|
| 959 |
+
}
|
| 960 |
+
|
| 961 |
+
// --------------------------------------------------------------------
|
| 962 |
+
|
| 963 |
+
TEST(MarshallingTest, TestInt128Unparsing) {
|
| 964 |
+
absl::int128 value;
|
| 965 |
+
|
| 966 |
+
value = 1;
|
| 967 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 968 |
+
value = 0;
|
| 969 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 970 |
+
value = -1;
|
| 971 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-1");
|
| 972 |
+
value = 123456789L;
|
| 973 |
+
EXPECT_EQ(absl::UnparseFlag(value), "123456789");
|
| 974 |
+
value = -987654321L;
|
| 975 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-987654321");
|
| 976 |
+
value = 0x7FFFFFFFFFFFFFFF;
|
| 977 |
+
EXPECT_EQ(absl::UnparseFlag(value), "9223372036854775807");
|
| 978 |
+
}
|
| 979 |
+
|
| 980 |
+
// --------------------------------------------------------------------
|
| 981 |
+
|
| 982 |
+
TEST(MarshallingTest, TestUint128Unparsing) {
|
| 983 |
+
absl::uint128 value;
|
| 984 |
+
|
| 985 |
+
value = 1;
|
| 986 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 987 |
+
value = 0;
|
| 988 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 989 |
+
value = 123456789L;
|
| 990 |
+
EXPECT_EQ(absl::UnparseFlag(value), "123456789");
|
| 991 |
+
value = absl::MakeUint128(0, 0xFFFFFFFFFFFFFFFF);
|
| 992 |
+
EXPECT_EQ(absl::UnparseFlag(value), "18446744073709551615");
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
// --------------------------------------------------------------------
|
| 996 |
+
|
| 997 |
+
TEST(MarshallingTest, TestFloatUnparsing) {
|
| 998 |
+
float value;
|
| 999 |
+
|
| 1000 |
+
value = 1.1f;
|
| 1001 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1.1");
|
| 1002 |
+
value = 0.01f;
|
| 1003 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0.01");
|
| 1004 |
+
value = 1.23e-2f;
|
| 1005 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0.0123");
|
| 1006 |
+
value = -0.71f;
|
| 1007 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-0.71");
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
// --------------------------------------------------------------------
|
| 1011 |
+
|
| 1012 |
+
TEST(MarshallingTest, TestDoubleUnparsing) {
|
| 1013 |
+
double value;
|
| 1014 |
+
|
| 1015 |
+
value = 1.1;
|
| 1016 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1.1");
|
| 1017 |
+
value = 0.01;
|
| 1018 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0.01");
|
| 1019 |
+
value = 1.23e-2;
|
| 1020 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0.0123");
|
| 1021 |
+
value = -0.71;
|
| 1022 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-0.71");
|
| 1023 |
+
value = -0;
|
| 1024 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 1025 |
+
value = std::nan("");
|
| 1026 |
+
EXPECT_EQ(absl::UnparseFlag(value), "nan");
|
| 1027 |
+
value = std::numeric_limits<double>::infinity();
|
| 1028 |
+
EXPECT_EQ(absl::UnparseFlag(value), "inf");
|
| 1029 |
+
}
|
| 1030 |
+
|
| 1031 |
+
// --------------------------------------------------------------------
|
| 1032 |
+
|
| 1033 |
+
TEST(MarshallingTest, TestStringUnparsing) {
|
| 1034 |
+
EXPECT_EQ(absl::UnparseFlag(""), "");
|
| 1035 |
+
EXPECT_EQ(absl::UnparseFlag(" "), " ");
|
| 1036 |
+
EXPECT_EQ(absl::UnparseFlag("qwerty"), "qwerty");
|
| 1037 |
+
EXPECT_EQ(absl::UnparseFlag("ASDFGH"), "ASDFGH");
|
| 1038 |
+
EXPECT_EQ(absl::UnparseFlag("\n\t "), "\n\t ");
|
| 1039 |
+
}
|
| 1040 |
+
|
| 1041 |
+
// --------------------------------------------------------------------
|
| 1042 |
+
|
| 1043 |
+
TEST(MarshallingTest, TestOptionalBoolUnparsing) {
|
| 1044 |
+
absl::optional<bool> value;
|
| 1045 |
+
|
| 1046 |
+
EXPECT_EQ(absl::UnparseFlag(value), "");
|
| 1047 |
+
value = true;
|
| 1048 |
+
EXPECT_EQ(absl::UnparseFlag(value), "true");
|
| 1049 |
+
value = false;
|
| 1050 |
+
EXPECT_EQ(absl::UnparseFlag(value), "false");
|
| 1051 |
+
value = absl::nullopt;
|
| 1052 |
+
EXPECT_EQ(absl::UnparseFlag(value), "");
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
// --------------------------------------------------------------------
|
| 1056 |
+
|
| 1057 |
+
TEST(MarshallingTest, TestOptionalIntUnparsing) {
|
| 1058 |
+
absl::optional<int> value;
|
| 1059 |
+
|
| 1060 |
+
EXPECT_EQ(absl::UnparseFlag(value), "");
|
| 1061 |
+
value = 0;
|
| 1062 |
+
EXPECT_EQ(absl::UnparseFlag(value), "0");
|
| 1063 |
+
value = -12;
|
| 1064 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-12");
|
| 1065 |
+
value = absl::nullopt;
|
| 1066 |
+
EXPECT_EQ(absl::UnparseFlag(value), "");
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
// --------------------------------------------------------------------
|
| 1070 |
+
|
| 1071 |
+
TEST(MarshallingTest, TestOptionalDoubleUnparsing) {
|
| 1072 |
+
absl::optional<double> value;
|
| 1073 |
+
|
| 1074 |
+
EXPECT_EQ(absl::UnparseFlag(value), "");
|
| 1075 |
+
value = 1.;
|
| 1076 |
+
EXPECT_EQ(absl::UnparseFlag(value), "1");
|
| 1077 |
+
value = -1.23;
|
| 1078 |
+
EXPECT_EQ(absl::UnparseFlag(value), "-1.23");
|
| 1079 |
+
value = absl::nullopt;
|
| 1080 |
+
EXPECT_EQ(absl::UnparseFlag(value), "");
|
| 1081 |
+
}
|
| 1082 |
+
|
| 1083 |
+
// --------------------------------------------------------------------
|
| 1084 |
+
|
| 1085 |
+
TEST(MarshallingTest, TestOptionalStringUnparsing) {
|
| 1086 |
+
absl::optional<std::string> strvalue;
|
| 1087 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), "");
|
| 1088 |
+
|
| 1089 |
+
strvalue = "asdfg";
|
| 1090 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), "asdfg");
|
| 1091 |
+
|
| 1092 |
+
strvalue = " ";
|
| 1093 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), " ");
|
| 1094 |
+
|
| 1095 |
+
strvalue = ""; // It is UB to set an optional string flag to ""
|
| 1096 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), "");
|
| 1097 |
+
}
|
| 1098 |
+
|
| 1099 |
+
// --------------------------------------------------------------------
|
| 1100 |
+
|
| 1101 |
+
#if defined(ABSL_HAVE_STD_OPTIONAL) && !defined(ABSL_USES_STD_OPTIONAL)
|
| 1102 |
+
|
| 1103 |
+
TEST(MarshallingTest, TestStdOptionalUnparsing) {
|
| 1104 |
+
std::optional<std::string> strvalue;
|
| 1105 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), "");
|
| 1106 |
+
|
| 1107 |
+
strvalue = "asdfg";
|
| 1108 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), "asdfg");
|
| 1109 |
+
|
| 1110 |
+
strvalue = " ";
|
| 1111 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), " ");
|
| 1112 |
+
|
| 1113 |
+
strvalue = ""; // It is UB to set an optional string flag to ""
|
| 1114 |
+
EXPECT_EQ(absl::UnparseFlag(strvalue), "");
|
| 1115 |
+
|
| 1116 |
+
std::optional<int> intvalue;
|
| 1117 |
+
EXPECT_EQ(absl::UnparseFlag(intvalue), "");
|
| 1118 |
+
|
| 1119 |
+
intvalue = 10;
|
| 1120 |
+
EXPECT_EQ(absl::UnparseFlag(intvalue), "10");
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
// --------------------------------------------------------------------
|
| 1124 |
+
|
| 1125 |
+
#endif
|
| 1126 |
+
|
| 1127 |
+
template <typename T>
|
| 1128 |
+
void TestRoundtrip(T v) {
|
| 1129 |
+
T new_v;
|
| 1130 |
+
std::string err;
|
| 1131 |
+
EXPECT_TRUE(absl::ParseFlag(absl::UnparseFlag(v), &new_v, &err));
|
| 1132 |
+
EXPECT_EQ(new_v, v);
|
| 1133 |
+
}
|
| 1134 |
+
|
| 1135 |
+
TEST(MarshallingTest, TestFloatRoundTrip) {
|
| 1136 |
+
TestRoundtrip(0.1f);
|
| 1137 |
+
TestRoundtrip(0.12f);
|
| 1138 |
+
TestRoundtrip(0.123f);
|
| 1139 |
+
TestRoundtrip(0.1234f);
|
| 1140 |
+
TestRoundtrip(0.12345f);
|
| 1141 |
+
TestRoundtrip(0.123456f);
|
| 1142 |
+
TestRoundtrip(0.1234567f);
|
| 1143 |
+
TestRoundtrip(0.12345678f);
|
| 1144 |
+
|
| 1145 |
+
TestRoundtrip(0.1e20f);
|
| 1146 |
+
TestRoundtrip(0.12e20f);
|
| 1147 |
+
TestRoundtrip(0.123e20f);
|
| 1148 |
+
TestRoundtrip(0.1234e20f);
|
| 1149 |
+
TestRoundtrip(0.12345e20f);
|
| 1150 |
+
TestRoundtrip(0.123456e20f);
|
| 1151 |
+
TestRoundtrip(0.1234567e20f);
|
| 1152 |
+
TestRoundtrip(0.12345678e20f);
|
| 1153 |
+
|
| 1154 |
+
TestRoundtrip(0.1e-20f);
|
| 1155 |
+
TestRoundtrip(0.12e-20f);
|
| 1156 |
+
TestRoundtrip(0.123e-20f);
|
| 1157 |
+
TestRoundtrip(0.1234e-20f);
|
| 1158 |
+
TestRoundtrip(0.12345e-20f);
|
| 1159 |
+
TestRoundtrip(0.123456e-20f);
|
| 1160 |
+
TestRoundtrip(0.1234567e-20f);
|
| 1161 |
+
TestRoundtrip(0.12345678e-20f);
|
| 1162 |
+
}
|
| 1163 |
+
|
| 1164 |
+
TEST(MarshallingTest, TestDoubleRoundTrip) {
|
| 1165 |
+
TestRoundtrip(0.1);
|
| 1166 |
+
TestRoundtrip(0.12);
|
| 1167 |
+
TestRoundtrip(0.123);
|
| 1168 |
+
TestRoundtrip(0.1234);
|
| 1169 |
+
TestRoundtrip(0.12345);
|
| 1170 |
+
TestRoundtrip(0.123456);
|
| 1171 |
+
TestRoundtrip(0.1234567);
|
| 1172 |
+
TestRoundtrip(0.12345678);
|
| 1173 |
+
TestRoundtrip(0.123456789);
|
| 1174 |
+
TestRoundtrip(0.1234567891);
|
| 1175 |
+
TestRoundtrip(0.12345678912);
|
| 1176 |
+
TestRoundtrip(0.123456789123);
|
| 1177 |
+
TestRoundtrip(0.1234567891234);
|
| 1178 |
+
TestRoundtrip(0.12345678912345);
|
| 1179 |
+
TestRoundtrip(0.123456789123456);
|
| 1180 |
+
TestRoundtrip(0.1234567891234567);
|
| 1181 |
+
TestRoundtrip(0.12345678912345678);
|
| 1182 |
+
|
| 1183 |
+
TestRoundtrip(0.1e50);
|
| 1184 |
+
TestRoundtrip(0.12e50);
|
| 1185 |
+
TestRoundtrip(0.123e50);
|
| 1186 |
+
TestRoundtrip(0.1234e50);
|
| 1187 |
+
TestRoundtrip(0.12345e50);
|
| 1188 |
+
TestRoundtrip(0.123456e50);
|
| 1189 |
+
TestRoundtrip(0.1234567e50);
|
| 1190 |
+
TestRoundtrip(0.12345678e50);
|
| 1191 |
+
TestRoundtrip(0.123456789e50);
|
| 1192 |
+
TestRoundtrip(0.1234567891e50);
|
| 1193 |
+
TestRoundtrip(0.12345678912e50);
|
| 1194 |
+
TestRoundtrip(0.123456789123e50);
|
| 1195 |
+
TestRoundtrip(0.1234567891234e50);
|
| 1196 |
+
TestRoundtrip(0.12345678912345e50);
|
| 1197 |
+
TestRoundtrip(0.123456789123456e50);
|
| 1198 |
+
TestRoundtrip(0.1234567891234567e50);
|
| 1199 |
+
TestRoundtrip(0.12345678912345678e50);
|
| 1200 |
+
|
| 1201 |
+
TestRoundtrip(0.1e-50);
|
| 1202 |
+
TestRoundtrip(0.12e-50);
|
| 1203 |
+
TestRoundtrip(0.123e-50);
|
| 1204 |
+
TestRoundtrip(0.1234e-50);
|
| 1205 |
+
TestRoundtrip(0.12345e-50);
|
| 1206 |
+
TestRoundtrip(0.123456e-50);
|
| 1207 |
+
TestRoundtrip(0.1234567e-50);
|
| 1208 |
+
TestRoundtrip(0.12345678e-50);
|
| 1209 |
+
TestRoundtrip(0.123456789e-50);
|
| 1210 |
+
TestRoundtrip(0.1234567891e-50);
|
| 1211 |
+
TestRoundtrip(0.12345678912e-50);
|
| 1212 |
+
TestRoundtrip(0.123456789123e-50);
|
| 1213 |
+
TestRoundtrip(0.1234567891234e-50);
|
| 1214 |
+
TestRoundtrip(0.12345678912345e-50);
|
| 1215 |
+
TestRoundtrip(0.123456789123456e-50);
|
| 1216 |
+
TestRoundtrip(0.1234567891234567e-50);
|
| 1217 |
+
TestRoundtrip(0.12345678912345678e-50);
|
| 1218 |
+
}
|
| 1219 |
+
|
| 1220 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/flags/reflection.cc
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2020 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/reflection.h"
|
| 17 |
+
|
| 18 |
+
#include <assert.h>
|
| 19 |
+
|
| 20 |
+
#include <atomic>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/config.h"
|
| 24 |
+
#include "absl/base/no_destructor.h"
|
| 25 |
+
#include "absl/base/thread_annotations.h"
|
| 26 |
+
#include "absl/container/flat_hash_map.h"
|
| 27 |
+
#include "absl/flags/commandlineflag.h"
|
| 28 |
+
#include "absl/flags/internal/private_handle_accessor.h"
|
| 29 |
+
#include "absl/flags/internal/registry.h"
|
| 30 |
+
#include "absl/flags/usage_config.h"
|
| 31 |
+
#include "absl/strings/str_cat.h"
|
| 32 |
+
#include "absl/strings/string_view.h"
|
| 33 |
+
#include "absl/synchronization/mutex.h"
|
| 34 |
+
|
| 35 |
+
namespace absl {
|
| 36 |
+
ABSL_NAMESPACE_BEGIN
|
| 37 |
+
namespace flags_internal {
|
| 38 |
+
|
| 39 |
+
// --------------------------------------------------------------------
|
| 40 |
+
// FlagRegistry
|
| 41 |
+
// A FlagRegistry singleton object holds all flag objects indexed by their
|
| 42 |
+
// names so that if you know a flag's name, you can access or set it. If the
|
| 43 |
+
// function is named FooLocked(), you must own the registry lock before
|
| 44 |
+
// calling the function; otherwise, you should *not* hold the lock, and the
|
| 45 |
+
// function will acquire it itself if needed.
|
| 46 |
+
// --------------------------------------------------------------------
|
| 47 |
+
|
| 48 |
+
class FlagRegistry {
|
| 49 |
+
public:
|
| 50 |
+
FlagRegistry() = default;
|
| 51 |
+
~FlagRegistry() = default;
|
| 52 |
+
|
| 53 |
+
// Store a flag in this registry. Takes ownership of *flag.
|
| 54 |
+
void RegisterFlag(CommandLineFlag& flag, const char* filename);
|
| 55 |
+
|
| 56 |
+
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.Lock(); }
|
| 57 |
+
void Unlock() ABSL_UNLOCK_FUNCTION(lock_) { lock_.Unlock(); }
|
| 58 |
+
|
| 59 |
+
// Returns the flag object for the specified name, or nullptr if not found.
|
| 60 |
+
// Will emit a warning if a 'retired' flag is specified.
|
| 61 |
+
CommandLineFlag* FindFlag(absl::string_view name);
|
| 62 |
+
|
| 63 |
+
static FlagRegistry& GlobalRegistry(); // returns a singleton registry
|
| 64 |
+
|
| 65 |
+
private:
|
| 66 |
+
friend class flags_internal::FlagSaverImpl; // reads all the flags in order
|
| 67 |
+
// to copy them
|
| 68 |
+
friend void ForEachFlag(std::function<void(CommandLineFlag&)> visitor);
|
| 69 |
+
friend void FinalizeRegistry();
|
| 70 |
+
|
| 71 |
+
// The map from name to flag, for FindFlag().
|
| 72 |
+
using FlagMap = absl::flat_hash_map<absl::string_view, CommandLineFlag*>;
|
| 73 |
+
using FlagIterator = FlagMap::iterator;
|
| 74 |
+
using FlagConstIterator = FlagMap::const_iterator;
|
| 75 |
+
FlagMap flags_;
|
| 76 |
+
std::vector<CommandLineFlag*> flat_flags_;
|
| 77 |
+
std::atomic<bool> finalized_flags_{false};
|
| 78 |
+
|
| 79 |
+
absl::Mutex lock_;
|
| 80 |
+
|
| 81 |
+
// Disallow
|
| 82 |
+
FlagRegistry(const FlagRegistry&);
|
| 83 |
+
FlagRegistry& operator=(const FlagRegistry&);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
namespace {
|
| 87 |
+
|
| 88 |
+
class FlagRegistryLock {
|
| 89 |
+
public:
|
| 90 |
+
explicit FlagRegistryLock(FlagRegistry& fr) : fr_(fr) { fr_.Lock(); }
|
| 91 |
+
~FlagRegistryLock() { fr_.Unlock(); }
|
| 92 |
+
|
| 93 |
+
private:
|
| 94 |
+
FlagRegistry& fr_;
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
} // namespace
|
| 98 |
+
|
| 99 |
+
CommandLineFlag* FlagRegistry::FindFlag(absl::string_view name) {
|
| 100 |
+
if (finalized_flags_.load(std::memory_order_acquire)) {
|
| 101 |
+
// We could save some gcus here if we make `Name()` be non-virtual.
|
| 102 |
+
// We could move the `const char*` name to the base class.
|
| 103 |
+
auto it = std::partition_point(
|
| 104 |
+
flat_flags_.begin(), flat_flags_.end(),
|
| 105 |
+
[=](CommandLineFlag* f) { return f->Name() < name; });
|
| 106 |
+
if (it != flat_flags_.end() && (*it)->Name() == name) return *it;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
FlagRegistryLock frl(*this);
|
| 110 |
+
auto it = flags_.find(name);
|
| 111 |
+
return it != flags_.end() ? it->second : nullptr;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void FlagRegistry::RegisterFlag(CommandLineFlag& flag, const char* filename) {
|
| 115 |
+
if (filename != nullptr &&
|
| 116 |
+
flag.Filename() != GetUsageConfig().normalize_filename(filename)) {
|
| 117 |
+
flags_internal::ReportUsageError(
|
| 118 |
+
absl::StrCat(
|
| 119 |
+
"Inconsistency between flag object and registration for flag '",
|
| 120 |
+
flag.Name(),
|
| 121 |
+
"', likely due to duplicate flags or an ODR violation. Relevant "
|
| 122 |
+
"files: ",
|
| 123 |
+
flag.Filename(), " and ", filename),
|
| 124 |
+
true);
|
| 125 |
+
std::exit(1);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
FlagRegistryLock registry_lock(*this);
|
| 129 |
+
|
| 130 |
+
std::pair<FlagIterator, bool> ins =
|
| 131 |
+
flags_.insert(FlagMap::value_type(flag.Name(), &flag));
|
| 132 |
+
if (ins.second == false) { // means the name was already in the map
|
| 133 |
+
CommandLineFlag& old_flag = *ins.first->second;
|
| 134 |
+
if (flag.IsRetired() != old_flag.IsRetired()) {
|
| 135 |
+
// All registrations must agree on the 'retired' flag.
|
| 136 |
+
flags_internal::ReportUsageError(
|
| 137 |
+
absl::StrCat(
|
| 138 |
+
"Retired flag '", flag.Name(), "' was defined normally in file '",
|
| 139 |
+
(flag.IsRetired() ? old_flag.Filename() : flag.Filename()), "'."),
|
| 140 |
+
true);
|
| 141 |
+
} else if (flags_internal::PrivateHandleAccessor::TypeId(flag) !=
|
| 142 |
+
flags_internal::PrivateHandleAccessor::TypeId(old_flag)) {
|
| 143 |
+
flags_internal::ReportUsageError(
|
| 144 |
+
absl::StrCat("Flag '", flag.Name(),
|
| 145 |
+
"' was defined more than once but with "
|
| 146 |
+
"differing types. Defined in files '",
|
| 147 |
+
old_flag.Filename(), "' and '", flag.Filename(), "'."),
|
| 148 |
+
true);
|
| 149 |
+
} else if (old_flag.IsRetired()) {
|
| 150 |
+
return;
|
| 151 |
+
} else if (old_flag.Filename() != flag.Filename()) {
|
| 152 |
+
flags_internal::ReportUsageError(
|
| 153 |
+
absl::StrCat("Flag '", flag.Name(),
|
| 154 |
+
"' was defined more than once (in files '",
|
| 155 |
+
old_flag.Filename(), "' and '", flag.Filename(), "')."),
|
| 156 |
+
true);
|
| 157 |
+
} else {
|
| 158 |
+
flags_internal::ReportUsageError(
|
| 159 |
+
absl::StrCat(
|
| 160 |
+
"Something is wrong with flag '", flag.Name(), "' in file '",
|
| 161 |
+
flag.Filename(), "'. One possibility: file '", flag.Filename(),
|
| 162 |
+
"' is being linked both statically and dynamically into this "
|
| 163 |
+
"executable. e.g. some files listed as srcs to a test and also "
|
| 164 |
+
"listed as srcs of some shared lib deps of the same test."),
|
| 165 |
+
true);
|
| 166 |
+
}
|
| 167 |
+
// All cases above are fatal, except for the retired flags.
|
| 168 |
+
std::exit(1);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
FlagRegistry& FlagRegistry::GlobalRegistry() {
|
| 173 |
+
static absl::NoDestructor<FlagRegistry> global_registry;
|
| 174 |
+
return *global_registry;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// --------------------------------------------------------------------
|
| 178 |
+
|
| 179 |
+
void ForEachFlag(std::function<void(CommandLineFlag&)> visitor) {
|
| 180 |
+
FlagRegistry& registry = FlagRegistry::GlobalRegistry();
|
| 181 |
+
|
| 182 |
+
if (registry.finalized_flags_.load(std::memory_order_acquire)) {
|
| 183 |
+
for (const auto& i : registry.flat_flags_) visitor(*i);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
FlagRegistryLock frl(registry);
|
| 187 |
+
for (const auto& i : registry.flags_) visitor(*i.second);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// --------------------------------------------------------------------
|
| 191 |
+
|
| 192 |
+
bool RegisterCommandLineFlag(CommandLineFlag& flag, const char* filename) {
|
| 193 |
+
FlagRegistry::GlobalRegistry().RegisterFlag(flag, filename);
|
| 194 |
+
return true;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
void FinalizeRegistry() {
|
| 198 |
+
auto& registry = FlagRegistry::GlobalRegistry();
|
| 199 |
+
FlagRegistryLock frl(registry);
|
| 200 |
+
if (registry.finalized_flags_.load(std::memory_order_relaxed)) {
|
| 201 |
+
// Was already finalized. Ignore the second time.
|
| 202 |
+
return;
|
| 203 |
+
}
|
| 204 |
+
registry.flat_flags_.reserve(registry.flags_.size());
|
| 205 |
+
for (const auto& f : registry.flags_) {
|
| 206 |
+
registry.flat_flags_.push_back(f.second);
|
| 207 |
+
}
|
| 208 |
+
std::sort(std::begin(registry.flat_flags_), std::end(registry.flat_flags_),
|
| 209 |
+
[](const CommandLineFlag* lhs, const CommandLineFlag* rhs) {
|
| 210 |
+
return lhs->Name() < rhs->Name();
|
| 211 |
+
});
|
| 212 |
+
registry.flags_.clear();
|
| 213 |
+
registry.finalized_flags_.store(true, std::memory_order_release);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
// --------------------------------------------------------------------
|
| 217 |
+
|
| 218 |
+
namespace {
|
| 219 |
+
|
| 220 |
+
class RetiredFlagObj final : public CommandLineFlag {
|
| 221 |
+
public:
|
| 222 |
+
constexpr RetiredFlagObj(const char* name, FlagFastTypeId type_id)
|
| 223 |
+
: name_(name), type_id_(type_id) {}
|
| 224 |
+
|
| 225 |
+
private:
|
| 226 |
+
absl::string_view Name() const override { return name_; }
|
| 227 |
+
std::string Filename() const override {
|
| 228 |
+
OnAccess();
|
| 229 |
+
return "RETIRED";
|
| 230 |
+
}
|
| 231 |
+
FlagFastTypeId TypeId() const override { return type_id_; }
|
| 232 |
+
std::string Help() const override {
|
| 233 |
+
OnAccess();
|
| 234 |
+
return "";
|
| 235 |
+
}
|
| 236 |
+
bool IsRetired() const override { return true; }
|
| 237 |
+
bool IsSpecifiedOnCommandLine() const override {
|
| 238 |
+
OnAccess();
|
| 239 |
+
return false;
|
| 240 |
+
}
|
| 241 |
+
std::string DefaultValue() const override {
|
| 242 |
+
OnAccess();
|
| 243 |
+
return "";
|
| 244 |
+
}
|
| 245 |
+
std::string CurrentValue() const override {
|
| 246 |
+
OnAccess();
|
| 247 |
+
return "";
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
// Any input is valid
|
| 251 |
+
bool ValidateInputValue(absl::string_view) const override {
|
| 252 |
+
OnAccess();
|
| 253 |
+
return true;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
std::unique_ptr<flags_internal::FlagStateInterface> SaveState() override {
|
| 257 |
+
return nullptr;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
bool ParseFrom(absl::string_view, flags_internal::FlagSettingMode,
|
| 261 |
+
flags_internal::ValueSource, std::string&) override {
|
| 262 |
+
OnAccess();
|
| 263 |
+
return false;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
void CheckDefaultValueParsingRoundtrip() const override { OnAccess(); }
|
| 267 |
+
|
| 268 |
+
void Read(void*) const override { OnAccess(); }
|
| 269 |
+
|
| 270 |
+
void OnAccess() const {
|
| 271 |
+
flags_internal::ReportUsageError(
|
| 272 |
+
absl::StrCat("Accessing retired flag '", name_, "'"), false);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
// Data members
|
| 276 |
+
const char* const name_;
|
| 277 |
+
const FlagFastTypeId type_id_;
|
| 278 |
+
};
|
| 279 |
+
|
| 280 |
+
} // namespace
|
| 281 |
+
|
| 282 |
+
void Retire(const char* name, FlagFastTypeId type_id, char* buf) {
|
| 283 |
+
static_assert(sizeof(RetiredFlagObj) == kRetiredFlagObjSize, "");
|
| 284 |
+
static_assert(alignof(RetiredFlagObj) == kRetiredFlagObjAlignment, "");
|
| 285 |
+
auto* flag = ::new (static_cast<void*>(buf))
|
| 286 |
+
flags_internal::RetiredFlagObj(name, type_id);
|
| 287 |
+
FlagRegistry::GlobalRegistry().RegisterFlag(*flag, nullptr);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
// --------------------------------------------------------------------
|
| 291 |
+
|
| 292 |
+
class FlagSaverImpl {
|
| 293 |
+
public:
|
| 294 |
+
FlagSaverImpl() = default;
|
| 295 |
+
FlagSaverImpl(const FlagSaverImpl&) = delete;
|
| 296 |
+
void operator=(const FlagSaverImpl&) = delete;
|
| 297 |
+
|
| 298 |
+
// Saves the flag states from the flag registry into this object.
|
| 299 |
+
// It's an error to call this more than once.
|
| 300 |
+
void SaveFromRegistry() {
|
| 301 |
+
assert(backup_registry_.empty()); // call only once!
|
| 302 |
+
flags_internal::ForEachFlag([&](CommandLineFlag& flag) {
|
| 303 |
+
if (auto flag_state =
|
| 304 |
+
flags_internal::PrivateHandleAccessor::SaveState(flag)) {
|
| 305 |
+
backup_registry_.emplace_back(std::move(flag_state));
|
| 306 |
+
}
|
| 307 |
+
});
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
// Restores the saved flag states into the flag registry.
|
| 311 |
+
void RestoreToRegistry() {
|
| 312 |
+
for (const auto& flag_state : backup_registry_) {
|
| 313 |
+
flag_state->Restore();
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
private:
|
| 318 |
+
std::vector<std::unique_ptr<flags_internal::FlagStateInterface>>
|
| 319 |
+
backup_registry_;
|
| 320 |
+
};
|
| 321 |
+
|
| 322 |
+
} // namespace flags_internal
|
| 323 |
+
|
| 324 |
+
FlagSaver::FlagSaver() : impl_(new flags_internal::FlagSaverImpl) {
|
| 325 |
+
impl_->SaveFromRegistry();
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
FlagSaver::~FlagSaver() {
|
| 329 |
+
if (!impl_) return;
|
| 330 |
+
|
| 331 |
+
impl_->RestoreToRegistry();
|
| 332 |
+
delete impl_;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// --------------------------------------------------------------------
|
| 336 |
+
|
| 337 |
+
CommandLineFlag* FindCommandLineFlag(absl::string_view name) {
|
| 338 |
+
if (name.empty()) return nullptr;
|
| 339 |
+
flags_internal::FlagRegistry& registry =
|
| 340 |
+
flags_internal::FlagRegistry::GlobalRegistry();
|
| 341 |
+
return registry.FindFlag(name);
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
// --------------------------------------------------------------------
|
| 345 |
+
|
| 346 |
+
absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> GetAllFlags() {
|
| 347 |
+
absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> res;
|
| 348 |
+
flags_internal::ForEachFlag([&](CommandLineFlag& flag) {
|
| 349 |
+
if (!flag.IsRetired()) res.insert({flag.Name(), &flag});
|
| 350 |
+
});
|
| 351 |
+
return res;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
ABSL_NAMESPACE_END
|
| 355 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/flags/usage.h
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#ifndef ABSL_FLAGS_USAGE_H_
|
| 17 |
+
#define ABSL_FLAGS_USAGE_H_
|
| 18 |
+
|
| 19 |
+
#include "absl/base/config.h"
|
| 20 |
+
#include "absl/strings/string_view.h"
|
| 21 |
+
|
| 22 |
+
// --------------------------------------------------------------------
|
| 23 |
+
// Usage reporting interfaces
|
| 24 |
+
|
| 25 |
+
namespace absl {
|
| 26 |
+
ABSL_NAMESPACE_BEGIN
|
| 27 |
+
|
| 28 |
+
// Sets the "usage" message to be used by help reporting routines.
|
| 29 |
+
// For example:
|
| 30 |
+
// absl::SetProgramUsageMessage(
|
| 31 |
+
// absl::StrCat("This program does nothing. Sample usage:\n", argv[0],
|
| 32 |
+
// " <uselessarg1> <uselessarg2>"));
|
| 33 |
+
// Do not include commandline flags in the usage: we do that for you!
|
| 34 |
+
// Note: Calling SetProgramUsageMessage twice will trigger a call to std::exit.
|
| 35 |
+
void SetProgramUsageMessage(absl::string_view new_usage_message);
|
| 36 |
+
|
| 37 |
+
// Returns the usage message set by SetProgramUsageMessage().
|
| 38 |
+
absl::string_view ProgramUsageMessage();
|
| 39 |
+
|
| 40 |
+
ABSL_NAMESPACE_END
|
| 41 |
+
} // namespace absl
|
| 42 |
+
|
| 43 |
+
#endif // ABS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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright 2022 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 |
+
|
| 17 |
+
load(
|
| 18 |
+
"//absl:copts/configure_copts.bzl",
|
| 19 |
+
"ABSL_DEFAULT_COPTS",
|
| 20 |
+
"ABSL_DEFAULT_LINKOPTS",
|
| 21 |
+
"ABSL_TEST_COPTS",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
package(
|
| 25 |
+
default_visibility = ["//visibility:public"],
|
| 26 |
+
features = [
|
| 27 |
+
"header_modules",
|
| 28 |
+
"layering_check",
|
| 29 |
+
"parse_headers",
|
| 30 |
+
],
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
licenses(["notice"])
|
| 34 |
+
|
| 35 |
+
# Public targets
|
| 36 |
+
|
| 37 |
+
cc_library(
|
| 38 |
+
name = "absl_check",
|
| 39 |
+
hdrs = ["absl_check.h"],
|
| 40 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 41 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 42 |
+
deps = [
|
| 43 |
+
"//absl/log/internal:check_impl",
|
| 44 |
+
],
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
cc_library(
|
| 48 |
+
name = "absl_log",
|
| 49 |
+
hdrs = ["absl_log.h"],
|
| 50 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 51 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 52 |
+
deps = [
|
| 53 |
+
"//absl/log/internal:log_impl",
|
| 54 |
+
],
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
cc_library(
|
| 58 |
+
name = "check",
|
| 59 |
+
hdrs = ["check.h"],
|
| 60 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 61 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 62 |
+
deps = [
|
| 63 |
+
"//absl/log/internal:check_impl",
|
| 64 |
+
"//absl/log/internal:check_op",
|
| 65 |
+
"//absl/log/internal:conditions",
|
| 66 |
+
"//absl/log/internal:log_message",
|
| 67 |
+
"//absl/log/internal:strip",
|
| 68 |
+
],
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
cc_library(
|
| 72 |
+
name = "die_if_null",
|
| 73 |
+
srcs = ["die_if_null.cc"],
|
| 74 |
+
hdrs = ["die_if_null.h"],
|
| 75 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 76 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 77 |
+
deps = [
|
| 78 |
+
":log",
|
| 79 |
+
"//absl/base:config",
|
| 80 |
+
"//absl/base:core_headers",
|
| 81 |
+
"//absl/strings",
|
| 82 |
+
],
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
cc_library(
|
| 86 |
+
name = "flags",
|
| 87 |
+
srcs = ["flags.cc"],
|
| 88 |
+
hdrs = ["flags.h"],
|
| 89 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 90 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 91 |
+
visibility = ["//visibility:public"],
|
| 92 |
+
deps = [
|
| 93 |
+
":globals",
|
| 94 |
+
"//absl/base:config",
|
| 95 |
+
"//absl/base:core_headers",
|
| 96 |
+
"//absl/base:log_severity",
|
| 97 |
+
"//absl/flags:flag",
|
| 98 |
+
"//absl/flags:marshalling",
|
| 99 |
+
"//absl/log/internal:config",
|
| 100 |
+
"//absl/log/internal:flags",
|
| 101 |
+
"//absl/log/internal:vlog_config",
|
| 102 |
+
"//absl/strings",
|
| 103 |
+
],
|
| 104 |
+
# Binaries which do not access these flags from C++ still want this library linked in.
|
| 105 |
+
alwayslink = True,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
cc_library(
|
| 109 |
+
name = "globals",
|
| 110 |
+
srcs = ["globals.cc"],
|
| 111 |
+
hdrs = ["globals.h"],
|
| 112 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 113 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 114 |
+
visibility = ["//visibility:public"],
|
| 115 |
+
deps = [
|
| 116 |
+
"//absl/base:atomic_hook",
|
| 117 |
+
"//absl/base:config",
|
| 118 |
+
"//absl/base:core_headers",
|
| 119 |
+
"//absl/base:log_severity",
|
| 120 |
+
"//absl/base:raw_logging_internal",
|
| 121 |
+
"//absl/hash",
|
| 122 |
+
"//absl/log/internal:vlog_config",
|
| 123 |
+
"//absl/strings",
|
| 124 |
+
],
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
cc_library(
|
| 128 |
+
name = "initialize",
|
| 129 |
+
srcs = ["initialize.cc"],
|
| 130 |
+
hdrs = ["initialize.h"],
|
| 131 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 132 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 133 |
+
visibility = ["//visibility:public"],
|
| 134 |
+
deps = [
|
| 135 |
+
":globals",
|
| 136 |
+
"//absl/base:config",
|
| 137 |
+
"//absl/log/internal:globals",
|
| 138 |
+
"//absl/time",
|
| 139 |
+
],
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
cc_library(
|
| 143 |
+
name = "log",
|
| 144 |
+
hdrs = ["log.h"],
|
| 145 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 146 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 147 |
+
deps = [
|
| 148 |
+
":vlog_is_on",
|
| 149 |
+
"//absl/log/internal:log_impl",
|
| 150 |
+
],
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
cc_library(
|
| 154 |
+
name = "log_entry",
|
| 155 |
+
srcs = ["log_entry.cc"],
|
| 156 |
+
hdrs = ["log_entry.h"],
|
| 157 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 158 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 159 |
+
deps = [
|
| 160 |
+
"//absl/base:config",
|
| 161 |
+
"//absl/base:core_headers",
|
| 162 |
+
"//absl/base:log_severity",
|
| 163 |
+
"//absl/log/internal:config",
|
| 164 |
+
"//absl/strings",
|
| 165 |
+
"//absl/time",
|
| 166 |
+
"//absl/types:span",
|
| 167 |
+
],
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
cc_library(
|
| 171 |
+
name = "log_sink",
|
| 172 |
+
srcs = ["log_sink.cc"],
|
| 173 |
+
hdrs = ["log_sink.h"],
|
| 174 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 175 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 176 |
+
deps = [
|
| 177 |
+
":log_entry",
|
| 178 |
+
"//absl/base:config",
|
| 179 |
+
],
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
cc_library(
|
| 183 |
+
name = "log_sink_registry",
|
| 184 |
+
hdrs = ["log_sink_registry.h"],
|
| 185 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 186 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 187 |
+
deps = [
|
| 188 |
+
":log_sink",
|
| 189 |
+
"//absl/base:config",
|
| 190 |
+
"//absl/log/internal:log_sink_set",
|
| 191 |
+
],
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
cc_library(
|
| 195 |
+
name = "log_streamer",
|
| 196 |
+
hdrs = ["log_streamer.h"],
|
| 197 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 198 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 199 |
+
deps = [
|
| 200 |
+
":absl_log",
|
| 201 |
+
"//absl/base:config",
|
| 202 |
+
"//absl/base:log_severity",
|
| 203 |
+
"//absl/strings",
|
| 204 |
+
"//absl/strings:internal",
|
| 205 |
+
"//absl/types:optional",
|
| 206 |
+
"//absl/utility",
|
| 207 |
+
],
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
cc_library(
|
| 211 |
+
name = "scoped_mock_log",
|
| 212 |
+
testonly = True,
|
| 213 |
+
srcs = ["scoped_mock_log.cc"],
|
| 214 |
+
hdrs = ["scoped_mock_log.h"],
|
| 215 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 216 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 217 |
+
deps = [
|
| 218 |
+
":log_entry",
|
| 219 |
+
":log_sink",
|
| 220 |
+
":log_sink_registry",
|
| 221 |
+
"//absl/base:config",
|
| 222 |
+
"//absl/base:log_severity",
|
| 223 |
+
"//absl/base:raw_logging_internal",
|
| 224 |
+
"//absl/strings",
|
| 225 |
+
"@com_google_googletest//:gtest",
|
| 226 |
+
],
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
cc_library(
|
| 230 |
+
name = "structured",
|
| 231 |
+
hdrs = ["structured.h"],
|
| 232 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 233 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 234 |
+
deps = [
|
| 235 |
+
"//absl/base:config",
|
| 236 |
+
"//absl/log/internal:structured",
|
| 237 |
+
"//absl/strings",
|
| 238 |
+
],
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
cc_library(
|
| 242 |
+
name = "absl_vlog_is_on",
|
| 243 |
+
hdrs = ["absl_vlog_is_on.h"],
|
| 244 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 245 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 246 |
+
visibility = [
|
| 247 |
+
"//absl/log:__subpackages__",
|
| 248 |
+
],
|
| 249 |
+
deps = [
|
| 250 |
+
"//absl/base:config",
|
| 251 |
+
"//absl/base:core_headers",
|
| 252 |
+
"//absl/log/internal:vlog_config",
|
| 253 |
+
"//absl/strings",
|
| 254 |
+
],
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
cc_library(
|
| 258 |
+
name = "vlog_is_on",
|
| 259 |
+
hdrs = ["vlog_is_on.h"],
|
| 260 |
+
copts = ABSL_DEFAULT_COPTS,
|
| 261 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 262 |
+
visibility = [
|
| 263 |
+
"//absl/log:__subpackages__",
|
| 264 |
+
],
|
| 265 |
+
deps = [
|
| 266 |
+
":absl_vlog_is_on",
|
| 267 |
+
],
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
# TODO(b/200695798): run this in TAP projects with -DABSL_MAX_VLOG_VERBOSITY={-100,100}
|
| 271 |
+
cc_test(
|
| 272 |
+
name = "vlog_is_on_test",
|
| 273 |
+
size = "small",
|
| 274 |
+
srcs = [
|
| 275 |
+
"vlog_is_on_test.cc",
|
| 276 |
+
],
|
| 277 |
+
copts = ABSL_TEST_COPTS,
|
| 278 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 279 |
+
deps = [
|
| 280 |
+
":flags",
|
| 281 |
+
":globals",
|
| 282 |
+
":log",
|
| 283 |
+
":scoped_mock_log",
|
| 284 |
+
":vlog_is_on",
|
| 285 |
+
"//absl/base:log_severity",
|
| 286 |
+
"//absl/flags:flag",
|
| 287 |
+
"//absl/types:optional",
|
| 288 |
+
"@com_google_googletest//:gtest",
|
| 289 |
+
"@com_google_googletest//:gtest_main",
|
| 290 |
+
],
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
# Test targets
|
| 294 |
+
|
| 295 |
+
cc_test(
|
| 296 |
+
name = "absl_check_test",
|
| 297 |
+
size = "small",
|
| 298 |
+
srcs = ["absl_check_test.cc"],
|
| 299 |
+
copts = ABSL_TEST_COPTS,
|
| 300 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 301 |
+
tags = [
|
| 302 |
+
"no_test:os:ios",
|
| 303 |
+
"no_test_ios",
|
| 304 |
+
"no_test_wasm",
|
| 305 |
+
],
|
| 306 |
+
deps = [
|
| 307 |
+
":absl_check",
|
| 308 |
+
":check_test_impl",
|
| 309 |
+
"@com_google_googletest//:gtest",
|
| 310 |
+
"@com_google_googletest//:gtest_main",
|
| 311 |
+
],
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
cc_test(
|
| 315 |
+
name = "absl_log_basic_test",
|
| 316 |
+
size = "small",
|
| 317 |
+
srcs = ["absl_log_basic_test.cc"],
|
| 318 |
+
copts = ABSL_TEST_COPTS,
|
| 319 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 320 |
+
deps = [
|
| 321 |
+
":absl_log",
|
| 322 |
+
":log_basic_test_impl",
|
| 323 |
+
"@com_google_googletest//:gtest",
|
| 324 |
+
"@com_google_googletest//:gtest_main",
|
| 325 |
+
],
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
cc_test(
|
| 329 |
+
name = "check_test",
|
| 330 |
+
size = "small",
|
| 331 |
+
srcs = ["check_test.cc"],
|
| 332 |
+
copts = ABSL_TEST_COPTS,
|
| 333 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 334 |
+
tags = [
|
| 335 |
+
"no_test:os:ios",
|
| 336 |
+
"no_test_ios",
|
| 337 |
+
"no_test_wasm",
|
| 338 |
+
],
|
| 339 |
+
deps = [
|
| 340 |
+
":check",
|
| 341 |
+
":check_test_impl",
|
| 342 |
+
"@com_google_googletest//:gtest",
|
| 343 |
+
"@com_google_googletest//:gtest_main",
|
| 344 |
+
],
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
cc_library(
|
| 348 |
+
name = "check_test_impl",
|
| 349 |
+
testonly = True,
|
| 350 |
+
copts = ABSL_TEST_COPTS,
|
| 351 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 352 |
+
tags = [
|
| 353 |
+
"no_test:os:ios",
|
| 354 |
+
"no_test_ios",
|
| 355 |
+
"no_test_wasm",
|
| 356 |
+
],
|
| 357 |
+
textual_hdrs = ["check_test_impl.inc"],
|
| 358 |
+
visibility = ["//visibility:private"],
|
| 359 |
+
deps = [
|
| 360 |
+
"//absl/base:config",
|
| 361 |
+
"//absl/base:core_headers",
|
| 362 |
+
"//absl/log/internal:test_helpers",
|
| 363 |
+
"//absl/status",
|
| 364 |
+
"@com_google_googletest//:gtest",
|
| 365 |
+
],
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
cc_test(
|
| 369 |
+
name = "die_if_null_test",
|
| 370 |
+
size = "small",
|
| 371 |
+
srcs = ["die_if_null_test.cc"],
|
| 372 |
+
copts = ABSL_TEST_COPTS,
|
| 373 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 374 |
+
deps = [
|
| 375 |
+
":die_if_null",
|
| 376 |
+
"//absl/base:core_headers",
|
| 377 |
+
"//absl/log/internal:test_helpers",
|
| 378 |
+
"@com_google_googletest//:gtest",
|
| 379 |
+
"@com_google_googletest//:gtest_main",
|
| 380 |
+
],
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
cc_test(
|
| 384 |
+
name = "flags_test",
|
| 385 |
+
size = "small",
|
| 386 |
+
srcs = ["flags_test.cc"],
|
| 387 |
+
copts = ABSL_TEST_COPTS,
|
| 388 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 389 |
+
deps = [
|
| 390 |
+
":flags",
|
| 391 |
+
":globals",
|
| 392 |
+
":log",
|
| 393 |
+
":scoped_mock_log",
|
| 394 |
+
"//absl/base:core_headers",
|
| 395 |
+
"//absl/base:log_severity",
|
| 396 |
+
"//absl/flags:flag",
|
| 397 |
+
"//absl/flags:reflection",
|
| 398 |
+
"//absl/log/internal:flags",
|
| 399 |
+
"//absl/log/internal:test_helpers",
|
| 400 |
+
"//absl/log/internal:test_matchers",
|
| 401 |
+
"//absl/strings",
|
| 402 |
+
"@com_google_googletest//:gtest",
|
| 403 |
+
"@com_google_googletest//:gtest_main",
|
| 404 |
+
],
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
cc_test(
|
| 408 |
+
name = "globals_test",
|
| 409 |
+
size = "small",
|
| 410 |
+
srcs = ["globals_test.cc"],
|
| 411 |
+
copts = ABSL_TEST_COPTS,
|
| 412 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 413 |
+
deps = [
|
| 414 |
+
":globals",
|
| 415 |
+
":log",
|
| 416 |
+
":scoped_mock_log",
|
| 417 |
+
"//absl/base:core_headers",
|
| 418 |
+
"//absl/base:log_severity",
|
| 419 |
+
"//absl/log/internal:globals",
|
| 420 |
+
"//absl/log/internal:test_helpers",
|
| 421 |
+
"@com_google_googletest//:gtest",
|
| 422 |
+
"@com_google_googletest//:gtest_main",
|
| 423 |
+
],
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
cc_test(
|
| 427 |
+
name = "log_basic_test",
|
| 428 |
+
size = "small",
|
| 429 |
+
srcs = ["log_basic_test.cc"],
|
| 430 |
+
copts = ABSL_TEST_COPTS,
|
| 431 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 432 |
+
deps = [
|
| 433 |
+
":log",
|
| 434 |
+
":log_basic_test_impl",
|
| 435 |
+
"@com_google_googletest//:gtest",
|
| 436 |
+
"@com_google_googletest//:gtest_main",
|
| 437 |
+
],
|
| 438 |
+
)
|
| 439 |
+
|
| 440 |
+
cc_library(
|
| 441 |
+
name = "log_basic_test_impl",
|
| 442 |
+
testonly = True,
|
| 443 |
+
copts = ABSL_TEST_COPTS,
|
| 444 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 445 |
+
textual_hdrs = ["log_basic_test_impl.inc"],
|
| 446 |
+
visibility = ["//visibility:private"],
|
| 447 |
+
deps = [
|
| 448 |
+
"//absl/base",
|
| 449 |
+
"//absl/base:log_severity",
|
| 450 |
+
"//absl/log:globals",
|
| 451 |
+
"//absl/log:log_entry",
|
| 452 |
+
"//absl/log:scoped_mock_log",
|
| 453 |
+
"//absl/log/internal:test_actions",
|
| 454 |
+
"//absl/log/internal:test_helpers",
|
| 455 |
+
"//absl/log/internal:test_matchers",
|
| 456 |
+
"@com_google_googletest//:gtest",
|
| 457 |
+
],
|
| 458 |
+
)
|
| 459 |
+
|
| 460 |
+
cc_test(
|
| 461 |
+
name = "log_entry_test",
|
| 462 |
+
size = "small",
|
| 463 |
+
srcs = ["log_entry_test.cc"],
|
| 464 |
+
copts = ABSL_TEST_COPTS,
|
| 465 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 466 |
+
deps = [
|
| 467 |
+
":log_entry",
|
| 468 |
+
"//absl/base:config",
|
| 469 |
+
"//absl/base:core_headers",
|
| 470 |
+
"//absl/base:log_severity",
|
| 471 |
+
"//absl/log/internal:append_truncated",
|
| 472 |
+
"//absl/log/internal:format",
|
| 473 |
+
"//absl/log/internal:test_helpers",
|
| 474 |
+
"//absl/strings",
|
| 475 |
+
"//absl/time",
|
| 476 |
+
"//absl/types:span",
|
| 477 |
+
"@com_google_googletest//:gtest",
|
| 478 |
+
"@com_google_googletest//:gtest_main",
|
| 479 |
+
],
|
| 480 |
+
)
|
| 481 |
+
|
| 482 |
+
cc_test(
|
| 483 |
+
name = "log_format_test",
|
| 484 |
+
size = "small",
|
| 485 |
+
srcs = ["log_format_test.cc"],
|
| 486 |
+
copts = ABSL_TEST_COPTS,
|
| 487 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 488 |
+
deps = [
|
| 489 |
+
":check",
|
| 490 |
+
":log",
|
| 491 |
+
":scoped_mock_log",
|
| 492 |
+
"//absl/log/internal:test_matchers",
|
| 493 |
+
"//absl/strings",
|
| 494 |
+
"//absl/strings:str_format",
|
| 495 |
+
"//absl/types:optional",
|
| 496 |
+
"@com_google_googletest//:gtest",
|
| 497 |
+
"@com_google_googletest//:gtest_main",
|
| 498 |
+
],
|
| 499 |
+
)
|
| 500 |
+
|
| 501 |
+
cc_test(
|
| 502 |
+
name = "log_macro_hygiene_test",
|
| 503 |
+
size = "small",
|
| 504 |
+
srcs = ["log_macro_hygiene_test.cc"],
|
| 505 |
+
copts = ABSL_TEST_COPTS,
|
| 506 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 507 |
+
deps = [
|
| 508 |
+
":log",
|
| 509 |
+
":scoped_mock_log",
|
| 510 |
+
"//absl/base:core_headers",
|
| 511 |
+
"//absl/base:log_severity",
|
| 512 |
+
"@com_google_googletest//:gtest",
|
| 513 |
+
"@com_google_googletest//:gtest_main",
|
| 514 |
+
],
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
cc_test(
|
| 518 |
+
name = "log_sink_test",
|
| 519 |
+
size = "medium",
|
| 520 |
+
srcs = ["log_sink_test.cc"],
|
| 521 |
+
copts = ABSL_TEST_COPTS,
|
| 522 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 523 |
+
tags = [
|
| 524 |
+
"no_test:os:ios",
|
| 525 |
+
"no_test_ios",
|
| 526 |
+
"no_test_wasm",
|
| 527 |
+
],
|
| 528 |
+
deps = [
|
| 529 |
+
":log",
|
| 530 |
+
":log_sink",
|
| 531 |
+
":log_sink_registry",
|
| 532 |
+
":scoped_mock_log",
|
| 533 |
+
"//absl/base:core_headers",
|
| 534 |
+
"//absl/log/internal:test_actions",
|
| 535 |
+
"//absl/log/internal:test_helpers",
|
| 536 |
+
"//absl/log/internal:test_matchers",
|
| 537 |
+
"//absl/strings",
|
| 538 |
+
"@com_google_googletest//:gtest",
|
| 539 |
+
"@com_google_googletest//:gtest_main",
|
| 540 |
+
],
|
| 541 |
+
)
|
| 542 |
+
|
| 543 |
+
cc_test(
|
| 544 |
+
name = "log_streamer_test",
|
| 545 |
+
size = "medium",
|
| 546 |
+
srcs = ["log_streamer_test.cc"],
|
| 547 |
+
copts = ABSL_TEST_COPTS,
|
| 548 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 549 |
+
deps = [
|
| 550 |
+
":log",
|
| 551 |
+
":log_streamer",
|
| 552 |
+
":scoped_mock_log",
|
| 553 |
+
"//absl/base",
|
| 554 |
+
"//absl/base:core_headers",
|
| 555 |
+
"//absl/base:log_severity",
|
| 556 |
+
"//absl/log/internal:test_actions",
|
| 557 |
+
"//absl/log/internal:test_helpers",
|
| 558 |
+
"//absl/log/internal:test_matchers",
|
| 559 |
+
"//absl/strings",
|
| 560 |
+
"@com_google_googletest//:gtest",
|
| 561 |
+
"@com_google_googletest//:gtest_main",
|
| 562 |
+
],
|
| 563 |
+
)
|
| 564 |
+
|
| 565 |
+
cc_test(
|
| 566 |
+
name = "log_modifier_methods_test",
|
| 567 |
+
size = "small",
|
| 568 |
+
srcs = ["log_modifier_methods_test.cc"],
|
| 569 |
+
copts = ABSL_TEST_COPTS,
|
| 570 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 571 |
+
deps = [
|
| 572 |
+
":log",
|
| 573 |
+
":log_sink",
|
| 574 |
+
":scoped_mock_log",
|
| 575 |
+
"//absl/log/internal:test_actions",
|
| 576 |
+
"//absl/log/internal:test_helpers",
|
| 577 |
+
"//absl/log/internal:test_matchers",
|
| 578 |
+
"//absl/strings",
|
| 579 |
+
"//absl/time",
|
| 580 |
+
"@com_google_googletest//:gtest",
|
| 581 |
+
"@com_google_googletest//:gtest_main",
|
| 582 |
+
],
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
cc_test(
|
| 586 |
+
name = "scoped_mock_log_test",
|
| 587 |
+
size = "small",
|
| 588 |
+
srcs = ["scoped_mock_log_test.cc"],
|
| 589 |
+
copts = ABSL_TEST_COPTS,
|
| 590 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 591 |
+
linkstatic = 1,
|
| 592 |
+
tags = [
|
| 593 |
+
"no_test:os:ios",
|
| 594 |
+
"no_test_ios",
|
| 595 |
+
"no_test_wasm",
|
| 596 |
+
],
|
| 597 |
+
deps = [
|
| 598 |
+
":globals",
|
| 599 |
+
":log",
|
| 600 |
+
":scoped_mock_log",
|
| 601 |
+
"//absl/base:core_headers",
|
| 602 |
+
"//absl/base:log_severity",
|
| 603 |
+
"//absl/log/internal:test_helpers",
|
| 604 |
+
"//absl/log/internal:test_matchers",
|
| 605 |
+
"//absl/memory",
|
| 606 |
+
"//absl/strings",
|
| 607 |
+
"//absl/synchronization",
|
| 608 |
+
"@com_google_googletest//:gtest",
|
| 609 |
+
"@com_google_googletest//:gtest_main",
|
| 610 |
+
],
|
| 611 |
+
)
|
| 612 |
+
|
| 613 |
+
cc_test(
|
| 614 |
+
name = "stripping_test",
|
| 615 |
+
size = "small",
|
| 616 |
+
srcs = ["stripping_test.cc"],
|
| 617 |
+
copts = ABSL_TEST_COPTS,
|
| 618 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 619 |
+
# This test requires all code live in the binary (instead of shared libraries)
|
| 620 |
+
# because we test for the existence of specific literals in the binary.
|
| 621 |
+
linkstatic = 1,
|
| 622 |
+
deps = [
|
| 623 |
+
":check",
|
| 624 |
+
":log",
|
| 625 |
+
"//absl/base:log_severity",
|
| 626 |
+
"//absl/base:strerror",
|
| 627 |
+
"//absl/flags:program_name",
|
| 628 |
+
"//absl/log/internal:test_helpers",
|
| 629 |
+
"//absl/status",
|
| 630 |
+
"//absl/strings",
|
| 631 |
+
"//absl/strings:str_format",
|
| 632 |
+
"@com_google_googletest//:gtest",
|
| 633 |
+
"@com_google_googletest//:gtest_main",
|
| 634 |
+
],
|
| 635 |
+
)
|
| 636 |
+
|
| 637 |
+
cc_test(
|
| 638 |
+
name = "structured_test",
|
| 639 |
+
size = "small",
|
| 640 |
+
srcs = ["structured_test.cc"],
|
| 641 |
+
copts = ABSL_TEST_COPTS,
|
| 642 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 643 |
+
deps = [
|
| 644 |
+
":log",
|
| 645 |
+
":scoped_mock_log",
|
| 646 |
+
":structured",
|
| 647 |
+
"//absl/base:core_headers",
|
| 648 |
+
"//absl/log/internal:test_helpers",
|
| 649 |
+
"//absl/log/internal:test_matchers",
|
| 650 |
+
"@com_google_googletest//:gtest",
|
| 651 |
+
"@com_google_googletest//:gtest_main",
|
| 652 |
+
],
|
| 653 |
+
)
|
| 654 |
+
|
| 655 |
+
cc_test(
|
| 656 |
+
name = "log_benchmark",
|
| 657 |
+
size = "small",
|
| 658 |
+
srcs = ["log_benchmark.cc"],
|
| 659 |
+
copts = ABSL_TEST_COPTS,
|
| 660 |
+
linkopts = ABSL_DEFAULT_LINKOPTS,
|
| 661 |
+
tags = ["benchmark"],
|
| 662 |
+
deps = [
|
| 663 |
+
":check",
|
| 664 |
+
":flags",
|
| 665 |
+
":globals",
|
| 666 |
+
":log",
|
| 667 |
+
":log_entry",
|
| 668 |
+
":log_sink",
|
| 669 |
+
":log_sink_registry",
|
| 670 |
+
"//absl/base:core_headers",
|
| 671 |
+
"//absl/base:log_severity",
|
| 672 |
+
"//absl/flags:flag",
|
| 673 |
+
"//absl/log/internal:flags",
|
| 674 |
+
"@com_github_google_benchmark//:benchmark_main",
|
| 675 |
+
],
|
| 676 |
+
)
|
weight/_dep/abseil-cpp/absl/log/CMakeLists.txt
ADDED
|
@@ -0,0 +1,1144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 The Abseil Authors.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
# Internal targets
|
| 17 |
+
absl_cc_library(
|
| 18 |
+
NAME
|
| 19 |
+
log_internal_check_impl
|
| 20 |
+
SRCS
|
| 21 |
+
HDRS
|
| 22 |
+
"internal/check_impl.h"
|
| 23 |
+
COPTS
|
| 24 |
+
${ABSL_DEFAULT_COPTS}
|
| 25 |
+
LINKOPTS
|
| 26 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 27 |
+
DEPS
|
| 28 |
+
absl::core_headers
|
| 29 |
+
absl::log_internal_check_op
|
| 30 |
+
absl::log_internal_conditions
|
| 31 |
+
absl::log_internal_message
|
| 32 |
+
absl::log_internal_strip
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
absl_cc_library(
|
| 36 |
+
NAME
|
| 37 |
+
log_internal_check_op
|
| 38 |
+
SRCS
|
| 39 |
+
"internal/check_op.cc"
|
| 40 |
+
HDRS
|
| 41 |
+
"internal/check_op.h"
|
| 42 |
+
COPTS
|
| 43 |
+
${ABSL_DEFAULT_COPTS}
|
| 44 |
+
LINKOPTS
|
| 45 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 46 |
+
DEPS
|
| 47 |
+
absl::config
|
| 48 |
+
absl::core_headers
|
| 49 |
+
absl::log_internal_nullguard
|
| 50 |
+
absl::log_internal_nullstream
|
| 51 |
+
absl::log_internal_strip
|
| 52 |
+
absl::strings
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
absl_cc_library(
|
| 56 |
+
NAME
|
| 57 |
+
log_internal_conditions
|
| 58 |
+
SRCS
|
| 59 |
+
"internal/conditions.cc"
|
| 60 |
+
HDRS
|
| 61 |
+
"internal/conditions.h"
|
| 62 |
+
COPTS
|
| 63 |
+
${ABSL_DEFAULT_COPTS}
|
| 64 |
+
LINKOPTS
|
| 65 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 66 |
+
DEPS
|
| 67 |
+
absl::base
|
| 68 |
+
absl::config
|
| 69 |
+
absl::core_headers
|
| 70 |
+
absl::log_internal_voidify
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
absl_cc_library(
|
| 74 |
+
NAME
|
| 75 |
+
log_internal_config
|
| 76 |
+
SRCS
|
| 77 |
+
HDRS
|
| 78 |
+
"internal/config.h"
|
| 79 |
+
COPTS
|
| 80 |
+
${ABSL_DEFAULT_COPTS}
|
| 81 |
+
LINKOPTS
|
| 82 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 83 |
+
DEPS
|
| 84 |
+
absl::config
|
| 85 |
+
absl::core_headers
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
absl_cc_library(
|
| 89 |
+
NAME
|
| 90 |
+
log_internal_flags
|
| 91 |
+
SRCS
|
| 92 |
+
HDRS
|
| 93 |
+
"internal/flags.h"
|
| 94 |
+
COPTS
|
| 95 |
+
${ABSL_DEFAULT_COPTS}
|
| 96 |
+
LINKOPTS
|
| 97 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 98 |
+
DEPS
|
| 99 |
+
absl::flags
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
absl_cc_library(
|
| 103 |
+
NAME
|
| 104 |
+
log_internal_format
|
| 105 |
+
SRCS
|
| 106 |
+
"internal/log_format.cc"
|
| 107 |
+
HDRS
|
| 108 |
+
"internal/log_format.h"
|
| 109 |
+
COPTS
|
| 110 |
+
${ABSL_DEFAULT_COPTS}
|
| 111 |
+
LINKOPTS
|
| 112 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 113 |
+
DEPS
|
| 114 |
+
absl::config
|
| 115 |
+
absl::core_headers
|
| 116 |
+
absl::log_internal_append_truncated
|
| 117 |
+
absl::log_internal_config
|
| 118 |
+
absl::log_internal_globals
|
| 119 |
+
absl::log_severity
|
| 120 |
+
absl::strings
|
| 121 |
+
absl::str_format
|
| 122 |
+
absl::time
|
| 123 |
+
absl::span
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
absl_cc_library(
|
| 127 |
+
NAME
|
| 128 |
+
log_internal_globals
|
| 129 |
+
SRCS
|
| 130 |
+
"internal/globals.cc"
|
| 131 |
+
HDRS
|
| 132 |
+
"internal/globals.h"
|
| 133 |
+
COPTS
|
| 134 |
+
${ABSL_DEFAULT_COPTS}
|
| 135 |
+
LINKOPTS
|
| 136 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 137 |
+
DEPS
|
| 138 |
+
absl::config
|
| 139 |
+
absl::core_headers
|
| 140 |
+
absl::log_severity
|
| 141 |
+
absl::raw_logging_internal
|
| 142 |
+
absl::strings
|
| 143 |
+
absl::time
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
absl_cc_library(
|
| 147 |
+
NAME
|
| 148 |
+
log_internal_log_impl
|
| 149 |
+
SRCS
|
| 150 |
+
HDRS
|
| 151 |
+
"internal/log_impl.h"
|
| 152 |
+
COPTS
|
| 153 |
+
${ABSL_DEFAULT_COPTS}
|
| 154 |
+
LINKOPTS
|
| 155 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 156 |
+
DEPS
|
| 157 |
+
absl::log_internal_conditions
|
| 158 |
+
absl::log_internal_message
|
| 159 |
+
absl::log_internal_strip
|
| 160 |
+
absl::absl_vlog_is_on
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
absl_cc_library(
|
| 164 |
+
NAME
|
| 165 |
+
log_internal_proto
|
| 166 |
+
SRCS
|
| 167 |
+
"internal/proto.cc"
|
| 168 |
+
HDRS
|
| 169 |
+
"internal/proto.h"
|
| 170 |
+
COPTS
|
| 171 |
+
${ABSL_DEFAULT_COPTS}
|
| 172 |
+
LINKOPTS
|
| 173 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 174 |
+
DEPS
|
| 175 |
+
absl::base
|
| 176 |
+
absl::config
|
| 177 |
+
absl::core_headers
|
| 178 |
+
absl::strings
|
| 179 |
+
absl::span
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
absl_cc_library(
|
| 183 |
+
NAME
|
| 184 |
+
log_internal_message
|
| 185 |
+
SRCS
|
| 186 |
+
"internal/log_message.cc"
|
| 187 |
+
HDRS
|
| 188 |
+
"internal/log_message.h"
|
| 189 |
+
COPTS
|
| 190 |
+
${ABSL_DEFAULT_COPTS}
|
| 191 |
+
LINKOPTS
|
| 192 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 193 |
+
DEPS
|
| 194 |
+
absl::base
|
| 195 |
+
absl::config
|
| 196 |
+
absl::core_headers
|
| 197 |
+
absl::errno_saver
|
| 198 |
+
absl::inlined_vector
|
| 199 |
+
absl::examine_stack
|
| 200 |
+
absl::log_internal_append_truncated
|
| 201 |
+
absl::log_internal_format
|
| 202 |
+
absl::log_internal_globals
|
| 203 |
+
absl::log_internal_proto
|
| 204 |
+
absl::log_internal_log_sink_set
|
| 205 |
+
absl::log_internal_nullguard
|
| 206 |
+
absl::log_globals
|
| 207 |
+
absl::log_entry
|
| 208 |
+
absl::log_severity
|
| 209 |
+
absl::log_sink
|
| 210 |
+
absl::log_sink_registry
|
| 211 |
+
absl::memory
|
| 212 |
+
absl::raw_logging_internal
|
| 213 |
+
absl::strings
|
| 214 |
+
absl::strerror
|
| 215 |
+
absl::time
|
| 216 |
+
absl::span
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
absl_cc_library(
|
| 220 |
+
NAME
|
| 221 |
+
log_internal_log_sink_set
|
| 222 |
+
SRCS
|
| 223 |
+
"internal/log_sink_set.cc"
|
| 224 |
+
HDRS
|
| 225 |
+
"internal/log_sink_set.h"
|
| 226 |
+
COPTS
|
| 227 |
+
${ABSL_DEFAULT_COPTS}
|
| 228 |
+
LINKOPTS
|
| 229 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 230 |
+
$<$<BOOL:${ANDROID}>:-llog>
|
| 231 |
+
DEPS
|
| 232 |
+
absl::base
|
| 233 |
+
absl::cleanup
|
| 234 |
+
absl::config
|
| 235 |
+
absl::core_headers
|
| 236 |
+
absl::log_internal_config
|
| 237 |
+
absl::log_internal_globals
|
| 238 |
+
absl::log_globals
|
| 239 |
+
absl::log_entry
|
| 240 |
+
absl::log_severity
|
| 241 |
+
absl::log_sink
|
| 242 |
+
absl::no_destructor
|
| 243 |
+
absl::raw_logging_internal
|
| 244 |
+
absl::synchronization
|
| 245 |
+
absl::span
|
| 246 |
+
absl::strings
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
absl_cc_library(
|
| 250 |
+
NAME
|
| 251 |
+
log_internal_nullguard
|
| 252 |
+
SRCS
|
| 253 |
+
"internal/nullguard.cc"
|
| 254 |
+
HDRS
|
| 255 |
+
"internal/nullguard.h"
|
| 256 |
+
COPTS
|
| 257 |
+
${ABSL_DEFAULT_COPTS}
|
| 258 |
+
LINKOPTS
|
| 259 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 260 |
+
DEPS
|
| 261 |
+
absl::config
|
| 262 |
+
absl::core_headers
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
absl_cc_library(
|
| 266 |
+
NAME
|
| 267 |
+
log_internal_nullstream
|
| 268 |
+
SRCS
|
| 269 |
+
HDRS
|
| 270 |
+
"internal/nullstream.h"
|
| 271 |
+
COPTS
|
| 272 |
+
${ABSL_DEFAULT_COPTS}
|
| 273 |
+
LINKOPTS
|
| 274 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 275 |
+
DEPS
|
| 276 |
+
absl::config
|
| 277 |
+
absl::core_headers
|
| 278 |
+
absl::log_severity
|
| 279 |
+
absl::strings
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
absl_cc_library(
|
| 283 |
+
NAME
|
| 284 |
+
log_internal_strip
|
| 285 |
+
SRCS
|
| 286 |
+
HDRS
|
| 287 |
+
"internal/strip.h"
|
| 288 |
+
COPTS
|
| 289 |
+
${ABSL_DEFAULT_COPTS}
|
| 290 |
+
LINKOPTS
|
| 291 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 292 |
+
DEPS
|
| 293 |
+
absl::log_internal_message
|
| 294 |
+
absl::log_internal_nullstream
|
| 295 |
+
absl::log_severity
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
absl_cc_library(
|
| 299 |
+
NAME
|
| 300 |
+
log_internal_test_actions
|
| 301 |
+
SRCS
|
| 302 |
+
"internal/test_actions.cc"
|
| 303 |
+
HDRS
|
| 304 |
+
"internal/test_actions.h"
|
| 305 |
+
COPTS
|
| 306 |
+
${ABSL_DEFAULT_COPTS}
|
| 307 |
+
LINKOPTS
|
| 308 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 309 |
+
DEPS
|
| 310 |
+
absl::config
|
| 311 |
+
absl::core_headers
|
| 312 |
+
absl::log_entry
|
| 313 |
+
absl::log_severity
|
| 314 |
+
absl::strings
|
| 315 |
+
absl::time
|
| 316 |
+
TESTONLY
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
absl_cc_library(
|
| 320 |
+
NAME
|
| 321 |
+
log_internal_test_helpers
|
| 322 |
+
SRCS
|
| 323 |
+
"internal/test_helpers.cc"
|
| 324 |
+
HDRS
|
| 325 |
+
"internal/test_helpers.h"
|
| 326 |
+
COPTS
|
| 327 |
+
${ABSL_DEFAULT_COPTS}
|
| 328 |
+
LINKOPTS
|
| 329 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 330 |
+
DEPS
|
| 331 |
+
absl::config
|
| 332 |
+
absl::log_globals
|
| 333 |
+
absl::log_initialize
|
| 334 |
+
absl::log_internal_globals
|
| 335 |
+
absl::log_severity
|
| 336 |
+
GTest::gtest
|
| 337 |
+
TESTONLY
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
absl_cc_library(
|
| 341 |
+
NAME
|
| 342 |
+
log_internal_test_matchers
|
| 343 |
+
SRCS
|
| 344 |
+
"internal/test_matchers.cc"
|
| 345 |
+
HDRS
|
| 346 |
+
"internal/test_matchers.h"
|
| 347 |
+
COPTS
|
| 348 |
+
${ABSL_DEFAULT_COPTS}
|
| 349 |
+
LINKOPTS
|
| 350 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 351 |
+
DEPS
|
| 352 |
+
absl::config
|
| 353 |
+
absl::core_headers
|
| 354 |
+
absl::log_entry
|
| 355 |
+
absl::log_internal_test_helpers
|
| 356 |
+
absl::log_severity
|
| 357 |
+
absl::strings
|
| 358 |
+
absl::time
|
| 359 |
+
GTest::gtest
|
| 360 |
+
GTest::gmock
|
| 361 |
+
TESTONLY
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
absl_cc_library(
|
| 365 |
+
NAME
|
| 366 |
+
log_internal_voidify
|
| 367 |
+
SRCS
|
| 368 |
+
HDRS
|
| 369 |
+
"internal/voidify.h"
|
| 370 |
+
COPTS
|
| 371 |
+
${ABSL_DEFAULT_COPTS}
|
| 372 |
+
LINKOPTS
|
| 373 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 374 |
+
DEPS
|
| 375 |
+
absl::config
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
absl_cc_library(
|
| 379 |
+
NAME
|
| 380 |
+
log_internal_append_truncated
|
| 381 |
+
SRCS
|
| 382 |
+
HDRS
|
| 383 |
+
"internal/append_truncated.h"
|
| 384 |
+
COPTS
|
| 385 |
+
${ABSL_DEFAULT_COPTS}
|
| 386 |
+
LINKOPTS
|
| 387 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 388 |
+
DEPS
|
| 389 |
+
absl::config
|
| 390 |
+
absl::strings
|
| 391 |
+
absl::span
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
# Public targets
|
| 395 |
+
absl_cc_library(
|
| 396 |
+
NAME
|
| 397 |
+
absl_check
|
| 398 |
+
SRCS
|
| 399 |
+
HDRS
|
| 400 |
+
"absl_check.h"
|
| 401 |
+
COPTS
|
| 402 |
+
${ABSL_DEFAULT_COPTS}
|
| 403 |
+
LINKOPTS
|
| 404 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 405 |
+
DEPS
|
| 406 |
+
absl::log_internal_check_impl
|
| 407 |
+
PUBLIC
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
absl_cc_library(
|
| 411 |
+
NAME
|
| 412 |
+
absl_log
|
| 413 |
+
SRCS
|
| 414 |
+
HDRS
|
| 415 |
+
"absl_log.h"
|
| 416 |
+
COPTS
|
| 417 |
+
${ABSL_DEFAULT_COPTS}
|
| 418 |
+
LINKOPTS
|
| 419 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 420 |
+
DEPS
|
| 421 |
+
absl::log_internal_log_impl
|
| 422 |
+
PUBLIC
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
absl_cc_library(
|
| 426 |
+
NAME
|
| 427 |
+
check
|
| 428 |
+
SRCS
|
| 429 |
+
HDRS
|
| 430 |
+
"check.h"
|
| 431 |
+
COPTS
|
| 432 |
+
${ABSL_DEFAULT_COPTS}
|
| 433 |
+
LINKOPTS
|
| 434 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 435 |
+
DEPS
|
| 436 |
+
absl::log_internal_check_impl
|
| 437 |
+
absl::core_headers
|
| 438 |
+
absl::log_internal_check_op
|
| 439 |
+
absl::log_internal_conditions
|
| 440 |
+
absl::log_internal_message
|
| 441 |
+
absl::log_internal_strip
|
| 442 |
+
PUBLIC
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
absl_cc_library(
|
| 446 |
+
NAME
|
| 447 |
+
die_if_null
|
| 448 |
+
SRCS
|
| 449 |
+
"die_if_null.cc"
|
| 450 |
+
HDRS
|
| 451 |
+
"die_if_null.h"
|
| 452 |
+
COPTS
|
| 453 |
+
${ABSL_DEFAULT_COPTS}
|
| 454 |
+
LINKOPTS
|
| 455 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 456 |
+
DEPS
|
| 457 |
+
absl::config
|
| 458 |
+
absl::core_headers
|
| 459 |
+
absl::log
|
| 460 |
+
absl::strings
|
| 461 |
+
PUBLIC
|
| 462 |
+
)
|
| 463 |
+
|
| 464 |
+
# Warning: Many linkers will strip the contents of this library because its
|
| 465 |
+
# symbols are only used in a global constructor. A workaround is for clients
|
| 466 |
+
# to link this using $<LINK_LIBRARY:WHOLE_ARCHIVE,absl::log_flags> instead of
|
| 467 |
+
# the plain absl::log_flags.
|
| 468 |
+
# TODO(b/320467376): Implement the equivalent of Bazel's alwayslink=True.
|
| 469 |
+
absl_cc_library(
|
| 470 |
+
NAME
|
| 471 |
+
log_flags
|
| 472 |
+
SRCS
|
| 473 |
+
"flags.cc"
|
| 474 |
+
HDRS
|
| 475 |
+
"flags.h"
|
| 476 |
+
COPTS
|
| 477 |
+
${ABSL_DEFAULT_COPTS}
|
| 478 |
+
LINKOPTS
|
| 479 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 480 |
+
DEPS
|
| 481 |
+
absl::config
|
| 482 |
+
absl::core_headers
|
| 483 |
+
absl::log_globals
|
| 484 |
+
absl::log_severity
|
| 485 |
+
absl::log_internal_config
|
| 486 |
+
absl::log_internal_flags
|
| 487 |
+
absl::flags
|
| 488 |
+
absl::flags_marshalling
|
| 489 |
+
absl::strings
|
| 490 |
+
absl::vlog_config_internal
|
| 491 |
+
PUBLIC
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
absl_cc_library(
|
| 495 |
+
NAME
|
| 496 |
+
log_globals
|
| 497 |
+
SRCS
|
| 498 |
+
"globals.cc"
|
| 499 |
+
HDRS
|
| 500 |
+
"globals.h"
|
| 501 |
+
COPTS
|
| 502 |
+
${ABSL_DEFAULT_COPTS}
|
| 503 |
+
LINKOPTS
|
| 504 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 505 |
+
DEPS
|
| 506 |
+
absl::atomic_hook
|
| 507 |
+
absl::config
|
| 508 |
+
absl::core_headers
|
| 509 |
+
absl::hash
|
| 510 |
+
absl::log_severity
|
| 511 |
+
absl::raw_logging_internal
|
| 512 |
+
absl::strings
|
| 513 |
+
absl::vlog_config_internal
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
absl_cc_library(
|
| 517 |
+
NAME
|
| 518 |
+
log_initialize
|
| 519 |
+
SRCS
|
| 520 |
+
"initialize.cc"
|
| 521 |
+
HDRS
|
| 522 |
+
"initialize.h"
|
| 523 |
+
COPTS
|
| 524 |
+
${ABSL_DEFAULT_COPTS}
|
| 525 |
+
LINKOPTS
|
| 526 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 527 |
+
DEPS
|
| 528 |
+
absl::config
|
| 529 |
+
absl::log_globals
|
| 530 |
+
absl::log_internal_globals
|
| 531 |
+
absl::time
|
| 532 |
+
PUBLIC
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
+
absl_cc_library(
|
| 536 |
+
NAME
|
| 537 |
+
log
|
| 538 |
+
SRCS
|
| 539 |
+
HDRS
|
| 540 |
+
"log.h"
|
| 541 |
+
COPTS
|
| 542 |
+
${ABSL_DEFAULT_COPTS}
|
| 543 |
+
LINKOPTS
|
| 544 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 545 |
+
DEPS
|
| 546 |
+
absl::log_internal_log_impl
|
| 547 |
+
absl::vlog_is_on
|
| 548 |
+
PUBLIC
|
| 549 |
+
)
|
| 550 |
+
|
| 551 |
+
absl_cc_library(
|
| 552 |
+
NAME
|
| 553 |
+
log_entry
|
| 554 |
+
SRCS
|
| 555 |
+
"log_entry.cc"
|
| 556 |
+
HDRS
|
| 557 |
+
"log_entry.h"
|
| 558 |
+
COPTS
|
| 559 |
+
${ABSL_DEFAULT_COPTS}
|
| 560 |
+
LINKOPTS
|
| 561 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 562 |
+
DEPS
|
| 563 |
+
absl::config
|
| 564 |
+
absl::core_headers
|
| 565 |
+
absl::log_internal_config
|
| 566 |
+
absl::log_severity
|
| 567 |
+
absl::span
|
| 568 |
+
absl::strings
|
| 569 |
+
absl::time
|
| 570 |
+
PUBLIC
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
absl_cc_library(
|
| 574 |
+
NAME
|
| 575 |
+
log_sink
|
| 576 |
+
SRCS
|
| 577 |
+
"log_sink.cc"
|
| 578 |
+
HDRS
|
| 579 |
+
"log_sink.h"
|
| 580 |
+
COPTS
|
| 581 |
+
${ABSL_DEFAULT_COPTS}
|
| 582 |
+
LINKOPTS
|
| 583 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 584 |
+
DEPS
|
| 585 |
+
absl::config
|
| 586 |
+
absl::log_entry
|
| 587 |
+
PUBLIC
|
| 588 |
+
)
|
| 589 |
+
|
| 590 |
+
absl_cc_library(
|
| 591 |
+
NAME
|
| 592 |
+
log_sink_registry
|
| 593 |
+
SRCS
|
| 594 |
+
HDRS
|
| 595 |
+
"log_sink_registry.h"
|
| 596 |
+
COPTS
|
| 597 |
+
${ABSL_DEFAULT_COPTS}
|
| 598 |
+
LINKOPTS
|
| 599 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 600 |
+
DEPS
|
| 601 |
+
absl::config
|
| 602 |
+
absl::log_sink
|
| 603 |
+
absl::log_internal_log_sink_set
|
| 604 |
+
PUBLIC
|
| 605 |
+
)
|
| 606 |
+
|
| 607 |
+
absl_cc_library(
|
| 608 |
+
NAME
|
| 609 |
+
log_streamer
|
| 610 |
+
SRCS
|
| 611 |
+
HDRS
|
| 612 |
+
"log_streamer.h"
|
| 613 |
+
COPTS
|
| 614 |
+
${ABSL_DEFAULT_COPTS}
|
| 615 |
+
LINKOPTS
|
| 616 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 617 |
+
DEPS
|
| 618 |
+
absl::config
|
| 619 |
+
absl::absl_log
|
| 620 |
+
absl::log_severity
|
| 621 |
+
absl::optional
|
| 622 |
+
absl::strings
|
| 623 |
+
absl::strings_internal
|
| 624 |
+
absl::utility
|
| 625 |
+
PUBLIC
|
| 626 |
+
)
|
| 627 |
+
|
| 628 |
+
absl_cc_library(
|
| 629 |
+
NAME
|
| 630 |
+
scoped_mock_log
|
| 631 |
+
SRCS
|
| 632 |
+
"scoped_mock_log.cc"
|
| 633 |
+
HDRS
|
| 634 |
+
"scoped_mock_log.h"
|
| 635 |
+
COPTS
|
| 636 |
+
${ABSL_DEFAULT_COPTS}
|
| 637 |
+
LINKOPTS
|
| 638 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 639 |
+
DEPS
|
| 640 |
+
absl::config
|
| 641 |
+
absl::log_entry
|
| 642 |
+
absl::log_severity
|
| 643 |
+
absl::log_sink
|
| 644 |
+
absl::log_sink_registry
|
| 645 |
+
absl::raw_logging_internal
|
| 646 |
+
absl::strings
|
| 647 |
+
GTest::gmock
|
| 648 |
+
GTest::gtest
|
| 649 |
+
PUBLIC
|
| 650 |
+
TESTONLY
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
+
absl_cc_library(
|
| 654 |
+
NAME
|
| 655 |
+
log_internal_structured
|
| 656 |
+
HDRS
|
| 657 |
+
"internal/structured.h"
|
| 658 |
+
COPTS
|
| 659 |
+
${ABSL_DEFAULT_COPTS}
|
| 660 |
+
LINKOPTS
|
| 661 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 662 |
+
DEPS
|
| 663 |
+
absl::config
|
| 664 |
+
absl::log_internal_message
|
| 665 |
+
absl::strings
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
+
absl_cc_library(
|
| 669 |
+
NAME
|
| 670 |
+
log_structured
|
| 671 |
+
HDRS
|
| 672 |
+
"structured.h"
|
| 673 |
+
COPTS
|
| 674 |
+
${ABSL_DEFAULT_COPTS}
|
| 675 |
+
LINKOPTS
|
| 676 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 677 |
+
DEPS
|
| 678 |
+
absl::config
|
| 679 |
+
absl::log_internal_structured
|
| 680 |
+
absl::strings
|
| 681 |
+
PUBLIC
|
| 682 |
+
)
|
| 683 |
+
|
| 684 |
+
absl_cc_library(
|
| 685 |
+
NAME
|
| 686 |
+
vlog_config_internal
|
| 687 |
+
SRCS
|
| 688 |
+
"internal/vlog_config.cc"
|
| 689 |
+
HDRS
|
| 690 |
+
"internal/vlog_config.h"
|
| 691 |
+
COPTS
|
| 692 |
+
${ABSL_DEFAULT_COPTS}
|
| 693 |
+
LINKOPTS
|
| 694 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 695 |
+
DEPS
|
| 696 |
+
absl::base
|
| 697 |
+
absl::config
|
| 698 |
+
absl::core_headers
|
| 699 |
+
absl::log_internal_fnmatch
|
| 700 |
+
absl::memory
|
| 701 |
+
absl::no_destructor
|
| 702 |
+
absl::strings
|
| 703 |
+
absl::synchronization
|
| 704 |
+
absl::optional
|
| 705 |
+
)
|
| 706 |
+
|
| 707 |
+
absl_cc_library(
|
| 708 |
+
NAME
|
| 709 |
+
absl_vlog_is_on
|
| 710 |
+
COPTS
|
| 711 |
+
${ABSL_DEFAULT_COPTS}
|
| 712 |
+
LINKOPTS
|
| 713 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 714 |
+
HDRS
|
| 715 |
+
"absl_vlog_is_on.h"
|
| 716 |
+
DEPS
|
| 717 |
+
absl::vlog_config_internal
|
| 718 |
+
absl::config
|
| 719 |
+
absl::core_headers
|
| 720 |
+
absl::strings
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
absl_cc_library(
|
| 724 |
+
NAME
|
| 725 |
+
vlog_is_on
|
| 726 |
+
COPTS
|
| 727 |
+
${ABSL_DEFAULT_COPTS}
|
| 728 |
+
LINKOPTS
|
| 729 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 730 |
+
HDRS
|
| 731 |
+
"vlog_is_on.h"
|
| 732 |
+
DEPS
|
| 733 |
+
absl::absl_vlog_is_on
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
absl_cc_test(
|
| 737 |
+
NAME
|
| 738 |
+
vlog_is_on_test
|
| 739 |
+
SRCS
|
| 740 |
+
"vlog_is_on_test.cc"
|
| 741 |
+
COPTS
|
| 742 |
+
${ABSL_TEST_COPTS}
|
| 743 |
+
LINKOPTS
|
| 744 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 745 |
+
DEPS
|
| 746 |
+
absl::log
|
| 747 |
+
absl::log_flags
|
| 748 |
+
absl::log_globals
|
| 749 |
+
absl::scoped_mock_log
|
| 750 |
+
absl::vlog_is_on
|
| 751 |
+
absl::log_severity
|
| 752 |
+
absl::flags
|
| 753 |
+
absl::optional
|
| 754 |
+
GTest::gmock_main
|
| 755 |
+
)
|
| 756 |
+
|
| 757 |
+
absl_cc_library(
|
| 758 |
+
NAME
|
| 759 |
+
log_internal_fnmatch
|
| 760 |
+
SRCS
|
| 761 |
+
"internal/fnmatch.cc"
|
| 762 |
+
HDRS
|
| 763 |
+
"internal/fnmatch.h"
|
| 764 |
+
COPTS
|
| 765 |
+
${ABSL_DEFAULT_COPTS}
|
| 766 |
+
LINKOPTS
|
| 767 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 768 |
+
DEPS
|
| 769 |
+
absl::config
|
| 770 |
+
absl::strings
|
| 771 |
+
)
|
| 772 |
+
|
| 773 |
+
# Test targets
|
| 774 |
+
|
| 775 |
+
absl_cc_test(
|
| 776 |
+
NAME
|
| 777 |
+
absl_check_test
|
| 778 |
+
SRCS
|
| 779 |
+
"absl_check_test.cc"
|
| 780 |
+
"check_test_impl.inc"
|
| 781 |
+
COPTS
|
| 782 |
+
${ABSL_TEST_COPTS}
|
| 783 |
+
LINKOPTS
|
| 784 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 785 |
+
DEPS
|
| 786 |
+
absl::absl_check
|
| 787 |
+
absl::config
|
| 788 |
+
absl::core_headers
|
| 789 |
+
absl::log_internal_test_helpers
|
| 790 |
+
absl::status
|
| 791 |
+
GTest::gmock_main
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
absl_cc_test(
|
| 795 |
+
NAME
|
| 796 |
+
absl_log_basic_test
|
| 797 |
+
SRCS
|
| 798 |
+
"log_basic_test.cc"
|
| 799 |
+
"log_basic_test_impl.inc"
|
| 800 |
+
COPTS
|
| 801 |
+
${ABSL_TEST_COPTS}
|
| 802 |
+
LINKOPTS
|
| 803 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 804 |
+
DEPS
|
| 805 |
+
absl::base
|
| 806 |
+
absl::absl_log
|
| 807 |
+
absl::log_entry
|
| 808 |
+
absl::log_globals
|
| 809 |
+
absl::log_severity
|
| 810 |
+
absl::log_internal_test_actions
|
| 811 |
+
absl::log_internal_test_helpers
|
| 812 |
+
absl::log_internal_test_matchers
|
| 813 |
+
absl::scoped_mock_log
|
| 814 |
+
GTest::gmock_main
|
| 815 |
+
)
|
| 816 |
+
|
| 817 |
+
absl_cc_test(
|
| 818 |
+
NAME
|
| 819 |
+
check_test
|
| 820 |
+
SRCS
|
| 821 |
+
"check_test.cc"
|
| 822 |
+
"check_test_impl.inc"
|
| 823 |
+
COPTS
|
| 824 |
+
${ABSL_TEST_COPTS}
|
| 825 |
+
LINKOPTS
|
| 826 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 827 |
+
DEPS
|
| 828 |
+
absl::check
|
| 829 |
+
absl::config
|
| 830 |
+
absl::core_headers
|
| 831 |
+
absl::log_internal_test_helpers
|
| 832 |
+
absl::status
|
| 833 |
+
GTest::gmock_main
|
| 834 |
+
)
|
| 835 |
+
|
| 836 |
+
absl_cc_test(
|
| 837 |
+
NAME
|
| 838 |
+
die_if_null_test
|
| 839 |
+
SRCS
|
| 840 |
+
"die_if_null_test.cc"
|
| 841 |
+
COPTS
|
| 842 |
+
${ABSL_TEST_COPTS}
|
| 843 |
+
LINKOPTS
|
| 844 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 845 |
+
DEPS
|
| 846 |
+
absl::core_headers
|
| 847 |
+
absl::die_if_null
|
| 848 |
+
absl::log_internal_test_helpers
|
| 849 |
+
GTest::gtest_main
|
| 850 |
+
)
|
| 851 |
+
|
| 852 |
+
absl_cc_test(
|
| 853 |
+
NAME
|
| 854 |
+
log_basic_test
|
| 855 |
+
SRCS
|
| 856 |
+
"log_basic_test.cc"
|
| 857 |
+
"log_basic_test_impl.inc"
|
| 858 |
+
COPTS
|
| 859 |
+
${ABSL_TEST_COPTS}
|
| 860 |
+
LINKOPTS
|
| 861 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 862 |
+
DEPS
|
| 863 |
+
absl::base
|
| 864 |
+
absl::log
|
| 865 |
+
absl::log_entry
|
| 866 |
+
absl::log_globals
|
| 867 |
+
absl::log_severity
|
| 868 |
+
absl::log_internal_test_actions
|
| 869 |
+
absl::log_internal_test_helpers
|
| 870 |
+
absl::log_internal_test_matchers
|
| 871 |
+
absl::scoped_mock_log
|
| 872 |
+
GTest::gmock_main
|
| 873 |
+
)
|
| 874 |
+
|
| 875 |
+
absl_cc_test(
|
| 876 |
+
NAME
|
| 877 |
+
log_entry_test
|
| 878 |
+
SRCS
|
| 879 |
+
"log_entry_test.cc"
|
| 880 |
+
COPTS
|
| 881 |
+
${ABSL_TEST_COPTS}
|
| 882 |
+
LINKOPTS
|
| 883 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 884 |
+
DEPS
|
| 885 |
+
absl::config
|
| 886 |
+
absl::core_headers
|
| 887 |
+
absl::log_entry
|
| 888 |
+
absl::log_internal_append_truncated
|
| 889 |
+
absl::log_internal_format
|
| 890 |
+
absl::log_internal_globals
|
| 891 |
+
absl::log_internal_test_helpers
|
| 892 |
+
absl::log_severity
|
| 893 |
+
absl::span
|
| 894 |
+
absl::strings
|
| 895 |
+
absl::time
|
| 896 |
+
GTest::gmock_main
|
| 897 |
+
)
|
| 898 |
+
|
| 899 |
+
absl_cc_test(
|
| 900 |
+
NAME
|
| 901 |
+
log_flags_test
|
| 902 |
+
SRCS
|
| 903 |
+
"flags_test.cc"
|
| 904 |
+
COPTS
|
| 905 |
+
${ABSL_TEST_COPTS}
|
| 906 |
+
LINKOPTS
|
| 907 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 908 |
+
DEPS
|
| 909 |
+
absl::core_headers
|
| 910 |
+
absl::log
|
| 911 |
+
absl::log_flags
|
| 912 |
+
absl::log_globals
|
| 913 |
+
absl::log_internal_flags
|
| 914 |
+
absl::log_internal_test_helpers
|
| 915 |
+
absl::log_internal_test_matchers
|
| 916 |
+
absl::log_severity
|
| 917 |
+
absl::flags
|
| 918 |
+
absl::flags_reflection
|
| 919 |
+
absl::scoped_mock_log
|
| 920 |
+
absl::strings
|
| 921 |
+
GTest::gmock_main
|
| 922 |
+
)
|
| 923 |
+
|
| 924 |
+
absl_cc_test(
|
| 925 |
+
NAME
|
| 926 |
+
log_globals_test
|
| 927 |
+
SRCS
|
| 928 |
+
"globals_test.cc"
|
| 929 |
+
COPTS
|
| 930 |
+
${ABSL_TEST_COPTS}
|
| 931 |
+
LINKOPTS
|
| 932 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 933 |
+
DEPS
|
| 934 |
+
absl::core_headers
|
| 935 |
+
absl::log
|
| 936 |
+
absl::log_globals
|
| 937 |
+
absl::log_internal_globals
|
| 938 |
+
absl::log_internal_test_helpers
|
| 939 |
+
absl::log_severity
|
| 940 |
+
absl::scoped_mock_log
|
| 941 |
+
GTest::gmock_main
|
| 942 |
+
)
|
| 943 |
+
|
| 944 |
+
absl_cc_test(
|
| 945 |
+
NAME
|
| 946 |
+
log_format_test
|
| 947 |
+
SRCS
|
| 948 |
+
"log_format_test.cc"
|
| 949 |
+
COPTS
|
| 950 |
+
${ABSL_TEST_COPTS}
|
| 951 |
+
LINKOPTS
|
| 952 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 953 |
+
DEPS
|
| 954 |
+
absl::check
|
| 955 |
+
absl::log
|
| 956 |
+
absl::log_internal_test_matchers
|
| 957 |
+
absl::optional
|
| 958 |
+
absl::scoped_mock_log
|
| 959 |
+
absl::str_format
|
| 960 |
+
absl::strings
|
| 961 |
+
GTest::gmock_main
|
| 962 |
+
)
|
| 963 |
+
|
| 964 |
+
absl_cc_test(
|
| 965 |
+
NAME
|
| 966 |
+
log_macro_hygiene_test
|
| 967 |
+
SRCS
|
| 968 |
+
"log_macro_hygiene_test.cc"
|
| 969 |
+
COPTS
|
| 970 |
+
${ABSL_TEST_COPTS}
|
| 971 |
+
LINKOPTS
|
| 972 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 973 |
+
DEPS
|
| 974 |
+
absl::core_headers
|
| 975 |
+
absl::log
|
| 976 |
+
absl::log_severity
|
| 977 |
+
absl::scoped_mock_log
|
| 978 |
+
GTest::gmock_main
|
| 979 |
+
)
|
| 980 |
+
|
| 981 |
+
absl_cc_test(
|
| 982 |
+
NAME
|
| 983 |
+
log_sink_test
|
| 984 |
+
SRCS
|
| 985 |
+
"log_sink_test.cc"
|
| 986 |
+
COPTS
|
| 987 |
+
${ABSL_TEST_COPTS}
|
| 988 |
+
LINKOPTS
|
| 989 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 990 |
+
DEPS
|
| 991 |
+
absl::core_headers
|
| 992 |
+
absl::log
|
| 993 |
+
absl::log_internal_test_actions
|
| 994 |
+
absl::log_internal_test_helpers
|
| 995 |
+
absl::log_internal_test_matchers
|
| 996 |
+
absl::log_sink
|
| 997 |
+
absl::log_sink_registry
|
| 998 |
+
absl::log_severity
|
| 999 |
+
absl::scoped_mock_log
|
| 1000 |
+
absl::strings
|
| 1001 |
+
GTest::gmock_main
|
| 1002 |
+
)
|
| 1003 |
+
|
| 1004 |
+
absl_cc_test(
|
| 1005 |
+
NAME
|
| 1006 |
+
log_streamer_test
|
| 1007 |
+
SRCS
|
| 1008 |
+
"log_streamer_test.cc"
|
| 1009 |
+
COPTS
|
| 1010 |
+
${ABSL_TEST_COPTS}
|
| 1011 |
+
LINKOPTS
|
| 1012 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 1013 |
+
DEPS
|
| 1014 |
+
absl::base
|
| 1015 |
+
absl::core_headers
|
| 1016 |
+
absl::log
|
| 1017 |
+
absl::log_internal_test_actions
|
| 1018 |
+
absl::log_internal_test_helpers
|
| 1019 |
+
absl::log_internal_test_matchers
|
| 1020 |
+
absl::log_streamer
|
| 1021 |
+
absl::log_severity
|
| 1022 |
+
absl::scoped_mock_log
|
| 1023 |
+
absl::strings
|
| 1024 |
+
GTest::gmock_main
|
| 1025 |
+
)
|
| 1026 |
+
|
| 1027 |
+
absl_cc_test(
|
| 1028 |
+
NAME
|
| 1029 |
+
log_modifier_methods_test
|
| 1030 |
+
SRCS
|
| 1031 |
+
"log_modifier_methods_test.cc"
|
| 1032 |
+
COPTS
|
| 1033 |
+
${ABSL_TEST_COPTS}
|
| 1034 |
+
LINKOPTS
|
| 1035 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 1036 |
+
DEPS
|
| 1037 |
+
absl::log
|
| 1038 |
+
absl::log_internal_test_actions
|
| 1039 |
+
absl::log_internal_test_helpers
|
| 1040 |
+
absl::log_internal_test_matchers
|
| 1041 |
+
absl::log_sink
|
| 1042 |
+
absl::scoped_mock_log
|
| 1043 |
+
absl::strings
|
| 1044 |
+
absl::time
|
| 1045 |
+
GTest::gmock_main
|
| 1046 |
+
)
|
| 1047 |
+
|
| 1048 |
+
absl_cc_test(
|
| 1049 |
+
NAME
|
| 1050 |
+
scoped_mock_log_test
|
| 1051 |
+
SRCS
|
| 1052 |
+
"scoped_mock_log_test.cc"
|
| 1053 |
+
COPTS
|
| 1054 |
+
${ABSL_TEST_COPTS}
|
| 1055 |
+
LINKOPTS
|
| 1056 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 1057 |
+
DEPS
|
| 1058 |
+
absl::core_headers
|
| 1059 |
+
absl::log
|
| 1060 |
+
absl::log_globals
|
| 1061 |
+
absl::log_internal_globals
|
| 1062 |
+
absl::log_internal_test_helpers
|
| 1063 |
+
absl::log_internal_test_matchers
|
| 1064 |
+
absl::log_severity
|
| 1065 |
+
absl::memory
|
| 1066 |
+
absl::scoped_mock_log
|
| 1067 |
+
absl::strings
|
| 1068 |
+
absl::synchronization
|
| 1069 |
+
GTest::gmock
|
| 1070 |
+
GTest::gtest_main
|
| 1071 |
+
)
|
| 1072 |
+
|
| 1073 |
+
absl_cc_test(
|
| 1074 |
+
NAME
|
| 1075 |
+
log_internal_stderr_log_sink_test
|
| 1076 |
+
SRCS
|
| 1077 |
+
"internal/stderr_log_sink_test.cc"
|
| 1078 |
+
COPTS
|
| 1079 |
+
${ABSL_TEST_COPTS}
|
| 1080 |
+
LINKOPTS
|
| 1081 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 1082 |
+
DEPS
|
| 1083 |
+
absl::core_headers
|
| 1084 |
+
absl::log
|
| 1085 |
+
absl::log_globals
|
| 1086 |
+
absl::log_internal_test_helpers
|
| 1087 |
+
absl::log_severity
|
| 1088 |
+
GTest::gmock_main
|
| 1089 |
+
)
|
| 1090 |
+
|
| 1091 |
+
absl_cc_test(
|
| 1092 |
+
NAME
|
| 1093 |
+
log_stripping_test
|
| 1094 |
+
SRCS
|
| 1095 |
+
"stripping_test.cc"
|
| 1096 |
+
COPTS
|
| 1097 |
+
${ABSL_TEST_COPTS}
|
| 1098 |
+
LINKOPTS
|
| 1099 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 1100 |
+
DEPS
|
| 1101 |
+
absl::check
|
| 1102 |
+
absl::flags_program_name
|
| 1103 |
+
absl::log
|
| 1104 |
+
absl::log_internal_test_helpers
|
| 1105 |
+
absl::log_severity
|
| 1106 |
+
absl::status
|
| 1107 |
+
absl::strerror
|
| 1108 |
+
absl::strings
|
| 1109 |
+
absl::str_format
|
| 1110 |
+
GTest::gmock_main
|
| 1111 |
+
)
|
| 1112 |
+
|
| 1113 |
+
absl_cc_test(
|
| 1114 |
+
NAME
|
| 1115 |
+
log_structured_test
|
| 1116 |
+
SRCS
|
| 1117 |
+
"structured_test.cc"
|
| 1118 |
+
COPTS
|
| 1119 |
+
${ABSL_TEST_COPTS}
|
| 1120 |
+
LINKOPTS
|
| 1121 |
+
${ABSL_DEFAULT_LINKOPTS}
|
| 1122 |
+
DEPS
|
| 1123 |
+
absl::core_headers
|
| 1124 |
+
absl::log
|
| 1125 |
+
absl::log_internal_test_helpers
|
| 1126 |
+
absl::log_internal_test_matchers
|
| 1127 |
+
absl::log_structured
|
| 1128 |
+
absl::scoped_mock_log
|
| 1129 |
+
GTest::gmock_main
|
| 1130 |
+
)
|
| 1131 |
+
|
| 1132 |
+
absl_cc_test(
|
| 1133 |
+
NAME
|
| 1134 |
+
internal_fnmatch_test
|
| 1135 |
+
SRCS
|
| 1136 |
+
"internal/fnmatch_test.cc"
|
| 1137 |
+
COPTS
|
| 1138 |
+
${ABSL_TEST_COPTS}
|
| 1139 |
+
LINKOPTS
|
| 1140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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/check.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header declares a family of `CHECK` macros.
|
| 20 |
+
//
|
| 21 |
+
// `CHECK` macros terminate the program with a fatal error if the specified
|
| 22 |
+
// condition is not true.
|
| 23 |
+
//
|
| 24 |
+
// Except for those whose names begin with `DCHECK`, these macros are not
|
| 25 |
+
// controlled by `NDEBUG` (cf. `assert`), so the check will be executed
|
| 26 |
+
// regardless of compilation mode. `CHECK` and friends are thus useful for
|
| 27 |
+
// confirming invariants in situations where continuing to run would be worse
|
| 28 |
+
// than terminating, e.g., due to risk of data corruption or security
|
| 29 |
+
// compromise. It is also more robust and portable to deliberately terminate
|
| 30 |
+
// at a particular place with a useful message and backtrace than to assume some
|
| 31 |
+
// ultimately unspecified and unreliable crashing behavior (such as a
|
| 32 |
+
// "segmentation fault").
|
| 33 |
+
|
| 34 |
+
#ifndef ABSL_LOG_CHECK_H_
|
| 35 |
+
#define ABSL_LOG_CHECK_H_
|
| 36 |
+
|
| 37 |
+
#include "absl/log/internal/check_impl.h"
|
| 38 |
+
#include "absl/log/internal/check_op.h" // IWYU pragma: export
|
| 39 |
+
#include "absl/log/internal/conditions.h" // IWYU pragma: export
|
| 40 |
+
#include "absl/log/internal/log_message.h" // IWYU pragma: export
|
| 41 |
+
#include "absl/log/internal/strip.h" // IWYU pragma: export
|
| 42 |
+
|
| 43 |
+
// CHECK()
|
| 44 |
+
//
|
| 45 |
+
// `CHECK` terminates the program with a fatal error if `condition` is not true.
|
| 46 |
+
//
|
| 47 |
+
// The message may include additional information such as stack traces, when
|
| 48 |
+
// available.
|
| 49 |
+
//
|
| 50 |
+
// Example:
|
| 51 |
+
//
|
| 52 |
+
// CHECK(!cheese.empty()) << "Out of Cheese";
|
| 53 |
+
//
|
| 54 |
+
// Might produce a message like:
|
| 55 |
+
//
|
| 56 |
+
// Check failed: !cheese.empty() Out of Cheese
|
| 57 |
+
#define CHECK(condition) ABSL_LOG_INTERNAL_CHECK_IMPL((condition), #condition)
|
| 58 |
+
|
| 59 |
+
// QCHECK()
|
| 60 |
+
//
|
| 61 |
+
// `QCHECK` behaves like `CHECK` but does not print a full stack trace and does
|
| 62 |
+
// not run registered error handlers (as `QFATAL`). It is useful when the
|
| 63 |
+
// problem is definitely unrelated to program flow, e.g. when validating user
|
| 64 |
+
// input.
|
| 65 |
+
#define QCHECK(condition) ABSL_LOG_INTERNAL_QCHECK_IMPL((condition), #condition)
|
| 66 |
+
|
| 67 |
+
// PCHECK()
|
| 68 |
+
//
|
| 69 |
+
// `PCHECK` behaves like `CHECK` but appends a description of the current state
|
| 70 |
+
// of `errno` to the failure message.
|
| 71 |
+
//
|
| 72 |
+
// Example:
|
| 73 |
+
//
|
| 74 |
+
// int fd = open("/var/empty/missing", O_RDONLY);
|
| 75 |
+
// PCHECK(fd != -1) << "posix is difficult";
|
| 76 |
+
//
|
| 77 |
+
// Might produce a message like:
|
| 78 |
+
//
|
| 79 |
+
// Check failed: fd != -1 posix is difficult: No such file or directory [2]
|
| 80 |
+
#define PCHECK(condition) ABSL_LOG_INTERNAL_PCHECK_IMPL((condition), #condition)
|
| 81 |
+
|
| 82 |
+
// DCHECK()
|
| 83 |
+
//
|
| 84 |
+
// `DCHECK` behaves like `CHECK` in debug mode and does nothing otherwise (as
|
| 85 |
+
// `DLOG`). Unlike with `CHECK` (but as with `assert`), it is not safe to rely
|
| 86 |
+
// on evaluation of `condition`: when `NDEBUG` is enabled, DCHECK does not
|
| 87 |
+
// evaluate the condition.
|
| 88 |
+
#define DCHECK(condition) ABSL_LOG_INTERNAL_DCHECK_IMPL((condition), #condition)
|
| 89 |
+
|
| 90 |
+
// `CHECK_EQ` and friends are syntactic sugar for `CHECK(x == y)` that
|
| 91 |
+
// automatically output the expression being tested and the evaluated values on
|
| 92 |
+
// either side.
|
| 93 |
+
//
|
| 94 |
+
// Example:
|
| 95 |
+
//
|
| 96 |
+
// int x = 3, y = 5;
|
| 97 |
+
// CHECK_EQ(2 * x, y) << "oops!";
|
| 98 |
+
//
|
| 99 |
+
// Might produce a message like:
|
| 100 |
+
//
|
| 101 |
+
// Check failed: 2 * x == y (6 vs. 5) oops!
|
| 102 |
+
//
|
| 103 |
+
// The values must implement the appropriate comparison operator as well as
|
| 104 |
+
// `operator<<(std::ostream&, ...)`. Care is taken to ensure that each
|
| 105 |
+
// argument is evaluated exactly once, and that anything which is legal to pass
|
| 106 |
+
// as a function argument is legal here. In particular, the arguments may be
|
| 107 |
+
// temporary expressions which will end up being destroyed at the end of the
|
| 108 |
+
// statement,
|
| 109 |
+
//
|
| 110 |
+
// Example:
|
| 111 |
+
//
|
| 112 |
+
// CHECK_EQ(std::string("abc")[1], 'b');
|
| 113 |
+
//
|
| 114 |
+
// WARNING: Passing `NULL` as an argument to `CHECK_EQ` and similar macros does
|
| 115 |
+
// not compile. Use `nullptr` instead.
|
| 116 |
+
#define CHECK_EQ(val1, val2) \
|
| 117 |
+
ABSL_LOG_INTERNAL_CHECK_EQ_IMPL((val1), #val1, (val2), #val2)
|
| 118 |
+
#define CHECK_NE(val1, val2) \
|
| 119 |
+
ABSL_LOG_INTERNAL_CHECK_NE_IMPL((val1), #val1, (val2), #val2)
|
| 120 |
+
#define CHECK_LE(val1, val2) \
|
| 121 |
+
ABSL_LOG_INTERNAL_CHECK_LE_IMPL((val1), #val1, (val2), #val2)
|
| 122 |
+
#define CHECK_LT(val1, val2) \
|
| 123 |
+
ABSL_LOG_INTERNAL_CHECK_LT_IMPL((val1), #val1, (val2), #val2)
|
| 124 |
+
#define CHECK_GE(val1, val2) \
|
| 125 |
+
ABSL_LOG_INTERNAL_CHECK_GE_IMPL((val1), #val1, (val2), #val2)
|
| 126 |
+
#define CHECK_GT(val1, val2) \
|
| 127 |
+
ABSL_LOG_INTERNAL_CHECK_GT_IMPL((val1), #val1, (val2), #val2)
|
| 128 |
+
#define QCHECK_EQ(val1, val2) \
|
| 129 |
+
ABSL_LOG_INTERNAL_QCHECK_EQ_IMPL((val1), #val1, (val2), #val2)
|
| 130 |
+
#define QCHECK_NE(val1, val2) \
|
| 131 |
+
ABSL_LOG_INTERNAL_QCHECK_NE_IMPL((val1), #val1, (val2), #val2)
|
| 132 |
+
#define QCHECK_LE(val1, val2) \
|
| 133 |
+
ABSL_LOG_INTERNAL_QCHECK_LE_IMPL((val1), #val1, (val2), #val2)
|
| 134 |
+
#define QCHECK_LT(val1, val2) \
|
| 135 |
+
ABSL_LOG_INTERNAL_QCHECK_LT_IMPL((val1), #val1, (val2), #val2)
|
| 136 |
+
#define QCHECK_GE(val1, val2) \
|
| 137 |
+
ABSL_LOG_INTERNAL_QCHECK_GE_IMPL((val1), #val1, (val2), #val2)
|
| 138 |
+
#define QCHECK_GT(val1, val2) \
|
| 139 |
+
ABSL_LOG_INTERNAL_QCHECK_GT_IMPL((val1), #val1, (val2), #val2)
|
| 140 |
+
#define DCHECK_EQ(val1, val2) \
|
| 141 |
+
ABSL_LOG_INTERNAL_DCHECK_EQ_IMPL((val1), #val1, (val2), #val2)
|
| 142 |
+
#define DCHECK_NE(val1, val2) \
|
| 143 |
+
ABSL_LOG_INTERNAL_DCHECK_NE_IMPL((val1), #val1, (val2), #val2)
|
| 144 |
+
#define DCHECK_LE(val1, val2) \
|
| 145 |
+
ABSL_LOG_INTERNAL_DCHECK_LE_IMPL((val1), #val1, (val2), #val2)
|
| 146 |
+
#define DCHECK_LT(val1, val2) \
|
| 147 |
+
ABSL_LOG_INTERNAL_DCHECK_LT_IMPL((val1), #val1, (val2), #val2)
|
| 148 |
+
#define DCHECK_GE(val1, val2) \
|
| 149 |
+
ABSL_LOG_INTERNAL_DCHECK_GE_IMPL((val1), #val1, (val2), #val2)
|
| 150 |
+
#define DCHECK_GT(val1, val2) \
|
| 151 |
+
ABSL_LOG_INTERNAL_DCHECK_GT_IMPL((val1), #val1, (val2), #val2)
|
| 152 |
+
|
| 153 |
+
// `CHECK_OK` and friends validate that the provided `absl::Status` or
|
| 154 |
+
// `absl::StatusOr<T>` is OK. If it isn't, they print a failure message that
|
| 155 |
+
// includes the actual status and terminate the program.
|
| 156 |
+
//
|
| 157 |
+
// As with all `DCHECK` variants, `DCHECK_OK` has no effect (not even
|
| 158 |
+
// evaluating its argument) if `NDEBUG` is enabled.
|
| 159 |
+
//
|
| 160 |
+
// Example:
|
| 161 |
+
//
|
| 162 |
+
// CHECK_OK(FunctionReturnsStatus(x, y, z)) << "oops!";
|
| 163 |
+
//
|
| 164 |
+
// Might produce a message like:
|
| 165 |
+
//
|
| 166 |
+
// Check failed: FunctionReturnsStatus(x, y, z) is OK (ABORTED: timeout) oops!
|
| 167 |
+
#define CHECK_OK(status) ABSL_LOG_INTERNAL_CHECK_OK_IMPL((status), #status)
|
| 168 |
+
#define QCHECK_OK(status) ABSL_LOG_INTERNAL_QCHECK_OK_IMPL((status), #status)
|
| 169 |
+
#define DCHECK_OK(status) ABSL_LOG_INTERNAL_DCHECK_OK_IMPL((status), #status)
|
| 170 |
+
|
| 171 |
+
// `CHECK_STREQ` and friends provide `CHECK_EQ` functionality for C strings,
|
| 172 |
+
// i.e., null-terminated char arrays. The `CASE` versions are case-insensitive.
|
| 173 |
+
//
|
| 174 |
+
// Example:
|
| 175 |
+
//
|
| 176 |
+
// CHECK_STREQ(argv[0], "./skynet");
|
| 177 |
+
//
|
| 178 |
+
// Note that both arguments may be temporary strings which are destroyed by the
|
| 179 |
+
// compiler at the end of the current full expression.
|
| 180 |
+
//
|
| 181 |
+
// Example:
|
| 182 |
+
//
|
| 183 |
+
// CHECK_STREQ(Foo().c_str(), Bar().c_str());
|
| 184 |
+
#define CHECK_STREQ(s1, s2) \
|
| 185 |
+
ABSL_LOG_INTERNAL_CHECK_STREQ_IMPL((s1), #s1, (s2), #s2)
|
| 186 |
+
#define CHECK_STRNE(s1, s2) \
|
| 187 |
+
ABSL_LOG_INTERNAL_CHECK_STRNE_IMPL((s1), #s1, (s2), #s2)
|
| 188 |
+
#define CHECK_STRCASEEQ(s1, s2) \
|
| 189 |
+
ABSL_LOG_INTERNAL_CHECK_STRCASEEQ_IMPL((s1), #s1, (s2), #s2)
|
| 190 |
+
#define CHECK_STRCASENE(s1, s2) \
|
| 191 |
+
ABSL_LOG_INTERNAL_CHECK_STRCASENE_IMPL((s1), #s1, (s2), #s2)
|
| 192 |
+
#define QCHECK_STREQ(s1, s2) \
|
| 193 |
+
ABSL_LOG_INTERNAL_QCHECK_STREQ_IMPL((s1), #s1, (s2), #s2)
|
| 194 |
+
#define QCHECK_STRNE(s1, s2) \
|
| 195 |
+
ABSL_LOG_INTERNAL_QCHECK_STRNE_IMPL((s1), #s1, (s2), #s2)
|
| 196 |
+
#define QCHECK_STRCASEEQ(s1, s2) \
|
| 197 |
+
ABSL_LOG_INTERNAL_QCHECK_STRCASEEQ_IMPL((s1), #s1, (s2), #s2)
|
| 198 |
+
#define QCHECK_STRCASENE(s1, s2) \
|
| 199 |
+
ABSL_LOG_INTERNAL_QCHECK_STRCASENE_IMPL((s1), #s1, (s2), #s2)
|
| 200 |
+
#define DCHECK_STREQ(s1, s2) \
|
| 201 |
+
ABSL_LOG_INTERNAL_DCHECK_STREQ_IMPL((s1), #s1, (s2), #s2)
|
| 202 |
+
#define DCHECK_STRNE(s1, s2) \
|
| 203 |
+
ABSL_LOG_INTERNAL_DCHECK_STRNE_IMPL((s1), #s1, (s2), #s2)
|
| 204 |
+
#define DCHECK_STRCASEEQ(s1, s2) \
|
| 205 |
+
ABSL_LOG_INTERNAL_DCHECK_STRCASEEQ_IMPL((s1), #s1, (s2), #s2)
|
| 206 |
+
#define DCHECK_STRCASENE(s1, s2) \
|
| 207 |
+
ABSL_LOG_INTERNAL_DCHECK_STRCASENE_IMPL((s1), #s1, (s2), #s2)
|
| 208 |
+
|
| 209 |
+
#endif // ABSL_LOG_CHECK_H_
|
weight/_dep/abseil-cpp/absl/log/check_test.cc
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/check.h"
|
| 17 |
+
|
| 18 |
+
#define ABSL_TEST_CHECK CHECK
|
| 19 |
+
#define ABSL_TEST_CHECK_OK CHECK_OK
|
| 20 |
+
#define ABSL_TEST_CHECK_EQ CHECK_EQ
|
| 21 |
+
#define ABSL_TEST_CHECK_NE CHECK_NE
|
| 22 |
+
#define ABSL_TEST_CHECK_GE CHECK_GE
|
| 23 |
+
#define ABSL_TEST_CHECK_LE CHECK_LE
|
| 24 |
+
#define ABSL_TEST_CHECK_GT CHECK_GT
|
| 25 |
+
#define ABSL_TEST_CHECK_LT CHECK_LT
|
| 26 |
+
#define ABSL_TEST_CHECK_STREQ CHECK_STREQ
|
| 27 |
+
#define ABSL_TEST_CHECK_STRNE CHECK_STRNE
|
| 28 |
+
#define ABSL_TEST_CHECK_STRCASEEQ CHECK_STRCASEEQ
|
| 29 |
+
#define ABSL_TEST_CHECK_STRCASENE CHECK_STRCASENE
|
| 30 |
+
|
| 31 |
+
#define ABSL_TEST_DCHECK DCHECK
|
| 32 |
+
#define ABSL_TEST_DCHECK_OK DCHECK_OK
|
| 33 |
+
#define ABSL_TEST_DCHECK_EQ DCHECK_EQ
|
| 34 |
+
#define ABSL_TEST_DCHECK_NE DCHECK_NE
|
| 35 |
+
#define ABSL_TEST_DCHECK_GE DCHECK_GE
|
| 36 |
+
#define ABSL_TEST_DCHECK_LE DCHECK_LE
|
| 37 |
+
#define ABSL_TEST_DCHECK_GT DCHECK_GT
|
| 38 |
+
#define ABSL_TEST_DCHECK_LT DCHECK_LT
|
| 39 |
+
#define ABSL_TEST_DCHECK_STREQ DCHECK_STREQ
|
| 40 |
+
#define ABSL_TEST_DCHECK_STRNE DCHECK_STRNE
|
| 41 |
+
#define ABSL_TEST_DCHECK_STRCASEEQ DCHECK_STRCASEEQ
|
| 42 |
+
#define ABSL_TEST_DCHECK_STRCASENE DCHECK_STRCASENE
|
| 43 |
+
|
| 44 |
+
#define ABSL_TEST_QCHECK QCHECK
|
| 45 |
+
#define ABSL_TEST_QCHECK_OK QCHECK_OK
|
| 46 |
+
#define ABSL_TEST_QCHECK_EQ QCHECK_EQ
|
| 47 |
+
#define ABSL_TEST_QCHECK_NE QCHECK_NE
|
| 48 |
+
#define ABSL_TEST_QCHECK_GE QCHECK_GE
|
| 49 |
+
#define ABSL_TEST_QCHECK_LE QCHECK_LE
|
| 50 |
+
#define ABSL_TEST_QCHECK_GT QCHECK_GT
|
| 51 |
+
#define ABSL_TEST_QCHECK_LT QCHECK_LT
|
| 52 |
+
#define ABSL_TEST_QCHECK_STREQ QCHECK_STREQ
|
| 53 |
+
#define ABSL_TEST_QCHECK_STRNE QCHECK_STRNE
|
| 54 |
+
#define ABSL_TEST_QCHECK_STRCASEEQ QCHECK_STRCASEEQ
|
| 55 |
+
#define ABSL_TEST_QCHECK_STRCASENE QCHECK_STRCASENE
|
| 56 |
+
|
| 57 |
+
#include "gtest/gtest.h"
|
| 58 |
+
#include "absl/log/check_test_impl.inc"
|
weight/_dep/abseil-cpp/absl/log/check_test_impl.inc
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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 |
+
#ifndef ABSL_LOG_CHECK_TEST_IMPL_H_
|
| 17 |
+
#define ABSL_LOG_CHECK_TEST_IMPL_H_
|
| 18 |
+
|
| 19 |
+
// Verify that both sets of macros behave identically by parameterizing the
|
| 20 |
+
// entire test file.
|
| 21 |
+
#ifndef ABSL_TEST_CHECK
|
| 22 |
+
#error ABSL_TEST_CHECK must be defined for these tests to work.
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
#include <ostream>
|
| 26 |
+
#include <string>
|
| 27 |
+
|
| 28 |
+
#include "gmock/gmock.h"
|
| 29 |
+
#include "gtest/gtest.h"
|
| 30 |
+
#include "absl/base/attributes.h"
|
| 31 |
+
#include "absl/base/config.h"
|
| 32 |
+
#include "absl/log/internal/test_helpers.h"
|
| 33 |
+
#include "absl/status/status.h"
|
| 34 |
+
|
| 35 |
+
// NOLINTBEGIN(misc-definitions-in-headers)
|
| 36 |
+
|
| 37 |
+
namespace absl_log_internal {
|
| 38 |
+
|
| 39 |
+
using ::testing::AllOf;
|
| 40 |
+
using ::testing::HasSubstr;
|
| 41 |
+
using ::testing::Not;
|
| 42 |
+
|
| 43 |
+
auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
|
| 44 |
+
new absl::log_internal::LogTestEnvironment);
|
| 45 |
+
|
| 46 |
+
#if GTEST_HAS_DEATH_TEST
|
| 47 |
+
|
| 48 |
+
TEST(CHECKDeathTest, TestBasicValues) {
|
| 49 |
+
ABSL_TEST_CHECK(true);
|
| 50 |
+
|
| 51 |
+
EXPECT_DEATH(ABSL_TEST_CHECK(false), "Check failed: false");
|
| 52 |
+
|
| 53 |
+
int i = 2;
|
| 54 |
+
ABSL_TEST_CHECK(i != 3); // NOLINT
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
#endif // GTEST_HAS_DEATH_TEST
|
| 58 |
+
|
| 59 |
+
TEST(CHECKTest, TestLogicExpressions) {
|
| 60 |
+
int i = 5;
|
| 61 |
+
ABSL_TEST_CHECK(i > 0 && i < 10);
|
| 62 |
+
ABSL_TEST_CHECK(i < 0 || i > 3);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
| 66 |
+
ABSL_CONST_INIT const auto global_var_check = [](int i) {
|
| 67 |
+
ABSL_TEST_CHECK(i > 0); // NOLINT
|
| 68 |
+
return i + 1;
|
| 69 |
+
}(3);
|
| 70 |
+
|
| 71 |
+
ABSL_CONST_INIT const auto global_var = [](int i) {
|
| 72 |
+
ABSL_TEST_CHECK_GE(i, 0); // NOLINT
|
| 73 |
+
return i + 1;
|
| 74 |
+
}(global_var_check);
|
| 75 |
+
#endif // ABSL_INTERNAL_CPLUSPLUS_LANG
|
| 76 |
+
|
| 77 |
+
TEST(CHECKTest, TestPlacementsInCompoundStatements) {
|
| 78 |
+
// check placement inside if/else clauses
|
| 79 |
+
if (true) ABSL_TEST_CHECK(true);
|
| 80 |
+
|
| 81 |
+
if (false)
|
| 82 |
+
; // NOLINT
|
| 83 |
+
else
|
| 84 |
+
ABSL_TEST_CHECK(true);
|
| 85 |
+
|
| 86 |
+
switch (0)
|
| 87 |
+
case 0:
|
| 88 |
+
ABSL_TEST_CHECK(true); // NOLINT
|
| 89 |
+
|
| 90 |
+
#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
| 91 |
+
constexpr auto var = [](int i) {
|
| 92 |
+
ABSL_TEST_CHECK(i > 0); // NOLINT
|
| 93 |
+
return i + 1;
|
| 94 |
+
}(global_var);
|
| 95 |
+
(void)var;
|
| 96 |
+
#endif // ABSL_INTERNAL_CPLUSPLUS_LANG
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
TEST(CHECKTest, TestBoolConvertible) {
|
| 100 |
+
struct Tester {
|
| 101 |
+
} tester;
|
| 102 |
+
ABSL_TEST_CHECK([&]() { return &tester; }());
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
#if GTEST_HAS_DEATH_TEST
|
| 106 |
+
|
| 107 |
+
TEST(CHECKDeathTest, TestChecksWithSideEffects) {
|
| 108 |
+
int var = 0;
|
| 109 |
+
ABSL_TEST_CHECK([&var]() {
|
| 110 |
+
++var;
|
| 111 |
+
return true;
|
| 112 |
+
}());
|
| 113 |
+
EXPECT_EQ(var, 1);
|
| 114 |
+
|
| 115 |
+
EXPECT_DEATH(ABSL_TEST_CHECK([&var]() {
|
| 116 |
+
++var;
|
| 117 |
+
return false;
|
| 118 |
+
}()) << var,
|
| 119 |
+
"Check failed: .* 2");
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
#endif // GTEST_HAS_DEATH_TEST
|
| 123 |
+
|
| 124 |
+
template <int a, int b>
|
| 125 |
+
constexpr int sum() {
|
| 126 |
+
return a + b;
|
| 127 |
+
}
|
| 128 |
+
#define MACRO_ONE 1
|
| 129 |
+
#define TEMPLATE_SUM(a, b) sum<a, b>()
|
| 130 |
+
#define CONCAT(a, b) a b
|
| 131 |
+
#define IDENTITY(x) x
|
| 132 |
+
|
| 133 |
+
TEST(CHECKTest, TestPassingMacroExpansion) {
|
| 134 |
+
ABSL_TEST_CHECK(IDENTITY(true));
|
| 135 |
+
ABSL_TEST_CHECK_EQ(TEMPLATE_SUM(MACRO_ONE, 2), 3);
|
| 136 |
+
ABSL_TEST_CHECK_STREQ(CONCAT("x", "y"), "xy");
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
#if GTEST_HAS_DEATH_TEST
|
| 140 |
+
|
| 141 |
+
TEST(CHECKTest, TestMacroExpansionInMessage) {
|
| 142 |
+
auto MessageGen = []() { ABSL_TEST_CHECK(IDENTITY(false)); };
|
| 143 |
+
EXPECT_DEATH(MessageGen(), HasSubstr("IDENTITY(false)"));
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
TEST(CHECKTest, TestNestedMacroExpansionInMessage) {
|
| 147 |
+
EXPECT_DEATH(ABSL_TEST_CHECK(IDENTITY(false)), HasSubstr("IDENTITY(false)"));
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
TEST(CHECKTest, TestMacroExpansionCompare) {
|
| 151 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(IDENTITY(false), IDENTITY(true)),
|
| 152 |
+
HasSubstr("IDENTITY(false) == IDENTITY(true)"));
|
| 153 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_GT(IDENTITY(1), IDENTITY(2)),
|
| 154 |
+
HasSubstr("IDENTITY(1) > IDENTITY(2)"));
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
TEST(CHECKTest, TestMacroExpansionStrCompare) {
|
| 158 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_STREQ(IDENTITY("x"), IDENTITY("y")),
|
| 159 |
+
HasSubstr("IDENTITY(\"x\") == IDENTITY(\"y\")"));
|
| 160 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_STRCASENE(IDENTITY("a"), IDENTITY("A")),
|
| 161 |
+
HasSubstr("IDENTITY(\"a\") != IDENTITY(\"A\")"));
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
TEST(CHECKTest, TestMacroExpansionStatus) {
|
| 165 |
+
EXPECT_DEATH(
|
| 166 |
+
ABSL_TEST_CHECK_OK(IDENTITY(absl::FailedPreconditionError("message"))),
|
| 167 |
+
HasSubstr("IDENTITY(absl::FailedPreconditionError(\"message\"))"));
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
TEST(CHECKTest, TestMacroExpansionComma) {
|
| 171 |
+
EXPECT_DEATH(ABSL_TEST_CHECK(TEMPLATE_SUM(MACRO_ONE, 2) == 4),
|
| 172 |
+
HasSubstr("TEMPLATE_SUM(MACRO_ONE, 2) == 4"));
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
TEST(CHECKTest, TestMacroExpansionCommaCompare) {
|
| 176 |
+
EXPECT_DEATH(
|
| 177 |
+
ABSL_TEST_CHECK_EQ(TEMPLATE_SUM(2, MACRO_ONE), TEMPLATE_SUM(3, 2)),
|
| 178 |
+
HasSubstr("TEMPLATE_SUM(2, MACRO_ONE) == TEMPLATE_SUM(3, 2)"));
|
| 179 |
+
EXPECT_DEATH(
|
| 180 |
+
ABSL_TEST_CHECK_GT(TEMPLATE_SUM(2, MACRO_ONE), TEMPLATE_SUM(3, 2)),
|
| 181 |
+
HasSubstr("TEMPLATE_SUM(2, MACRO_ONE) > TEMPLATE_SUM(3, 2)"));
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
TEST(CHECKTest, TestMacroExpansionCommaStrCompare) {
|
| 185 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_STREQ(CONCAT("x", "y"), "z"),
|
| 186 |
+
HasSubstr("CONCAT(\"x\", \"y\") == \"z\""));
|
| 187 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_STRNE(CONCAT("x", "y"), "xy"),
|
| 188 |
+
HasSubstr("CONCAT(\"x\", \"y\") != \"xy\""));
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
#endif // GTEST_HAS_DEATH_TEST
|
| 192 |
+
|
| 193 |
+
#undef TEMPLATE_SUM
|
| 194 |
+
#undef CONCAT
|
| 195 |
+
#undef MACRO
|
| 196 |
+
#undef ONE
|
| 197 |
+
|
| 198 |
+
#if GTEST_HAS_DEATH_TEST
|
| 199 |
+
|
| 200 |
+
TEST(CHECKDeachTest, TestOrderOfInvocationsBetweenCheckAndMessage) {
|
| 201 |
+
int counter = 0;
|
| 202 |
+
|
| 203 |
+
auto GetStr = [&counter]() -> std::string {
|
| 204 |
+
return counter++ == 0 ? "" : "non-empty";
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
EXPECT_DEATH(ABSL_TEST_CHECK(!GetStr().empty()) << GetStr(),
|
| 208 |
+
HasSubstr("non-empty"));
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
TEST(CHECKTest, TestSecondaryFailure) {
|
| 212 |
+
auto FailingRoutine = []() {
|
| 213 |
+
ABSL_TEST_CHECK(false) << "Secondary";
|
| 214 |
+
return false;
|
| 215 |
+
};
|
| 216 |
+
EXPECT_DEATH(ABSL_TEST_CHECK(FailingRoutine()) << "Primary",
|
| 217 |
+
AllOf(HasSubstr("Secondary"), Not(HasSubstr("Primary"))));
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
TEST(CHECKTest, TestSecondaryFailureInMessage) {
|
| 221 |
+
auto MessageGen = []() {
|
| 222 |
+
ABSL_TEST_CHECK(false) << "Secondary";
|
| 223 |
+
return "Primary";
|
| 224 |
+
};
|
| 225 |
+
EXPECT_DEATH(ABSL_TEST_CHECK(false) << MessageGen(),
|
| 226 |
+
AllOf(HasSubstr("Secondary"), Not(HasSubstr("Primary"))));
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
#endif // GTEST_HAS_DEATH_TEST
|
| 230 |
+
|
| 231 |
+
TEST(CHECKTest, TestBinaryChecksWithPrimitives) {
|
| 232 |
+
ABSL_TEST_CHECK_EQ(1, 1);
|
| 233 |
+
ABSL_TEST_CHECK_NE(1, 2);
|
| 234 |
+
ABSL_TEST_CHECK_GE(1, 1);
|
| 235 |
+
ABSL_TEST_CHECK_GE(2, 1);
|
| 236 |
+
ABSL_TEST_CHECK_LE(1, 1);
|
| 237 |
+
ABSL_TEST_CHECK_LE(1, 2);
|
| 238 |
+
ABSL_TEST_CHECK_GT(2, 1);
|
| 239 |
+
ABSL_TEST_CHECK_LT(1, 2);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
// For testing using CHECK*() on anonymous enums.
|
| 243 |
+
enum { CASE_A, CASE_B };
|
| 244 |
+
|
| 245 |
+
TEST(CHECKTest, TestBinaryChecksWithEnumValues) {
|
| 246 |
+
// Tests using CHECK*() on anonymous enums.
|
| 247 |
+
ABSL_TEST_CHECK_EQ(CASE_A, CASE_A);
|
| 248 |
+
ABSL_TEST_CHECK_NE(CASE_A, CASE_B);
|
| 249 |
+
ABSL_TEST_CHECK_GE(CASE_A, CASE_A);
|
| 250 |
+
ABSL_TEST_CHECK_GE(CASE_B, CASE_A);
|
| 251 |
+
ABSL_TEST_CHECK_LE(CASE_A, CASE_A);
|
| 252 |
+
ABSL_TEST_CHECK_LE(CASE_A, CASE_B);
|
| 253 |
+
ABSL_TEST_CHECK_GT(CASE_B, CASE_A);
|
| 254 |
+
ABSL_TEST_CHECK_LT(CASE_A, CASE_B);
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
TEST(CHECKTest, TestBinaryChecksWithNullptr) {
|
| 258 |
+
const void* p_null = nullptr;
|
| 259 |
+
const void* p_not_null = &p_null;
|
| 260 |
+
ABSL_TEST_CHECK_EQ(p_null, nullptr);
|
| 261 |
+
ABSL_TEST_CHECK_EQ(nullptr, p_null);
|
| 262 |
+
ABSL_TEST_CHECK_NE(p_not_null, nullptr);
|
| 263 |
+
ABSL_TEST_CHECK_NE(nullptr, p_not_null);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
#if GTEST_HAS_DEATH_TEST
|
| 267 |
+
|
| 268 |
+
// Test logging of various char-typed values by failing CHECK*().
|
| 269 |
+
TEST(CHECKDeathTest, TestComparingCharsValues) {
|
| 270 |
+
{
|
| 271 |
+
char a = ';';
|
| 272 |
+
char b = 'b';
|
| 273 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 274 |
+
"Check failed: a == b \\(';' vs. 'b'\\)");
|
| 275 |
+
b = 1;
|
| 276 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 277 |
+
"Check failed: a == b \\(';' vs. char value 1\\)");
|
| 278 |
+
}
|
| 279 |
+
{
|
| 280 |
+
signed char a = ';';
|
| 281 |
+
signed char b = 'b';
|
| 282 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 283 |
+
"Check failed: a == b \\(';' vs. 'b'\\)");
|
| 284 |
+
b = -128;
|
| 285 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 286 |
+
"Check failed: a == b \\(';' vs. signed char value -128\\)");
|
| 287 |
+
}
|
| 288 |
+
{
|
| 289 |
+
unsigned char a = ';';
|
| 290 |
+
unsigned char b = 'b';
|
| 291 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 292 |
+
"Check failed: a == b \\(';' vs. 'b'\\)");
|
| 293 |
+
b = 128;
|
| 294 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 295 |
+
"Check failed: a == b \\(';' vs. unsigned char value 128\\)");
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
TEST(CHECKDeathTest, TestNullValuesAreReportedCleanly) {
|
| 300 |
+
const char* a = nullptr;
|
| 301 |
+
const char* b = nullptr;
|
| 302 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_NE(a, b),
|
| 303 |
+
"Check failed: a != b \\(\\(null\\) vs. \\(null\\)\\)");
|
| 304 |
+
|
| 305 |
+
a = "xx";
|
| 306 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(a, b),
|
| 307 |
+
"Check failed: a == b \\(xx vs. \\(null\\)\\)");
|
| 308 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_EQ(b, a),
|
| 309 |
+
"Check failed: b == a \\(\\(null\\) vs. xx\\)");
|
| 310 |
+
|
| 311 |
+
std::nullptr_t n{};
|
| 312 |
+
EXPECT_DEATH(ABSL_TEST_CHECK_NE(n, nullptr),
|
| 313 |
+
"Check failed: n != nullptr \\(\\(null\\) vs. \\(null\\)\\)");
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
#endif // GTEST_HAS_DEATH_TEST
|
| 317 |
+
|
| 318 |
+
TEST(CHECKTest, TestSTREQ) {
|
| 319 |
+
ABSL_TEST_CHECK_STREQ("this", "this");
|
| 320 |
+
ABSL_TEST_CHECK_STREQ(nullptr, nullptr);
|
| 321 |
+
ABSL_TEST_CHECK_STRCASEEQ("this", "tHiS");
|
| 322 |
+
ABSL_TEST_CHECK_STRCASEEQ(nullptr, nullptr);
|
| 323 |
+
ABSL_TEST_CHECK_STRNE("this", "tHiS");
|
| 324 |
+
ABSL_TEST_CHECK_STRNE("this", nullptr);
|
| 325 |
+
ABSL_TEST_CHECK_STRCASENE("this", "that");
|
| 326 |
+
ABSL_TEST_CHECK_STRCASENE(nullptr, "that");
|
| 327 |
+
ABSL_TEST_CHECK_STREQ((std::string("a") + "b").c_str(), "ab");
|
| 328 |
+
ABSL_TEST_CHECK_STREQ(std::string("test").c_str(),
|
| 329 |
+
(std::string("te") + std::string("st")).c_str());
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
TEST(CHECKTest, TestComparisonPlacementsInCompoundStatements) {
|
| 333 |
+
// check placement inside if/else clauses
|
| 334 |
+
if (true) ABSL_TEST_CHECK_EQ(1, 1);
|
| 335 |
+
if (true) ABSL_TEST_CHECK_STREQ("c", "c");
|
| 336 |
+
|
| 337 |
+
if (false)
|
| 338 |
+
; // NOLINT
|
| 339 |
+
else
|
| 340 |
+
ABSL_TEST_CHECK_LE(0, 1);
|
| 341 |
+
|
| 342 |
+
if (false)
|
| 343 |
+
; // NOLINT
|
| 344 |
+
else
|
| 345 |
+
ABSL_TEST_CHECK_STRNE("a", "b");
|
| 346 |
+
|
| 347 |
+
switch (0)
|
| 348 |
+
case 0:
|
| 349 |
+
ABSL_TEST_CHECK_NE(1, 0);
|
| 350 |
+
|
| 351 |
+
switch (0)
|
| 352 |
+
case 0:
|
| 353 |
+
ABSL_TEST_CHECK_STRCASEEQ("A", "a");
|
| 354 |
+
|
| 355 |
+
#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
| 356 |
+
constexpr auto var = [](int i) {
|
| 357 |
+
ABSL_TEST_CHECK_GT(i, 0);
|
| 358 |
+
return i + 1;
|
| 359 |
+
}(global_var);
|
| 360 |
+
(void)var;
|
| 361 |
+
|
| 362 |
+
// CHECK_STR... checks are not supported in constexpr routines.
|
| 363 |
+
// constexpr auto var2 = [](int i) {
|
| 364 |
+
// ABSL_TEST_CHECK_STRNE("c", "d");
|
| 365 |
+
// return i + 1;
|
| 366 |
+
// }(global_var);
|
| 367 |
+
|
| 368 |
+
#if defined(__GNUC__)
|
| 369 |
+
int var3 = (({ ABSL_TEST_CHECK_LE(1, 2); }), global_var < 10) ? 1 : 0;
|
| 370 |
+
(void)var3;
|
| 371 |
+
|
| 372 |
+
int var4 = (({ ABSL_TEST_CHECK_STREQ("a", "a"); }), global_var < 10) ? 1 : 0;
|
| 373 |
+
(void)var4;
|
| 374 |
+
#endif // __GNUC__
|
| 375 |
+
#endif // ABSL_INTERNAL_CPLUSPLUS_LANG
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
TEST(CHECKTest, TestDCHECK) {
|
| 379 |
+
#ifdef NDEBUG
|
| 380 |
+
ABSL_TEST_DCHECK(1 == 2) << " DCHECK's shouldn't be compiled in normal mode";
|
| 381 |
+
#endif
|
| 382 |
+
ABSL_TEST_DCHECK(1 == 1); // NOLINT(readability/check)
|
| 383 |
+
ABSL_TEST_DCHECK_EQ(1, 1);
|
| 384 |
+
ABSL_TEST_DCHECK_NE(1, 2);
|
| 385 |
+
ABSL_TEST_DCHECK_GE(1, 1);
|
| 386 |
+
ABSL_TEST_DCHECK_GE(2, 1);
|
| 387 |
+
ABSL_TEST_DCHECK_LE(1, 1);
|
| 388 |
+
ABSL_TEST_DCHECK_LE(1, 2);
|
| 389 |
+
ABSL_TEST_DCHECK_GT(2, 1);
|
| 390 |
+
ABSL_TEST_DCHECK_LT(1, 2);
|
| 391 |
+
|
| 392 |
+
// Test DCHECK on std::nullptr_t
|
| 393 |
+
const void* p_null = nullptr;
|
| 394 |
+
const void* p_not_null = &p_null;
|
| 395 |
+
ABSL_TEST_DCHECK_EQ(p_null, nullptr);
|
| 396 |
+
ABSL_TEST_DCHECK_EQ(nullptr, p_null);
|
| 397 |
+
ABSL_TEST_DCHECK_NE(p_not_null, nullptr);
|
| 398 |
+
ABSL_TEST_DCHECK_NE(nullptr, p_not_null);
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
TEST(CHECKTest, TestQCHECK) {
|
| 402 |
+
// The tests that QCHECK does the same as CHECK
|
| 403 |
+
ABSL_TEST_QCHECK(1 == 1); // NOLINT(readability/check)
|
| 404 |
+
ABSL_TEST_QCHECK_EQ(1, 1);
|
| 405 |
+
ABSL_TEST_QCHECK_NE(1, 2);
|
| 406 |
+
ABSL_TEST_QCHECK_GE(1, 1);
|
| 407 |
+
ABSL_TEST_QCHECK_GE(2, 1);
|
| 408 |
+
ABSL_TEST_QCHECK_LE(1, 1);
|
| 409 |
+
ABSL_TEST_QCHECK_LE(1, 2);
|
| 410 |
+
ABSL_TEST_QCHECK_GT(2, 1);
|
| 411 |
+
ABSL_TEST_QCHECK_LT(1, 2);
|
| 412 |
+
|
| 413 |
+
// Tests using QCHECK*() on anonymous enums.
|
| 414 |
+
ABSL_TEST_QCHECK_EQ(CASE_A, CASE_A);
|
| 415 |
+
ABSL_TEST_QCHECK_NE(CASE_A, CASE_B);
|
| 416 |
+
ABSL_TEST_QCHECK_GE(CASE_A, CASE_A);
|
| 417 |
+
ABSL_TEST_QCHECK_GE(CASE_B, CASE_A);
|
| 418 |
+
ABSL_TEST_QCHECK_LE(CASE_A, CASE_A);
|
| 419 |
+
ABSL_TEST_QCHECK_LE(CASE_A, CASE_B);
|
| 420 |
+
ABSL_TEST_QCHECK_GT(CASE_B, CASE_A);
|
| 421 |
+
ABSL_TEST_QCHECK_LT(CASE_A, CASE_B);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
TEST(CHECKTest, TestQCHECKPlacementsInCompoundStatements) {
|
| 425 |
+
// check placement inside if/else clauses
|
| 426 |
+
if (true) ABSL_TEST_QCHECK(true);
|
| 427 |
+
|
| 428 |
+
if (false)
|
| 429 |
+
; // NOLINT
|
| 430 |
+
else
|
| 431 |
+
ABSL_TEST_QCHECK(true);
|
| 432 |
+
|
| 433 |
+
if (false)
|
| 434 |
+
; // NOLINT
|
| 435 |
+
else
|
| 436 |
+
ABSL_TEST_QCHECK(true);
|
| 437 |
+
|
| 438 |
+
switch (0)
|
| 439 |
+
case 0:
|
| 440 |
+
ABSL_TEST_QCHECK(true);
|
| 441 |
+
|
| 442 |
+
#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
| 443 |
+
constexpr auto var = [](int i) {
|
| 444 |
+
ABSL_TEST_QCHECK(i > 0); // NOLINT
|
| 445 |
+
return i + 1;
|
| 446 |
+
}(global_var);
|
| 447 |
+
(void)var;
|
| 448 |
+
|
| 449 |
+
#if defined(__GNUC__)
|
| 450 |
+
int var2 = (({ ABSL_TEST_CHECK_LE(1, 2); }), global_var < 10) ? 1 : 0;
|
| 451 |
+
(void)var2;
|
| 452 |
+
#endif // __GNUC__
|
| 453 |
+
#endif // ABSL_INTERNAL_CPLUSPLUS_LANG
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
class ComparableType {
|
| 457 |
+
public:
|
| 458 |
+
explicit ComparableType(int v) : v_(v) {}
|
| 459 |
+
|
| 460 |
+
void MethodWithCheck(int i) {
|
| 461 |
+
ABSL_TEST_CHECK_EQ(*this, i);
|
| 462 |
+
ABSL_TEST_CHECK_EQ(i, *this);
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
int Get() const { return v_; }
|
| 466 |
+
|
| 467 |
+
private:
|
| 468 |
+
friend bool operator==(const ComparableType& lhs, const ComparableType& rhs) {
|
| 469 |
+
return lhs.v_ == rhs.v_;
|
| 470 |
+
}
|
| 471 |
+
friend bool operator!=(const ComparableType& lhs, const ComparableType& rhs) {
|
| 472 |
+
return lhs.v_ != rhs.v_;
|
| 473 |
+
}
|
| 474 |
+
friend bool operator<(const ComparableType& lhs, const ComparableType& rhs) {
|
| 475 |
+
return lhs.v_ < rhs.v_;
|
| 476 |
+
}
|
| 477 |
+
friend bool operator<=(const ComparableType& lhs, const ComparableType& rhs) {
|
| 478 |
+
return lhs.v_ <= rhs.v_;
|
| 479 |
+
}
|
| 480 |
+
friend bool operator>(const ComparableType& lhs, const ComparableType& rhs) {
|
| 481 |
+
return lhs.v_ > rhs.v_;
|
| 482 |
+
}
|
| 483 |
+
friend bool operator>=(const ComparableType& lhs, const ComparableType& rhs) {
|
| 484 |
+
return lhs.v_ >= rhs.v_;
|
| 485 |
+
}
|
| 486 |
+
friend bool operator==(const ComparableType& lhs, int rhs) {
|
| 487 |
+
return lhs.v_ == rhs;
|
| 488 |
+
}
|
| 489 |
+
friend bool operator==(int lhs, const ComparableType& rhs) {
|
| 490 |
+
return lhs == rhs.v_;
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
friend std::ostream& operator<<(std::ostream& out, const ComparableType& v) {
|
| 494 |
+
return out << "ComparableType{" << v.Get() << "}";
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
int v_;
|
| 498 |
+
};
|
| 499 |
+
|
| 500 |
+
TEST(CHECKTest, TestUserDefinedCompOp) {
|
| 501 |
+
ABSL_TEST_CHECK_EQ(ComparableType{0}, ComparableType{0});
|
| 502 |
+
ABSL_TEST_CHECK_NE(ComparableType{1}, ComparableType{2});
|
| 503 |
+
ABSL_TEST_CHECK_LT(ComparableType{1}, ComparableType{2});
|
| 504 |
+
ABSL_TEST_CHECK_LE(ComparableType{1}, ComparableType{2});
|
| 505 |
+
ABSL_TEST_CHECK_GT(ComparableType{2}, ComparableType{1});
|
| 506 |
+
ABSL_TEST_CHECK_GE(ComparableType{2}, ComparableType{2});
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
TEST(CHECKTest, TestCheckInMethod) {
|
| 510 |
+
ComparableType v{1};
|
| 511 |
+
v.MethodWithCheck(1);
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
TEST(CHECKDeathTest, TestUserDefinedStreaming) {
|
| 515 |
+
ComparableType v1{1};
|
| 516 |
+
ComparableType v2{2};
|
| 517 |
+
|
| 518 |
+
EXPECT_DEATH(
|
| 519 |
+
ABSL_TEST_CHECK_EQ(v1, v2),
|
| 520 |
+
HasSubstr(
|
| 521 |
+
"Check failed: v1 == v2 (ComparableType{1} vs. ComparableType{2})"));
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
} // namespace absl_log_internal
|
| 525 |
+
|
| 526 |
+
// NOLINTEND(misc-definitions-in-headers)
|
| 527 |
+
|
| 528 |
+
#endif // ABSL_LOG_CHECK_TEST_IMPL_H_
|
weight/_dep/abseil-cpp/absl/log/die_if_null.cc
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "absl/log/die_if_null.h"
|
| 16 |
+
|
| 17 |
+
#include "absl/base/config.h"
|
| 18 |
+
#include "absl/log/log.h"
|
| 19 |
+
#include "absl/strings/str_cat.h"
|
| 20 |
+
|
| 21 |
+
namespace absl {
|
| 22 |
+
ABSL_NAMESPACE_BEGIN
|
| 23 |
+
namespace log_internal {
|
| 24 |
+
|
| 25 |
+
void DieBecauseNull(const char* file, int line, const char* exprtext) {
|
| 26 |
+
LOG(FATAL).AtLocation(file, line)
|
| 27 |
+
<< absl::StrCat("Check failed: '", exprtext, "' Must be non-null");
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
} // namespace log_internal
|
| 31 |
+
ABSL_NAMESPACE_END
|
| 32 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/log/die_if_null.h
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/die_if_null.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header declares macro `ABSL_DIE_IF_NULL`.
|
| 20 |
+
|
| 21 |
+
#ifndef ABSL_LOG_DIE_IF_NULL_H_
|
| 22 |
+
#define ABSL_LOG_DIE_IF_NULL_H_
|
| 23 |
+
|
| 24 |
+
#include <stdint.h>
|
| 25 |
+
|
| 26 |
+
#include <utility>
|
| 27 |
+
|
| 28 |
+
#include "absl/base/attributes.h"
|
| 29 |
+
#include "absl/base/config.h"
|
| 30 |
+
#include "absl/base/optimization.h"
|
| 31 |
+
|
| 32 |
+
// ABSL_DIE_IF_NULL()
|
| 33 |
+
//
|
| 34 |
+
// `ABSL_DIE_IF_NULL` behaves as `CHECK_NE` against `nullptr` but *also*
|
| 35 |
+
// "returns" its argument. It is useful in initializers where statements (like
|
| 36 |
+
// `CHECK_NE`) can't be used. Outside initializers, prefer `CHECK` or
|
| 37 |
+
// `CHECK_NE`. `ABSL_DIE_IF_NULL` works for both raw pointers and (compatible)
|
| 38 |
+
// smart pointers including `std::unique_ptr` and `std::shared_ptr`; more
|
| 39 |
+
// generally, it works for any type that can be compared to nullptr_t. For
|
| 40 |
+
// types that aren't raw pointers, `ABSL_DIE_IF_NULL` returns a reference to
|
| 41 |
+
// its argument, preserving the value category. Example:
|
| 42 |
+
//
|
| 43 |
+
// Foo() : bar_(ABSL_DIE_IF_NULL(MethodReturningUniquePtr())) {}
|
| 44 |
+
//
|
| 45 |
+
// Use `CHECK(ptr)` or `CHECK(ptr != nullptr)` if the returned pointer is
|
| 46 |
+
// unused.
|
| 47 |
+
#define ABSL_DIE_IF_NULL(val) \
|
| 48 |
+
::absl::log_internal::DieIfNull(__FILE__, __LINE__, #val, (val))
|
| 49 |
+
|
| 50 |
+
namespace absl {
|
| 51 |
+
ABSL_NAMESPACE_BEGIN
|
| 52 |
+
namespace log_internal {
|
| 53 |
+
|
| 54 |
+
// Crashes the process after logging `exprtext` annotated at the `file` and
|
| 55 |
+
// `line` location. Called when `ABSL_DIE_IF_NULL` fails. Calling this function
|
| 56 |
+
// generates less code than its implementation would if inlined, for a slight
|
| 57 |
+
// code size reduction each time `ABSL_DIE_IF_NULL` is called.
|
| 58 |
+
ABSL_ATTRIBUTE_NORETURN ABSL_ATTRIBUTE_NOINLINE void DieBecauseNull(
|
| 59 |
+
const char* file, int line, const char* exprtext);
|
| 60 |
+
|
| 61 |
+
// Helper for `ABSL_DIE_IF_NULL`.
|
| 62 |
+
template <typename T>
|
| 63 |
+
ABSL_MUST_USE_RESULT T DieIfNull(const char* file, int line,
|
| 64 |
+
const char* exprtext, T&& t) {
|
| 65 |
+
if (ABSL_PREDICT_FALSE(t == nullptr)) {
|
| 66 |
+
// Call a non-inline helper function for a small code size improvement.
|
| 67 |
+
DieBecauseNull(file, line, exprtext);
|
| 68 |
+
}
|
| 69 |
+
return std::forward<T>(t);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
} // namespace log_internal
|
| 73 |
+
ABSL_NAMESPACE_END
|
| 74 |
+
} // namespace absl
|
| 75 |
+
|
| 76 |
+
#endif // ABSL_LOG_DIE_IF_NULL_H_
|
weight/_dep/abseil-cpp/absl/log/die_if_null_test.cc
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/die_if_null.h"
|
| 17 |
+
|
| 18 |
+
#include <stdint.h>
|
| 19 |
+
|
| 20 |
+
#include <memory>
|
| 21 |
+
#include <utility>
|
| 22 |
+
|
| 23 |
+
#include "gtest/gtest.h"
|
| 24 |
+
#include "absl/base/attributes.h"
|
| 25 |
+
#include "absl/log/internal/test_helpers.h"
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
|
| 29 |
+
auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
|
| 30 |
+
new absl::log_internal::LogTestEnvironment);
|
| 31 |
+
|
| 32 |
+
// TODO(b/69907837): Revisit these tests with the goal of making them less
|
| 33 |
+
// convoluted.
|
| 34 |
+
TEST(AbslDieIfNull, Simple) {
|
| 35 |
+
int64_t t;
|
| 36 |
+
void* ptr = static_cast<void*>(&t);
|
| 37 |
+
void* ref = ABSL_DIE_IF_NULL(ptr);
|
| 38 |
+
ASSERT_EQ(ptr, ref);
|
| 39 |
+
|
| 40 |
+
char* t_as_char;
|
| 41 |
+
t_as_char = ABSL_DIE_IF_NULL(reinterpret_cast<char*>(&t));
|
| 42 |
+
(void)t_as_char;
|
| 43 |
+
|
| 44 |
+
unsigned char* t_as_uchar;
|
| 45 |
+
t_as_uchar = ABSL_DIE_IF_NULL(reinterpret_cast<unsigned char*>(&t));
|
| 46 |
+
(void)t_as_uchar;
|
| 47 |
+
|
| 48 |
+
int* t_as_int;
|
| 49 |
+
t_as_int = ABSL_DIE_IF_NULL(reinterpret_cast<int*>(&t));
|
| 50 |
+
(void)t_as_int;
|
| 51 |
+
|
| 52 |
+
int64_t* t_as_int64_t;
|
| 53 |
+
t_as_int64_t = ABSL_DIE_IF_NULL(reinterpret_cast<int64_t*>(&t));
|
| 54 |
+
(void)t_as_int64_t;
|
| 55 |
+
|
| 56 |
+
std::unique_ptr<int64_t> sptr(new int64_t);
|
| 57 |
+
EXPECT_EQ(sptr.get(), ABSL_DIE_IF_NULL(sptr).get());
|
| 58 |
+
ABSL_DIE_IF_NULL(sptr).reset();
|
| 59 |
+
|
| 60 |
+
int64_t* int_ptr = new int64_t();
|
| 61 |
+
EXPECT_EQ(int_ptr, ABSL_DIE_IF_NULL(std::unique_ptr<int64_t>(int_ptr)).get());
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
#if GTEST_HAS_DEATH_TEST
|
| 65 |
+
TEST(DeathCheckAbslDieIfNull, Simple) {
|
| 66 |
+
void* ptr;
|
| 67 |
+
ASSERT_DEATH({ ptr = ABSL_DIE_IF_NULL(nullptr); }, "");
|
| 68 |
+
(void)ptr;
|
| 69 |
+
|
| 70 |
+
std::unique_ptr<int64_t> sptr;
|
| 71 |
+
ASSERT_DEATH(ptr = ABSL_DIE_IF_NULL(sptr).get(), "");
|
| 72 |
+
}
|
| 73 |
+
#endif
|
| 74 |
+
|
| 75 |
+
// Ensures that ABSL_DIE_IF_NULL works with C++11's std::unique_ptr and
|
| 76 |
+
// std::shared_ptr.
|
| 77 |
+
TEST(AbslDieIfNull, DoesNotCompareSmartPointerToNULL) {
|
| 78 |
+
std::unique_ptr<int> up(new int);
|
| 79 |
+
EXPECT_EQ(&up, &ABSL_DIE_IF_NULL(up));
|
| 80 |
+
ABSL_DIE_IF_NULL(up).reset();
|
| 81 |
+
|
| 82 |
+
std::shared_ptr<int> sp(new int);
|
| 83 |
+
EXPECT_EQ(&sp, &ABSL_DIE_IF_NULL(sp));
|
| 84 |
+
ABSL_DIE_IF_NULL(sp).reset();
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// Verifies that ABSL_DIE_IF_NULL returns an rvalue reference if its argument is
|
| 88 |
+
// an rvalue reference.
|
| 89 |
+
TEST(AbslDieIfNull, PreservesRValues) {
|
| 90 |
+
int64_t* ptr = new int64_t();
|
| 91 |
+
auto uptr = ABSL_DIE_IF_NULL(std::unique_ptr<int64_t>(ptr));
|
| 92 |
+
EXPECT_EQ(ptr, uptr.get());
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// Verifies that ABSL_DIE_IF_NULL returns an lvalue if its argument is an
|
| 96 |
+
// lvalue.
|
| 97 |
+
TEST(AbslDieIfNull, PreservesLValues) {
|
| 98 |
+
int64_t array[2] = {0};
|
| 99 |
+
int64_t* a = array + 0;
|
| 100 |
+
int64_t* b = array + 1;
|
| 101 |
+
using std::swap;
|
| 102 |
+
swap(ABSL_DIE_IF_NULL(a), ABSL_DIE_IF_NULL(b));
|
| 103 |
+
EXPECT_EQ(array + 1, a);
|
| 104 |
+
EXPECT_EQ(array + 0, b);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/log/flags.cc
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/internal/flags.h"
|
| 17 |
+
|
| 18 |
+
#include <stddef.h>
|
| 19 |
+
|
| 20 |
+
#include <algorithm>
|
| 21 |
+
#include <cstdlib>
|
| 22 |
+
#include <string>
|
| 23 |
+
|
| 24 |
+
#include "absl/base/attributes.h"
|
| 25 |
+
#include "absl/base/config.h"
|
| 26 |
+
#include "absl/base/log_severity.h"
|
| 27 |
+
#include "absl/flags/flag.h"
|
| 28 |
+
#include "absl/flags/marshalling.h"
|
| 29 |
+
#include "absl/log/globals.h"
|
| 30 |
+
#include "absl/log/internal/config.h"
|
| 31 |
+
#include "absl/log/internal/vlog_config.h"
|
| 32 |
+
#include "absl/strings/numbers.h"
|
| 33 |
+
#include "absl/strings/string_view.h"
|
| 34 |
+
|
| 35 |
+
namespace absl {
|
| 36 |
+
ABSL_NAMESPACE_BEGIN
|
| 37 |
+
namespace log_internal {
|
| 38 |
+
namespace {
|
| 39 |
+
|
| 40 |
+
void SyncLoggingFlags() {
|
| 41 |
+
absl::SetFlag(&FLAGS_minloglevel, static_cast<int>(absl::MinLogLevel()));
|
| 42 |
+
absl::SetFlag(&FLAGS_log_prefix, absl::ShouldPrependLogPrefix());
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
bool RegisterSyncLoggingFlags() {
|
| 46 |
+
log_internal::SetLoggingGlobalsListener(&SyncLoggingFlags);
|
| 47 |
+
return true;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
ABSL_ATTRIBUTE_UNUSED const bool unused = RegisterSyncLoggingFlags();
|
| 51 |
+
|
| 52 |
+
template <typename T>
|
| 53 |
+
T GetFromEnv(const char* varname, T dflt) {
|
| 54 |
+
const char* val = ::getenv(varname);
|
| 55 |
+
if (val != nullptr) {
|
| 56 |
+
std::string err;
|
| 57 |
+
ABSL_INTERNAL_CHECK(absl::ParseFlag(val, &dflt, &err), err.c_str());
|
| 58 |
+
}
|
| 59 |
+
return dflt;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
constexpr absl::LogSeverityAtLeast StderrThresholdDefault() {
|
| 63 |
+
return absl::LogSeverityAtLeast::kError;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
} // namespace
|
| 67 |
+
} // namespace log_internal
|
| 68 |
+
ABSL_NAMESPACE_END
|
| 69 |
+
} // namespace absl
|
| 70 |
+
|
| 71 |
+
ABSL_FLAG(int, stderrthreshold,
|
| 72 |
+
static_cast<int>(absl::log_internal::StderrThresholdDefault()),
|
| 73 |
+
"Log messages at or above this threshold level are copied to stderr.")
|
| 74 |
+
.OnUpdate([] {
|
| 75 |
+
absl::log_internal::RawSetStderrThreshold(
|
| 76 |
+
static_cast<absl::LogSeverityAtLeast>(
|
| 77 |
+
absl::GetFlag(FLAGS_stderrthreshold)));
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
ABSL_FLAG(int, minloglevel, static_cast<int>(absl::LogSeverityAtLeast::kInfo),
|
| 81 |
+
"Messages logged at a lower level than this don't actually "
|
| 82 |
+
"get logged anywhere")
|
| 83 |
+
.OnUpdate([] {
|
| 84 |
+
absl::log_internal::RawSetMinLogLevel(
|
| 85 |
+
static_cast<absl::LogSeverityAtLeast>(
|
| 86 |
+
absl::GetFlag(FLAGS_minloglevel)));
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
ABSL_FLAG(std::string, log_backtrace_at, "",
|
| 90 |
+
"Emit a backtrace when logging at file:linenum.")
|
| 91 |
+
.OnUpdate([] {
|
| 92 |
+
const std::string log_backtrace_at =
|
| 93 |
+
absl::GetFlag(FLAGS_log_backtrace_at);
|
| 94 |
+
if (log_backtrace_at.empty()) {
|
| 95 |
+
absl::ClearLogBacktraceLocation();
|
| 96 |
+
return;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
const size_t last_colon = log_backtrace_at.rfind(':');
|
| 100 |
+
if (last_colon == log_backtrace_at.npos) {
|
| 101 |
+
absl::ClearLogBacktraceLocation();
|
| 102 |
+
return;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
const absl::string_view file =
|
| 106 |
+
absl::string_view(log_backtrace_at).substr(0, last_colon);
|
| 107 |
+
int line;
|
| 108 |
+
if (!absl::SimpleAtoi(
|
| 109 |
+
absl::string_view(log_backtrace_at).substr(last_colon + 1),
|
| 110 |
+
&line)) {
|
| 111 |
+
absl::ClearLogBacktraceLocation();
|
| 112 |
+
return;
|
| 113 |
+
}
|
| 114 |
+
absl::SetLogBacktraceLocation(file, line);
|
| 115 |
+
});
|
| 116 |
+
|
| 117 |
+
ABSL_FLAG(bool, log_prefix, true,
|
| 118 |
+
"Prepend the log prefix to the start of each log line")
|
| 119 |
+
.OnUpdate([] {
|
| 120 |
+
absl::log_internal::RawEnableLogPrefix(absl::GetFlag(FLAGS_log_prefix));
|
| 121 |
+
});
|
| 122 |
+
|
| 123 |
+
ABSL_FLAG(int, v, 0,
|
| 124 |
+
"Show all VLOG(m) messages for m <= this. Overridable by --vmodule.")
|
| 125 |
+
.OnUpdate([] {
|
| 126 |
+
absl::log_internal::UpdateGlobalVLogLevel(absl::GetFlag(FLAGS_v));
|
| 127 |
+
});
|
| 128 |
+
|
| 129 |
+
ABSL_FLAG(
|
| 130 |
+
std::string, vmodule, "",
|
| 131 |
+
"per-module log verbosity level."
|
| 132 |
+
" Argument is a comma-separated list of <module name>=<log level>."
|
| 133 |
+
" <module name> is a glob pattern, matched against the filename base"
|
| 134 |
+
" (that is, name ignoring .cc/.h./-inl.h)."
|
| 135 |
+
" A pattern without slashes matches just the file name portion, otherwise"
|
| 136 |
+
" the whole file path below the workspace root"
|
| 137 |
+
" (still without .cc/.h./-inl.h) is matched."
|
| 138 |
+
" ? and * in the glob pattern match any single or sequence of characters"
|
| 139 |
+
" respectively including slashes."
|
| 140 |
+
" <log level> overrides any value given by --v.")
|
| 141 |
+
.OnUpdate([] {
|
| 142 |
+
absl::log_internal::UpdateVModule(absl::GetFlag(FLAGS_vmodule));
|
| 143 |
+
});
|
weight/_dep/abseil-cpp/absl/log/flags.h
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/flags.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
|
| 20 |
+
#ifndef ABSL_LOG_FLAGS_H_
|
| 21 |
+
#define ABSL_LOG_FLAGS_H_
|
| 22 |
+
|
| 23 |
+
// The Abseil Logging library supports the following command line flags to
|
| 24 |
+
// configure logging behavior at runtime:
|
| 25 |
+
//
|
| 26 |
+
// --stderrthreshold=<value>
|
| 27 |
+
// Log messages at or above this threshold level are copied to stderr.
|
| 28 |
+
//
|
| 29 |
+
// --minloglevel=<value>
|
| 30 |
+
// Messages logged at a lower level than this are discarded and don't actually
|
| 31 |
+
// get logged anywhere.
|
| 32 |
+
//
|
| 33 |
+
// --log_backtrace_at=<file:linenum>
|
| 34 |
+
// Emit a backtrace (stack trace) when logging at file:linenum.
|
| 35 |
+
//
|
| 36 |
+
// To use these commandline flags, the //absl/log:flags library must be
|
| 37 |
+
// explicitly linked, and absl::ParseCommandLine() must be called before the
|
| 38 |
+
// call to absl::InitializeLog().
|
| 39 |
+
//
|
| 40 |
+
// To configure the Log library programmatically, use the interfaces defined in
|
| 41 |
+
// absl/log/globals.h.
|
| 42 |
+
|
| 43 |
+
#endif // ABSL_LOG_FLAGS_H_
|
weight/_dep/ab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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/internal/flags.h"
|
| 17 |
+
|
| 18 |
+
#include <string>
|
| 19 |
+
|
| 20 |
+
#include "gmock/gmock.h"
|
| 21 |
+
#include "gtest/gtest.h"
|
| 22 |
+
#include "absl/base/attributes.h"
|
| 23 |
+
#include "absl/base/log_severity.h"
|
| 24 |
+
#include "absl/flags/flag.h"
|
| 25 |
+
#include "absl/flags/reflection.h"
|
| 26 |
+
#include "absl/log/globals.h"
|
| 27 |
+
#include "absl/log/internal/test_helpers.h"
|
| 28 |
+
#include "absl/log/internal/test_matchers.h"
|
| 29 |
+
#include "absl/log/log.h"
|
| 30 |
+
#include "absl/log/scoped_mock_log.h"
|
| 31 |
+
#include "absl/strings/str_cat.h"
|
| 32 |
+
|
| 33 |
+
namespace {
|
| 34 |
+
using ::absl::log_internal::TextMessage;
|
| 35 |
+
|
| 36 |
+
using ::testing::HasSubstr;
|
| 37 |
+
using ::testing::Not;
|
| 38 |
+
|
| 39 |
+
auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
|
| 40 |
+
new absl::log_internal::LogTestEnvironment);
|
| 41 |
+
|
| 42 |
+
constexpr static absl::LogSeverityAtLeast DefaultStderrThreshold() {
|
| 43 |
+
return absl::LogSeverityAtLeast::kError;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
class LogFlagsTest : public ::testing::Test {
|
| 47 |
+
protected:
|
| 48 |
+
absl::FlagSaver flag_saver_;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
// This test is disabled because it adds order dependency to the test suite.
|
| 52 |
+
// This order dependency is currently not fixable due to the way the
|
| 53 |
+
// stderrthreshold global value is out of sync with the stderrthreshold flag.
|
| 54 |
+
TEST_F(LogFlagsTest, DISABLED_StderrKnobsDefault) {
|
| 55 |
+
EXPECT_EQ(absl::StderrThreshold(), DefaultStderrThreshold());
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
TEST_F(LogFlagsTest, SetStderrThreshold) {
|
| 59 |
+
absl::SetFlag(&FLAGS_stderrthreshold,
|
| 60 |
+
static_cast<int>(absl::LogSeverityAtLeast::kInfo));
|
| 61 |
+
|
| 62 |
+
EXPECT_EQ(absl::StderrThreshold(), absl::LogSeverityAtLeast::kInfo);
|
| 63 |
+
|
| 64 |
+
absl::SetFlag(&FLAGS_stderrthreshold,
|
| 65 |
+
static_cast<int>(absl::LogSeverityAtLeast::kError));
|
| 66 |
+
|
| 67 |
+
EXPECT_EQ(absl::StderrThreshold(), absl::LogSeverityAtLeast::kError);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
TEST_F(LogFlagsTest, SetMinLogLevel) {
|
| 71 |
+
absl::SetFlag(&FLAGS_minloglevel,
|
| 72 |
+
static_cast<int>(absl::LogSeverityAtLeast::kError));
|
| 73 |
+
|
| 74 |
+
EXPECT_EQ(absl::MinLogLevel(), absl::LogSeverityAtLeast::kError);
|
| 75 |
+
|
| 76 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(
|
| 77 |
+
absl::LogSeverityAtLeast::kWarning);
|
| 78 |
+
|
| 79 |
+
EXPECT_EQ(absl::GetFlag(FLAGS_minloglevel),
|
| 80 |
+
static_cast<int>(absl::LogSeverityAtLeast::kWarning));
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
TEST_F(LogFlagsTest, PrependLogPrefix) {
|
| 84 |
+
absl::SetFlag(&FLAGS_log_prefix, false);
|
| 85 |
+
|
| 86 |
+
EXPECT_EQ(absl::ShouldPrependLogPrefix(), false);
|
| 87 |
+
|
| 88 |
+
absl::EnableLogPrefix(true);
|
| 89 |
+
|
| 90 |
+
EXPECT_EQ(absl::GetFlag(FLAGS_log_prefix), true);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
TEST_F(LogFlagsTest, EmptyBacktraceAtFlag) {
|
| 94 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 95 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 96 |
+
|
| 97 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 98 |
+
|
| 99 |
+
test_sink.StartCapturingLogs();
|
| 100 |
+
absl::SetFlag(&FLAGS_log_backtrace_at, "");
|
| 101 |
+
LOG(INFO) << "hello world";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
TEST_F(LogFlagsTest, BacktraceAtNonsense) {
|
| 105 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 106 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 107 |
+
|
| 108 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 109 |
+
|
| 110 |
+
test_sink.StartCapturingLogs();
|
| 111 |
+
absl::SetFlag(&FLAGS_log_backtrace_at, "gibberish");
|
| 112 |
+
LOG(INFO) << "hello world";
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
TEST_F(LogFlagsTest, BacktraceAtWrongFile) {
|
| 116 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 117 |
+
const int log_line = __LINE__ + 1;
|
| 118 |
+
auto do_log = [] { LOG(INFO) << "hello world"; };
|
| 119 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 120 |
+
|
| 121 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 122 |
+
|
| 123 |
+
test_sink.StartCapturingLogs();
|
| 124 |
+
absl::SetFlag(&FLAGS_log_backtrace_at,
|
| 125 |
+
absl::StrCat("some_other_file.cc:", log_line));
|
| 126 |
+
do_log();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
TEST_F(LogFlagsTest, BacktraceAtWrongLine) {
|
| 130 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 131 |
+
const int log_line = __LINE__ + 1;
|
| 132 |
+
auto do_log = [] { LOG(INFO) << "hello world"; };
|
| 133 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 134 |
+
|
| 135 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 136 |
+
|
| 137 |
+
test_sink.StartCapturingLogs();
|
| 138 |
+
absl::SetFlag(&FLAGS_log_backtrace_at,
|
| 139 |
+
absl::StrCat("flags_test.cc:", log_line + 1));
|
| 140 |
+
do_log();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
TEST_F(LogFlagsTest, BacktraceAtWholeFilename) {
|
| 144 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 145 |
+
const int log_line = __LINE__ + 1;
|
| 146 |
+
auto do_log = [] { LOG(INFO) << "hello world"; };
|
| 147 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 148 |
+
|
| 149 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 150 |
+
|
| 151 |
+
test_sink.StartCapturingLogs();
|
| 152 |
+
absl::SetFlag(&FLAGS_log_backtrace_at, absl::StrCat(__FILE__, ":", log_line));
|
| 153 |
+
do_log();
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
TEST_F(LogFlagsTest, BacktraceAtNonmatchingSuffix) {
|
| 157 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 158 |
+
const int log_line = __LINE__ + 1;
|
| 159 |
+
auto do_log = [] { LOG(INFO) << "hello world"; };
|
| 160 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 161 |
+
|
| 162 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 163 |
+
|
| 164 |
+
test_sink.StartCapturingLogs();
|
| 165 |
+
absl::SetFlag(&FLAGS_log_backtrace_at,
|
| 166 |
+
absl::StrCat("flags_test.cc:", log_line, "gibberish"));
|
| 167 |
+
do_log();
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
TEST_F(LogFlagsTest, LogsBacktrace) {
|
| 171 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
|
| 172 |
+
const int log_line = __LINE__ + 1;
|
| 173 |
+
auto do_log = [] { LOG(INFO) << "hello world"; };
|
| 174 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 175 |
+
|
| 176 |
+
testing::InSequence seq;
|
| 177 |
+
EXPECT_CALL(test_sink, Send(TextMessage(HasSubstr("(stacktrace:"))));
|
| 178 |
+
EXPECT_CALL(test_sink, Send(TextMessage(Not(HasSubstr("(stacktrace:")))));
|
| 179 |
+
|
| 180 |
+
test_sink.StartCapturingLogs();
|
| 181 |
+
absl::SetFlag(&FLAGS_log_backtrace_at,
|
| 182 |
+
absl::StrC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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "absl/log/globals.h"
|
| 16 |
+
|
| 17 |
+
#include <atomic>
|
| 18 |
+
#include <cstddef>
|
| 19 |
+
#include <cstdint>
|
| 20 |
+
#include <cstdlib>
|
| 21 |
+
#include <cstring>
|
| 22 |
+
#include <string>
|
| 23 |
+
|
| 24 |
+
#include "absl/base/attributes.h"
|
| 25 |
+
#include "absl/base/config.h"
|
| 26 |
+
#include "absl/base/internal/atomic_hook.h"
|
| 27 |
+
#include "absl/base/internal/raw_logging.h"
|
| 28 |
+
#include "absl/base/log_severity.h"
|
| 29 |
+
#include "absl/hash/hash.h"
|
| 30 |
+
#include "absl/strings/string_view.h"
|
| 31 |
+
|
| 32 |
+
namespace absl {
|
| 33 |
+
ABSL_NAMESPACE_BEGIN
|
| 34 |
+
namespace {
|
| 35 |
+
|
| 36 |
+
// These atomics represent logging library configuration.
|
| 37 |
+
// Integer types are used instead of absl::LogSeverity to ensure that a
|
| 38 |
+
// lock-free std::atomic is used when possible.
|
| 39 |
+
ABSL_CONST_INIT std::atomic<int> min_log_level{
|
| 40 |
+
static_cast<int>(absl::LogSeverityAtLeast::kInfo)};
|
| 41 |
+
ABSL_CONST_INIT std::atomic<int> stderrthreshold{
|
| 42 |
+
static_cast<int>(absl::LogSeverityAtLeast::kError)};
|
| 43 |
+
// We evaluate this value as a hash comparison to avoid having to
|
| 44 |
+
// hold a mutex or make a copy (to access the value of a string-typed flag) in
|
| 45 |
+
// very hot codepath.
|
| 46 |
+
ABSL_CONST_INIT std::atomic<size_t> log_backtrace_at_hash{0};
|
| 47 |
+
ABSL_CONST_INIT std::atomic<bool> prepend_log_prefix{true};
|
| 48 |
+
|
| 49 |
+
constexpr char kDefaultAndroidTag[] = "native";
|
| 50 |
+
ABSL_CONST_INIT std::atomic<const char*> android_log_tag{kDefaultAndroidTag};
|
| 51 |
+
|
| 52 |
+
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
|
| 53 |
+
absl::base_internal::AtomicHook<log_internal::LoggingGlobalsListener>
|
| 54 |
+
logging_globals_listener;
|
| 55 |
+
|
| 56 |
+
size_t HashSiteForLogBacktraceAt(absl::string_view file, int line) {
|
| 57 |
+
return absl::HashOf(file, line);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void TriggerLoggingGlobalsListener() {
|
| 61 |
+
auto* listener = logging_globals_listener.Load();
|
| 62 |
+
if (listener != nullptr) listener();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
} // namespace
|
| 66 |
+
|
| 67 |
+
namespace log_internal {
|
| 68 |
+
|
| 69 |
+
void RawSetMinLogLevel(absl::LogSeverityAtLeast severity) {
|
| 70 |
+
min_log_level.store(static_cast<int>(severity), std::memory_order_release);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void RawSetStderrThreshold(absl::LogSeverityAtLeast severity) {
|
| 74 |
+
stderrthreshold.store(static_cast<int>(severity), std::memory_order_release);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void RawEnableLogPrefix(bool on_off) {
|
| 78 |
+
prepend_log_prefix.store(on_off, std::memory_order_release);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void SetLoggingGlobalsListener(LoggingGlobalsListener l) {
|
| 82 |
+
logging_globals_listener.Store(l);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
} // namespace log_internal
|
| 86 |
+
|
| 87 |
+
absl::LogSeverityAtLeast MinLogLevel() {
|
| 88 |
+
return static_cast<absl::LogSeverityAtLeast>(
|
| 89 |
+
min_log_level.load(std::memory_order_acquire));
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void SetMinLogLevel(absl::LogSeverityAtLeast severity) {
|
| 93 |
+
log_internal::RawSetMinLogLevel(severity);
|
| 94 |
+
TriggerLoggingGlobalsListener();
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
namespace log_internal {
|
| 98 |
+
|
| 99 |
+
ScopedMinLogLevel::ScopedMinLogLevel(absl::LogSeverityAtLeast severity)
|
| 100 |
+
: saved_severity_(absl::MinLogLevel()) {
|
| 101 |
+
absl::SetMinLogLevel(severity);
|
| 102 |
+
}
|
| 103 |
+
ScopedMinLogLevel::~ScopedMinLogLevel() {
|
| 104 |
+
absl::SetMinLogLevel(saved_severity_);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
} // namespace log_internal
|
| 108 |
+
|
| 109 |
+
absl::LogSeverityAtLeast StderrThreshold() {
|
| 110 |
+
return static_cast<absl::LogSeverityAtLeast>(
|
| 111 |
+
stderrthreshold.load(std::memory_order_acquire));
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void SetStderrThreshold(absl::LogSeverityAtLeast severity) {
|
| 115 |
+
log_internal::RawSetStderrThreshold(severity);
|
| 116 |
+
TriggerLoggingGlobalsListener();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
ScopedStderrThreshold::ScopedStderrThreshold(absl::LogSeverityAtLeast severity)
|
| 120 |
+
: saved_severity_(absl::StderrThreshold()) {
|
| 121 |
+
absl::SetStderrThreshold(severity);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
ScopedStderrThreshold::~ScopedStderrThreshold() {
|
| 125 |
+
absl::SetStderrThreshold(saved_severity_);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
namespace log_internal {
|
| 129 |
+
|
| 130 |
+
const char* GetAndroidNativeTag() {
|
| 131 |
+
return android_log_tag.load(std::memory_order_acquire);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
} // namespace log_internal
|
| 135 |
+
|
| 136 |
+
void SetAndroidNativeTag(const char* tag) {
|
| 137 |
+
ABSL_CONST_INIT static std::atomic<const std::string*> user_log_tag(nullptr);
|
| 138 |
+
ABSL_INTERNAL_CHECK(tag, "tag must be non-null.");
|
| 139 |
+
|
| 140 |
+
const std::string* tag_str = new std::string(tag);
|
| 141 |
+
ABSL_INTERNAL_CHECK(
|
| 142 |
+
android_log_tag.exchange(tag_str->c_str(), std::memory_order_acq_rel) ==
|
| 143 |
+
kDefaultAndroidTag,
|
| 144 |
+
"SetAndroidNativeTag() must only be called once per process!");
|
| 145 |
+
user_log_tag.store(tag_str, std::memory_order_relaxed);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
namespace log_internal {
|
| 149 |
+
|
| 150 |
+
bool ShouldLogBacktraceAt(absl::string_view file, int line) {
|
| 151 |
+
const size_t flag_hash =
|
| 152 |
+
log_backtrace_at_hash.load(std::memory_order_relaxed);
|
| 153 |
+
|
| 154 |
+
return flag_hash != 0 && flag_hash == HashSiteForLogBacktraceAt(file, line);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
} // namespace log_internal
|
| 158 |
+
|
| 159 |
+
void SetLogBacktraceLocation(absl::string_view file, int line) {
|
| 160 |
+
log_backtrace_at_hash.store(HashSiteForLogBacktraceAt(file, line),
|
| 161 |
+
std::memory_order_relaxed);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
void ClearLogBacktraceLocation() {
|
| 165 |
+
log_backtrace_at_hash.store(0, std::memory_order_relaxed);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
bool ShouldPrependLogPrefix() {
|
| 169 |
+
return prepend_log_prefix.load(std::memory_order_acquire);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
void EnableLogPrefix(bool on_off) {
|
| 173 |
+
log_internal::RawEnableLogPrefix(on_off);
|
| 174 |
+
TriggerLoggingGlobalsListener();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
ABSL_NAMESPACE_END
|
| 178 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/log/globals.h
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/globals.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header declares global logging library configuration knobs.
|
| 20 |
+
|
| 21 |
+
#ifndef ABSL_LOG_GLOBALS_H_
|
| 22 |
+
#define ABSL_LOG_GLOBALS_H_
|
| 23 |
+
|
| 24 |
+
#include "absl/base/attributes.h"
|
| 25 |
+
#include "absl/base/config.h"
|
| 26 |
+
#include "absl/base/log_severity.h"
|
| 27 |
+
#include "absl/log/internal/vlog_config.h"
|
| 28 |
+
#include "absl/strings/string_view.h"
|
| 29 |
+
|
| 30 |
+
namespace absl {
|
| 31 |
+
ABSL_NAMESPACE_BEGIN
|
| 32 |
+
|
| 33 |
+
//------------------------------------------------------------------------------
|
| 34 |
+
// Minimum Log Level
|
| 35 |
+
//------------------------------------------------------------------------------
|
| 36 |
+
//
|
| 37 |
+
// Messages logged at or above this severity are directed to all registered log
|
| 38 |
+
// sinks or skipped otherwise. This parameter can also be modified using
|
| 39 |
+
// command line flag --minloglevel.
|
| 40 |
+
// See absl/base/log_severity.h for descriptions of severity levels.
|
| 41 |
+
|
| 42 |
+
// MinLogLevel()
|
| 43 |
+
//
|
| 44 |
+
// Returns the value of the Minimum Log Level parameter.
|
| 45 |
+
// This function is async-signal-safe.
|
| 46 |
+
ABSL_MUST_USE_RESULT absl::LogSeverityAtLeast MinLogLevel();
|
| 47 |
+
|
| 48 |
+
// SetMinLogLevel()
|
| 49 |
+
//
|
| 50 |
+
// Updates the value of Minimum Log Level parameter.
|
| 51 |
+
// This function is async-signal-safe.
|
| 52 |
+
void SetMinLogLevel(absl::LogSeverityAtLeast severity);
|
| 53 |
+
|
| 54 |
+
namespace log_internal {
|
| 55 |
+
|
| 56 |
+
// ScopedMinLogLevel
|
| 57 |
+
//
|
| 58 |
+
// RAII type used to temporarily update the Min Log Level parameter.
|
| 59 |
+
class ScopedMinLogLevel final {
|
| 60 |
+
public:
|
| 61 |
+
explicit ScopedMinLogLevel(absl::LogSeverityAtLeast severity);
|
| 62 |
+
ScopedMinLogLevel(const ScopedMinLogLevel&) = delete;
|
| 63 |
+
ScopedMinLogLevel& operator=(const ScopedMinLogLevel&) = delete;
|
| 64 |
+
~ScopedMinLogLevel();
|
| 65 |
+
|
| 66 |
+
private:
|
| 67 |
+
absl::LogSeverityAtLeast saved_severity_;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
} // namespace log_internal
|
| 71 |
+
|
| 72 |
+
//------------------------------------------------------------------------------
|
| 73 |
+
// Stderr Threshold
|
| 74 |
+
//------------------------------------------------------------------------------
|
| 75 |
+
//
|
| 76 |
+
// Messages logged at or above this level are directed to stderr in
|
| 77 |
+
// addition to other registered log sinks. This parameter can also be modified
|
| 78 |
+
// using command line flag --stderrthreshold.
|
| 79 |
+
// See absl/base/log_severity.h for descriptions of severity levels.
|
| 80 |
+
|
| 81 |
+
// StderrThreshold()
|
| 82 |
+
//
|
| 83 |
+
// Returns the value of the Stderr Threshold parameter.
|
| 84 |
+
// This function is async-signal-safe.
|
| 85 |
+
ABSL_MUST_USE_RESULT absl::LogSeverityAtLeast StderrThreshold();
|
| 86 |
+
|
| 87 |
+
// SetStderrThreshold()
|
| 88 |
+
//
|
| 89 |
+
// Updates the Stderr Threshold parameter.
|
| 90 |
+
// This function is async-signal-safe.
|
| 91 |
+
void SetStderrThreshold(absl::LogSeverityAtLeast severity);
|
| 92 |
+
inline void SetStderrThreshold(absl::LogSeverity severity) {
|
| 93 |
+
absl::SetStderrThreshold(static_cast<absl::LogSeverityAtLeast>(severity));
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// ScopedStderrThreshold
|
| 97 |
+
//
|
| 98 |
+
// RAII type used to temporarily update the Stderr Threshold parameter.
|
| 99 |
+
class ScopedStderrThreshold final {
|
| 100 |
+
public:
|
| 101 |
+
explicit ScopedStderrThreshold(absl::LogSeverityAtLeast severity);
|
| 102 |
+
ScopedStderrThreshold(const ScopedStderrThreshold&) = delete;
|
| 103 |
+
ScopedStderrThreshold& operator=(const ScopedStderrThreshold&) = delete;
|
| 104 |
+
~ScopedStderrThreshold();
|
| 105 |
+
|
| 106 |
+
private:
|
| 107 |
+
absl::LogSeverityAtLeast saved_severity_;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
//------------------------------------------------------------------------------
|
| 111 |
+
// Log Backtrace At
|
| 112 |
+
//------------------------------------------------------------------------------
|
| 113 |
+
//
|
| 114 |
+
// Users can request an existing `LOG` statement, specified by file and line
|
| 115 |
+
// number, to also include a backtrace when logged.
|
| 116 |
+
|
| 117 |
+
// ShouldLogBacktraceAt()
|
| 118 |
+
//
|
| 119 |
+
// Returns true if we should log a backtrace at the specified location.
|
| 120 |
+
namespace log_internal {
|
| 121 |
+
ABSL_MUST_USE_RESULT bool ShouldLogBacktraceAt(absl::string_view file,
|
| 122 |
+
int line);
|
| 123 |
+
} // namespace log_internal
|
| 124 |
+
|
| 125 |
+
// SetLogBacktraceLocation()
|
| 126 |
+
//
|
| 127 |
+
// Sets the location the backtrace should be logged at. If the specified
|
| 128 |
+
// location isn't a `LOG` statement, the effect will be the same as
|
| 129 |
+
// `ClearLogBacktraceLocation` (but less efficient).
|
| 130 |
+
void SetLogBacktraceLocation(absl::string_view file, int line);
|
| 131 |
+
|
| 132 |
+
// ClearLogBacktraceLocation()
|
| 133 |
+
//
|
| 134 |
+
// Clears the set location so that backtraces will no longer be logged at it.
|
| 135 |
+
void ClearLogBacktraceLocation();
|
| 136 |
+
|
| 137 |
+
//------------------------------------------------------------------------------
|
| 138 |
+
// Prepend Log Prefix
|
| 139 |
+
//------------------------------------------------------------------------------
|
| 140 |
+
//
|
| 141 |
+
// This option tells the logging library that every logged message
|
| 142 |
+
// should include the prefix (severity, date, time, PID, etc.)
|
| 143 |
+
|
| 144 |
+
// ShouldPrependLogPrefix()
|
| 145 |
+
//
|
| 146 |
+
// Returns the value of the Prepend Log Prefix option.
|
| 147 |
+
// This function is async-signal-safe.
|
| 148 |
+
ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix();
|
| 149 |
+
|
| 150 |
+
// EnableLogPrefix()
|
| 151 |
+
//
|
| 152 |
+
// Updates the value of the Prepend Log Prefix option.
|
| 153 |
+
// This function is async-signal-safe.
|
| 154 |
+
void EnableLogPrefix(bool on_off);
|
| 155 |
+
|
| 156 |
+
//------------------------------------------------------------------------------
|
| 157 |
+
// Set Global VLOG Level
|
| 158 |
+
//------------------------------------------------------------------------------
|
| 159 |
+
//
|
| 160 |
+
// Sets the global `(ABSL_)VLOG(_IS_ON)` level to `log_level`. This level is
|
| 161 |
+
// applied to any sites whose filename doesn't match any `module_pattern`.
|
| 162 |
+
// Returns the prior value.
|
| 163 |
+
inline int SetGlobalVLogLevel(int log_level) {
|
| 164 |
+
return absl::log_internal::UpdateGlobalVLogLevel(log_level);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
//------------------------------------------------------------------------------
|
| 168 |
+
// Set VLOG Level
|
| 169 |
+
//------------------------------------------------------------------------------
|
| 170 |
+
//
|
| 171 |
+
// Sets `(ABSL_)VLOG(_IS_ON)` level for `module_pattern` to `log_level`. This
|
| 172 |
+
// allows programmatic control of what is normally set by the --vmodule flag.
|
| 173 |
+
// Returns the level that previously applied to `module_pattern`.
|
| 174 |
+
inline int SetVLogLevel(absl::string_view module_pattern, int log_level) {
|
| 175 |
+
return absl::log_internal::PrependVModule(module_pattern, log_level);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
//------------------------------------------------------------------------------
|
| 179 |
+
// Configure Android Native Log Tag
|
| 180 |
+
//------------------------------------------------------------------------------
|
| 181 |
+
//
|
| 182 |
+
// The logging library forwards to the Android system log API when built for
|
| 183 |
+
// Android. That API takes a string "tag" value in addition to a message and
|
| 184 |
+
// severity level. The tag is used to identify the source of messages and to
|
| 185 |
+
// filter them. This library uses the tag "native" by default.
|
| 186 |
+
|
| 187 |
+
// SetAndroidNativeTag()
|
| 188 |
+
//
|
| 189 |
+
// Stores a copy of the string pointed to by `tag` and uses it as the Android
|
| 190 |
+
// logging tag thereafter. `tag` must not be null.
|
| 191 |
+
// This function must not be called more than once!
|
| 192 |
+
void SetAndroidNativeTag(const char* tag);
|
| 193 |
+
|
| 194 |
+
namespace log_internal {
|
| 195 |
+
// GetAndroidNativeTag()
|
| 196 |
+
//
|
| 197 |
+
// Returns the configured Android logging tag.
|
| 198 |
+
const char* GetAndroidNativeTag();
|
| 199 |
+
} // namespace log_internal
|
| 200 |
+
|
| 201 |
+
namespace log_internal {
|
| 202 |
+
|
| 203 |
+
using LoggingGlobalsListener = void (*)();
|
| 204 |
+
void SetLoggingGlobalsListener(LoggingGlobalsListener l);
|
| 205 |
+
|
| 206 |
+
// Internal implementation for the setter routines. These are used
|
| 207 |
+
// to break circular dependencies between flags and globals. Each "Raw"
|
| 208 |
+
// routine corresponds to the non-"Raw" counterpart and used to set the
|
| 209 |
+
// configuration parameter directly without calling back to the listener.
|
| 210 |
+
void RawSetMinLogLevel(absl::LogSeverityAtLeast severity);
|
| 211 |
+
void RawSetStderrThreshold(absl::LogSeverityAtLeast severity);
|
| 212 |
+
void RawEnableLogPrefix(bool on_off);
|
| 213 |
+
|
| 214 |
+
} // namespace log_internal
|
| 215 |
+
ABSL_NAMESPACE_END
|
| 216 |
+
} // namespace absl
|
| 217 |
+
|
| 218 |
+
#endif // ABSL_LOG_GLOBALS_H_
|
weight/_dep/abseil-cpp/absl/log/globals_test.cc
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/globals.h"
|
| 17 |
+
|
| 18 |
+
#include "gmock/gmock.h"
|
| 19 |
+
#include "gtest/gtest.h"
|
| 20 |
+
#include "absl/base/attributes.h"
|
| 21 |
+
#include "absl/base/log_severity.h"
|
| 22 |
+
#include "absl/log/internal/globals.h"
|
| 23 |
+
#include "absl/log/internal/test_helpers.h"
|
| 24 |
+
#include "absl/log/log.h"
|
| 25 |
+
#include "absl/log/scoped_mock_log.h"
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
using ::testing::_;
|
| 29 |
+
using ::testing::StrEq;
|
| 30 |
+
|
| 31 |
+
auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
|
| 32 |
+
new absl::log_internal::LogTestEnvironment);
|
| 33 |
+
|
| 34 |
+
constexpr static absl::LogSeverityAtLeast DefaultMinLogLevel() {
|
| 35 |
+
return absl::LogSeverityAtLeast::kInfo;
|
| 36 |
+
}
|
| 37 |
+
constexpr static absl::LogSeverityAtLeast DefaultStderrThreshold() {
|
| 38 |
+
return absl::LogSeverityAtLeast::kError;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
TEST(TestGlobals, MinLogLevel) {
|
| 42 |
+
EXPECT_EQ(absl::MinLogLevel(), DefaultMinLogLevel());
|
| 43 |
+
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kError);
|
| 44 |
+
EXPECT_EQ(absl::MinLogLevel(), absl::LogSeverityAtLeast::kError);
|
| 45 |
+
absl::SetMinLogLevel(DefaultMinLogLevel());
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
TEST(TestGlobals, ScopedMinLogLevel) {
|
| 49 |
+
EXPECT_EQ(absl::MinLogLevel(), DefaultMinLogLevel());
|
| 50 |
+
{
|
| 51 |
+
absl::log_internal::ScopedMinLogLevel scoped_stderr_threshold(
|
| 52 |
+
absl::LogSeverityAtLeast::kError);
|
| 53 |
+
EXPECT_EQ(absl::MinLogLevel(), absl::LogSeverityAtLeast::kError);
|
| 54 |
+
}
|
| 55 |
+
EXPECT_EQ(absl::MinLogLevel(), DefaultMinLogLevel());
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
TEST(TestGlobals, StderrThreshold) {
|
| 59 |
+
EXPECT_EQ(absl::StderrThreshold(), DefaultStderrThreshold());
|
| 60 |
+
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kError);
|
| 61 |
+
EXPECT_EQ(absl::StderrThreshold(), absl::LogSeverityAtLeast::kError);
|
| 62 |
+
absl::SetStderrThreshold(DefaultStderrThreshold());
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
TEST(TestGlobals, ScopedStderrThreshold) {
|
| 66 |
+
EXPECT_EQ(absl::StderrThreshold(), DefaultStderrThreshold());
|
| 67 |
+
{
|
| 68 |
+
absl::ScopedStderrThreshold scoped_stderr_threshold(
|
| 69 |
+
absl::LogSeverityAtLeast::kError);
|
| 70 |
+
EXPECT_EQ(absl::StderrThreshold(), absl::LogSeverityAtLeast::kError);
|
| 71 |
+
}
|
| 72 |
+
EXPECT_EQ(absl::StderrThreshold(), DefaultStderrThreshold());
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
TEST(TestGlobals, LogBacktraceAt) {
|
| 76 |
+
EXPECT_FALSE(absl::log_internal::ShouldLogBacktraceAt("some_file.cc", 111));
|
| 77 |
+
absl::SetLogBacktraceLocation("some_file.cc", 111);
|
| 78 |
+
EXPECT_TRUE(absl::log_internal::ShouldLogBacktraceAt("some_file.cc", 111));
|
| 79 |
+
EXPECT_FALSE(
|
| 80 |
+
absl::log_internal::ShouldLogBacktraceAt("another_file.cc", 222));
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
TEST(TestGlobals, LogPrefix) {
|
| 84 |
+
EXPECT_TRUE(absl::ShouldPrependLogPrefix());
|
| 85 |
+
absl::EnableLogPrefix(false);
|
| 86 |
+
EXPECT_FALSE(absl::ShouldPrependLogPrefix());
|
| 87 |
+
absl::EnableLogPrefix(true);
|
| 88 |
+
EXPECT_TRUE(absl::ShouldPrependLogPrefix());
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
TEST(TestGlobals, SetGlobalVLogLevel) {
|
| 92 |
+
EXPECT_EQ(absl::SetGlobalVLogLevel(42), 0);
|
| 93 |
+
EXPECT_EQ(absl::SetGlobalVLogLevel(1337), 42);
|
| 94 |
+
// Restore the value since it affects the default unset module value for
|
| 95 |
+
// `SetVLogLevel()`.
|
| 96 |
+
EXPECT_EQ(absl::SetGlobalVLogLevel(0), 1337);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
TEST(TestGlobals, SetVLogLevel) {
|
| 100 |
+
EXPECT_EQ(absl::SetVLogLevel("setvloglevel", 42), 0);
|
| 101 |
+
EXPECT_EQ(absl::SetVLogLevel("setvloglevel", 1337), 42);
|
| 102 |
+
EXPECT_EQ(absl::SetVLogLevel("othersetvloglevel", 50), 0);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
TEST(TestGlobals, AndroidLogTag) {
|
| 106 |
+
// Verify invalid tags result in a check failure.
|
| 107 |
+
EXPECT_DEATH_IF_SUPPORTED(absl::SetAndroidNativeTag(nullptr), ".*");
|
| 108 |
+
|
| 109 |
+
// Verify valid tags applied.
|
| 110 |
+
EXPECT_THAT(absl::log_internal::GetAndroidNativeTag(), StrEq("native"));
|
| 111 |
+
absl::SetAndroidNativeTag("test_tag");
|
| 112 |
+
EXPECT_THAT(absl::log_internal::GetAndroidNativeTag(), StrEq("test_tag"));
|
| 113 |
+
|
| 114 |
+
// Verify that additional calls (more than 1) result in a check failure.
|
| 115 |
+
EXPECT_DEATH_IF_SUPPORTED(absl::SetAndroidNativeTag("test_tag_fail"), ".*");
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
TEST(TestExitOnDFatal, OffTest) {
|
| 119 |
+
// Turn off...
|
| 120 |
+
absl::log_internal::SetExitOnDFatal(false);
|
| 121 |
+
EXPECT_FALSE(absl::log_internal::ExitOnDFatal());
|
| 122 |
+
|
| 123 |
+
// We don't die.
|
| 124 |
+
{
|
| 125 |
+
absl::ScopedMockLog log(absl::MockLogDefault::kDisallowUnexpected);
|
| 126 |
+
|
| 127 |
+
// LOG(DFATAL) has severity FATAL if debugging, but is
|
| 128 |
+
// downgraded to ERROR if not debugging.
|
| 129 |
+
EXPECT_CALL(log, Log(absl::kLogDebugFatal, _, "This should not be fatal"));
|
| 130 |
+
|
| 131 |
+
log.StartCapturingLogs();
|
| 132 |
+
LOG(DFATAL) << "This should not be fatal";
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
#if GTEST_HAS_DEATH_TEST
|
| 137 |
+
TEST(TestDeathWhileExitOnDFatal, OnTest) {
|
| 138 |
+
absl::log_internal::SetExitOnDFatal(true);
|
| 139 |
+
EXPECT_TRUE(absl::log_internal::ExitOnDFatal());
|
| 140 |
+
|
| 141 |
+
// Death comes on little cats' feet.
|
| 142 |
+
EXPECT_DEBUG_DEATH({ LOG(DFATAL) << "This should be fatal in debug mode"; },
|
| 143 |
+
"This should be fatal in debug mode");
|
| 144 |
+
}
|
| 145 |
+
#endif
|
| 146 |
+
|
| 147 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/log/initialize.cc
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "absl/log/initialize.h"
|
| 16 |
+
|
| 17 |
+
#include "absl/base/config.h"
|
| 18 |
+
#include "absl/log/internal/globals.h"
|
| 19 |
+
#include "absl/time/time.h"
|
| 20 |
+
|
| 21 |
+
namespace absl {
|
| 22 |
+
ABSL_NAMESPACE_BEGIN
|
| 23 |
+
|
| 24 |
+
namespace {
|
| 25 |
+
void InitializeLogImpl(absl::TimeZone time_zone) {
|
| 26 |
+
// This comes first since it is used by RAW_LOG.
|
| 27 |
+
absl::log_internal::SetTimeZone(time_zone);
|
| 28 |
+
|
| 29 |
+
// Note that initialization is complete, so logs can now be sent to their
|
| 30 |
+
// proper destinations rather than stderr.
|
| 31 |
+
log_internal::SetInitialized();
|
| 32 |
+
}
|
| 33 |
+
} // namespace
|
| 34 |
+
|
| 35 |
+
void InitializeLog() { InitializeLogImpl(absl::LocalTimeZone()); }
|
| 36 |
+
|
| 37 |
+
ABSL_NAMESPACE_END
|
| 38 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/log/initialize.h
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/initialize.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header declares the Abseil Log initialization routine InitializeLog().
|
| 20 |
+
|
| 21 |
+
#ifndef ABSL_LOG_INITIALIZE_H_
|
| 22 |
+
#define ABSL_LOG_INITIALIZE_H_
|
| 23 |
+
|
| 24 |
+
#include "absl/base/config.h"
|
| 25 |
+
|
| 26 |
+
namespace absl {
|
| 27 |
+
ABSL_NAMESPACE_BEGIN
|
| 28 |
+
|
| 29 |
+
// InitializeLog()
|
| 30 |
+
//
|
| 31 |
+
// Initializes the Abseil logging library.
|
| 32 |
+
//
|
| 33 |
+
// Before this function is called, all log messages are directed only to stderr.
|
| 34 |
+
// After initialization is finished, log messages are directed to all registered
|
| 35 |
+
// `LogSink`s.
|
| 36 |
+
//
|
| 37 |
+
// It is an error to call this function twice.
|
| 38 |
+
//
|
| 39 |
+
// There is no corresponding function to shut down the logging library.
|
| 40 |
+
void InitializeLog();
|
| 41 |
+
|
| 42 |
+
ABSL_NAMESPACE_END
|
| 43 |
+
} // namespace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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/internal/check_op.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This file declares helpers routines and macros used to implement `CHECK`
|
| 20 |
+
// macros.
|
| 21 |
+
|
| 22 |
+
#ifndef ABSL_LOG_INTERNAL_CHECK_OP_H_
|
| 23 |
+
#define ABSL_LOG_INTERNAL_CHECK_OP_H_
|
| 24 |
+
|
| 25 |
+
#include <stdint.h>
|
| 26 |
+
|
| 27 |
+
#include <ostream>
|
| 28 |
+
#include <sstream>
|
| 29 |
+
#include <string>
|
| 30 |
+
#include <utility>
|
| 31 |
+
|
| 32 |
+
#include "absl/base/attributes.h"
|
| 33 |
+
#include "absl/base/config.h"
|
| 34 |
+
#include "absl/base/optimization.h"
|
| 35 |
+
#include "absl/log/internal/nullguard.h"
|
| 36 |
+
#include "absl/log/internal/nullstream.h"
|
| 37 |
+
#include "absl/log/internal/strip.h"
|
| 38 |
+
|
| 39 |
+
// `ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL` wraps string literals that
|
| 40 |
+
// should be stripped when `ABSL_MIN_LOG_LEVEL` exceeds `kFatal`.
|
| 41 |
+
#ifdef ABSL_MIN_LOG_LEVEL
|
| 42 |
+
#define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(literal) \
|
| 43 |
+
(::absl::LogSeverity::kFatal >= \
|
| 44 |
+
static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) \
|
| 45 |
+
? (literal) \
|
| 46 |
+
: "")
|
| 47 |
+
#else
|
| 48 |
+
#define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(literal) (literal)
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#ifdef NDEBUG
|
| 52 |
+
// `NDEBUG` is defined, so `DCHECK_EQ(x, y)` and so on do nothing. However, we
|
| 53 |
+
// still want the compiler to parse `x` and `y`, because we don't want to lose
|
| 54 |
+
// potentially useful errors and warnings.
|
| 55 |
+
#define ABSL_LOG_INTERNAL_DCHECK_NOP(x, y) \
|
| 56 |
+
while (false && ((void)(x), (void)(y), 0)) \
|
| 57 |
+
::absl::log_internal::NullStream().InternalStream()
|
| 58 |
+
#endif
|
| 59 |
+
|
| 60 |
+
#define ABSL_LOG_INTERNAL_CHECK_OP(name, op, val1, val1_text, val2, val2_text) \
|
| 61 |
+
while ( \
|
| 62 |
+
::std::string* absl_log_internal_check_op_result ABSL_ATTRIBUTE_UNUSED = \
|
| 63 |
+
::absl::log_internal::name##Impl( \
|
| 64 |
+
::absl::log_internal::GetReferenceableValue(val1), \
|
| 65 |
+
::absl::log_internal::GetReferenceableValue(val2), \
|
| 66 |
+
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val1_text \
|
| 67 |
+
" " #op " " val2_text))) \
|
| 68 |
+
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \
|
| 69 |
+
ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_op_result).InternalStream()
|
| 70 |
+
#define ABSL_LOG_INTERNAL_QCHECK_OP(name, op, val1, val1_text, val2, \
|
| 71 |
+
val2_text) \
|
| 72 |
+
while (::std::string* absl_log_internal_qcheck_op_result = \
|
| 73 |
+
::absl::log_internal::name##Impl( \
|
| 74 |
+
::absl::log_internal::GetReferenceableValue(val1), \
|
| 75 |
+
::absl::log_internal::GetReferenceableValue(val2), \
|
| 76 |
+
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL( \
|
| 77 |
+
val1_text " " #op " " val2_text))) \
|
| 78 |
+
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \
|
| 79 |
+
ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_op_result).InternalStream()
|
| 80 |
+
#define ABSL_LOG_INTERNAL_CHECK_STROP(func, op, expected, s1, s1_text, s2, \
|
| 81 |
+
s2_text) \
|
| 82 |
+
while (::std::string* absl_log_internal_check_strop_result = \
|
| 83 |
+
::absl::log_internal::Check##func##expected##Impl( \
|
| 84 |
+
(s1), (s2), \
|
| 85 |
+
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(s1_text " " #op \
|
| 86 |
+
" " s2_text))) \
|
| 87 |
+
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \
|
| 88 |
+
ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_strop_result) \
|
| 89 |
+
.InternalStream()
|
| 90 |
+
#define ABSL_LOG_INTERNAL_QCHECK_STROP(func, op, expected, s1, s1_text, s2, \
|
| 91 |
+
s2_text) \
|
| 92 |
+
while (::std::string* absl_log_internal_qcheck_strop_result = \
|
| 93 |
+
::absl::log_internal::Check##func##expected##Impl( \
|
| 94 |
+
(s1), (s2), \
|
| 95 |
+
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(s1_text " " #op \
|
| 96 |
+
" " s2_text))) \
|
| 97 |
+
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \
|
| 98 |
+
ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_strop_result) \
|
| 99 |
+
.InternalStream()
|
| 100 |
+
// This one is tricky:
|
| 101 |
+
// * We must evaluate `val` exactly once, yet we need to do two things with it:
|
| 102 |
+
// evaluate `.ok()` and (sometimes) `.ToString()`.
|
| 103 |
+
// * `val` might be an `absl::Status` or some `absl::StatusOr<T>`.
|
| 104 |
+
// * `val` might be e.g. `ATemporary().GetStatus()`, which may return a
|
| 105 |
+
// reference to a member of `ATemporary` that is only valid until the end of
|
| 106 |
+
// the full expression.
|
| 107 |
+
// * We don't want this file to depend on `absl::Status` `#include`s or linkage,
|
| 108 |
+
// nor do we want to move the definition to status and introduce a dependency
|
| 109 |
+
// in the other direction. We can be assured that callers must already have a
|
| 110 |
+
// `Status` and the necessary `#include`s and linkage.
|
| 111 |
+
// * Callsites should be small and fast (at least when `val.ok()`): one branch,
|
| 112 |
+
// minimal stack footprint.
|
| 113 |
+
// * In particular, the string concat stuff should be out-of-line and emitted
|
| 114 |
+
// in only one TU to save linker input size
|
| 115 |
+
// * We want the `val.ok()` check inline so static analyzers and optimizers can
|
| 116 |
+
// see it.
|
| 117 |
+
// * As usual, no braces so we can stream into the expansion with `operator<<`.
|
| 118 |
+
// * Also as usual, it must expand to a single (partial) statement with no
|
| 119 |
+
// ambiguous-else problems.
|
| 120 |
+
// * When stripped by `ABSL_MIN_LOG_LEVEL`, we must discard the `<expr> is OK`
|
| 121 |
+
// string literal and abort without doing any streaming. We don't need to
|
| 122 |
+
// strip the call to stringify the non-ok `Status` as long as we don't log it;
|
| 123 |
+
// dropping the `Status`'s message text is out of scope.
|
| 124 |
+
#define ABSL_LOG_INTERNAL_CHECK_OK(val, val_text) \
|
| 125 |
+
for (::std::pair<const ::absl::Status*, ::std::string*> \
|
| 126 |
+
absl_log_internal_check_ok_goo; \
|
| 127 |
+
absl_log_internal_check_ok_goo.first = \
|
| 128 |
+
::absl::log_internal::AsStatus(val), \
|
| 129 |
+
absl_log_internal_check_ok_goo.second = \
|
| 130 |
+
ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok()) \
|
| 131 |
+
? nullptr \
|
| 132 |
+
: ::absl::status_internal::MakeCheckFailString( \
|
| 133 |
+
absl_log_internal_check_ok_goo.first, \
|
| 134 |
+
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val_text \
|
| 135 |
+
" is OK")), \
|
| 136 |
+
!ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok());) \
|
| 137 |
+
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \
|
| 138 |
+
ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_ok_goo.second) \
|
| 139 |
+
.InternalStream()
|
| 140 |
+
#define ABSL_LOG_INTERNAL_QCHECK_OK(val, val_text) \
|
| 141 |
+
for (::std::pair<const ::absl::Status*, ::std::string*> \
|
| 142 |
+
absl_log_internal_qcheck_ok_goo; \
|
| 143 |
+
absl_log_internal_qcheck_ok_goo.first = \
|
| 144 |
+
::absl::log_internal::AsStatus(val), \
|
| 145 |
+
absl_log_internal_qcheck_ok_goo.second = \
|
| 146 |
+
ABSL_PREDICT_TRUE(absl_log_internal_qcheck_ok_goo.first->ok()) \
|
| 147 |
+
? nullptr \
|
| 148 |
+
: ::absl::status_internal::MakeCheckFailString( \
|
| 149 |
+
absl_log_internal_qcheck_ok_goo.first, \
|
| 150 |
+
ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val_text \
|
| 151 |
+
" is OK")), \
|
| 152 |
+
!ABSL_PREDICT_TRUE(absl_log_internal_qcheck_ok_goo.first->ok());) \
|
| 153 |
+
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \
|
| 154 |
+
ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_ok_goo.second) \
|
| 155 |
+
.InternalStream()
|
| 156 |
+
|
| 157 |
+
namespace absl {
|
| 158 |
+
ABSL_NAMESPACE_BEGIN
|
| 159 |
+
|
| 160 |
+
class Status;
|
| 161 |
+
template <typename T>
|
| 162 |
+
class StatusOr;
|
| 163 |
+
|
| 164 |
+
namespace status_internal {
|
| 165 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION std::string* MakeCheckFailString(
|
| 166 |
+
const absl::Status* status, const char* prefix);
|
| 167 |
+
} // namespace status_internal
|
| 168 |
+
|
| 169 |
+
namespace log_internal {
|
| 170 |
+
|
| 171 |
+
// Convert a Status or a StatusOr to its underlying status value.
|
| 172 |
+
//
|
| 173 |
+
// (This implementation does not require a dep on absl::Status to work.)
|
| 174 |
+
inline const absl::Status* AsStatus(const absl::Status& s) { return &s; }
|
| 175 |
+
template <typename T>
|
| 176 |
+
const absl::Status* AsStatus(const absl::StatusOr<T>& s) {
|
| 177 |
+
return &s.status();
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// A helper class for formatting `expr (V1 vs. V2)` in a `CHECK_XX` statement.
|
| 181 |
+
// See `MakeCheckOpString` for sample usage.
|
| 182 |
+
class CheckOpMessageBuilder final {
|
| 183 |
+
public:
|
| 184 |
+
// Inserts `exprtext` and ` (` to the stream.
|
| 185 |
+
explicit CheckOpMessageBuilder(const char* exprtext);
|
| 186 |
+
~CheckOpMessageBuilder() = default;
|
| 187 |
+
// For inserting the first variable.
|
| 188 |
+
std::ostream& ForVar1() { return stream_; }
|
| 189 |
+
// For inserting the second variable (adds an intermediate ` vs. `).
|
| 190 |
+
std::ostream& ForVar2();
|
| 191 |
+
// Get the result (inserts the closing `)`).
|
| 192 |
+
std::string* NewString();
|
| 193 |
+
|
| 194 |
+
private:
|
| 195 |
+
std::ostringstream stream_;
|
| 196 |
+
};
|
| 197 |
+
|
| 198 |
+
// This formats a value for a failing `CHECK_XX` statement. Ordinarily, it uses
|
| 199 |
+
// the definition for `operator<<`, with a few special cases below.
|
| 200 |
+
template <typename T>
|
| 201 |
+
inline void MakeCheckOpValueString(std::ostream& os, const T& v) {
|
| 202 |
+
os << log_internal::NullGuard<T>::Guard(v);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// Overloads for char types provide readable values for unprintable characters.
|
| 206 |
+
void MakeCheckOpValueString(std::ostream& os, char v);
|
| 207 |
+
void MakeCheckOpValueString(std::ostream& os, signed char v);
|
| 208 |
+
void MakeCheckOpValueString(std::ostream& os, unsigned char v);
|
| 209 |
+
void MakeCheckOpValueString(std::ostream& os, const void* p);
|
| 210 |
+
|
| 211 |
+
namespace detect_specialization {
|
| 212 |
+
|
| 213 |
+
// MakeCheckOpString is being specialized for every T and U pair that is being
|
| 214 |
+
// passed to the CHECK_op macros. However, there is a lot of redundancy in these
|
| 215 |
+
// specializations that creates unnecessary library and binary bloat.
|
| 216 |
+
// The number of instantiations tends to be O(n^2) because we have two
|
| 217 |
+
// independent inputs. This technique works by reducing `n`.
|
| 218 |
+
//
|
| 219 |
+
// Most user-defined types being passed to CHECK_op end up being printed as a
|
| 220 |
+
// builtin type. For example, enums tend to be implicitly converted to its
|
| 221 |
+
// underlying type when calling operator<<, and pointers are printed with the
|
| 222 |
+
// `const void*` overload.
|
| 223 |
+
// To reduce the number of instantiations we coerce these values before calling
|
| 224 |
+
// MakeCheckOpString instead of inside it.
|
| 225 |
+
//
|
| 226 |
+
// To detect if this coercion is needed, we duplicate all the relevant
|
| 227 |
+
// operator<< overloads as specified in the standard, just in a different
|
| 228 |
+
// namespace. If the call to `stream << value` becomes ambiguous, it means that
|
| 229 |
+
// one of these overloads is the one selected by overload resolution. We then
|
| 230 |
+
// do overload resolution again just with our overload set to see which one gets
|
| 231 |
+
// selected. That tells us which type to coerce to.
|
| 232 |
+
// If the augmented call was not ambiguous, it means that none of these were
|
| 233 |
+
// selected and we can't coerce the input.
|
| 234 |
+
//
|
| 235 |
+
// As a secondary step to reduce code duplication, we promote integral types to
|
| 236 |
+
// their 64-bit variant. This does not change the printed value, but reduces the
|
| 237 |
+
// number of instantiations even further. Promoting an integer is very cheap at
|
| 238 |
+
// the call site.
|
| 239 |
+
int64_t operator<<(std::ostream&, short value); // NOLINT
|
| 240 |
+
int64_t operator<<(std::ostream&, unsigned short value); // NOLINT
|
| 241 |
+
int64_t operator<<(std::ostream&, int value);
|
| 242 |
+
int64_t operator<<(std::ostream&, unsigned int value);
|
| 243 |
+
int64_t operator<<(std::ostream&, long value); // NOLINT
|
| 244 |
+
uint64_t operator<<(std::ostream&, unsigned long value); // NOLINT
|
| 245 |
+
int64_t operator<<(std::ostream&, long long value); // NOLINT
|
| 246 |
+
uint64_t operator<<(std::ostream&, unsigned long long value); // NOLINT
|
| 247 |
+
float operator<<(std::ostream&, float value);
|
| 248 |
+
double operator<<(std::ostream&, double value);
|
| 249 |
+
long double operator<<(std::ostream&, long double value);
|
| 250 |
+
bool operator<<(std::ostream&, bool value);
|
| 251 |
+
const void* operator<<(std::ostream&, const void* value);
|
| 252 |
+
const void* operator<<(std::ostream&, std::nullptr_t);
|
| 253 |
+
|
| 254 |
+
// These `char` overloads are specified like this in the standard, so we have to
|
| 255 |
+
// write them exactly the same to ensure the call is ambiguous.
|
| 256 |
+
// If we wrote it in a different way (eg taking std::ostream instead of the
|
| 257 |
+
// template) then one call might have a higher rank than the other and it would
|
| 258 |
+
// not be ambiguous.
|
| 259 |
+
template <typename Traits>
|
| 260 |
+
char operator<<(std::basic_ostream<char, Traits>&, char);
|
| 261 |
+
template <typename Traits>
|
| 262 |
+
signed char operator<<(std::basic_ostream<char, Traits>&, signed char);
|
| 263 |
+
template <typename Traits>
|
| 264 |
+
unsigned char operator<<(std::basic_ostream<char, Traits>&, unsigned char);
|
| 265 |
+
template <typename Traits>
|
| 266 |
+
const char* operator<<(std::basic_ostream<char, Traits>&, const char*);
|
| 267 |
+
template <typename Traits>
|
| 268 |
+
const signed char* operator<<(std::basic_ostream<char, Traits>&,
|
| 269 |
+
const signed char*);
|
| 270 |
+
template <typename Traits>
|
| 271 |
+
const unsigned char* operator<<(std::basic_ostream<char, Traits>&,
|
| 272 |
+
const unsigned char*);
|
| 273 |
+
|
| 274 |
+
// This overload triggers when the call is not ambiguous.
|
| 275 |
+
// It means that T is being printed with some overload not on this list.
|
| 276 |
+
// We keep the value as `const T&`.
|
| 277 |
+
template <typename T, typename = decltype(std::declval<std::ostream&>()
|
| 278 |
+
<< std::declval<const T&>())>
|
| 279 |
+
const T& Detect(int);
|
| 280 |
+
|
| 281 |
+
// This overload triggers when the call is ambiguous.
|
| 282 |
+
// It means that T is either one from this list or printed as one from this
|
| 283 |
+
// list. Eg an enum that decays to `int` for printing.
|
| 284 |
+
// We ask the overload set to give us the type we want to convert it to.
|
| 285 |
+
template <typename T>
|
| 286 |
+
decltype(detect_specialization::operator<<(std::declval<std::ostream&>(),
|
| 287 |
+
std::declval<const T&>()))
|
| 288 |
+
Detect(char);
|
| 289 |
+
|
| 290 |
+
} // namespace detect_specialization
|
| 291 |
+
|
| 292 |
+
template <typename T>
|
| 293 |
+
using CheckOpStreamType = decltype(detect_specialization::Detect<T>(0));
|
| 294 |
+
|
| 295 |
+
// Build the error message string. Specify no inlining for code size.
|
| 296 |
+
template <typename T1, typename T2>
|
| 297 |
+
ABSL_ATTRIBUTE_RETURNS_NONNULL std::string* MakeCheckOpString(
|
| 298 |
+
T1 v1, T2 v2, const char* exprtext) ABSL_ATTRIBUTE_NOINLINE;
|
| 299 |
+
|
| 300 |
+
template <typename T1, typename T2>
|
| 301 |
+
std::string* MakeCheckOpString(T1 v1, T2 v2, const char* exprtext) {
|
| 302 |
+
CheckOpMessageBuilder comb(exprtext);
|
| 303 |
+
MakeCheckOpValueString(comb.ForVar1(), v1);
|
| 304 |
+
MakeCheckOpValueString(comb.ForVar2(), v2);
|
| 305 |
+
return comb.NewString();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
// Add a few commonly used instantiations as extern to reduce size of objects
|
| 309 |
+
// files.
|
| 310 |
+
#define ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(x) \
|
| 311 |
+
extern template std::string* MakeCheckOpString(x, x, const char*)
|
| 312 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(bool);
|
| 313 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(int64_t);
|
| 314 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(uint64_t);
|
| 315 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(float);
|
| 316 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(double);
|
| 317 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(char);
|
| 318 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(unsigned char);
|
| 319 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const std::string&);
|
| 320 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const absl::string_view&);
|
| 321 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const char*);
|
| 322 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const signed char*);
|
| 323 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const unsigned char*);
|
| 324 |
+
ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const void*);
|
| 325 |
+
#undef ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN
|
| 326 |
+
|
| 327 |
+
// `ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT` skips formatting the Check_OP result
|
| 328 |
+
// string iff `ABSL_MIN_LOG_LEVEL` exceeds `kFatal`, instead returning an empty
|
| 329 |
+
// string.
|
| 330 |
+
#ifdef ABSL_MIN_LOG_LEVEL
|
| 331 |
+
#define ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, exprtext) \
|
| 332 |
+
((::absl::LogSeverity::kFatal >= \
|
| 333 |
+
static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL)) \
|
| 334 |
+
? MakeCheckOpString<U1, U2>(v1, v2, exprtext) \
|
| 335 |
+
: new std::string())
|
| 336 |
+
#else
|
| 337 |
+
#define ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, exprtext) \
|
| 338 |
+
MakeCheckOpString<U1, U2>(v1, v2, exprtext)
|
| 339 |
+
#endif
|
| 340 |
+
|
| 341 |
+
// Helper functions for `ABSL_LOG_INTERNAL_CHECK_OP` macro family. The
|
| 342 |
+
// `(int, int)` override works around the issue that the compiler will not
|
| 343 |
+
// instantiate the template version of the function on values of unnamed enum
|
| 344 |
+
// type.
|
| 345 |
+
#define ABSL_LOG_INTERNAL_CHECK_OP_IMPL(name, op) \
|
| 346 |
+
template <typename T1, typename T2> \
|
| 347 |
+
inline constexpr ::std::string* name##Impl(const T1& v1, const T2& v2, \
|
| 348 |
+
const char* exprtext) { \
|
| 349 |
+
using U1 = CheckOpStreamType<T1>; \
|
| 350 |
+
using U2 = CheckOpStreamType<T2>; \
|
| 351 |
+
return ABSL_PREDICT_TRUE(v1 op v2) \
|
| 352 |
+
? nullptr \
|
| 353 |
+
: ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, \
|
| 354 |
+
exprtext); \
|
| 355 |
+
} \
|
| 356 |
+
inline constexpr ::std::string* name##Impl(int v1, int v2, \
|
| 357 |
+
const char* exprtext) { \
|
| 358 |
+
return name##Impl<int, int>(v1, v2, exprtext); \
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_EQ, ==)
|
| 362 |
+
ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_NE, !=)
|
| 363 |
+
ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_LE, <=)
|
| 364 |
+
ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_LT, <)
|
| 365 |
+
ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_GE, >=)
|
| 366 |
+
ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_GT, >)
|
| 367 |
+
#undef ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT
|
| 368 |
+
#undef ABSL_LOG_INTERNAL_CHECK_OP_IMPL
|
| 369 |
+
|
| 370 |
+
std::string* CheckstrcmptrueImpl(const char* s1, const char* s2,
|
| 371 |
+
const char* exprtext);
|
| 372 |
+
std::string* CheckstrcmpfalseImpl(const char* s1, const char* s2,
|
| 373 |
+
const char* exprtext);
|
| 374 |
+
std::string* CheckstrcasecmptrueImpl(const char* s1, const char* s2,
|
| 375 |
+
const char* exprtext);
|
| 376 |
+
std::string* CheckstrcasecmpfalseImpl(const char* s1, const char* s2,
|
| 377 |
+
const char* exprtext);
|
| 378 |
+
|
| 379 |
+
// `CHECK_EQ` and friends want to pass their arguments by reference, however
|
| 380 |
+
// this winds up exposing lots of cases where people have defined and
|
| 381 |
+
// initialized static const data members but never declared them (i.e. in a .cc
|
| 382 |
+
// file), meaning they are not referenceable. This function avoids that problem
|
| 383 |
+
// for integers (the most common cases) by overloading for every primitive
|
| 384 |
+
// integer type, even the ones we discourage, and returning them by value.
|
| 385 |
+
template <typename T>
|
| 386 |
+
inline constexpr const T& GetReferenceableValue(const T& t) {
|
| 387 |
+
return t;
|
| 388 |
+
}
|
| 389 |
+
inline constexpr char GetReferenceableValue(char t) { return t; }
|
| 390 |
+
inline constexpr unsigned char GetReferenceableValue(unsigned char t) {
|
| 391 |
+
return t;
|
| 392 |
+
}
|
| 393 |
+
inline constexpr signed char GetReferenceableValue(signed char t) { return t; }
|
| 394 |
+
inline constexpr short GetReferenceableValue(short t) { return t; } // NOLINT
|
| 395 |
+
inline constexpr unsigned short GetReferenceableValue( // NOLINT
|
| 396 |
+
unsigned short t) { // NOLINT
|
| 397 |
+
return t;
|
| 398 |
+
}
|
| 399 |
+
inline constexpr int GetReferenceableValue(int t) { return t; }
|
| 400 |
+
inline constexpr unsigned int GetReferenceableValue(unsigned int t) {
|
| 401 |
+
return t;
|
| 402 |
+
}
|
| 403 |
+
inline constexpr long GetReferenceableValue(long t) { return t; } // NOLINT
|
| 404 |
+
inline constexpr unsigned long GetReferenceableValue( // NOLINT
|
| 405 |
+
unsigned long t) { // NOLINT
|
| 406 |
+
return t;
|
| 407 |
+
}
|
| 408 |
+
inline constexpr long long GetReferenceableValue(long long t) { // NOLINT
|
| 409 |
+
return t;
|
| 410 |
+
}
|
| 411 |
+
inline constexpr unsigned long long GetReferenceableValue( // NOLINT
|
| 412 |
+
unsigned long long t) { // NOLINT
|
| 413 |
+
return t;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
} // namespace log_internal
|
| 417 |
+
ABSL_NAMESPACE_END
|
| 418 |
+
} // namespace absl
|
| 419 |
+
|
| 420 |
+
#endif // ABSL_LOG_INTERNAL_CHECK_OP_H_
|
weight/_dep/abseil-cp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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/log.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header declares a family of LOG macros.
|
| 20 |
+
//
|
| 21 |
+
// Basic invocation looks like this:
|
| 22 |
+
//
|
| 23 |
+
// LOG(INFO) << "Found " << num_cookies << " cookies";
|
| 24 |
+
//
|
| 25 |
+
// Most `LOG` macros take a severity level argument. The severity levels are
|
| 26 |
+
// `INFO`, `WARNING`, `ERROR`, and `FATAL`. They are defined
|
| 27 |
+
// in absl/base/log_severity.h.
|
| 28 |
+
// * The `FATAL` severity level terminates the program with a stack trace after
|
| 29 |
+
// logging its message. Error handlers registered with `RunOnFailure`
|
| 30 |
+
// (process_state.h) are run, but exit handlers registered with `atexit(3)`
|
| 31 |
+
// are not.
|
| 32 |
+
// * The `QFATAL` pseudo-severity level is equivalent to `FATAL` but triggers
|
| 33 |
+
// quieter termination messages, e.g. without a full stack trace, and skips
|
| 34 |
+
// running registered error handlers.
|
| 35 |
+
// * The `DFATAL` pseudo-severity level is defined as `FATAL` in debug mode and
|
| 36 |
+
// as `ERROR` otherwise.
|
| 37 |
+
// Some preprocessor shenanigans are used to ensure that e.g. `LOG(INFO)` has
|
| 38 |
+
// the same meaning even if a local symbol or preprocessor macro named `INFO` is
|
| 39 |
+
// defined. To specify a severity level using an expression instead of a
|
| 40 |
+
// literal, use `LEVEL(expr)`.
|
| 41 |
+
// Example:
|
| 42 |
+
//
|
| 43 |
+
// LOG(LEVEL(stale ? absl::LogSeverity::kWarning : absl::LogSeverity::kInfo))
|
| 44 |
+
// << "Cookies are " << days << " days old";
|
| 45 |
+
|
| 46 |
+
// `LOG` macros evaluate to an unterminated statement. The value at the end of
|
| 47 |
+
// the statement supports some chainable methods:
|
| 48 |
+
//
|
| 49 |
+
// * .AtLocation(absl::string_view file, int line)
|
| 50 |
+
// .AtLocation(absl::SourceLocation loc)
|
| 51 |
+
// Overrides the location inferred from the callsite. The string pointed to
|
| 52 |
+
// by `file` must be valid until the end of the statement.
|
| 53 |
+
// * .NoPrefix()
|
| 54 |
+
// Omits the prefix from this line. The prefix includes metadata about the
|
| 55 |
+
// logged data such as source code location and timestamp.
|
| 56 |
+
// * .WithVerbosity(int verbose_level)
|
| 57 |
+
// Sets the verbosity field of the logged message as if it was logged by
|
| 58 |
+
// `VLOG(verbose_level)`. Unlike `VLOG`, this method does not affect
|
| 59 |
+
// evaluation of the statement when the specified `verbose_level` has been
|
| 60 |
+
// disabled. The only effect is on `LogSink` implementations which make use
|
| 61 |
+
// of the `absl::LogSink::verbosity()` value. The value
|
| 62 |
+
// `absl::LogEntry::kNoVerbosityLevel` can be specified to mark the message
|
| 63 |
+
// not verbose.
|
| 64 |
+
// * .WithTimestamp(absl::Time timestamp)
|
| 65 |
+
// Uses the specified timestamp instead of one collected at the time of
|
| 66 |
+
// execution.
|
| 67 |
+
// * .WithThreadID(absl::LogEntry::tid_t tid)
|
| 68 |
+
// Uses the specified thread ID instead of one collected at the time of
|
| 69 |
+
// execution.
|
| 70 |
+
// * .WithMetadataFrom(const absl::LogEntry &entry)
|
| 71 |
+
// Copies all metadata (but no data) from the specified `absl::LogEntry`.
|
| 72 |
+
// This can be used to change the severity of a message, but it has some
|
| 73 |
+
// limitations:
|
| 74 |
+
// * `ABSL_MIN_LOG_LEVEL` is evaluated against the severity passed into
|
| 75 |
+
// `LOG` (or the implicit `FATAL` level of `CHECK`).
|
| 76 |
+
// * `LOG(FATAL)` and `CHECK` terminate the process unconditionally, even if
|
| 77 |
+
// the severity is changed later.
|
| 78 |
+
// `.WithMetadataFrom(entry)` should almost always be used in combination
|
| 79 |
+
// with `LOG(LEVEL(entry.log_severity()))`.
|
| 80 |
+
// * .WithPerror()
|
| 81 |
+
// Appends to the logged message a colon, a space, a textual description of
|
| 82 |
+
// the current value of `errno` (as by `strerror(3)`), and the numerical
|
| 83 |
+
// value of `errno`.
|
| 84 |
+
// * .ToSinkAlso(absl::LogSink* sink)
|
| 85 |
+
// Sends this message to `*sink` in addition to whatever other sinks it
|
| 86 |
+
// would otherwise have been sent to. `sink` must not be null.
|
| 87 |
+
// * .ToSinkOnly(absl::LogSink* sink)
|
| 88 |
+
// Sends this message to `*sink` and no others. `sink` must not be null.
|
| 89 |
+
//
|
| 90 |
+
// No interfaces in this header are async-signal-safe; their use in signal
|
| 91 |
+
// handlers is unsupported and may deadlock your program or eat your lunch.
|
| 92 |
+
//
|
| 93 |
+
// Many logging statements are inherently conditional. For example,
|
| 94 |
+
// `LOG_IF(INFO, !foo)` does nothing if `foo` is true. Even seemingly
|
| 95 |
+
// unconditional statements like `LOG(INFO)` might be disabled at
|
| 96 |
+
// compile-time to minimize binary size or for security reasons.
|
| 97 |
+
//
|
| 98 |
+
// * Except for the condition in a `CHECK` or `QCHECK` statement, programs must
|
| 99 |
+
// not rely on evaluation of expressions anywhere in logging statements for
|
| 100 |
+
// correctness. For example, this is ok:
|
| 101 |
+
//
|
| 102 |
+
// CHECK((fp = fopen("config.ini", "r")) != nullptr);
|
| 103 |
+
//
|
| 104 |
+
// But this is probably not ok:
|
| 105 |
+
//
|
| 106 |
+
// LOG(INFO) << "Server status: " << StartServerAndReturnStatusString();
|
| 107 |
+
//
|
| 108 |
+
// The example below is bad too; the `i++` in the `LOG_IF` condition might
|
| 109 |
+
// not be evaluated, resulting in an infinite loop:
|
| 110 |
+
//
|
| 111 |
+
// for (int i = 0; i < 1000000;)
|
| 112 |
+
// LOG_IF(INFO, i++ % 1000 == 0) << "Still working...";
|
| 113 |
+
//
|
| 114 |
+
// * Except where otherwise noted, conditions which cause a statement not to log
|
| 115 |
+
// also cause expressions not to be evaluated. Programs may rely on this for
|
| 116 |
+
// performance reasons, e.g. by streaming the result of an expensive function
|
| 117 |
+
// call into a `DLOG` or `LOG_EVERY_N` statement.
|
| 118 |
+
// * Care has been taken to ensure that expressions are parsed by the compiler
|
| 119 |
+
// even if they are never evaluated. This means that syntax errors will be
|
| 120 |
+
// caught and variables will be considered used for the purposes of
|
| 121 |
+
// unused-variable diagnostics. For example, this statement won't compile
|
| 122 |
+
// even if `INFO`-level logging has been compiled out:
|
| 123 |
+
//
|
| 124 |
+
// int number_of_cakes = 40;
|
| 125 |
+
// LOG(INFO) << "Number of cakes: " << number_of_cake; // Note the typo!
|
| 126 |
+
//
|
| 127 |
+
// Similarly, this won't produce unused-variable compiler diagnostics even
|
| 128 |
+
// if `INFO`-level logging is compiled out:
|
| 129 |
+
//
|
| 130 |
+
// {
|
| 131 |
+
// char fox_line1[] = "Hatee-hatee-hatee-ho!";
|
| 132 |
+
// LOG_IF(ERROR, false) << "The fox says " << fox_line1;
|
| 133 |
+
// char fox_line2[] = "A-oo-oo-oo-ooo!";
|
| 134 |
+
// LOG(INFO) << "The fox also says " << fox_line2;
|
| 135 |
+
// }
|
| 136 |
+
//
|
| 137 |
+
// This error-checking is not perfect; for example, symbols that have been
|
| 138 |
+
// declared but not defined may not produce link errors if used in logging
|
| 139 |
+
// statements that compile away.
|
| 140 |
+
//
|
| 141 |
+
// Expressions streamed into these macros are formatted using `operator<<` just
|
| 142 |
+
// as they would be if streamed into a `std::ostream`, however it should be
|
| 143 |
+
// noted that their actual type is unspecified.
|
| 144 |
+
//
|
| 145 |
+
// To implement a custom formatting operator for a type you own, there are two
|
| 146 |
+
// options: `AbslStringify()` or `std::ostream& operator<<(std::ostream&, ...)`.
|
| 147 |
+
// It is recommended that users make their types loggable through
|
| 148 |
+
// `AbslStringify()` as it is a universal stringification extension that also
|
| 149 |
+
// enables `absl::StrFormat` and `absl::StrCat` support. If both
|
| 150 |
+
// `AbslStringify()` and `std::ostream& operator<<(std::ostream&, ...)` are
|
| 151 |
+
// defined, `AbslStringify()` will be used.
|
| 152 |
+
//
|
| 153 |
+
// To use the `AbslStringify()` API, define a friend function template in your
|
| 154 |
+
// type's namespace with the following signature:
|
| 155 |
+
//
|
| 156 |
+
// template <typename Sink>
|
| 157 |
+
// void AbslStringify(Sink& sink, const UserDefinedType& value);
|
| 158 |
+
//
|
| 159 |
+
// `Sink` has the same interface as `absl::FormatSink`, but without
|
| 160 |
+
// `PutPaddedString()`.
|
| 161 |
+
//
|
| 162 |
+
// Example:
|
| 163 |
+
//
|
| 164 |
+
// struct Point {
|
| 165 |
+
// template <typename Sink>
|
| 166 |
+
// friend void AbslStringify(Sink& sink, const Point& p) {
|
| 167 |
+
// absl::Format(&sink, "(%v, %v)", p.x, p.y);
|
| 168 |
+
// }
|
| 169 |
+
//
|
| 170 |
+
// int x;
|
| 171 |
+
// int y;
|
| 172 |
+
// };
|
| 173 |
+
//
|
| 174 |
+
// To use `std::ostream& operator<<(std::ostream&, ...)`, define
|
| 175 |
+
// `std::ostream& operator<<(std::ostream&, ...)` in your type's namespace (for
|
| 176 |
+
// ADL) just as you would to stream it to `std::cout`.
|
| 177 |
+
//
|
| 178 |
+
// Currently `AbslStringify()` ignores output manipulators but this is not
|
| 179 |
+
// guaranteed behavior and may be subject to change in the future. If you would
|
| 180 |
+
// like guaranteed behavior regarding output manipulators, please use
|
| 181 |
+
// `std::ostream& operator<<(std::ostream&, ...)` to make custom types loggable
|
| 182 |
+
// instead.
|
| 183 |
+
//
|
| 184 |
+
// Those macros that support streaming honor output manipulators and `fmtflag`
|
| 185 |
+
// changes that output data (e.g. `std::ends`) or control formatting of data
|
| 186 |
+
// (e.g. `std::hex` and `std::fixed`), however flushing such a stream is
|
| 187 |
+
// ignored. The message produced by a log statement is sent to registered
|
| 188 |
+
// `absl::LogSink` instances at the end of the statement; those sinks are
|
| 189 |
+
// responsible for their own flushing (e.g. to disk) semantics.
|
| 190 |
+
//
|
| 191 |
+
// Flag settings are not carried over from one `LOG` statement to the next; this
|
| 192 |
+
// is a bit different than e.g. `std::cout`:
|
| 193 |
+
//
|
| 194 |
+
// LOG(INFO) << std::hex << 0xdeadbeef; // logs "0xdeadbeef"
|
| 195 |
+
// LOG(INFO) << 0xdeadbeef; // logs "3735928559"
|
| 196 |
+
|
| 197 |
+
#ifndef ABSL_LOG_LOG_H_
|
| 198 |
+
#define ABSL_LOG_LOG_H_
|
| 199 |
+
|
| 200 |
+
#include "absl/log/internal/log_impl.h"
|
| 201 |
+
#include "absl/log/vlog_is_on.h" // IWYU pragma: export
|
| 202 |
+
|
| 203 |
+
// LOG()
|
| 204 |
+
//
|
| 205 |
+
// `LOG` takes a single argument which is a severity level. Data streamed in
|
| 206 |
+
// comprise the logged message.
|
| 207 |
+
// Example:
|
| 208 |
+
//
|
| 209 |
+
// LOG(INFO) << "Found " << num_cookies << " cookies";
|
| 210 |
+
#define LOG(severity) ABSL_LOG_INTERNAL_LOG_IMPL(_##severity)
|
| 211 |
+
|
| 212 |
+
// PLOG()
|
| 213 |
+
//
|
| 214 |
+
// `PLOG` behaves like `LOG` except that a description of the current state of
|
| 215 |
+
// `errno` is appended to the streamed message.
|
| 216 |
+
#define PLOG(severity) ABSL_LOG_INTERNAL_PLOG_IMPL(_##severity)
|
| 217 |
+
|
| 218 |
+
// DLOG()
|
| 219 |
+
//
|
| 220 |
+
// `DLOG` behaves like `LOG` in debug mode (i.e. `#ifndef NDEBUG`). Otherwise
|
| 221 |
+
// it compiles away and does nothing. Note that `DLOG(FATAL)` does not
|
| 222 |
+
// terminate the program if `NDEBUG` is defined.
|
| 223 |
+
#define DLOG(severity) ABSL_LOG_INTERNAL_DLOG_IMPL(_##severity)
|
| 224 |
+
|
| 225 |
+
// `VLOG` uses numeric levels to provide verbose logging that can configured at
|
| 226 |
+
// runtime, including at a per-module level. `VLOG` statements are logged at
|
| 227 |
+
// `INFO` severity if they are logged at all; the numeric levels are on a
|
| 228 |
+
// different scale than the proper severity levels. Positive levels are
|
| 229 |
+
// disabled by default. Negative levels should not be used.
|
| 230 |
+
// Example:
|
| 231 |
+
//
|
| 232 |
+
// VLOG(1) << "I print when you run the program with --v=1 or higher";
|
| 233 |
+
// VLOG(2) << "I print when you run the program with --v=2 or higher";
|
| 234 |
+
//
|
| 235 |
+
// See vlog_is_on.h for further documentation, including the usage of the
|
| 236 |
+
// --vmodule flag to log at different levels in different source files.
|
| 237 |
+
#define VLOG(severity) ABSL_LOG_INTERNAL_VLOG_IMPL(severity)
|
| 238 |
+
|
| 239 |
+
// `DVLOG` behaves like `VLOG` in debug mode (i.e. `#ifndef NDEBUG`).
|
| 240 |
+
// Otherwise, it compiles away and does nothing.
|
| 241 |
+
#define DVLOG(severity) ABSL_LOG_INTERNAL_DVLOG_IMPL(severity)
|
| 242 |
+
|
| 243 |
+
// `LOG_IF` and friends add a second argument which specifies a condition. If
|
| 244 |
+
// the condition is false, nothing is logged.
|
| 245 |
+
// Example:
|
| 246 |
+
//
|
| 247 |
+
// LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
|
| 248 |
+
//
|
| 249 |
+
// There is no `VLOG_IF` because the order of evaluation of the arguments is
|
| 250 |
+
// ambiguous and the alternate spelling with an `if`-statement is trivial.
|
| 251 |
+
#define LOG_IF(severity, condition) \
|
| 252 |
+
ABSL_LOG_INTERNAL_LOG_IF_IMPL(_##severity, condition)
|
| 253 |
+
#define PLOG_IF(severity, condition) \
|
| 254 |
+
ABSL_LOG_INTERNAL_PLOG_IF_IMPL(_##severity, condition)
|
| 255 |
+
#define DLOG_IF(severity, condition) \
|
| 256 |
+
ABSL_LOG_INTERNAL_DLOG_IF_IMPL(_##severity, condition)
|
| 257 |
+
|
| 258 |
+
// LOG_EVERY_N
|
| 259 |
+
//
|
| 260 |
+
// An instance of `LOG_EVERY_N` increments a hidden zero-initialized counter
|
| 261 |
+
// every time execution passes through it and logs the specified message when
|
| 262 |
+
// the counter's value is a multiple of `n`, doing nothing otherwise. Each
|
| 263 |
+
// instance has its own counter. The counter's value can be logged by streaming
|
| 264 |
+
// the symbol `COUNTER`. `LOG_EVERY_N` is thread-safe.
|
| 265 |
+
// Example:
|
| 266 |
+
//
|
| 267 |
+
// LOG_EVERY_N(WARNING, 1000) << "Got a packet with a bad CRC (" << COUNTER
|
| 268 |
+
// << " total)";
|
| 269 |
+
#define LOG_EVERY_N(severity, n) \
|
| 270 |
+
ABSL_LOG_INTERNAL_LOG_EVERY_N_IMPL(_##severity, n)
|
| 271 |
+
|
| 272 |
+
// LOG_FIRST_N
|
| 273 |
+
//
|
| 274 |
+
// `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is
|
| 275 |
+
// logged when the counter's value is less than `n`. `LOG_FIRST_N` is
|
| 276 |
+
// thread-safe.
|
| 277 |
+
#define LOG_FIRST_N(severity, n) \
|
| 278 |
+
ABSL_LOG_INTERNAL_LOG_FIRST_N_IMPL(_##severity, n)
|
| 279 |
+
|
| 280 |
+
// LOG_EVERY_POW_2
|
| 281 |
+
//
|
| 282 |
+
// `LOG_EVERY_POW_2` behaves like `LOG_EVERY_N` except that the specified
|
| 283 |
+
// message is logged when the counter's value is a power of 2.
|
| 284 |
+
// `LOG_EVERY_POW_2` is thread-safe.
|
| 285 |
+
#define LOG_EVERY_POW_2(severity) \
|
| 286 |
+
ABSL_LOG_INTERNAL_LOG_EVERY_POW_2_IMPL(_##severity)
|
| 287 |
+
|
| 288 |
+
// LOG_EVERY_N_SEC
|
| 289 |
+
//
|
| 290 |
+
// An instance of `LOG_EVERY_N_SEC` uses a hidden state variable to log the
|
| 291 |
+
// specified message at most once every `n_seconds`. A hidden counter of
|
| 292 |
+
// executions (whether a message is logged or not) is also maintained and can be
|
| 293 |
+
// logged by streaming the symbol `COUNTER`. `LOG_EVERY_N_SEC` is thread-safe.
|
| 294 |
+
// Example:
|
| 295 |
+
//
|
| 296 |
+
// LOG_EVERY_N_SEC(INFO, 2.5) << "Got " << COUNTER << " cookies so far";
|
| 297 |
+
#define LOG_EVERY_N_SEC(severity, n_seconds) \
|
| 298 |
+
ABSL_LOG_INTERNAL_LOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
|
| 299 |
+
|
| 300 |
+
#define PLOG_EVERY_N(severity, n) \
|
| 301 |
+
ABSL_LOG_INTERNAL_PLOG_EVERY_N_IMPL(_##severity, n)
|
| 302 |
+
#define PLOG_FIRST_N(severity, n) \
|
| 303 |
+
ABSL_LOG_INTERNAL_PLOG_FIRST_N_IMPL(_##severity, n)
|
| 304 |
+
#define PLOG_EVERY_POW_2(severity) \
|
| 305 |
+
ABSL_LOG_INTERNAL_PLOG_EVERY_POW_2_IMPL(_##severity)
|
| 306 |
+
#define PLOG_EVERY_N_SEC(severity, n_seconds) \
|
| 307 |
+
ABSL_LOG_INTERNAL_PLOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
|
| 308 |
+
|
| 309 |
+
#define DLOG_EVERY_N(severity, n) \
|
| 310 |
+
ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(_##severity, n)
|
| 311 |
+
#define DLOG_FIRST_N(severity, n) \
|
| 312 |
+
ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(_##severity, n)
|
| 313 |
+
#define DLOG_EVERY_POW_2(severity) \
|
| 314 |
+
ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(_##severity)
|
| 315 |
+
#define DLOG_EVERY_N_SEC(severity, n_seconds) \
|
| 316 |
+
ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
|
| 317 |
+
|
| 318 |
+
#define VLOG_EVERY_N(severity, n) \
|
| 319 |
+
ABSL_LOG_INTERNAL_VLOG_EVERY_N_IMPL(severity, n)
|
| 320 |
+
#define VLOG_FIRST_N(severity, n) \
|
| 321 |
+
ABSL_LOG_INTERNAL_VLOG_FIRST_N_IMPL(severity, n)
|
| 322 |
+
#define VLOG_EVERY_POW_2(severity) \
|
| 323 |
+
ABSL_LOG_INTERNAL_VLOG_EVERY_POW_2_IMPL(severity)
|
| 324 |
+
#define VLOG_EVERY_N_SEC(severity, n_seconds) \
|
| 325 |
+
ABSL_LOG_INTERNAL_VLOG_EVERY_N_SEC_IMPL(severity, n_seconds)
|
| 326 |
+
|
| 327 |
+
// `LOG_IF_EVERY_N` and friends behave as the corresponding `LOG_EVERY_N`
|
| 328 |
+
// but neither increment a counter nor log a message if condition is false (as
|
| 329 |
+
// `LOG_IF`).
|
| 330 |
+
// Example:
|
| 331 |
+
//
|
| 332 |
+
// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER
|
| 333 |
+
// << "th big cookie";
|
| 334 |
+
#define LOG_IF_EVERY_N(severity, condition, n) \
|
| 335 |
+
ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_IMPL(_##severity, condition, n)
|
| 336 |
+
#define LOG_IF_FIRST_N(severity, condition, n) \
|
| 337 |
+
ABSL_LOG_INTERNAL_LOG_IF_FIRST_N_IMPL(_##severity, condition, n)
|
| 338 |
+
#define LOG_IF_EVERY_POW_2(severity, condition) \
|
| 339 |
+
ABSL_LOG_INTERNAL_LOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
|
| 340 |
+
#define LOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
|
| 341 |
+
ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
|
| 342 |
+
|
| 343 |
+
#define PLOG_IF_EVERY_N(severity, condition, n) \
|
| 344 |
+
ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_IMPL(_##severity, condition, n)
|
| 345 |
+
#define PLOG_IF_FIRST_N(severity, condition, n) \
|
| 346 |
+
ABSL_LOG_INTERNAL_PLOG_IF_FIRST_N_IMPL(_##severity, condition, n)
|
| 347 |
+
#define PLOG_IF_EVERY_POW_2(severity, condition) \
|
| 348 |
+
ABSL_LOG_INTERNAL_PLOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
|
| 349 |
+
#define PLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
|
| 350 |
+
ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
|
| 351 |
+
|
| 352 |
+
#define DLOG_IF_EVERY_N(severity, condition, n) \
|
| 353 |
+
ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(_##severity, condition, n)
|
| 354 |
+
#define DLOG_IF_FIRST_N(severity, condition, n) \
|
| 355 |
+
ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(_##severity, condition, n)
|
| 356 |
+
#define DLOG_IF_EVERY_POW_2(severity, condition) \
|
| 357 |
+
ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
|
| 358 |
+
#define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
|
| 359 |
+
ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
|
| 360 |
+
|
| 361 |
+
#endif // ABSL_LOG_LOG_H_
|
weight/_dep/abseil-cpp/absl/log/log_basic_test.cc
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/log.h"
|
| 17 |
+
|
| 18 |
+
#define ABSL_TEST_LOG LOG
|
| 19 |
+
|
| 20 |
+
#include "gtest/gtest.h"
|
| 21 |
+
#include "absl/log/log_basic_test_impl.inc"
|
weight/_dep/abseil-cpp/absl/log/log_basic_test_impl.inc
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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 |
+
// The testcases in this file are expected to pass or be skipped with any value
|
| 17 |
+
// of ABSL_MIN_LOG_LEVEL
|
| 18 |
+
|
| 19 |
+
#ifndef ABSL_LOG_LOG_BASIC_TEST_IMPL_H_
|
| 20 |
+
#define ABSL_LOG_LOG_BASIC_TEST_IMPL_H_
|
| 21 |
+
|
| 22 |
+
// Verify that both sets of macros behave identically by parameterizing the
|
| 23 |
+
// entire test file.
|
| 24 |
+
#ifndef ABSL_TEST_LOG
|
| 25 |
+
#error ABSL_TEST_LOG must be defined for these tests to work.
|
| 26 |
+
#endif
|
| 27 |
+
|
| 28 |
+
#include <cerrno>
|
| 29 |
+
#include <sstream>
|
| 30 |
+
#include <string>
|
| 31 |
+
|
| 32 |
+
#include "gmock/gmock.h"
|
| 33 |
+
#include "gtest/gtest.h"
|
| 34 |
+
#include "absl/base/internal/sysinfo.h"
|
| 35 |
+
#include "absl/base/log_severity.h"
|
| 36 |
+
#include "absl/log/globals.h"
|
| 37 |
+
#include "absl/log/internal/test_actions.h"
|
| 38 |
+
#include "absl/log/internal/test_helpers.h"
|
| 39 |
+
#include "absl/log/internal/test_matchers.h"
|
| 40 |
+
#include "absl/log/log_entry.h"
|
| 41 |
+
#include "absl/log/scoped_mock_log.h"
|
| 42 |
+
|
| 43 |
+
namespace absl_log_internal {
|
| 44 |
+
#if GTEST_HAS_DEATH_TEST
|
| 45 |
+
using ::absl::log_internal::DeathTestExpectedLogging;
|
| 46 |
+
using ::absl::log_internal::DeathTestUnexpectedLogging;
|
| 47 |
+
using ::absl::log_internal::DeathTestValidateExpectations;
|
| 48 |
+
using ::absl::log_internal::DiedOfFatal;
|
| 49 |
+
using ::absl::log_internal::DiedOfQFatal;
|
| 50 |
+
#endif
|
| 51 |
+
using ::absl::log_internal::LoggingEnabledAt;
|
| 52 |
+
using ::absl::log_internal::LogSeverity;
|
| 53 |
+
using ::absl::log_internal::Prefix;
|
| 54 |
+
using ::absl::log_internal::SourceBasename;
|
| 55 |
+
using ::absl::log_internal::SourceFilename;
|
| 56 |
+
using ::absl::log_internal::SourceLine;
|
| 57 |
+
using ::absl::log_internal::Stacktrace;
|
| 58 |
+
using ::absl::log_internal::TextMessage;
|
| 59 |
+
using ::absl::log_internal::ThreadID;
|
| 60 |
+
using ::absl::log_internal::TimestampInMatchWindow;
|
| 61 |
+
using ::absl::log_internal::Verbosity;
|
| 62 |
+
using ::testing::AnyNumber;
|
| 63 |
+
using ::testing::Eq;
|
| 64 |
+
using ::testing::IsEmpty;
|
| 65 |
+
using ::testing::IsTrue;
|
| 66 |
+
|
| 67 |
+
class BasicLogTest : public testing::TestWithParam<absl::LogSeverityAtLeast> {};
|
| 68 |
+
|
| 69 |
+
std::string ThresholdName(
|
| 70 |
+
testing::TestParamInfo<absl::LogSeverityAtLeast> severity) {
|
| 71 |
+
std::stringstream ostr;
|
| 72 |
+
ostr << severity.param;
|
| 73 |
+
return ostr.str().substr(
|
| 74 |
+
severity.param == absl::LogSeverityAtLeast::kInfinity ? 0 : 2);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
INSTANTIATE_TEST_SUITE_P(WithParam, BasicLogTest,
|
| 78 |
+
testing::Values(absl::LogSeverityAtLeast::kInfo,
|
| 79 |
+
absl::LogSeverityAtLeast::kWarning,
|
| 80 |
+
absl::LogSeverityAtLeast::kError,
|
| 81 |
+
absl::LogSeverityAtLeast::kFatal,
|
| 82 |
+
absl::LogSeverityAtLeast::kInfinity),
|
| 83 |
+
ThresholdName);
|
| 84 |
+
|
| 85 |
+
TEST_P(BasicLogTest, Info) {
|
| 86 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 87 |
+
|
| 88 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 89 |
+
|
| 90 |
+
const int log_line = __LINE__ + 1;
|
| 91 |
+
auto do_log = [] { ABSL_TEST_LOG(INFO) << "hello world"; };
|
| 92 |
+
|
| 93 |
+
if (LoggingEnabledAt(absl::LogSeverity::kInfo)) {
|
| 94 |
+
EXPECT_CALL(
|
| 95 |
+
test_sink,
|
| 96 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 97 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 98 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 99 |
+
LogSeverity(Eq(absl::LogSeverity::kInfo)),
|
| 100 |
+
TimestampInMatchWindow(),
|
| 101 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 102 |
+
TextMessage(Eq("hello world")),
|
| 103 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 104 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 105 |
+
literal: "hello world"
|
| 106 |
+
})pb")),
|
| 107 |
+
Stacktrace(IsEmpty()))));
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
test_sink.StartCapturingLogs();
|
| 111 |
+
do_log();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
TEST_P(BasicLogTest, Warning) {
|
| 115 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 116 |
+
|
| 117 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 118 |
+
|
| 119 |
+
const int log_line = __LINE__ + 1;
|
| 120 |
+
auto do_log = [] { ABSL_TEST_LOG(WARNING) << "hello world"; };
|
| 121 |
+
|
| 122 |
+
if (LoggingEnabledAt(absl::LogSeverity::kWarning)) {
|
| 123 |
+
EXPECT_CALL(
|
| 124 |
+
test_sink,
|
| 125 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 126 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 127 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 128 |
+
LogSeverity(Eq(absl::LogSeverity::kWarning)),
|
| 129 |
+
TimestampInMatchWindow(),
|
| 130 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 131 |
+
TextMessage(Eq("hello world")),
|
| 132 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 133 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 134 |
+
literal: "hello world"
|
| 135 |
+
})pb")),
|
| 136 |
+
Stacktrace(IsEmpty()))));
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
test_sink.StartCapturingLogs();
|
| 140 |
+
do_log();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
TEST_P(BasicLogTest, Error) {
|
| 144 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 145 |
+
|
| 146 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 147 |
+
|
| 148 |
+
const int log_line = __LINE__ + 1;
|
| 149 |
+
auto do_log = [] { ABSL_TEST_LOG(ERROR) << "hello world"; };
|
| 150 |
+
|
| 151 |
+
if (LoggingEnabledAt(absl::LogSeverity::kError)) {
|
| 152 |
+
EXPECT_CALL(
|
| 153 |
+
test_sink,
|
| 154 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 155 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 156 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 157 |
+
LogSeverity(Eq(absl::LogSeverity::kError)),
|
| 158 |
+
TimestampInMatchWindow(),
|
| 159 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 160 |
+
TextMessage(Eq("hello world")),
|
| 161 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 162 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 163 |
+
literal: "hello world"
|
| 164 |
+
})pb")),
|
| 165 |
+
Stacktrace(IsEmpty()))));
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
test_sink.StartCapturingLogs();
|
| 169 |
+
do_log();
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
#if GTEST_HAS_DEATH_TEST
|
| 173 |
+
using BasicLogDeathTest = BasicLogTest;
|
| 174 |
+
|
| 175 |
+
INSTANTIATE_TEST_SUITE_P(WithParam, BasicLogDeathTest,
|
| 176 |
+
testing::Values(absl::LogSeverityAtLeast::kInfo,
|
| 177 |
+
absl::LogSeverityAtLeast::kFatal,
|
| 178 |
+
absl::LogSeverityAtLeast::kInfinity),
|
| 179 |
+
ThresholdName);
|
| 180 |
+
|
| 181 |
+
TEST_P(BasicLogDeathTest, Fatal) {
|
| 182 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 183 |
+
|
| 184 |
+
const int log_line = __LINE__ + 1;
|
| 185 |
+
auto do_log = [] { ABSL_TEST_LOG(FATAL) << "hello world"; };
|
| 186 |
+
|
| 187 |
+
EXPECT_EXIT(
|
| 188 |
+
{
|
| 189 |
+
absl::ScopedMockLog test_sink(
|
| 190 |
+
absl::MockLogDefault::kDisallowUnexpected);
|
| 191 |
+
|
| 192 |
+
EXPECT_CALL(test_sink, Send)
|
| 193 |
+
.Times(AnyNumber())
|
| 194 |
+
.WillRepeatedly(DeathTestUnexpectedLogging());
|
| 195 |
+
|
| 196 |
+
::testing::InSequence s;
|
| 197 |
+
|
| 198 |
+
// Note the logic in DeathTestValidateExpectations() caters for the case
|
| 199 |
+
// of logging being disabled at FATAL level.
|
| 200 |
+
|
| 201 |
+
if (LoggingEnabledAt(absl::LogSeverity::kFatal)) {
|
| 202 |
+
// The first call without the stack trace.
|
| 203 |
+
EXPECT_CALL(
|
| 204 |
+
test_sink,
|
| 205 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 206 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 207 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 208 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 209 |
+
TimestampInMatchWindow(),
|
| 210 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 211 |
+
TextMessage(Eq("hello world")),
|
| 212 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 213 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 214 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 215 |
+
Stacktrace(IsEmpty()))))
|
| 216 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 217 |
+
|
| 218 |
+
// The second call with the stack trace.
|
| 219 |
+
EXPECT_CALL(
|
| 220 |
+
test_sink,
|
| 221 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 222 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 223 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 224 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 225 |
+
TimestampInMatchWindow(),
|
| 226 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 227 |
+
TextMessage(Eq("hello world")),
|
| 228 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 229 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 230 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 231 |
+
Stacktrace(Not(IsEmpty())))))
|
| 232 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
test_sink.StartCapturingLogs();
|
| 236 |
+
do_log();
|
| 237 |
+
},
|
| 238 |
+
DiedOfFatal, DeathTestValidateExpectations());
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
TEST_P(BasicLogDeathTest, QFatal) {
|
| 242 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 243 |
+
|
| 244 |
+
const int log_line = __LINE__ + 1;
|
| 245 |
+
auto do_log = [] { ABSL_TEST_LOG(QFATAL) << "hello world"; };
|
| 246 |
+
|
| 247 |
+
EXPECT_EXIT(
|
| 248 |
+
{
|
| 249 |
+
absl::ScopedMockLog test_sink(
|
| 250 |
+
absl::MockLogDefault::kDisallowUnexpected);
|
| 251 |
+
|
| 252 |
+
EXPECT_CALL(test_sink, Send)
|
| 253 |
+
.Times(AnyNumber())
|
| 254 |
+
.WillRepeatedly(DeathTestUnexpectedLogging());
|
| 255 |
+
|
| 256 |
+
if (LoggingEnabledAt(absl::LogSeverity::kFatal)) {
|
| 257 |
+
EXPECT_CALL(
|
| 258 |
+
test_sink,
|
| 259 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 260 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 261 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 262 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 263 |
+
TimestampInMatchWindow(),
|
| 264 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 265 |
+
TextMessage(Eq("hello world")),
|
| 266 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 267 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 268 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 269 |
+
Stacktrace(IsEmpty()))))
|
| 270 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
test_sink.StartCapturingLogs();
|
| 274 |
+
do_log();
|
| 275 |
+
},
|
| 276 |
+
DiedOfQFatal, DeathTestValidateExpectations());
|
| 277 |
+
}
|
| 278 |
+
#endif
|
| 279 |
+
|
| 280 |
+
#ifdef NDEBUG
|
| 281 |
+
TEST_P(BasicLogTest, DFatal) {
|
| 282 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 283 |
+
|
| 284 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 285 |
+
|
| 286 |
+
const int log_line = __LINE__ + 1;
|
| 287 |
+
auto do_log = [] { ABSL_TEST_LOG(DFATAL) << "hello world"; };
|
| 288 |
+
|
| 289 |
+
if (LoggingEnabledAt(absl::LogSeverity::kError)) {
|
| 290 |
+
EXPECT_CALL(
|
| 291 |
+
test_sink,
|
| 292 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 293 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 294 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 295 |
+
LogSeverity(Eq(absl::LogSeverity::kError)),
|
| 296 |
+
TimestampInMatchWindow(),
|
| 297 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 298 |
+
TextMessage(Eq("hello world")),
|
| 299 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 300 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 301 |
+
literal: "hello world"
|
| 302 |
+
})pb")),
|
| 303 |
+
Stacktrace(IsEmpty()))));
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
test_sink.StartCapturingLogs();
|
| 307 |
+
do_log();
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
#elif GTEST_HAS_DEATH_TEST
|
| 311 |
+
TEST_P(BasicLogDeathTest, DFatal) {
|
| 312 |
+
// TODO(b/242568884): re-enable once bug is fixed.
|
| 313 |
+
// absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 314 |
+
|
| 315 |
+
const int log_line = __LINE__ + 1;
|
| 316 |
+
auto do_log = [] { ABSL_TEST_LOG(DFATAL) << "hello world"; };
|
| 317 |
+
|
| 318 |
+
EXPECT_EXIT(
|
| 319 |
+
{
|
| 320 |
+
absl::ScopedMockLog test_sink(
|
| 321 |
+
absl::MockLogDefault::kDisallowUnexpected);
|
| 322 |
+
|
| 323 |
+
EXPECT_CALL(test_sink, Send)
|
| 324 |
+
.Times(AnyNumber())
|
| 325 |
+
.WillRepeatedly(DeathTestUnexpectedLogging());
|
| 326 |
+
|
| 327 |
+
::testing::InSequence s;
|
| 328 |
+
|
| 329 |
+
if (LoggingEnabledAt(absl::LogSeverity::kFatal)) {
|
| 330 |
+
// The first call without the stack trace.
|
| 331 |
+
EXPECT_CALL(
|
| 332 |
+
test_sink,
|
| 333 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 334 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 335 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 336 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 337 |
+
TimestampInMatchWindow(),
|
| 338 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 339 |
+
TextMessage(Eq("hello world")),
|
| 340 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 341 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 342 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 343 |
+
Stacktrace(IsEmpty()))))
|
| 344 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 345 |
+
|
| 346 |
+
// The second call with the stack trace.
|
| 347 |
+
EXPECT_CALL(
|
| 348 |
+
test_sink,
|
| 349 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 350 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 351 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 352 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 353 |
+
TimestampInMatchWindow(),
|
| 354 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 355 |
+
TextMessage(Eq("hello world")),
|
| 356 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 357 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 358 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 359 |
+
Stacktrace(Not(IsEmpty())))))
|
| 360 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
test_sink.StartCapturingLogs();
|
| 364 |
+
do_log();
|
| 365 |
+
},
|
| 366 |
+
DiedOfFatal, DeathTestValidateExpectations());
|
| 367 |
+
}
|
| 368 |
+
#endif
|
| 369 |
+
|
| 370 |
+
TEST_P(BasicLogTest, Level) {
|
| 371 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 372 |
+
|
| 373 |
+
for (auto severity : {absl::LogSeverity::kInfo, absl::LogSeverity::kWarning,
|
| 374 |
+
absl::LogSeverity::kError}) {
|
| 375 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 376 |
+
|
| 377 |
+
const int log_line = __LINE__ + 2;
|
| 378 |
+
auto do_log = [severity] {
|
| 379 |
+
ABSL_TEST_LOG(LEVEL(severity)) << "hello world";
|
| 380 |
+
};
|
| 381 |
+
|
| 382 |
+
if (LoggingEnabledAt(severity)) {
|
| 383 |
+
EXPECT_CALL(
|
| 384 |
+
test_sink,
|
| 385 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 386 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 387 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 388 |
+
LogSeverity(Eq(severity)), TimestampInMatchWindow(),
|
| 389 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 390 |
+
TextMessage(Eq("hello world")),
|
| 391 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 392 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 393 |
+
literal: "hello world"
|
| 394 |
+
})pb")),
|
| 395 |
+
Stacktrace(IsEmpty()))));
|
| 396 |
+
}
|
| 397 |
+
test_sink.StartCapturingLogs();
|
| 398 |
+
do_log();
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
#if GTEST_HAS_DEATH_TEST
|
| 403 |
+
TEST_P(BasicLogDeathTest, Level) {
|
| 404 |
+
// TODO(b/242568884): re-enable once bug is fixed.
|
| 405 |
+
// absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 406 |
+
|
| 407 |
+
// Ensure that `severity` is not a compile-time constant to prove that
|
| 408 |
+
// `LOG(LEVEL(severity))` works regardless:
|
| 409 |
+
auto volatile severity = absl::LogSeverity::kFatal;
|
| 410 |
+
|
| 411 |
+
const int log_line = __LINE__ + 1;
|
| 412 |
+
auto do_log = [severity] { ABSL_TEST_LOG(LEVEL(severity)) << "hello world"; };
|
| 413 |
+
|
| 414 |
+
EXPECT_EXIT(
|
| 415 |
+
{
|
| 416 |
+
absl::ScopedMockLog test_sink(
|
| 417 |
+
absl::MockLogDefault::kDisallowUnexpected);
|
| 418 |
+
|
| 419 |
+
EXPECT_CALL(test_sink, Send)
|
| 420 |
+
.Times(AnyNumber())
|
| 421 |
+
.WillRepeatedly(DeathTestUnexpectedLogging());
|
| 422 |
+
|
| 423 |
+
::testing::InSequence s;
|
| 424 |
+
|
| 425 |
+
if (LoggingEnabledAt(absl::LogSeverity::kFatal)) {
|
| 426 |
+
EXPECT_CALL(
|
| 427 |
+
test_sink,
|
| 428 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 429 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 430 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 431 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 432 |
+
TimestampInMatchWindow(),
|
| 433 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 434 |
+
TextMessage(Eq("hello world")),
|
| 435 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 436 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 437 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 438 |
+
Stacktrace(IsEmpty()))))
|
| 439 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 440 |
+
|
| 441 |
+
EXPECT_CALL(
|
| 442 |
+
test_sink,
|
| 443 |
+
Send(AllOf(SourceFilename(Eq(__FILE__)),
|
| 444 |
+
SourceBasename(Eq("log_basic_test_impl.inc")),
|
| 445 |
+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
|
| 446 |
+
LogSeverity(Eq(absl::LogSeverity::kFatal)),
|
| 447 |
+
TimestampInMatchWindow(),
|
| 448 |
+
ThreadID(Eq(absl::base_internal::GetTID())),
|
| 449 |
+
TextMessage(Eq("hello world")),
|
| 450 |
+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
|
| 451 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 452 |
+
R"pb(value { literal: "hello world" })pb")),
|
| 453 |
+
Stacktrace(Not(IsEmpty())))))
|
| 454 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
test_sink.StartCapturingLogs();
|
| 458 |
+
do_log();
|
| 459 |
+
},
|
| 460 |
+
DiedOfFatal, DeathTestValidateExpectations());
|
| 461 |
+
}
|
| 462 |
+
#endif
|
| 463 |
+
|
| 464 |
+
TEST_P(BasicLogTest, LevelClampsNegativeValues) {
|
| 465 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 466 |
+
|
| 467 |
+
if (!LoggingEnabledAt(absl::LogSeverity::kInfo)) {
|
| 468 |
+
GTEST_SKIP() << "This test cases required INFO log to be enabled";
|
| 469 |
+
return;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 473 |
+
|
| 474 |
+
EXPECT_CALL(test_sink, Send(LogSeverity(Eq(absl::LogSeverity::kInfo))));
|
| 475 |
+
|
| 476 |
+
test_sink.StartCapturingLogs();
|
| 477 |
+
ABSL_TEST_LOG(LEVEL(-1)) << "hello world";
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
TEST_P(BasicLogTest, LevelClampsLargeValues) {
|
| 481 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
|
| 482 |
+
|
| 483 |
+
if (!LoggingEnabledAt(absl::LogSeverity::kError)) {
|
| 484 |
+
GTEST_SKIP() << "This test cases required ERROR log to be enabled";
|
| 485 |
+
return;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 489 |
+
|
| 490 |
+
EXPECT_CALL(test_sink, Send(LogSeverity(Eq(absl::LogSeverity::kError))));
|
| 491 |
+
|
| 492 |
+
test_sink.StartCapturingLogs();
|
| 493 |
+
ABSL_TEST_LOG(LEVEL(static_cast<int>(absl::LogSeverity::kFatal) + 1))
|
| 494 |
+
<< "hello world";
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
TEST(ErrnoPreservationTest, InSeverityExpression) {
|
| 498 |
+
errno = 77;
|
| 499 |
+
int saved_errno;
|
| 500 |
+
ABSL_TEST_LOG(LEVEL((saved_errno = errno, absl::LogSeverity::kInfo)));
|
| 501 |
+
EXPECT_THAT(saved_errno, Eq(77));
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
TEST(ErrnoPreservationTest, InStreamedExpression) {
|
| 505 |
+
if (!LoggingEnabledAt(absl::LogSeverity::kInfo)) {
|
| 506 |
+
GTEST_SKIP() << "This test cases required INFO log to be enabled";
|
| 507 |
+
return;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
errno = 77;
|
| 511 |
+
int saved_errno = 0;
|
| 512 |
+
ABSL_TEST_LOG(INFO) << (saved_errno = errno, "hello world");
|
| 513 |
+
EXPECT_THAT(saved_errno, Eq(77));
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
TEST(ErrnoPreservationTest, AfterStatement) {
|
| 517 |
+
errno = 77;
|
| 518 |
+
ABSL_TEST_LOG(INFO);
|
| 519 |
+
const int saved_errno = errno;
|
| 520 |
+
EXPECT_THAT(saved_errno, Eq(77));
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
// Tests that using a variable/parameter in a logging statement suppresses
|
| 524 |
+
// unused-variable/parameter warnings.
|
| 525 |
+
// -----------------------------------------------------------------------
|
| 526 |
+
class UnusedVariableWarningCompileTest {
|
| 527 |
+
// These four don't prove anything unless `ABSL_MIN_LOG_LEVEL` is greater than
|
| 528 |
+
// `kInfo`.
|
| 529 |
+
static void LoggedVariable() {
|
| 530 |
+
const int x = 0;
|
| 531 |
+
ABSL_TEST_LOG(INFO) << x;
|
| 532 |
+
}
|
| 533 |
+
static void LoggedParameter(const int x) { ABSL_TEST_LOG(INFO) << x; }
|
| 534 |
+
static void SeverityVariable() {
|
| 535 |
+
const int x = 0;
|
| 536 |
+
ABSL_TEST_LOG(LEVEL(x)) << "hello world";
|
| 537 |
+
}
|
| 538 |
+
static void SeverityParameter(const int x) {
|
| 539 |
+
ABSL_TEST_LOG(LEVEL(x)) << "hello world";
|
| 540 |
+
}
|
| 541 |
+
};
|
| 542 |
+
|
| 543 |
+
} // namespace absl_log_internal
|
| 544 |
+
|
| 545 |
+
#endif // ABSL_LOG_LOG_BASIC_TEST_IMPL_H_
|
weight/_dep/abseil-cpp/absl/log/log_benchmark.cc
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "absl/base/attributes.h"
|
| 16 |
+
#include "absl/base/log_severity.h"
|
| 17 |
+
#include "absl/flags/flag.h"
|
| 18 |
+
#include "absl/log/check.h"
|
| 19 |
+
#include "absl/log/globals.h"
|
| 20 |
+
#include "absl/log/log.h"
|
| 21 |
+
#include "absl/log/log_entry.h"
|
| 22 |
+
#include "absl/log/log_sink.h"
|
| 23 |
+
#include "absl/log/log_sink_registry.h"
|
| 24 |
+
#include "benchmark/benchmark.h"
|
| 25 |
+
|
| 26 |
+
namespace {
|
| 27 |
+
|
| 28 |
+
class NullLogSink : public absl::LogSink {
|
| 29 |
+
public:
|
| 30 |
+
NullLogSink() { absl::AddLogSink(this); }
|
| 31 |
+
|
| 32 |
+
~NullLogSink() override { absl::RemoveLogSink(this); }
|
| 33 |
+
|
| 34 |
+
void Send(const absl::LogEntry&) override {}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
constexpr int x = -1;
|
| 38 |
+
|
| 39 |
+
void BM_SuccessfulBinaryCheck(benchmark::State& state) {
|
| 40 |
+
int n = 0;
|
| 41 |
+
while (state.KeepRunningBatch(8)) {
|
| 42 |
+
CHECK_GE(n, x);
|
| 43 |
+
CHECK_GE(n, x);
|
| 44 |
+
CHECK_GE(n, x);
|
| 45 |
+
CHECK_GE(n, x);
|
| 46 |
+
CHECK_GE(n, x);
|
| 47 |
+
CHECK_GE(n, x);
|
| 48 |
+
CHECK_GE(n, x);
|
| 49 |
+
CHECK_GE(n, x);
|
| 50 |
+
++n;
|
| 51 |
+
}
|
| 52 |
+
benchmark::DoNotOptimize(n);
|
| 53 |
+
}
|
| 54 |
+
BENCHMARK(BM_SuccessfulBinaryCheck);
|
| 55 |
+
|
| 56 |
+
static void BM_SuccessfulUnaryCheck(benchmark::State& state) {
|
| 57 |
+
int n = 0;
|
| 58 |
+
while (state.KeepRunningBatch(8)) {
|
| 59 |
+
CHECK(n >= x);
|
| 60 |
+
CHECK(n >= x);
|
| 61 |
+
CHECK(n >= x);
|
| 62 |
+
CHECK(n >= x);
|
| 63 |
+
CHECK(n >= x);
|
| 64 |
+
CHECK(n >= x);
|
| 65 |
+
CHECK(n >= x);
|
| 66 |
+
CHECK(n >= x);
|
| 67 |
+
++n;
|
| 68 |
+
}
|
| 69 |
+
benchmark::DoNotOptimize(n);
|
| 70 |
+
}
|
| 71 |
+
BENCHMARK(BM_SuccessfulUnaryCheck);
|
| 72 |
+
|
| 73 |
+
static void BM_DisabledLogOverhead(benchmark::State& state) {
|
| 74 |
+
absl::ScopedStderrThreshold disable_stderr_logging(
|
| 75 |
+
absl::LogSeverityAtLeast::kInfinity);
|
| 76 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(
|
| 77 |
+
absl::LogSeverityAtLeast::kInfinity);
|
| 78 |
+
for (auto _ : state) {
|
| 79 |
+
LOG(INFO);
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
BENCHMARK(BM_DisabledLogOverhead);
|
| 83 |
+
|
| 84 |
+
static void BM_EnabledLogOverhead(benchmark::State& state) {
|
| 85 |
+
absl::ScopedStderrThreshold stderr_logging(
|
| 86 |
+
absl::LogSeverityAtLeast::kInfinity);
|
| 87 |
+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(
|
| 88 |
+
absl::LogSeverityAtLeast::kInfo);
|
| 89 |
+
ABSL_ATTRIBUTE_UNUSED NullLogSink null_sink;
|
| 90 |
+
for (auto _ : state) {
|
| 91 |
+
LOG(INFO);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
BENCHMARK(BM_EnabledLogOverhead);
|
| 95 |
+
|
| 96 |
+
} // namespace
|
| 97 |
+
|
weight/_dep/abseil-cpp/absl/log/log_entry.cc
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/log_entry.h"
|
| 17 |
+
|
| 18 |
+
#include "absl/base/config.h"
|
| 19 |
+
|
| 20 |
+
namespace absl {
|
| 21 |
+
ABSL_NAMESPACE_BEGIN
|
| 22 |
+
|
| 23 |
+
#ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
|
| 24 |
+
constexpr int LogEntry::kNoVerbosityLevel;
|
| 25 |
+
constexpr int LogEntry::kNoVerboseLevel;
|
| 26 |
+
#endif
|
| 27 |
+
|
| 28 |
+
// https://github.com/abseil/abseil-cpp/issues/1465
|
| 29 |
+
// CMake builds on Apple platforms error when libraries are empty.
|
| 30 |
+
// Our CMake configuration can avoid this error on header-only libraries,
|
| 31 |
+
// but since this library is conditionally empty, including a single
|
| 32 |
+
// variable is an easy workaround.
|
| 33 |
+
#ifdef __APPLE__
|
| 34 |
+
namespace log_internal {
|
| 35 |
+
extern const char kAvoidEmptyLogEntryLibraryWarning;
|
| 36 |
+
const char kAvoidEmptyLogEntryLibraryWarning = 0;
|
| 37 |
+
} // namespace log_internal
|
| 38 |
+
#endif // __APPLE__
|
| 39 |
+
|
| 40 |
+
ABSL_NAMESPACE_END
|
| 41 |
+
} // namespace absl
|
weight/_dep/abseil-cpp/absl/log/log_entry.h
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: log/log_entry.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header declares `class absl::LogEntry`, which represents a log record as
|
| 20 |
+
// passed to `LogSink::Send`. Data returned by pointer or by reference or by
|
| 21 |
+
// `absl::string_view` must be copied if they are needed after the lifetime of
|
| 22 |
+
// the `absl::LogEntry`.
|
| 23 |
+
|
| 24 |
+
#ifndef ABSL_LOG_LOG_ENTRY_H_
|
| 25 |
+
#define ABSL_LOG_LOG_ENTRY_H_
|
| 26 |
+
|
| 27 |
+
#include <cstddef>
|
| 28 |
+
#include <string>
|
| 29 |
+
|
| 30 |
+
#include "absl/base/attributes.h"
|
| 31 |
+
#include "absl/base/config.h"
|
| 32 |
+
#include "absl/base/log_severity.h"
|
| 33 |
+
#include "absl/log/internal/config.h"
|
| 34 |
+
#include "absl/strings/string_view.h"
|
| 35 |
+
#include "absl/time/time.h"
|
| 36 |
+
#include "absl/types/span.h"
|
| 37 |
+
|
| 38 |
+
namespace absl {
|
| 39 |
+
ABSL_NAMESPACE_BEGIN
|
| 40 |
+
|
| 41 |
+
namespace log_internal {
|
| 42 |
+
// Test only friend.
|
| 43 |
+
class LogEntryTestPeer;
|
| 44 |
+
class LogMessage;
|
| 45 |
+
} // namespace log_internal
|
| 46 |
+
|
| 47 |
+
// LogEntry
|
| 48 |
+
//
|
| 49 |
+
// Represents a single entry in a log, i.e., one `LOG` statement or failed
|
| 50 |
+
// `CHECK`.
|
| 51 |
+
//
|
| 52 |
+
// `LogEntry` is thread-compatible.
|
| 53 |
+
class LogEntry final {
|
| 54 |
+
public:
|
| 55 |
+
using tid_t = log_internal::Tid;
|
| 56 |
+
|
| 57 |
+
// For non-verbose log entries, `verbosity()` returns `kNoVerbosityLevel`.
|
| 58 |
+
static constexpr int kNoVerbosityLevel = -1;
|
| 59 |
+
static constexpr int kNoVerboseLevel = -1; // TO BE removed
|
| 60 |
+
|
| 61 |
+
// Pass `LogEntry` by reference, and do not store it as its state does not
|
| 62 |
+
// outlive the call to `LogSink::Send()`.
|
| 63 |
+
LogEntry(const LogEntry&) = delete;
|
| 64 |
+
LogEntry& operator=(const LogEntry&) = delete;
|
| 65 |
+
|
| 66 |
+
// Source file and line where the log message occurred. Taken from `__FILE__`
|
| 67 |
+
// and `__LINE__` unless overridden by `LOG(...).AtLocation(...)`.
|
| 68 |
+
//
|
| 69 |
+
// Take special care not to use the values returned by `source_filename()` and
|
| 70 |
+
// `source_basename()` after the lifetime of the entry. This is always
|
| 71 |
+
// incorrect, but it will often work in practice because they usually point
|
| 72 |
+
// into a statically allocated character array obtained from `__FILE__`.
|
| 73 |
+
// Statements like `LOG(INFO).AtLocation(std::string(...), ...)` will expose
|
| 74 |
+
// the bug. If you need the data later, you must copy them.
|
| 75 |
+
absl::string_view source_filename() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 76 |
+
return full_filename_;
|
| 77 |
+
}
|
| 78 |
+
absl::string_view source_basename() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 79 |
+
return base_filename_;
|
| 80 |
+
}
|
| 81 |
+
int source_line() const { return line_; }
|
| 82 |
+
|
| 83 |
+
// LogEntry::prefix()
|
| 84 |
+
//
|
| 85 |
+
// True unless the metadata prefix was suppressed once by
|
| 86 |
+
// `LOG(...).NoPrefix()` or globally by `absl::EnableLogPrefix(false)`.
|
| 87 |
+
// Implies `text_message_with_prefix() == text_message()`.
|
| 88 |
+
bool prefix() const { return prefix_; }
|
| 89 |
+
|
| 90 |
+
// LogEntry::log_severity()
|
| 91 |
+
//
|
| 92 |
+
// Returns this entry's severity. For `LOG`, taken from the first argument;
|
| 93 |
+
// for `CHECK`, always `absl::LogSeverity::kFatal`.
|
| 94 |
+
absl::LogSeverity log_severity() const { return severity_; }
|
| 95 |
+
|
| 96 |
+
// LogEntry::verbosity()
|
| 97 |
+
//
|
| 98 |
+
// Returns this entry's verbosity, or `kNoVerbosityLevel` for a non-verbose
|
| 99 |
+
// entry. Taken from the argument to `VLOG` or from
|
| 100 |
+
// `LOG(...).WithVerbosity(...)`.
|
| 101 |
+
int verbosity() const { return verbose_level_; }
|
| 102 |
+
|
| 103 |
+
// LogEntry::timestamp()
|
| 104 |
+
//
|
| 105 |
+
// Returns the time at which this entry was written. Captured during
|
| 106 |
+
// evaluation of `LOG`, but can be overridden by
|
| 107 |
+
// `LOG(...).WithTimestamp(...)`.
|
| 108 |
+
//
|
| 109 |
+
// Take care not to rely on timestamps increasing monotonically, or even to
|
| 110 |
+
// rely on timestamps having any particular relationship with reality (since
|
| 111 |
+
// they can be overridden).
|
| 112 |
+
absl::Time timestamp() const { return timestamp_; }
|
| 113 |
+
|
| 114 |
+
// LogEntry::tid()
|
| 115 |
+
//
|
| 116 |
+
// Returns the ID of the thread that wrote this entry. Captured during
|
| 117 |
+
// evaluation of `LOG`, but can be overridden by `LOG(...).WithThreadID(...)`.
|
| 118 |
+
//
|
| 119 |
+
// Take care not to *rely* on reported thread IDs as they can be overridden as
|
| 120 |
+
// specified above.
|
| 121 |
+
tid_t tid() const { return tid_; }
|
| 122 |
+
|
| 123 |
+
// Text-formatted version of the log message. An underlying buffer holds
|
| 124 |
+
// these contiguous data:
|
| 125 |
+
//
|
| 126 |
+
// * A prefix formed by formatting metadata (timestamp, filename, line number,
|
| 127 |
+
// etc.)
|
| 128 |
+
// The prefix may be empty - see `LogEntry::prefix()` - and may rarely be
|
| 129 |
+
// truncated if the metadata are very long.
|
| 130 |
+
// * The streamed data
|
| 131 |
+
// The data may be empty if nothing was streamed, or may be truncated to fit
|
| 132 |
+
// the buffer.
|
| 133 |
+
// * A newline
|
| 134 |
+
// * A nul terminator
|
| 135 |
+
//
|
| 136 |
+
// The newline and nul terminator will be present even if the prefix and/or
|
| 137 |
+
// data are truncated.
|
| 138 |
+
//
|
| 139 |
+
// These methods give access to the most commonly useful substrings of the
|
| 140 |
+
// buffer's contents. Other combinations can be obtained with substring
|
| 141 |
+
// arithmetic.
|
| 142 |
+
//
|
| 143 |
+
// The buffer does not outlive the entry; if you need the data later, you must
|
| 144 |
+
// copy them.
|
| 145 |
+
absl::string_view text_message_with_prefix_and_newline() const
|
| 146 |
+
ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 147 |
+
return absl::string_view(
|
| 148 |
+
text_message_with_prefix_and_newline_and_nul_.data(),
|
| 149 |
+
text_message_with_prefix_and_newline_and_nul_.size() - 1);
|
| 150 |
+
}
|
| 151 |
+
absl::string_view text_message_with_prefix() const
|
| 152 |
+
ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 153 |
+
return absl::string_view(
|
| 154 |
+
text_message_with_prefix_and_newline_and_nul_.data(),
|
| 155 |
+
text_message_with_prefix_and_newline_and_nul_.size() - 2);
|
| 156 |
+
}
|
| 157 |
+
absl::string_view text_message_with_newline() const
|
| 158 |
+
ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 159 |
+
return absl::string_view(
|
| 160 |
+
text_message_with_prefix_and_newline_and_nul_.data() + prefix_len_,
|
| 161 |
+
text_message_with_prefix_and_newline_and_nul_.size() - prefix_len_ - 1);
|
| 162 |
+
}
|
| 163 |
+
absl::string_view text_message() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 164 |
+
return absl::string_view(
|
| 165 |
+
text_message_with_prefix_and_newline_and_nul_.data() + prefix_len_,
|
| 166 |
+
text_message_with_prefix_and_newline_and_nul_.size() - prefix_len_ - 2);
|
| 167 |
+
}
|
| 168 |
+
const char* text_message_with_prefix_and_newline_c_str() const
|
| 169 |
+
ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 170 |
+
return text_message_with_prefix_and_newline_and_nul_.data();
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// Returns a serialized protobuf holding the operands streamed into this
|
| 174 |
+
// log message. The message definition is not yet published.
|
| 175 |
+
//
|
| 176 |
+
// The buffer does not outlive the entry; if you need the data later, you must
|
| 177 |
+
// copy them.
|
| 178 |
+
absl::string_view encoded_message() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 179 |
+
return encoding_;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// LogEntry::stacktrace()
|
| 183 |
+
//
|
| 184 |
+
// Optional stacktrace, e.g. for `FATAL` logs and failed `CHECK`s.
|
| 185 |
+
//
|
| 186 |
+
// Fatal entries are dispatched to each sink twice: first with all data and
|
| 187 |
+
// metadata but no stacktrace, and then with the stacktrace. This is done
|
| 188 |
+
// because stacktrace collection is sometimes slow and fallible, and it's
|
| 189 |
+
// critical to log enough information to diagnose the failure even if the
|
| 190 |
+
// stacktrace collection hangs.
|
| 191 |
+
//
|
| 192 |
+
// The buffer does not outlive the entry; if you need the data later, you must
|
| 193 |
+
// copy them.
|
| 194 |
+
absl::string_view stacktrace() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
|
| 195 |
+
return stacktrace_;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
private:
|
| 199 |
+
LogEntry() = default;
|
| 200 |
+
|
| 201 |
+
absl::string_view full_filename_;
|
| 202 |
+
absl::string_view base_filename_;
|
| 203 |
+
int line_;
|
| 204 |
+
bool prefix_;
|
| 205 |
+
absl::LogSeverity severity_;
|
| 206 |
+
int verbose_level_; // >=0 for `VLOG`, etc.; otherwise `kNoVerbosityLevel`.
|
| 207 |
+
absl::Time timestamp_;
|
| 208 |
+
tid_t tid_;
|
| 209 |
+
absl::Span<const char> text_message_with_prefix_and_newline_and_nul_;
|
| 210 |
+
size_t prefix_len_;
|
| 211 |
+
absl::string_view encoding_;
|
| 212 |
+
std::string stacktrace_;
|
| 213 |
+
|
| 214 |
+
friend class log_internal::LogEntryTestPeer;
|
| 215 |
+
friend class log_internal::LogMessage;
|
| 216 |
+
};
|
| 217 |
+
|
| 218 |
+
ABSL_NAMESPACE_END
|
| 219 |
+
} // namespace absl
|
| 220 |
+
|
| 221 |
+
#endif // ABSL_LOG_LOG_ENTRY_H_
|
weight/_dep/abseil-cpp/absl/log/log_entry_test.cc
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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/log/log_entry.h"
|
| 17 |
+
|
| 18 |
+
#include <stddef.h>
|
| 19 |
+
#include <stdint.h>
|
| 20 |
+
|
| 21 |
+
#include <cstring>
|
| 22 |
+
#include <limits>
|
| 23 |
+
#include <string>
|
| 24 |
+
#include <type_traits>
|
| 25 |
+
#include <utility>
|
| 26 |
+
#include <vector>
|
| 27 |
+
|
| 28 |
+
#include "gmock/gmock.h"
|
| 29 |
+
#include "gtest/gtest.h"
|
| 30 |
+
#include "absl/base/attributes.h"
|
| 31 |
+
#include "absl/base/config.h"
|
| 32 |
+
#include "absl/base/log_severity.h"
|
| 33 |
+
#include "absl/log/internal/append_truncated.h"
|
| 34 |
+
#include "absl/log/internal/log_format.h"
|
| 35 |
+
#include "absl/log/internal/test_helpers.h"
|
| 36 |
+
#include "absl/strings/numbers.h"
|
| 37 |
+
#include "absl/strings/str_split.h"
|
| 38 |
+
#include "absl/strings/string_view.h"
|
| 39 |
+
#include "absl/time/civil_time.h"
|
| 40 |
+
#include "absl/time/time.h"
|
| 41 |
+
#include "absl/types/span.h"
|
| 42 |
+
|
| 43 |
+
namespace {
|
| 44 |
+
using ::absl::log_internal::LogEntryTestPeer;
|
| 45 |
+
using ::testing::Eq;
|
| 46 |
+
using ::testing::IsTrue;
|
| 47 |
+
using ::testing::StartsWith;
|
| 48 |
+
using ::testing::StrEq;
|
| 49 |
+
|
| 50 |
+
auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
|
| 51 |
+
new absl::log_internal::LogTestEnvironment);
|
| 52 |
+
} // namespace
|
| 53 |
+
|
| 54 |
+
namespace absl {
|
| 55 |
+
ABSL_NAMESPACE_BEGIN
|
| 56 |
+
namespace log_internal {
|
| 57 |
+
|
| 58 |
+
class LogEntryTestPeer {
|
| 59 |
+
public:
|
| 60 |
+
LogEntryTestPeer(absl::string_view base_filename, int line, bool prefix,
|
| 61 |
+
absl::LogSeverity severity, absl::string_view timestamp,
|
| 62 |
+
absl::LogEntry::tid_t tid, PrefixFormat format,
|
| 63 |
+
absl::string_view text_message)
|
| 64 |
+
: format_{format}, buf_(15000, '\0') {
|
| 65 |
+
entry_.base_filename_ = base_filename;
|
| 66 |
+
entry_.line_ = line;
|
| 67 |
+
entry_.prefix_ = prefix;
|
| 68 |
+
entry_.severity_ = severity;
|
| 69 |
+
std::string time_err;
|
| 70 |
+
EXPECT_THAT(
|
| 71 |
+
absl::ParseTime("%Y-%m-%d%ET%H:%M:%E*S", timestamp,
|
| 72 |
+
absl::LocalTimeZone(), &entry_.timestamp_, &time_err),
|
| 73 |
+
IsTrue())
|
| 74 |
+
<< "Failed to parse time " << timestamp << ": " << time_err;
|
| 75 |
+
entry_.tid_ = tid;
|
| 76 |
+
std::pair<absl::string_view, std::string> timestamp_bits =
|
| 77 |
+
absl::StrSplit(timestamp, absl::ByChar('.'));
|
| 78 |
+
EXPECT_THAT(absl::ParseCivilTime(timestamp_bits.first, &ci_.cs), IsTrue())
|
| 79 |
+
<< "Failed to parse time " << timestamp_bits.first;
|
| 80 |
+
timestamp_bits.second.resize(9, '0');
|
| 81 |
+
int64_t nanos = 0;
|
| 82 |
+
EXPECT_THAT(absl::SimpleAtoi(timestamp_bits.second, &nanos), IsTrue())
|
| 83 |
+
<< "Failed to parse time " << timestamp_bits.first;
|
| 84 |
+
ci_.subsecond = absl::Nanoseconds(nanos);
|
| 85 |
+
|
| 86 |
+
absl::Span<char> view = absl::MakeSpan(buf_);
|
| 87 |
+
view.remove_suffix(2);
|
| 88 |
+
entry_.prefix_len_ =
|
| 89 |
+
entry_.prefix_
|
| 90 |
+
? log_internal::FormatLogPrefix(
|
| 91 |
+
entry_.log_severity(), entry_.timestamp(), entry_.tid(),
|
| 92 |
+
entry_.source_basename(), entry_.source_line(), format_, view)
|
| 93 |
+
: 0;
|
| 94 |
+
|
| 95 |
+
EXPECT_THAT(entry_.prefix_len_,
|
| 96 |
+
Eq(static_cast<size_t>(view.data() - buf_.data())));
|
| 97 |
+
log_internal::AppendTruncated(text_message, view);
|
| 98 |
+
view = absl::Span<char>(view.data(), view.size() + 2);
|
| 99 |
+
view[0] = '\n';
|
| 100 |
+
view[1] = '\0';
|
| 101 |
+
view.remove_prefix(2);
|
| 102 |
+
buf_.resize(static_cast<size_t>(view.data() - buf_.data()));
|
| 103 |
+
entry_.text_message_with_prefix_and_newline_and_nul_ = absl::MakeSpan(buf_);
|
| 104 |
+
}
|
| 105 |
+
LogEntryTestPeer(const LogEntryTestPeer&) = delete;
|
| 106 |
+
LogEntryTestPeer& operator=(const LogEntryTestPeer&) = delete;
|
| 107 |
+
|
| 108 |
+
std::string FormatLogMessage() const {
|
| 109 |
+
return log_internal::FormatLogMessage(
|
| 110 |
+
entry_.log_severity(), ci_.cs, ci_.subsecond, entry_.tid(),
|
| 111 |
+
entry_.source_basename(), entry_.source_line(), format_,
|
| 112 |
+
entry_.text_message());
|
| 113 |
+
}
|
| 114 |
+
std::string FormatPrefixIntoSizedBuffer(size_t sz) {
|
| 115 |
+
std::string str(sz, '\0');
|
| 116 |
+
absl::Span<char> buf(&str[0], str.size());
|
| 117 |
+
const size_t prefix_size = log_internal::FormatLogPrefix(
|
| 118 |
+
entry_.log_severity(), entry_.timestamp(), entry_.tid(),
|
| 119 |
+
entry_.source_basename(), entry_.source_line(), format_, buf);
|
| 120 |
+
EXPECT_THAT(prefix_size, Eq(static_cast<size_t>(buf.data() - str.data())));
|
| 121 |
+
str.resize(prefix_size);
|
| 122 |
+
return str;
|
| 123 |
+
}
|
| 124 |
+
const absl::LogEntry& entry() const { return entry_; }
|
| 125 |
+
|
| 126 |
+
private:
|
| 127 |
+
absl::LogEntry entry_;
|
| 128 |
+
PrefixFormat format_;
|
| 129 |
+
absl::TimeZone::CivilInfo ci_;
|
| 130 |
+
std::vector<char> buf_;
|
| 131 |
+
};
|
| 132 |
+
|
| 133 |
+
} // namespace log_internal
|
| 134 |
+
ABSL_NAMESPACE_END
|
| 135 |
+
} // namespace absl
|
| 136 |
+
|
| 137 |
+
namespace {
|
| 138 |
+
constexpr bool kUsePrefix = true, kNoPrefix = false;
|
| 139 |
+
|
| 140 |
+
TEST(LogEntryTest, Baseline) {
|
| 141 |
+
LogEntryTestPeer entry("foo.cc", 1234, kUsePrefix, absl::LogSeverity::kInfo,
|
| 142 |
+
"2020-01-02T03:04:05.6789", 451,
|
| 143 |
+
absl::log_internal::PrefixFormat::kNotRaw,
|
| 144 |
+
"hello world");
|
| 145 |
+
EXPECT_THAT(entry.FormatLogMessage(),
|
| 146 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] hello world"));
|
| 147 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 148 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] "));
|
| 149 |
+
for (size_t sz = strlen("I0102 03:04:05.678900 451 foo.cc:1234] ") + 20;
|
| 150 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 151 |
+
EXPECT_THAT("I0102 03:04:05.678900 451 foo.cc:1234] ",
|
| 152 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 153 |
+
|
| 154 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix_and_newline(),
|
| 155 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] hello world\n"));
|
| 156 |
+
EXPECT_THAT(
|
| 157 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 158 |
+
StrEq("I0102 03:04:05.678900 451 foo.cc:1234] hello world\n"));
|
| 159 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix(),
|
| 160 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] hello world"));
|
| 161 |
+
EXPECT_THAT(entry.entry().text_message(), Eq("hello world"));
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
TEST(LogEntryTest, NoPrefix) {
|
| 165 |
+
LogEntryTestPeer entry("foo.cc", 1234, kNoPrefix, absl::LogSeverity::kInfo,
|
| 166 |
+
"2020-01-02T03:04:05.6789", 451,
|
| 167 |
+
absl::log_internal::PrefixFormat::kNotRaw,
|
| 168 |
+
"hello world");
|
| 169 |
+
EXPECT_THAT(entry.FormatLogMessage(),
|
| 170 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] hello world"));
|
| 171 |
+
// These methods are not responsible for honoring `prefix()`.
|
| 172 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 173 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] "));
|
| 174 |
+
for (size_t sz = strlen("I0102 03:04:05.678900 451 foo.cc:1234] ") + 20;
|
| 175 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 176 |
+
EXPECT_THAT("I0102 03:04:05.678900 451 foo.cc:1234] ",
|
| 177 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 178 |
+
|
| 179 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix_and_newline(),
|
| 180 |
+
Eq("hello world\n"));
|
| 181 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 182 |
+
StrEq("hello world\n"));
|
| 183 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix(), Eq("hello world"));
|
| 184 |
+
EXPECT_THAT(entry.entry().text_message(), Eq("hello world"));
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
TEST(LogEntryTest, EmptyFields) {
|
| 188 |
+
LogEntryTestPeer entry("", 0, kUsePrefix, absl::LogSeverity::kInfo,
|
| 189 |
+
"2020-01-02T03:04:05", 0,
|
| 190 |
+
absl::log_internal::PrefixFormat::kNotRaw, "");
|
| 191 |
+
const std::string format_message = entry.FormatLogMessage();
|
| 192 |
+
EXPECT_THAT(format_message, Eq("I0102 03:04:05.000000 0 :0] "));
|
| 193 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000), Eq(format_message));
|
| 194 |
+
for (size_t sz = format_message.size() + 20;
|
| 195 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 196 |
+
EXPECT_THAT(format_message,
|
| 197 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 198 |
+
|
| 199 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix_and_newline(),
|
| 200 |
+
Eq("I0102 03:04:05.000000 0 :0] \n"));
|
| 201 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 202 |
+
StrEq("I0102 03:04:05.000000 0 :0] \n"));
|
| 203 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix(),
|
| 204 |
+
Eq("I0102 03:04:05.000000 0 :0] "));
|
| 205 |
+
EXPECT_THAT(entry.entry().text_message(), Eq(""));
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
TEST(LogEntryTest, NegativeFields) {
|
| 209 |
+
// When Abseil's minimum C++ version is C++17, this conditional can be
|
| 210 |
+
// converted to a constexpr if and the static_cast below removed.
|
| 211 |
+
if (std::is_signed<absl::LogEntry::tid_t>::value) {
|
| 212 |
+
LogEntryTestPeer entry(
|
| 213 |
+
"foo.cc", -1234, kUsePrefix, absl::LogSeverity::kInfo,
|
| 214 |
+
"2020-01-02T03:04:05.6789", static_cast<absl::LogEntry::tid_t>(-451),
|
| 215 |
+
absl::log_internal::PrefixFormat::kNotRaw, "hello world");
|
| 216 |
+
EXPECT_THAT(entry.FormatLogMessage(),
|
| 217 |
+
Eq("I0102 03:04:05.678900 -451 foo.cc:-1234] hello world"));
|
| 218 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 219 |
+
Eq("I0102 03:04:05.678900 -451 foo.cc:-1234] "));
|
| 220 |
+
for (size_t sz =
|
| 221 |
+
strlen("I0102 03:04:05.678900 -451 foo.cc:-1234] ") + 20;
|
| 222 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 223 |
+
EXPECT_THAT("I0102 03:04:05.678900 -451 foo.cc:-1234] ",
|
| 224 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 225 |
+
|
| 226 |
+
EXPECT_THAT(
|
| 227 |
+
entry.entry().text_message_with_prefix_and_newline(),
|
| 228 |
+
Eq("I0102 03:04:05.678900 -451 foo.cc:-1234] hello world\n"));
|
| 229 |
+
EXPECT_THAT(
|
| 230 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 231 |
+
StrEq("I0102 03:04:05.678900 -451 foo.cc:-1234] hello world\n"));
|
| 232 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix(),
|
| 233 |
+
Eq("I0102 03:04:05.678900 -451 foo.cc:-1234] hello world"));
|
| 234 |
+
EXPECT_THAT(entry.entry().text_message(), Eq("hello world"));
|
| 235 |
+
} else {
|
| 236 |
+
LogEntryTestPeer entry("foo.cc", -1234, kUsePrefix,
|
| 237 |
+
absl::LogSeverity::kInfo, "2020-01-02T03:04:05.6789",
|
| 238 |
+
451, absl::log_internal::PrefixFormat::kNotRaw,
|
| 239 |
+
"hello world");
|
| 240 |
+
EXPECT_THAT(entry.FormatLogMessage(),
|
| 241 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:-1234] hello world"));
|
| 242 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 243 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:-1234] "));
|
| 244 |
+
for (size_t sz =
|
| 245 |
+
strlen("I0102 03:04:05.678900 451 foo.cc:-1234] ") + 20;
|
| 246 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 247 |
+
EXPECT_THAT("I0102 03:04:05.678900 451 foo.cc:-1234] ",
|
| 248 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 249 |
+
|
| 250 |
+
EXPECT_THAT(
|
| 251 |
+
entry.entry().text_message_with_prefix_and_newline(),
|
| 252 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:-1234] hello world\n"));
|
| 253 |
+
EXPECT_THAT(
|
| 254 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 255 |
+
StrEq("I0102 03:04:05.678900 451 foo.cc:-1234] hello world\n"));
|
| 256 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix(),
|
| 257 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:-1234] hello world"));
|
| 258 |
+
EXPECT_THAT(entry.entry().text_message(), Eq("hello world"));
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
TEST(LogEntryTest, LongFields) {
|
| 263 |
+
LogEntryTestPeer entry(
|
| 264 |
+
"I am the very model of a modern Major-General / "
|
| 265 |
+
"I've information vegetable, animal, and mineral.",
|
| 266 |
+
2147483647, kUsePrefix, absl::LogSeverity::kInfo,
|
| 267 |
+
"2020-01-02T03:04:05.678967896789", 2147483647,
|
| 268 |
+
absl::log_internal::PrefixFormat::kNotRaw,
|
| 269 |
+
"I know the kings of England, and I quote the fights historical / "
|
| 270 |
+
"From Marathon to Waterloo, in order categorical.");
|
| 271 |
+
EXPECT_THAT(entry.FormatLogMessage(),
|
| 272 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 273 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 274 |
+
"and mineral.:2147483647] I know the kings of England, and I "
|
| 275 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 276 |
+
"order categorical."));
|
| 277 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 278 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 279 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 280 |
+
"and mineral.:2147483647] "));
|
| 281 |
+
for (size_t sz =
|
| 282 |
+
strlen("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 283 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 284 |
+
"and mineral.:2147483647] ") +
|
| 285 |
+
20;
|
| 286 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 287 |
+
EXPECT_THAT(
|
| 288 |
+
"I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 289 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 290 |
+
"and mineral.:2147483647] ",
|
| 291 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 292 |
+
|
| 293 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix_and_newline(),
|
| 294 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 295 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 296 |
+
"and mineral.:2147483647] I know the kings of England, and I "
|
| 297 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 298 |
+
"order categorical.\n"));
|
| 299 |
+
EXPECT_THAT(
|
| 300 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 301 |
+
StrEq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 302 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 303 |
+
"and mineral.:2147483647] I know the kings of England, and I "
|
| 304 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 305 |
+
"order categorical.\n"));
|
| 306 |
+
EXPECT_THAT(entry.entry().text_message_with_prefix(),
|
| 307 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 308 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 309 |
+
"and mineral.:2147483647] I know the kings of England, and I "
|
| 310 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 311 |
+
"order categorical."));
|
| 312 |
+
EXPECT_THAT(
|
| 313 |
+
entry.entry().text_message(),
|
| 314 |
+
Eq("I know the kings of England, and I quote the fights historical / "
|
| 315 |
+
"From Marathon to Waterloo, in order categorical."));
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
TEST(LogEntryTest, LongNegativeFields) {
|
| 319 |
+
// When Abseil's minimum C++ version is C++17, this conditional can be
|
| 320 |
+
// converted to a constexpr if and the static_cast below removed.
|
| 321 |
+
if (std::is_signed<absl::LogEntry::tid_t>::value) {
|
| 322 |
+
LogEntryTestPeer entry(
|
| 323 |
+
"I am the very model of a modern Major-General / "
|
| 324 |
+
"I've information vegetable, animal, and mineral.",
|
| 325 |
+
-2147483647, kUsePrefix, absl::LogSeverity::kInfo,
|
| 326 |
+
"2020-01-02T03:04:05.678967896789",
|
| 327 |
+
static_cast<absl::LogEntry::tid_t>(-2147483647),
|
| 328 |
+
absl::log_internal::PrefixFormat::kNotRaw,
|
| 329 |
+
"I know the kings of England, and I quote the fights historical / "
|
| 330 |
+
"From Marathon to Waterloo, in order categorical.");
|
| 331 |
+
EXPECT_THAT(
|
| 332 |
+
entry.FormatLogMessage(),
|
| 333 |
+
Eq("I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 334 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 335 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 336 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 337 |
+
"order categorical."));
|
| 338 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 339 |
+
Eq("I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 340 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 341 |
+
"and mineral.:-2147483647] "));
|
| 342 |
+
for (size_t sz =
|
| 343 |
+
strlen(
|
| 344 |
+
"I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 345 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 346 |
+
"and mineral.:-2147483647] ") +
|
| 347 |
+
20;
|
| 348 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 349 |
+
EXPECT_THAT(
|
| 350 |
+
"I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 351 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 352 |
+
"and mineral.:-2147483647] ",
|
| 353 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 354 |
+
|
| 355 |
+
EXPECT_THAT(
|
| 356 |
+
entry.entry().text_message_with_prefix_and_newline(),
|
| 357 |
+
Eq("I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 358 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 359 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 360 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 361 |
+
"order categorical.\n"));
|
| 362 |
+
EXPECT_THAT(
|
| 363 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 364 |
+
StrEq("I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 365 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 366 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 367 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 368 |
+
"order categorical.\n"));
|
| 369 |
+
EXPECT_THAT(
|
| 370 |
+
entry.entry().text_message_with_prefix(),
|
| 371 |
+
Eq("I0102 03:04:05.678967 -2147483647 I am the very model of a "
|
| 372 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 373 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 374 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 375 |
+
"order categorical."));
|
| 376 |
+
EXPECT_THAT(
|
| 377 |
+
entry.entry().text_message(),
|
| 378 |
+
Eq("I know the kings of England, and I quote the fights historical / "
|
| 379 |
+
"From Marathon to Waterloo, in order categorical."));
|
| 380 |
+
} else {
|
| 381 |
+
LogEntryTestPeer entry(
|
| 382 |
+
"I am the very model of a modern Major-General / "
|
| 383 |
+
"I've information vegetable, animal, and mineral.",
|
| 384 |
+
-2147483647, kUsePrefix, absl::LogSeverity::kInfo,
|
| 385 |
+
"2020-01-02T03:04:05.678967896789", 2147483647,
|
| 386 |
+
absl::log_internal::PrefixFormat::kNotRaw,
|
| 387 |
+
"I know the kings of England, and I quote the fights historical / "
|
| 388 |
+
"From Marathon to Waterloo, in order categorical.");
|
| 389 |
+
EXPECT_THAT(
|
| 390 |
+
entry.FormatLogMessage(),
|
| 391 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 392 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 393 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 394 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 395 |
+
"order categorical."));
|
| 396 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 397 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 398 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 399 |
+
"and mineral.:-2147483647] "));
|
| 400 |
+
for (size_t sz =
|
| 401 |
+
strlen(
|
| 402 |
+
"I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 403 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 404 |
+
"and mineral.:-2147483647] ") +
|
| 405 |
+
20;
|
| 406 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 407 |
+
EXPECT_THAT(
|
| 408 |
+
"I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 409 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 410 |
+
"and mineral.:-2147483647] ",
|
| 411 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 412 |
+
|
| 413 |
+
EXPECT_THAT(
|
| 414 |
+
entry.entry().text_message_with_prefix_and_newline(),
|
| 415 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 416 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 417 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 418 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 419 |
+
"order categorical.\n"));
|
| 420 |
+
EXPECT_THAT(
|
| 421 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 422 |
+
StrEq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 423 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 424 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 425 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 426 |
+
"order categorical.\n"));
|
| 427 |
+
EXPECT_THAT(
|
| 428 |
+
entry.entry().text_message_with_prefix(),
|
| 429 |
+
Eq("I0102 03:04:05.678967 2147483647 I am the very model of a "
|
| 430 |
+
"modern Major-General / I've information vegetable, animal, "
|
| 431 |
+
"and mineral.:-2147483647] I know the kings of England, and I "
|
| 432 |
+
"quote the fights historical / From Marathon to Waterloo, in "
|
| 433 |
+
"order categorical."));
|
| 434 |
+
EXPECT_THAT(
|
| 435 |
+
entry.entry().text_message(),
|
| 436 |
+
Eq("I know the kings of England, and I quote the fights historical / "
|
| 437 |
+
"From Marathon to Waterloo, in order categorical."));
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
TEST(LogEntryTest, Raw) {
|
| 442 |
+
LogEntryTestPeer entry("foo.cc", 1234, kUsePrefix, absl::LogSeverity::kInfo,
|
| 443 |
+
"2020-01-02T03:04:05.6789", 451,
|
| 444 |
+
absl::log_internal::PrefixFormat::kRaw, "hello world");
|
| 445 |
+
EXPECT_THAT(
|
| 446 |
+
entry.FormatLogMessage(),
|
| 447 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] RAW: hello world"));
|
| 448 |
+
EXPECT_THAT(entry.FormatPrefixIntoSizedBuffer(1000),
|
| 449 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] RAW: "));
|
| 450 |
+
for (size_t sz =
|
| 451 |
+
strlen("I0102 03:04:05.678900 451 foo.cc:1234] RAW: ") + 20;
|
| 452 |
+
sz != std::numeric_limits<size_t>::max(); sz--)
|
| 453 |
+
EXPECT_THAT("I0102 03:04:05.678900 451 foo.cc:1234] RAW: ",
|
| 454 |
+
StartsWith(entry.FormatPrefixIntoSizedBuffer(sz)));
|
| 455 |
+
|
| 456 |
+
EXPECT_THAT(
|
| 457 |
+
entry.entry().text_message_with_prefix_and_newline(),
|
| 458 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] RAW: hello world\n"));
|
| 459 |
+
EXPECT_THAT(
|
| 460 |
+
entry.entry().text_message_with_prefix_and_newline_c_str(),
|
| 461 |
+
StrEq("I0102 03:04:05.678900 451 foo.cc:1234] RAW: hello world\n"));
|
| 462 |
+
EXPECT_THAT(
|
| 463 |
+
entry.entry().text_message_with_prefix(),
|
| 464 |
+
Eq("I0102 03:04:05.678900 451 foo.cc:1234] RAW: hello world"));
|
| 465 |
+
EXPECT_THAT(entry.entry().text_message(), Eq("hello world"));
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/log/log_format_test.cc
ADDED
|
@@ -0,0 +1,1872 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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 <math.h>
|
| 17 |
+
|
| 18 |
+
#include <iomanip>
|
| 19 |
+
#include <ios>
|
| 20 |
+
#include <limits>
|
| 21 |
+
#include <ostream>
|
| 22 |
+
#include <sstream>
|
| 23 |
+
#include <string>
|
| 24 |
+
#include <type_traits>
|
| 25 |
+
|
| 26 |
+
#ifdef __ANDROID__
|
| 27 |
+
#include <android/api-level.h>
|
| 28 |
+
#endif
|
| 29 |
+
#include "gmock/gmock.h"
|
| 30 |
+
#include "gtest/gtest.h"
|
| 31 |
+
#include "absl/log/check.h"
|
| 32 |
+
#include "absl/log/internal/test_matchers.h"
|
| 33 |
+
#include "absl/log/log.h"
|
| 34 |
+
#include "absl/log/scoped_mock_log.h"
|
| 35 |
+
#include "absl/strings/match.h"
|
| 36 |
+
#include "absl/strings/str_cat.h"
|
| 37 |
+
#include "absl/strings/str_format.h"
|
| 38 |
+
#include "absl/strings/string_view.h"
|
| 39 |
+
#include "absl/types/optional.h"
|
| 40 |
+
|
| 41 |
+
namespace {
|
| 42 |
+
using ::absl::log_internal::AsString;
|
| 43 |
+
using ::absl::log_internal::MatchesOstream;
|
| 44 |
+
using ::absl::log_internal::RawEncodedMessage;
|
| 45 |
+
using ::absl::log_internal::TextMessage;
|
| 46 |
+
using ::absl::log_internal::TextPrefix;
|
| 47 |
+
using ::testing::AllOf;
|
| 48 |
+
using ::testing::AnyOf;
|
| 49 |
+
using ::testing::Each;
|
| 50 |
+
using ::testing::EndsWith;
|
| 51 |
+
using ::testing::Eq;
|
| 52 |
+
using ::testing::Ge;
|
| 53 |
+
using ::testing::IsEmpty;
|
| 54 |
+
using ::testing::Le;
|
| 55 |
+
using ::testing::SizeIs;
|
| 56 |
+
using ::testing::Types;
|
| 57 |
+
|
| 58 |
+
// Some aspects of formatting streamed data (e.g. pointer handling) are
|
| 59 |
+
// implementation-defined. Others are buggy in supported implementations.
|
| 60 |
+
// These tests validate that the formatting matches that performed by a
|
| 61 |
+
// `std::ostream` and also that the result is one of a list of expected formats.
|
| 62 |
+
|
| 63 |
+
std::ostringstream ComparisonStream() {
|
| 64 |
+
std::ostringstream str;
|
| 65 |
+
str.setf(std::ios_base::showbase | std::ios_base::boolalpha |
|
| 66 |
+
std::ios_base::internal);
|
| 67 |
+
return str;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
TEST(LogFormatTest, NoMessage) {
|
| 71 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 72 |
+
|
| 73 |
+
const int log_line = __LINE__ + 1;
|
| 74 |
+
auto do_log = [] { LOG(INFO); };
|
| 75 |
+
|
| 76 |
+
EXPECT_CALL(test_sink,
|
| 77 |
+
Send(AllOf(TextMessage(MatchesOstream(ComparisonStream())),
|
| 78 |
+
TextPrefix(AsString(EndsWith(absl::StrCat(
|
| 79 |
+
" log_format_test.cc:", log_line, "] ")))),
|
| 80 |
+
TextMessage(IsEmpty()),
|
| 81 |
+
ENCODED_MESSAGE(EqualsProto(R"pb()pb")))));
|
| 82 |
+
|
| 83 |
+
test_sink.StartCapturingLogs();
|
| 84 |
+
do_log();
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
template <typename T>
|
| 88 |
+
class CharLogFormatTest : public testing::Test {};
|
| 89 |
+
using CharTypes = Types<char, signed char, unsigned char>;
|
| 90 |
+
TYPED_TEST_SUITE(CharLogFormatTest, CharTypes);
|
| 91 |
+
|
| 92 |
+
TYPED_TEST(CharLogFormatTest, Printable) {
|
| 93 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 94 |
+
|
| 95 |
+
const TypeParam value = 'x';
|
| 96 |
+
auto comparison_stream = ComparisonStream();
|
| 97 |
+
comparison_stream << value;
|
| 98 |
+
|
| 99 |
+
EXPECT_CALL(
|
| 100 |
+
test_sink,
|
| 101 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 102 |
+
TextMessage(Eq("x")),
|
| 103 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "x" })pb")))));
|
| 104 |
+
|
| 105 |
+
test_sink.StartCapturingLogs();
|
| 106 |
+
LOG(INFO) << value;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
TYPED_TEST(CharLogFormatTest, Unprintable) {
|
| 110 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 111 |
+
|
| 112 |
+
constexpr auto value = static_cast<TypeParam>(0xeeu);
|
| 113 |
+
auto comparison_stream = ComparisonStream();
|
| 114 |
+
comparison_stream << value;
|
| 115 |
+
|
| 116 |
+
EXPECT_CALL(
|
| 117 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 118 |
+
TextMessage(Eq("\xee")),
|
| 119 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 120 |
+
str: "\xee"
|
| 121 |
+
})pb")))));
|
| 122 |
+
|
| 123 |
+
test_sink.StartCapturingLogs();
|
| 124 |
+
LOG(INFO) << value;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
template <typename T>
|
| 128 |
+
class UnsignedIntLogFormatTest : public testing::Test {};
|
| 129 |
+
using UnsignedIntTypes = Types<unsigned short, unsigned int, // NOLINT
|
| 130 |
+
unsigned long, unsigned long long>; // NOLINT
|
| 131 |
+
TYPED_TEST_SUITE(UnsignedIntLogFormatTest, UnsignedIntTypes);
|
| 132 |
+
|
| 133 |
+
TYPED_TEST(UnsignedIntLogFormatTest, Positive) {
|
| 134 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 135 |
+
|
| 136 |
+
const TypeParam value = 224;
|
| 137 |
+
auto comparison_stream = ComparisonStream();
|
| 138 |
+
comparison_stream << value;
|
| 139 |
+
|
| 140 |
+
EXPECT_CALL(
|
| 141 |
+
test_sink,
|
| 142 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 143 |
+
TextMessage(Eq("224")),
|
| 144 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb")))));
|
| 145 |
+
|
| 146 |
+
test_sink.StartCapturingLogs();
|
| 147 |
+
LOG(INFO) << value;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
TYPED_TEST(UnsignedIntLogFormatTest, BitfieldPositive) {
|
| 151 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 152 |
+
|
| 153 |
+
const struct {
|
| 154 |
+
TypeParam bits : 6;
|
| 155 |
+
} value{42};
|
| 156 |
+
auto comparison_stream = ComparisonStream();
|
| 157 |
+
comparison_stream << value.bits;
|
| 158 |
+
|
| 159 |
+
EXPECT_CALL(
|
| 160 |
+
test_sink,
|
| 161 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 162 |
+
TextMessage(Eq("42")),
|
| 163 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "42" })pb")))));
|
| 164 |
+
|
| 165 |
+
test_sink.StartCapturingLogs();
|
| 166 |
+
LOG(INFO) << value.bits;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
template <typename T>
|
| 170 |
+
class SignedIntLogFormatTest : public testing::Test {};
|
| 171 |
+
using SignedIntTypes =
|
| 172 |
+
Types<signed short, signed int, signed long, signed long long>; // NOLINT
|
| 173 |
+
TYPED_TEST_SUITE(SignedIntLogFormatTest, SignedIntTypes);
|
| 174 |
+
|
| 175 |
+
TYPED_TEST(SignedIntLogFormatTest, Positive) {
|
| 176 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 177 |
+
|
| 178 |
+
const TypeParam value = 224;
|
| 179 |
+
auto comparison_stream = ComparisonStream();
|
| 180 |
+
comparison_stream << value;
|
| 181 |
+
|
| 182 |
+
EXPECT_CALL(
|
| 183 |
+
test_sink,
|
| 184 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 185 |
+
TextMessage(Eq("224")),
|
| 186 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb")))));
|
| 187 |
+
|
| 188 |
+
test_sink.StartCapturingLogs();
|
| 189 |
+
LOG(INFO) << value;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
TYPED_TEST(SignedIntLogFormatTest, Negative) {
|
| 193 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 194 |
+
|
| 195 |
+
const TypeParam value = -112;
|
| 196 |
+
auto comparison_stream = ComparisonStream();
|
| 197 |
+
comparison_stream << value;
|
| 198 |
+
|
| 199 |
+
EXPECT_CALL(
|
| 200 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 201 |
+
TextMessage(Eq("-112")),
|
| 202 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 203 |
+
str: "-112"
|
| 204 |
+
})pb")))));
|
| 205 |
+
|
| 206 |
+
test_sink.StartCapturingLogs();
|
| 207 |
+
LOG(INFO) << value;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
TYPED_TEST(SignedIntLogFormatTest, BitfieldPositive) {
|
| 211 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 212 |
+
|
| 213 |
+
const struct {
|
| 214 |
+
TypeParam bits : 6;
|
| 215 |
+
} value{21};
|
| 216 |
+
auto comparison_stream = ComparisonStream();
|
| 217 |
+
comparison_stream << value.bits;
|
| 218 |
+
|
| 219 |
+
EXPECT_CALL(
|
| 220 |
+
test_sink,
|
| 221 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 222 |
+
TextMessage(Eq("21")),
|
| 223 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "21" })pb")))));
|
| 224 |
+
|
| 225 |
+
test_sink.StartCapturingLogs();
|
| 226 |
+
LOG(INFO) << value.bits;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
TYPED_TEST(SignedIntLogFormatTest, BitfieldNegative) {
|
| 230 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 231 |
+
|
| 232 |
+
const struct {
|
| 233 |
+
TypeParam bits : 6;
|
| 234 |
+
} value{-21};
|
| 235 |
+
auto comparison_stream = ComparisonStream();
|
| 236 |
+
comparison_stream << value.bits;
|
| 237 |
+
|
| 238 |
+
EXPECT_CALL(
|
| 239 |
+
test_sink,
|
| 240 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 241 |
+
TextMessage(Eq("-21")),
|
| 242 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "-21" })pb")))));
|
| 243 |
+
|
| 244 |
+
test_sink.StartCapturingLogs();
|
| 245 |
+
LOG(INFO) << value.bits;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
// Ignore these test cases on GCC due to "is too small to hold all values ..."
|
| 249 |
+
// warning.
|
| 250 |
+
#if !defined(__GNUC__) || defined(__clang__)
|
| 251 |
+
// The implementation may choose a signed or unsigned integer type to represent
|
| 252 |
+
// this enum, so it may be tested by either `UnsignedEnumLogFormatTest` or
|
| 253 |
+
// `SignedEnumLogFormatTest`.
|
| 254 |
+
enum MyUnsignedEnum {
|
| 255 |
+
MyUnsignedEnum_ZERO = 0,
|
| 256 |
+
MyUnsignedEnum_FORTY_TWO = 42,
|
| 257 |
+
MyUnsignedEnum_TWO_HUNDRED_TWENTY_FOUR = 224,
|
| 258 |
+
};
|
| 259 |
+
enum MyUnsignedIntEnum : unsigned int {
|
| 260 |
+
MyUnsignedIntEnum_ZERO = 0,
|
| 261 |
+
MyUnsignedIntEnum_FORTY_TWO = 42,
|
| 262 |
+
MyUnsignedIntEnum_TWO_HUNDRED_TWENTY_FOUR = 224,
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
template <typename T>
|
| 266 |
+
class UnsignedEnumLogFormatTest : public testing::Test {};
|
| 267 |
+
using UnsignedEnumTypes = std::conditional<
|
| 268 |
+
std::is_signed<std::underlying_type<MyUnsignedEnum>::type>::value,
|
| 269 |
+
Types<MyUnsignedIntEnum>, Types<MyUnsignedEnum, MyUnsignedIntEnum>>::type;
|
| 270 |
+
TYPED_TEST_SUITE(UnsignedEnumLogFormatTest, UnsignedEnumTypes);
|
| 271 |
+
|
| 272 |
+
TYPED_TEST(UnsignedEnumLogFormatTest, Positive) {
|
| 273 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 274 |
+
|
| 275 |
+
const TypeParam value = static_cast<TypeParam>(224);
|
| 276 |
+
auto comparison_stream = ComparisonStream();
|
| 277 |
+
comparison_stream << value;
|
| 278 |
+
|
| 279 |
+
EXPECT_CALL(
|
| 280 |
+
test_sink,
|
| 281 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 282 |
+
TextMessage(Eq("224")),
|
| 283 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb")))));
|
| 284 |
+
|
| 285 |
+
test_sink.StartCapturingLogs();
|
| 286 |
+
LOG(INFO) << value;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
TYPED_TEST(UnsignedEnumLogFormatTest, BitfieldPositive) {
|
| 290 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 291 |
+
|
| 292 |
+
const struct {
|
| 293 |
+
TypeParam bits : 6;
|
| 294 |
+
} value{static_cast<TypeParam>(42)};
|
| 295 |
+
auto comparison_stream = ComparisonStream();
|
| 296 |
+
comparison_stream << value.bits;
|
| 297 |
+
|
| 298 |
+
EXPECT_CALL(
|
| 299 |
+
test_sink,
|
| 300 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 301 |
+
TextMessage(Eq("42")),
|
| 302 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "42" })pb")))));
|
| 303 |
+
|
| 304 |
+
test_sink.StartCapturingLogs();
|
| 305 |
+
LOG(INFO) << value.bits;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
enum MySignedEnum {
|
| 309 |
+
MySignedEnum_NEGATIVE_ONE_HUNDRED_TWELVE = -112,
|
| 310 |
+
MySignedEnum_NEGATIVE_TWENTY_ONE = -21,
|
| 311 |
+
MySignedEnum_ZERO = 0,
|
| 312 |
+
MySignedEnum_TWENTY_ONE = 21,
|
| 313 |
+
MySignedEnum_TWO_HUNDRED_TWENTY_FOUR = 224,
|
| 314 |
+
};
|
| 315 |
+
enum MySignedIntEnum : signed int {
|
| 316 |
+
MySignedIntEnum_NEGATIVE_ONE_HUNDRED_TWELVE = -112,
|
| 317 |
+
MySignedIntEnum_NEGATIVE_TWENTY_ONE = -21,
|
| 318 |
+
MySignedIntEnum_ZERO = 0,
|
| 319 |
+
MySignedIntEnum_TWENTY_ONE = 21,
|
| 320 |
+
MySignedIntEnum_TWO_HUNDRED_TWENTY_FOUR = 224,
|
| 321 |
+
};
|
| 322 |
+
|
| 323 |
+
template <typename T>
|
| 324 |
+
class SignedEnumLogFormatTest : public testing::Test {};
|
| 325 |
+
using SignedEnumTypes = std::conditional<
|
| 326 |
+
std::is_signed<std::underlying_type<MyUnsignedEnum>::type>::value,
|
| 327 |
+
Types<MyUnsignedEnum, MySignedEnum, MySignedIntEnum>,
|
| 328 |
+
Types<MySignedEnum, MySignedIntEnum>>::type;
|
| 329 |
+
TYPED_TEST_SUITE(SignedEnumLogFormatTest, SignedEnumTypes);
|
| 330 |
+
|
| 331 |
+
TYPED_TEST(SignedEnumLogFormatTest, Positive) {
|
| 332 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 333 |
+
|
| 334 |
+
const TypeParam value = static_cast<TypeParam>(224);
|
| 335 |
+
auto comparison_stream = ComparisonStream();
|
| 336 |
+
comparison_stream << value;
|
| 337 |
+
|
| 338 |
+
EXPECT_CALL(
|
| 339 |
+
test_sink,
|
| 340 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 341 |
+
TextMessage(Eq("224")),
|
| 342 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb")))));
|
| 343 |
+
|
| 344 |
+
test_sink.StartCapturingLogs();
|
| 345 |
+
LOG(INFO) << value;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
TYPED_TEST(SignedEnumLogFormatTest, Negative) {
|
| 349 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 350 |
+
|
| 351 |
+
const TypeParam value = static_cast<TypeParam>(-112);
|
| 352 |
+
auto comparison_stream = ComparisonStream();
|
| 353 |
+
comparison_stream << value;
|
| 354 |
+
|
| 355 |
+
EXPECT_CALL(
|
| 356 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 357 |
+
TextMessage(Eq("-112")),
|
| 358 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 359 |
+
str: "-112"
|
| 360 |
+
})pb")))));
|
| 361 |
+
|
| 362 |
+
test_sink.StartCapturingLogs();
|
| 363 |
+
LOG(INFO) << value;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
TYPED_TEST(SignedEnumLogFormatTest, BitfieldPositive) {
|
| 367 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 368 |
+
|
| 369 |
+
const struct {
|
| 370 |
+
TypeParam bits : 6;
|
| 371 |
+
} value{static_cast<TypeParam>(21)};
|
| 372 |
+
auto comparison_stream = ComparisonStream();
|
| 373 |
+
comparison_stream << value.bits;
|
| 374 |
+
|
| 375 |
+
EXPECT_CALL(
|
| 376 |
+
test_sink,
|
| 377 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 378 |
+
TextMessage(Eq("21")),
|
| 379 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "21" })pb")))));
|
| 380 |
+
|
| 381 |
+
test_sink.StartCapturingLogs();
|
| 382 |
+
LOG(INFO) << value.bits;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
TYPED_TEST(SignedEnumLogFormatTest, BitfieldNegative) {
|
| 386 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 387 |
+
|
| 388 |
+
const struct {
|
| 389 |
+
TypeParam bits : 6;
|
| 390 |
+
} value{static_cast<TypeParam>(-21)};
|
| 391 |
+
auto comparison_stream = ComparisonStream();
|
| 392 |
+
comparison_stream << value.bits;
|
| 393 |
+
|
| 394 |
+
EXPECT_CALL(
|
| 395 |
+
test_sink,
|
| 396 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 397 |
+
TextMessage(Eq("-21")),
|
| 398 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "-21" })pb")))));
|
| 399 |
+
|
| 400 |
+
test_sink.StartCapturingLogs();
|
| 401 |
+
LOG(INFO) << value.bits;
|
| 402 |
+
}
|
| 403 |
+
#endif
|
| 404 |
+
|
| 405 |
+
TEST(FloatLogFormatTest, Positive) {
|
| 406 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 407 |
+
|
| 408 |
+
const float value = 6.02e23f;
|
| 409 |
+
auto comparison_stream = ComparisonStream();
|
| 410 |
+
comparison_stream << value;
|
| 411 |
+
|
| 412 |
+
EXPECT_CALL(test_sink,
|
| 413 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 414 |
+
TextMessage(Eq("6.02e+23")),
|
| 415 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 416 |
+
str: "6.02e+23"
|
| 417 |
+
})pb")))));
|
| 418 |
+
|
| 419 |
+
test_sink.StartCapturingLogs();
|
| 420 |
+
LOG(INFO) << value;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
TEST(FloatLogFormatTest, Negative) {
|
| 424 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 425 |
+
|
| 426 |
+
const float value = -6.02e23f;
|
| 427 |
+
auto comparison_stream = ComparisonStream();
|
| 428 |
+
comparison_stream << value;
|
| 429 |
+
|
| 430 |
+
EXPECT_CALL(test_sink,
|
| 431 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 432 |
+
TextMessage(Eq("-6.02e+23")),
|
| 433 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 434 |
+
str: "-6.02e+23"
|
| 435 |
+
})pb")))));
|
| 436 |
+
|
| 437 |
+
test_sink.StartCapturingLogs();
|
| 438 |
+
LOG(INFO) << value;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
TEST(FloatLogFormatTest, NegativeExponent) {
|
| 442 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 443 |
+
|
| 444 |
+
const float value = 6.02e-23f;
|
| 445 |
+
auto comparison_stream = ComparisonStream();
|
| 446 |
+
comparison_stream << value;
|
| 447 |
+
|
| 448 |
+
EXPECT_CALL(test_sink,
|
| 449 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 450 |
+
TextMessage(Eq("6.02e-23")),
|
| 451 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 452 |
+
str: "6.02e-23"
|
| 453 |
+
})pb")))));
|
| 454 |
+
|
| 455 |
+
test_sink.StartCapturingLogs();
|
| 456 |
+
LOG(INFO) << value;
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
TEST(DoubleLogFormatTest, Positive) {
|
| 460 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 461 |
+
|
| 462 |
+
const double value = 6.02e23;
|
| 463 |
+
auto comparison_stream = ComparisonStream();
|
| 464 |
+
comparison_stream << value;
|
| 465 |
+
|
| 466 |
+
EXPECT_CALL(test_sink,
|
| 467 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 468 |
+
TextMessage(Eq("6.02e+23")),
|
| 469 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 470 |
+
str: "6.02e+23"
|
| 471 |
+
})pb")))));
|
| 472 |
+
|
| 473 |
+
test_sink.StartCapturingLogs();
|
| 474 |
+
LOG(INFO) << value;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
TEST(DoubleLogFormatTest, Negative) {
|
| 478 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 479 |
+
|
| 480 |
+
const double value = -6.02e23;
|
| 481 |
+
auto comparison_stream = ComparisonStream();
|
| 482 |
+
comparison_stream << value;
|
| 483 |
+
|
| 484 |
+
EXPECT_CALL(test_sink,
|
| 485 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 486 |
+
TextMessage(Eq("-6.02e+23")),
|
| 487 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 488 |
+
str: "-6.02e+23"
|
| 489 |
+
})pb")))));
|
| 490 |
+
|
| 491 |
+
test_sink.StartCapturingLogs();
|
| 492 |
+
LOG(INFO) << value;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
TEST(DoubleLogFormatTest, NegativeExponent) {
|
| 496 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 497 |
+
|
| 498 |
+
const double value = 6.02e-23;
|
| 499 |
+
auto comparison_stream = ComparisonStream();
|
| 500 |
+
comparison_stream << value;
|
| 501 |
+
|
| 502 |
+
EXPECT_CALL(test_sink,
|
| 503 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 504 |
+
TextMessage(Eq("6.02e-23")),
|
| 505 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 506 |
+
str: "6.02e-23"
|
| 507 |
+
})pb")))));
|
| 508 |
+
|
| 509 |
+
test_sink.StartCapturingLogs();
|
| 510 |
+
LOG(INFO) << value;
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
template <typename T>
|
| 514 |
+
class FloatingPointLogFormatTest : public testing::Test {};
|
| 515 |
+
using FloatingPointTypes = Types<float, double>;
|
| 516 |
+
TYPED_TEST_SUITE(FloatingPointLogFormatTest, FloatingPointTypes);
|
| 517 |
+
|
| 518 |
+
TYPED_TEST(FloatingPointLogFormatTest, Zero) {
|
| 519 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 520 |
+
|
| 521 |
+
const TypeParam value = 0.0;
|
| 522 |
+
auto comparison_stream = ComparisonStream();
|
| 523 |
+
comparison_stream << value;
|
| 524 |
+
|
| 525 |
+
EXPECT_CALL(
|
| 526 |
+
test_sink,
|
| 527 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 528 |
+
TextMessage(Eq("0")),
|
| 529 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "0" })pb")))));
|
| 530 |
+
|
| 531 |
+
test_sink.StartCapturingLogs();
|
| 532 |
+
LOG(INFO) << value;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
TYPED_TEST(FloatingPointLogFormatTest, Integer) {
|
| 536 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 537 |
+
|
| 538 |
+
const TypeParam value = 1.0;
|
| 539 |
+
auto comparison_stream = ComparisonStream();
|
| 540 |
+
comparison_stream << value;
|
| 541 |
+
|
| 542 |
+
EXPECT_CALL(
|
| 543 |
+
test_sink,
|
| 544 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 545 |
+
TextMessage(Eq("1")),
|
| 546 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "1" })pb")))));
|
| 547 |
+
|
| 548 |
+
test_sink.StartCapturingLogs();
|
| 549 |
+
LOG(INFO) << value;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
TYPED_TEST(FloatingPointLogFormatTest, Infinity) {
|
| 553 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 554 |
+
|
| 555 |
+
const TypeParam value = std::numeric_limits<TypeParam>::infinity();
|
| 556 |
+
auto comparison_stream = ComparisonStream();
|
| 557 |
+
comparison_stream << value;
|
| 558 |
+
|
| 559 |
+
EXPECT_CALL(
|
| 560 |
+
test_sink,
|
| 561 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 562 |
+
TextMessage(AnyOf(Eq("inf"), Eq("Inf"))),
|
| 563 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "inf" })pb")))));
|
| 564 |
+
|
| 565 |
+
test_sink.StartCapturingLogs();
|
| 566 |
+
LOG(INFO) << value;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
TYPED_TEST(FloatingPointLogFormatTest, NegativeInfinity) {
|
| 570 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 571 |
+
|
| 572 |
+
const TypeParam value = -std::numeric_limits<TypeParam>::infinity();
|
| 573 |
+
auto comparison_stream = ComparisonStream();
|
| 574 |
+
comparison_stream << value;
|
| 575 |
+
|
| 576 |
+
EXPECT_CALL(
|
| 577 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 578 |
+
TextMessage(AnyOf(Eq("-inf"), Eq("-Inf"))),
|
| 579 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 580 |
+
str: "-inf"
|
| 581 |
+
})pb")))));
|
| 582 |
+
|
| 583 |
+
test_sink.StartCapturingLogs();
|
| 584 |
+
LOG(INFO) << value;
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
TYPED_TEST(FloatingPointLogFormatTest, NaN) {
|
| 588 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 589 |
+
|
| 590 |
+
const TypeParam value = std::numeric_limits<TypeParam>::quiet_NaN();
|
| 591 |
+
auto comparison_stream = ComparisonStream();
|
| 592 |
+
comparison_stream << value;
|
| 593 |
+
|
| 594 |
+
EXPECT_CALL(
|
| 595 |
+
test_sink,
|
| 596 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 597 |
+
TextMessage(AnyOf(Eq("nan"), Eq("NaN"))),
|
| 598 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "nan" })pb")))));
|
| 599 |
+
test_sink.StartCapturingLogs();
|
| 600 |
+
LOG(INFO) << value;
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
TYPED_TEST(FloatingPointLogFormatTest, NegativeNaN) {
|
| 604 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 605 |
+
|
| 606 |
+
const TypeParam value =
|
| 607 |
+
std::copysign(std::numeric_limits<TypeParam>::quiet_NaN(), -1.0);
|
| 608 |
+
auto comparison_stream = ComparisonStream();
|
| 609 |
+
comparison_stream << value;
|
| 610 |
+
|
| 611 |
+
EXPECT_CALL(
|
| 612 |
+
test_sink,
|
| 613 |
+
Send(AllOf(
|
| 614 |
+
TextMessage(MatchesOstream(comparison_stream)),
|
| 615 |
+
TextMessage(AnyOf(Eq("-nan"), Eq("nan"), Eq("NaN"), Eq("-nan(ind)"))),
|
| 616 |
+
ENCODED_MESSAGE(
|
| 617 |
+
AnyOf(EqualsProto(R"pb(value { str: "-nan" })pb"),
|
| 618 |
+
EqualsProto(R"pb(value { str: "nan" })pb"),
|
| 619 |
+
EqualsProto(R"pb(value { str: "-nan(ind)" })pb"))))));
|
| 620 |
+
test_sink.StartCapturingLogs();
|
| 621 |
+
LOG(INFO) << value;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
template <typename T>
|
| 625 |
+
class VoidPtrLogFormatTest : public testing::Test {};
|
| 626 |
+
using VoidPtrTypes = Types<void *, const void *>;
|
| 627 |
+
TYPED_TEST_SUITE(VoidPtrLogFormatTest, VoidPtrTypes);
|
| 628 |
+
|
| 629 |
+
TYPED_TEST(VoidPtrLogFormatTest, Null) {
|
| 630 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 631 |
+
|
| 632 |
+
const TypeParam value = nullptr;
|
| 633 |
+
auto comparison_stream = ComparisonStream();
|
| 634 |
+
comparison_stream << value;
|
| 635 |
+
|
| 636 |
+
EXPECT_CALL(
|
| 637 |
+
test_sink,
|
| 638 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 639 |
+
TextMessage(AnyOf(Eq("(nil)"), Eq("0"), Eq("0x0"),
|
| 640 |
+
Eq("00000000"), Eq("0000000000000000"))))));
|
| 641 |
+
|
| 642 |
+
test_sink.StartCapturingLogs();
|
| 643 |
+
LOG(INFO) << value;
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
TYPED_TEST(VoidPtrLogFormatTest, NonNull) {
|
| 647 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 648 |
+
|
| 649 |
+
const TypeParam value = reinterpret_cast<TypeParam>(0xdeadbeefULL);
|
| 650 |
+
auto comparison_stream = ComparisonStream();
|
| 651 |
+
comparison_stream << value;
|
| 652 |
+
|
| 653 |
+
EXPECT_CALL(
|
| 654 |
+
test_sink,
|
| 655 |
+
Send(AllOf(
|
| 656 |
+
TextMessage(MatchesOstream(comparison_stream)),
|
| 657 |
+
TextMessage(
|
| 658 |
+
AnyOf(Eq("0xdeadbeef"), Eq("DEADBEEF"), Eq("00000000DEADBEEF"))),
|
| 659 |
+
ENCODED_MESSAGE(AnyOf(
|
| 660 |
+
EqualsProto(R"pb(value { str: "0xdeadbeef" })pb"),
|
| 661 |
+
EqualsProto(R"pb(value { str: "00000000DEADBEEF" })pb"))))));
|
| 662 |
+
|
| 663 |
+
test_sink.StartCapturingLogs();
|
| 664 |
+
LOG(INFO) << value;
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
template <typename T>
|
| 668 |
+
class VolatilePtrLogFormatTest : public testing::Test {};
|
| 669 |
+
using VolatilePtrTypes =
|
| 670 |
+
Types<volatile void*, const volatile void*, volatile char*,
|
| 671 |
+
const volatile char*, volatile signed char*,
|
| 672 |
+
const volatile signed char*, volatile unsigned char*,
|
| 673 |
+
const volatile unsigned char*>;
|
| 674 |
+
TYPED_TEST_SUITE(VolatilePtrLogFormatTest, VolatilePtrTypes);
|
| 675 |
+
|
| 676 |
+
TYPED_TEST(VolatilePtrLogFormatTest, Null) {
|
| 677 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 678 |
+
|
| 679 |
+
const TypeParam value = nullptr;
|
| 680 |
+
auto comparison_stream = ComparisonStream();
|
| 681 |
+
comparison_stream << value;
|
| 682 |
+
|
| 683 |
+
EXPECT_CALL(
|
| 684 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 685 |
+
TextMessage(Eq("false")),
|
| 686 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 687 |
+
str: "false"
|
| 688 |
+
})pb")))));
|
| 689 |
+
|
| 690 |
+
test_sink.StartCapturingLogs();
|
| 691 |
+
LOG(INFO) << value;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
TYPED_TEST(VolatilePtrLogFormatTest, NonNull) {
|
| 695 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 696 |
+
|
| 697 |
+
const TypeParam value = reinterpret_cast<TypeParam>(0xdeadbeefLL);
|
| 698 |
+
auto comparison_stream = ComparisonStream();
|
| 699 |
+
comparison_stream << value;
|
| 700 |
+
|
| 701 |
+
EXPECT_CALL(
|
| 702 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 703 |
+
TextMessage(Eq("true")),
|
| 704 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 705 |
+
str: "true"
|
| 706 |
+
})pb")))));
|
| 707 |
+
|
| 708 |
+
test_sink.StartCapturingLogs();
|
| 709 |
+
LOG(INFO) << value;
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
template <typename T>
|
| 713 |
+
class CharPtrLogFormatTest : public testing::Test {};
|
| 714 |
+
using CharPtrTypes = Types<char, const char, signed char, const signed char,
|
| 715 |
+
unsigned char, const unsigned char>;
|
| 716 |
+
TYPED_TEST_SUITE(CharPtrLogFormatTest, CharPtrTypes);
|
| 717 |
+
|
| 718 |
+
TYPED_TEST(CharPtrLogFormatTest, Null) {
|
| 719 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 720 |
+
|
| 721 |
+
// Streaming `([cv] char *)nullptr` into a `std::ostream` is UB, and some C++
|
| 722 |
+
// standard library implementations choose to crash. We take measures to log
|
| 723 |
+
// something useful instead of crashing, even when that differs from the
|
| 724 |
+
// standard library in use (and thus the behavior of `std::ostream`).
|
| 725 |
+
TypeParam* const value = nullptr;
|
| 726 |
+
|
| 727 |
+
EXPECT_CALL(
|
| 728 |
+
test_sink,
|
| 729 |
+
Send(AllOf(
|
| 730 |
+
// `MatchesOstream` deliberately omitted since we deliberately differ.
|
| 731 |
+
TextMessage(Eq("(null)")),
|
| 732 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(null)" })pb")))));
|
| 733 |
+
|
| 734 |
+
test_sink.StartCapturingLogs();
|
| 735 |
+
LOG(INFO) << value;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
TYPED_TEST(CharPtrLogFormatTest, NonNull) {
|
| 739 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 740 |
+
|
| 741 |
+
TypeParam data[] = {'v', 'a', 'l', 'u', 'e', '\0'};
|
| 742 |
+
TypeParam* const value = data;
|
| 743 |
+
auto comparison_stream = ComparisonStream();
|
| 744 |
+
comparison_stream << value;
|
| 745 |
+
|
| 746 |
+
EXPECT_CALL(
|
| 747 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 748 |
+
TextMessage(Eq("value")),
|
| 749 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 750 |
+
str: "value"
|
| 751 |
+
})pb")))));
|
| 752 |
+
|
| 753 |
+
test_sink.StartCapturingLogs();
|
| 754 |
+
LOG(INFO) << value;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
TEST(BoolLogFormatTest, True) {
|
| 758 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 759 |
+
|
| 760 |
+
const bool value = true;
|
| 761 |
+
auto comparison_stream = ComparisonStream();
|
| 762 |
+
comparison_stream << value;
|
| 763 |
+
|
| 764 |
+
EXPECT_CALL(
|
| 765 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 766 |
+
TextMessage(Eq("true")),
|
| 767 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 768 |
+
str: "true"
|
| 769 |
+
})pb")))));
|
| 770 |
+
|
| 771 |
+
test_sink.StartCapturingLogs();
|
| 772 |
+
LOG(INFO) << value;
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
TEST(BoolLogFormatTest, False) {
|
| 776 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 777 |
+
|
| 778 |
+
const bool value = false;
|
| 779 |
+
auto comparison_stream = ComparisonStream();
|
| 780 |
+
comparison_stream << value;
|
| 781 |
+
|
| 782 |
+
EXPECT_CALL(
|
| 783 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 784 |
+
TextMessage(Eq("false")),
|
| 785 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 786 |
+
str: "false"
|
| 787 |
+
})pb")))));
|
| 788 |
+
|
| 789 |
+
test_sink.StartCapturingLogs();
|
| 790 |
+
LOG(INFO) << value;
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
TEST(LogFormatTest, StringLiteral) {
|
| 794 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 795 |
+
|
| 796 |
+
auto comparison_stream = ComparisonStream();
|
| 797 |
+
comparison_stream << "value";
|
| 798 |
+
|
| 799 |
+
EXPECT_CALL(test_sink,
|
| 800 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 801 |
+
TextMessage(Eq("value")),
|
| 802 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 803 |
+
literal: "value"
|
| 804 |
+
})pb")))));
|
| 805 |
+
|
| 806 |
+
test_sink.StartCapturingLogs();
|
| 807 |
+
LOG(INFO) << "value";
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
TEST(LogFormatTest, CharArray) {
|
| 811 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 812 |
+
|
| 813 |
+
char value[] = "value";
|
| 814 |
+
auto comparison_stream = ComparisonStream();
|
| 815 |
+
comparison_stream << value;
|
| 816 |
+
|
| 817 |
+
EXPECT_CALL(
|
| 818 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 819 |
+
TextMessage(Eq("value")),
|
| 820 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 821 |
+
str: "value"
|
| 822 |
+
})pb")))));
|
| 823 |
+
|
| 824 |
+
test_sink.StartCapturingLogs();
|
| 825 |
+
LOG(INFO) << value;
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
class CustomClass {};
|
| 829 |
+
std::ostream& operator<<(std::ostream& os, const CustomClass&) {
|
| 830 |
+
return os << "CustomClass{}";
|
| 831 |
+
}
|
| 832 |
+
|
| 833 |
+
TEST(LogFormatTest, Custom) {
|
| 834 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 835 |
+
|
| 836 |
+
CustomClass value;
|
| 837 |
+
auto comparison_stream = ComparisonStream();
|
| 838 |
+
comparison_stream << value;
|
| 839 |
+
|
| 840 |
+
EXPECT_CALL(test_sink,
|
| 841 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 842 |
+
TextMessage(Eq("CustomClass{}")),
|
| 843 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 844 |
+
str: "CustomClass{}"
|
| 845 |
+
})pb")))));
|
| 846 |
+
test_sink.StartCapturingLogs();
|
| 847 |
+
LOG(INFO) << value;
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
class CustomClassNonCopyable {
|
| 851 |
+
public:
|
| 852 |
+
CustomClassNonCopyable() = default;
|
| 853 |
+
CustomClassNonCopyable(const CustomClassNonCopyable&) = delete;
|
| 854 |
+
CustomClassNonCopyable& operator=(const CustomClassNonCopyable&) = delete;
|
| 855 |
+
};
|
| 856 |
+
std::ostream& operator<<(std::ostream& os, const CustomClassNonCopyable&) {
|
| 857 |
+
return os << "CustomClassNonCopyable{}";
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
TEST(LogFormatTest, CustomNonCopyable) {
|
| 861 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 862 |
+
|
| 863 |
+
CustomClassNonCopyable value;
|
| 864 |
+
auto comparison_stream = ComparisonStream();
|
| 865 |
+
comparison_stream << value;
|
| 866 |
+
|
| 867 |
+
EXPECT_CALL(
|
| 868 |
+
test_sink,
|
| 869 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 870 |
+
TextMessage(Eq("CustomClassNonCopyable{}")),
|
| 871 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 872 |
+
R"pb(value { str: "CustomClassNonCopyable{}" })pb")))));
|
| 873 |
+
|
| 874 |
+
test_sink.StartCapturingLogs();
|
| 875 |
+
LOG(INFO) << value;
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
struct Point {
|
| 879 |
+
template <typename Sink>
|
| 880 |
+
friend void AbslStringify(Sink& sink, const Point& p) {
|
| 881 |
+
absl::Format(&sink, "(%d, %d)", p.x, p.y);
|
| 882 |
+
}
|
| 883 |
+
|
| 884 |
+
int x = 10;
|
| 885 |
+
int y = 20;
|
| 886 |
+
};
|
| 887 |
+
|
| 888 |
+
TEST(LogFormatTest, AbslStringifyExample) {
|
| 889 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 890 |
+
|
| 891 |
+
Point p;
|
| 892 |
+
|
| 893 |
+
EXPECT_CALL(
|
| 894 |
+
test_sink,
|
| 895 |
+
Send(AllOf(
|
| 896 |
+
TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))),
|
| 897 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(10, 20)" })pb")))));
|
| 898 |
+
|
| 899 |
+
test_sink.StartCapturingLogs();
|
| 900 |
+
LOG(INFO) << p;
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
struct PointWithAbslStringifiyAndOstream {
|
| 904 |
+
template <typename Sink>
|
| 905 |
+
friend void AbslStringify(Sink& sink,
|
| 906 |
+
const PointWithAbslStringifiyAndOstream& p) {
|
| 907 |
+
absl::Format(&sink, "(%d, %d)", p.x, p.y);
|
| 908 |
+
}
|
| 909 |
+
|
| 910 |
+
int x = 10;
|
| 911 |
+
int y = 20;
|
| 912 |
+
};
|
| 913 |
+
|
| 914 |
+
ABSL_ATTRIBUTE_UNUSED std::ostream& operator<<(
|
| 915 |
+
std::ostream& os, const PointWithAbslStringifiyAndOstream&) {
|
| 916 |
+
return os << "Default to AbslStringify()";
|
| 917 |
+
}
|
| 918 |
+
|
| 919 |
+
TEST(LogFormatTest, CustomWithAbslStringifyAndOstream) {
|
| 920 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 921 |
+
|
| 922 |
+
PointWithAbslStringifiyAndOstream p;
|
| 923 |
+
|
| 924 |
+
EXPECT_CALL(
|
| 925 |
+
test_sink,
|
| 926 |
+
Send(AllOf(
|
| 927 |
+
TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))),
|
| 928 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(10, 20)" })pb")))));
|
| 929 |
+
|
| 930 |
+
test_sink.StartCapturingLogs();
|
| 931 |
+
LOG(INFO) << p;
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
struct PointStreamsNothing {
|
| 935 |
+
template <typename Sink>
|
| 936 |
+
friend void AbslStringify(Sink&, const PointStreamsNothing&) {}
|
| 937 |
+
|
| 938 |
+
int x = 10;
|
| 939 |
+
int y = 20;
|
| 940 |
+
};
|
| 941 |
+
|
| 942 |
+
TEST(LogFormatTest, AbslStringifyStreamsNothing) {
|
| 943 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 944 |
+
|
| 945 |
+
PointStreamsNothing p;
|
| 946 |
+
|
| 947 |
+
EXPECT_CALL(
|
| 948 |
+
test_sink,
|
| 949 |
+
Send(AllOf(TextMessage(Eq("77")), TextMessage(Eq(absl::StrCat(p, 77))),
|
| 950 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" })pb")))));
|
| 951 |
+
|
| 952 |
+
test_sink.StartCapturingLogs();
|
| 953 |
+
LOG(INFO) << p << 77;
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
struct PointMultipleAppend {
|
| 957 |
+
template <typename Sink>
|
| 958 |
+
friend void AbslStringify(Sink& sink, const PointMultipleAppend& p) {
|
| 959 |
+
sink.Append("(");
|
| 960 |
+
sink.Append(absl::StrCat(p.x, ", ", p.y, ")"));
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
int x = 10;
|
| 964 |
+
int y = 20;
|
| 965 |
+
};
|
| 966 |
+
|
| 967 |
+
TEST(LogFormatTest, AbslStringifyMultipleAppend) {
|
| 968 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 969 |
+
|
| 970 |
+
PointMultipleAppend p;
|
| 971 |
+
|
| 972 |
+
EXPECT_CALL(
|
| 973 |
+
test_sink,
|
| 974 |
+
Send(AllOf(
|
| 975 |
+
TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))),
|
| 976 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(" }
|
| 977 |
+
value { str: "10, 20)" })pb")))));
|
| 978 |
+
|
| 979 |
+
test_sink.StartCapturingLogs();
|
| 980 |
+
LOG(INFO) << p;
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
TEST(ManipulatorLogFormatTest, BoolAlphaTrue) {
|
| 984 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 985 |
+
|
| 986 |
+
const bool value = true;
|
| 987 |
+
auto comparison_stream = ComparisonStream();
|
| 988 |
+
comparison_stream << std::noboolalpha << value << " " //
|
| 989 |
+
<< std::boolalpha << value << " " //
|
| 990 |
+
<< std::noboolalpha << value;
|
| 991 |
+
|
| 992 |
+
EXPECT_CALL(test_sink,
|
| 993 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 994 |
+
TextMessage(Eq("1 true 1")),
|
| 995 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 996 |
+
R"pb(value { str: "1" }
|
| 997 |
+
value { literal: " " }
|
| 998 |
+
value { str: "true" }
|
| 999 |
+
value { literal: " " }
|
| 1000 |
+
value { str: "1" })pb")))));
|
| 1001 |
+
|
| 1002 |
+
test_sink.StartCapturingLogs();
|
| 1003 |
+
LOG(INFO) << std::noboolalpha << value << " " //
|
| 1004 |
+
<< std::boolalpha << value << " " //
|
| 1005 |
+
<< std::noboolalpha << value;
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
TEST(ManipulatorLogFormatTest, BoolAlphaFalse) {
|
| 1009 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1010 |
+
|
| 1011 |
+
const bool value = false;
|
| 1012 |
+
auto comparison_stream = ComparisonStream();
|
| 1013 |
+
comparison_stream << std::noboolalpha << value << " " //
|
| 1014 |
+
<< std::boolalpha << value << " " //
|
| 1015 |
+
<< std::noboolalpha << value;
|
| 1016 |
+
|
| 1017 |
+
EXPECT_CALL(test_sink,
|
| 1018 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1019 |
+
TextMessage(Eq("0 false 0")),
|
| 1020 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 1021 |
+
R"pb(value { str: "0" }
|
| 1022 |
+
value { literal: " " }
|
| 1023 |
+
value { str: "false" }
|
| 1024 |
+
value { literal: " " }
|
| 1025 |
+
value { str: "0" })pb")))));
|
| 1026 |
+
|
| 1027 |
+
test_sink.StartCapturingLogs();
|
| 1028 |
+
LOG(INFO) << std::noboolalpha << value << " " //
|
| 1029 |
+
<< std::boolalpha << value << " " //
|
| 1030 |
+
<< std::noboolalpha << value;
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
TEST(ManipulatorLogFormatTest, ShowPoint) {
|
| 1034 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1035 |
+
|
| 1036 |
+
const double value = 77.0;
|
| 1037 |
+
auto comparison_stream = ComparisonStream();
|
| 1038 |
+
comparison_stream << std::noshowpoint << value << " " //
|
| 1039 |
+
<< std::showpoint << value << " " //
|
| 1040 |
+
<< std::noshowpoint << value;
|
| 1041 |
+
|
| 1042 |
+
EXPECT_CALL(
|
| 1043 |
+
test_sink,
|
| 1044 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1045 |
+
TextMessage(Eq("77 77.0000 77")),
|
| 1046 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" }
|
| 1047 |
+
value { literal: " " }
|
| 1048 |
+
value { str: "77.0000" }
|
| 1049 |
+
value { literal: " " }
|
| 1050 |
+
value { str: "77" })pb")))));
|
| 1051 |
+
|
| 1052 |
+
test_sink.StartCapturingLogs();
|
| 1053 |
+
LOG(INFO) << std::noshowpoint << value << " " //
|
| 1054 |
+
<< std::showpoint << value << " " //
|
| 1055 |
+
<< std::noshowpoint << value;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
TEST(ManipulatorLogFormatTest, ShowPos) {
|
| 1059 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1060 |
+
|
| 1061 |
+
const int value = 77;
|
| 1062 |
+
auto comparison_stream = ComparisonStream();
|
| 1063 |
+
comparison_stream << std::noshowpos << value << " " //
|
| 1064 |
+
<< std::showpos << value << " " //
|
| 1065 |
+
<< std::noshowpos << value;
|
| 1066 |
+
|
| 1067 |
+
EXPECT_CALL(
|
| 1068 |
+
test_sink,
|
| 1069 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1070 |
+
TextMessage(Eq("77 +77 77")),
|
| 1071 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" }
|
| 1072 |
+
value { literal: " " }
|
| 1073 |
+
value { str: "+77" }
|
| 1074 |
+
value { literal: " " }
|
| 1075 |
+
value { str: "77" })pb")))));
|
| 1076 |
+
|
| 1077 |
+
test_sink.StartCapturingLogs();
|
| 1078 |
+
LOG(INFO) << std::noshowpos << value << " " //
|
| 1079 |
+
<< std::showpos << value << " " //
|
| 1080 |
+
<< std::noshowpos << value;
|
| 1081 |
+
}
|
| 1082 |
+
|
| 1083 |
+
TEST(ManipulatorLogFormatTest, UppercaseFloat) {
|
| 1084 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1085 |
+
|
| 1086 |
+
const double value = 7.7e7;
|
| 1087 |
+
auto comparison_stream = ComparisonStream();
|
| 1088 |
+
comparison_stream << std::nouppercase << value << " " //
|
| 1089 |
+
<< std::uppercase << value << " " //
|
| 1090 |
+
<< std::nouppercase << value;
|
| 1091 |
+
|
| 1092 |
+
EXPECT_CALL(test_sink,
|
| 1093 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1094 |
+
TextMessage(Eq("7.7e+07 7.7E+07 7.7e+07")),
|
| 1095 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 1096 |
+
R"pb(value { str: "7.7e+07" }
|
| 1097 |
+
value { literal: " " }
|
| 1098 |
+
value { str: "7.7E+07" }
|
| 1099 |
+
value { literal: " " }
|
| 1100 |
+
value { str: "7.7e+07" })pb")))));
|
| 1101 |
+
|
| 1102 |
+
test_sink.StartCapturingLogs();
|
| 1103 |
+
LOG(INFO) << std::nouppercase << value << " " //
|
| 1104 |
+
<< std::uppercase << value << " " //
|
| 1105 |
+
<< std::nouppercase << value;
|
| 1106 |
+
}
|
| 1107 |
+
|
| 1108 |
+
TEST(ManipulatorLogFormatTest, Hex) {
|
| 1109 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1110 |
+
|
| 1111 |
+
const int value = 0x77;
|
| 1112 |
+
auto comparison_stream = ComparisonStream();
|
| 1113 |
+
comparison_stream << std::hex << value;
|
| 1114 |
+
|
| 1115 |
+
EXPECT_CALL(
|
| 1116 |
+
test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1117 |
+
TextMessage(Eq("0x77")),
|
| 1118 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1119 |
+
str: "0x77"
|
| 1120 |
+
})pb")))));
|
| 1121 |
+
test_sink.StartCapturingLogs();
|
| 1122 |
+
LOG(INFO) << std::hex << value;
|
| 1123 |
+
}
|
| 1124 |
+
|
| 1125 |
+
TEST(ManipulatorLogFormatTest, Oct) {
|
| 1126 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1127 |
+
|
| 1128 |
+
const int value = 077;
|
| 1129 |
+
auto comparison_stream = ComparisonStream();
|
| 1130 |
+
comparison_stream << std::oct << value;
|
| 1131 |
+
|
| 1132 |
+
EXPECT_CALL(
|
| 1133 |
+
test_sink,
|
| 1134 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1135 |
+
TextMessage(Eq("077")),
|
| 1136 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "077" })pb")))));
|
| 1137 |
+
|
| 1138 |
+
test_sink.StartCapturingLogs();
|
| 1139 |
+
LOG(INFO) << std::oct << value;
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
TEST(ManipulatorLogFormatTest, Dec) {
|
| 1143 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1144 |
+
|
| 1145 |
+
const int value = 77;
|
| 1146 |
+
auto comparison_stream = ComparisonStream();
|
| 1147 |
+
comparison_stream << std::hex << std::dec << value;
|
| 1148 |
+
|
| 1149 |
+
EXPECT_CALL(
|
| 1150 |
+
test_sink,
|
| 1151 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1152 |
+
TextMessage(Eq("77")),
|
| 1153 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" })pb")))));
|
| 1154 |
+
|
| 1155 |
+
test_sink.StartCapturingLogs();
|
| 1156 |
+
LOG(INFO) << std::hex << std::dec << value;
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
TEST(ManipulatorLogFormatTest, ShowbaseHex) {
|
| 1160 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1161 |
+
|
| 1162 |
+
const int value = 0x77;
|
| 1163 |
+
auto comparison_stream = ComparisonStream();
|
| 1164 |
+
comparison_stream << std::hex //
|
| 1165 |
+
<< std::noshowbase << value << " " //
|
| 1166 |
+
<< std::showbase << value << " " //
|
| 1167 |
+
<< std::noshowbase << value;
|
| 1168 |
+
|
| 1169 |
+
EXPECT_CALL(
|
| 1170 |
+
test_sink,
|
| 1171 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1172 |
+
TextMessage(Eq("77 0x77 77")),
|
| 1173 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" }
|
| 1174 |
+
value { literal: " " }
|
| 1175 |
+
value { str: "0x77" }
|
| 1176 |
+
value { literal: " " }
|
| 1177 |
+
value { str: "77" })pb")))));
|
| 1178 |
+
|
| 1179 |
+
test_sink.StartCapturingLogs();
|
| 1180 |
+
LOG(INFO) << std::hex //
|
| 1181 |
+
<< std::noshowbase << value << " " //
|
| 1182 |
+
<< std::showbase << value << " " //
|
| 1183 |
+
<< std::noshowbase << value;
|
| 1184 |
+
}
|
| 1185 |
+
|
| 1186 |
+
TEST(ManipulatorLogFormatTest, ShowbaseOct) {
|
| 1187 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1188 |
+
|
| 1189 |
+
const int value = 077;
|
| 1190 |
+
auto comparison_stream = ComparisonStream();
|
| 1191 |
+
comparison_stream << std::oct //
|
| 1192 |
+
<< std::noshowbase << value << " " //
|
| 1193 |
+
<< std::showbase << value << " " //
|
| 1194 |
+
<< std::noshowbase << value;
|
| 1195 |
+
|
| 1196 |
+
EXPECT_CALL(
|
| 1197 |
+
test_sink,
|
| 1198 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1199 |
+
TextMessage(Eq("77 077 77")),
|
| 1200 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" }
|
| 1201 |
+
value { literal: " " }
|
| 1202 |
+
value { str: "077" }
|
| 1203 |
+
value { literal: " " }
|
| 1204 |
+
value { str: "77" })pb")))));
|
| 1205 |
+
|
| 1206 |
+
test_sink.StartCapturingLogs();
|
| 1207 |
+
LOG(INFO) << std::oct //
|
| 1208 |
+
<< std::noshowbase << value << " " //
|
| 1209 |
+
<< std::showbase << value << " " //
|
| 1210 |
+
<< std::noshowbase << value;
|
| 1211 |
+
}
|
| 1212 |
+
|
| 1213 |
+
TEST(ManipulatorLogFormatTest, UppercaseHex) {
|
| 1214 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1215 |
+
|
| 1216 |
+
const int value = 0xbeef;
|
| 1217 |
+
auto comparison_stream = ComparisonStream();
|
| 1218 |
+
comparison_stream //
|
| 1219 |
+
<< std::hex //
|
| 1220 |
+
<< std::nouppercase << value << " " //
|
| 1221 |
+
<< std::uppercase << value << " " //
|
| 1222 |
+
<< std::nouppercase << value;
|
| 1223 |
+
|
| 1224 |
+
EXPECT_CALL(test_sink,
|
| 1225 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1226 |
+
TextMessage(Eq("0xbeef 0XBEEF 0xbeef")),
|
| 1227 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 1228 |
+
R"pb(value { str: "0xbeef" }
|
| 1229 |
+
value { literal: " " }
|
| 1230 |
+
value { str: "0XBEEF" }
|
| 1231 |
+
value { literal: " " }
|
| 1232 |
+
value { str: "0xbeef" })pb")))));
|
| 1233 |
+
|
| 1234 |
+
test_sink.StartCapturingLogs();
|
| 1235 |
+
LOG(INFO) << std::hex //
|
| 1236 |
+
<< std::nouppercase << value << " " //
|
| 1237 |
+
<< std::uppercase << value << " " //
|
| 1238 |
+
<< std::nouppercase << value;
|
| 1239 |
+
}
|
| 1240 |
+
|
| 1241 |
+
TEST(ManipulatorLogFormatTest, FixedFloat) {
|
| 1242 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1243 |
+
|
| 1244 |
+
const double value = 7.7e7;
|
| 1245 |
+
auto comparison_stream = ComparisonStream();
|
| 1246 |
+
comparison_stream << std::fixed << value;
|
| 1247 |
+
|
| 1248 |
+
EXPECT_CALL(
|
| 1249 |
+
test_sink,
|
| 1250 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1251 |
+
TextMessage(Eq("77000000.000000")),
|
| 1252 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1253 |
+
str: "77000000.000000"
|
| 1254 |
+
})pb")))));
|
| 1255 |
+
|
| 1256 |
+
test_sink.StartCapturingLogs();
|
| 1257 |
+
LOG(INFO) << std::fixed << value;
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
TEST(ManipulatorLogFormatTest, ScientificFloat) {
|
| 1261 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1262 |
+
|
| 1263 |
+
const double value = 7.7e7;
|
| 1264 |
+
auto comparison_stream = ComparisonStream();
|
| 1265 |
+
comparison_stream << std::scientific << value;
|
| 1266 |
+
|
| 1267 |
+
EXPECT_CALL(test_sink,
|
| 1268 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1269 |
+
TextMessage(Eq("7.700000e+07")),
|
| 1270 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1271 |
+
str: "7.700000e+07"
|
| 1272 |
+
})pb")))));
|
| 1273 |
+
|
| 1274 |
+
test_sink.StartCapturingLogs();
|
| 1275 |
+
LOG(INFO) << std::scientific << value;
|
| 1276 |
+
}
|
| 1277 |
+
|
| 1278 |
+
#if defined(__BIONIC__) && (!defined(__ANDROID_API__) || __ANDROID_API__ < 22)
|
| 1279 |
+
// Bionic doesn't support `%a` until API 22, so this prints 'a' even if the
|
| 1280 |
+
// C++ standard library implements it correctly (by forwarding to printf).
|
| 1281 |
+
#elif defined(__GLIBCXX__) && __cplusplus < 201402L
|
| 1282 |
+
// libstdc++ shipped C++11 support without `std::hexfloat`.
|
| 1283 |
+
#else
|
| 1284 |
+
TEST(ManipulatorLogFormatTest, FixedAndScientificFloat) {
|
| 1285 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1286 |
+
|
| 1287 |
+
const double value = 7.7e7;
|
| 1288 |
+
auto comparison_stream = ComparisonStream();
|
| 1289 |
+
comparison_stream << std::setiosflags(std::ios_base::scientific |
|
| 1290 |
+
std::ios_base::fixed)
|
| 1291 |
+
<< value;
|
| 1292 |
+
|
| 1293 |
+
EXPECT_CALL(
|
| 1294 |
+
test_sink,
|
| 1295 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1296 |
+
TextMessage(AnyOf(Eq("0x1.25bb50p+26"), Eq("0x1.25bb5p+26"),
|
| 1297 |
+
Eq("0x1.25bb500000000p+26"))),
|
| 1298 |
+
ENCODED_MESSAGE(
|
| 1299 |
+
AnyOf(EqualsProto(R"pb(value { str: "0x1.25bb5p+26" })pb"),
|
| 1300 |
+
EqualsProto(R"pb(value {
|
| 1301 |
+
str: "0x1.25bb500000000p+26"
|
| 1302 |
+
})pb"))))));
|
| 1303 |
+
|
| 1304 |
+
test_sink.StartCapturingLogs();
|
| 1305 |
+
|
| 1306 |
+
// This combination should mean the same thing as `std::hexfloat`.
|
| 1307 |
+
LOG(INFO) << std::setiosflags(std::ios_base::scientific |
|
| 1308 |
+
std::ios_base::fixed)
|
| 1309 |
+
<< value;
|
| 1310 |
+
}
|
| 1311 |
+
#endif
|
| 1312 |
+
|
| 1313 |
+
#if defined(__BIONIC__) && (!defined(__ANDROID_API__) || __ANDROID_API__ < 22)
|
| 1314 |
+
// Bionic doesn't support `%a` until API 22, so this prints 'a' even if the C++
|
| 1315 |
+
// standard library supports `std::hexfloat` (by forwarding to printf).
|
| 1316 |
+
#elif defined(__GLIBCXX__) && __cplusplus < 201402L
|
| 1317 |
+
// libstdc++ shipped C++11 support without `std::hexfloat`.
|
| 1318 |
+
#else
|
| 1319 |
+
TEST(ManipulatorLogFormatTest, HexfloatFloat) {
|
| 1320 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1321 |
+
|
| 1322 |
+
const double value = 7.7e7;
|
| 1323 |
+
auto comparison_stream = ComparisonStream();
|
| 1324 |
+
comparison_stream << std::hexfloat << value;
|
| 1325 |
+
|
| 1326 |
+
EXPECT_CALL(
|
| 1327 |
+
test_sink,
|
| 1328 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1329 |
+
TextMessage(AnyOf(Eq("0x1.25bb50p+26"), Eq("0x1.25bb5p+26"),
|
| 1330 |
+
Eq("0x1.25bb500000000p+26"))),
|
| 1331 |
+
ENCODED_MESSAGE(
|
| 1332 |
+
AnyOf(EqualsProto(R"pb(value { str: "0x1.25bb5p+26" })pb"),
|
| 1333 |
+
EqualsProto(R"pb(value {
|
| 1334 |
+
str: "0x1.25bb500000000p+26"
|
| 1335 |
+
})pb"))))));
|
| 1336 |
+
|
| 1337 |
+
test_sink.StartCapturingLogs();
|
| 1338 |
+
LOG(INFO) << std::hexfloat << value;
|
| 1339 |
+
}
|
| 1340 |
+
#endif
|
| 1341 |
+
|
| 1342 |
+
TEST(ManipulatorLogFormatTest, DefaultFloatFloat) {
|
| 1343 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1344 |
+
|
| 1345 |
+
const double value = 7.7e7;
|
| 1346 |
+
auto comparison_stream = ComparisonStream();
|
| 1347 |
+
comparison_stream << std::hexfloat << std::defaultfloat << value;
|
| 1348 |
+
|
| 1349 |
+
EXPECT_CALL(test_sink,
|
| 1350 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1351 |
+
TextMessage(Eq("7.7e+07")),
|
| 1352 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1353 |
+
str: "7.7e+07"
|
| 1354 |
+
})pb")))));
|
| 1355 |
+
|
| 1356 |
+
test_sink.StartCapturingLogs();
|
| 1357 |
+
LOG(INFO) << std::hexfloat << std::defaultfloat << value;
|
| 1358 |
+
}
|
| 1359 |
+
|
| 1360 |
+
TEST(ManipulatorLogFormatTest, Ends) {
|
| 1361 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1362 |
+
|
| 1363 |
+
auto comparison_stream = ComparisonStream();
|
| 1364 |
+
comparison_stream << std::ends;
|
| 1365 |
+
|
| 1366 |
+
EXPECT_CALL(
|
| 1367 |
+
test_sink,
|
| 1368 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1369 |
+
TextMessage(Eq(absl::string_view("\0", 1))),
|
| 1370 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "\0" })pb")))));
|
| 1371 |
+
|
| 1372 |
+
test_sink.StartCapturingLogs();
|
| 1373 |
+
LOG(INFO) << std::ends;
|
| 1374 |
+
}
|
| 1375 |
+
|
| 1376 |
+
TEST(ManipulatorLogFormatTest, Endl) {
|
| 1377 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1378 |
+
|
| 1379 |
+
auto comparison_stream = ComparisonStream();
|
| 1380 |
+
comparison_stream << std::endl;
|
| 1381 |
+
|
| 1382 |
+
EXPECT_CALL(
|
| 1383 |
+
test_sink,
|
| 1384 |
+
Send(AllOf(
|
| 1385 |
+
TextMessage(MatchesOstream(comparison_stream)),
|
| 1386 |
+
TextMessage(Eq("\n")),
|
| 1387 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "\n" })pb")))));
|
| 1388 |
+
|
| 1389 |
+
test_sink.StartCapturingLogs();
|
| 1390 |
+
LOG(INFO) << std::endl;
|
| 1391 |
+
}
|
| 1392 |
+
|
| 1393 |
+
TEST(ManipulatorLogFormatTest, SetIosFlags) {
|
| 1394 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1395 |
+
|
| 1396 |
+
const int value = 0x77;
|
| 1397 |
+
auto comparison_stream = ComparisonStream();
|
| 1398 |
+
comparison_stream << std::resetiosflags(std::ios_base::basefield)
|
| 1399 |
+
<< std::setiosflags(std::ios_base::hex) << value << " " //
|
| 1400 |
+
<< std::resetiosflags(std::ios_base::basefield)
|
| 1401 |
+
<< std::setiosflags(std::ios_base::dec) << value;
|
| 1402 |
+
|
| 1403 |
+
EXPECT_CALL(
|
| 1404 |
+
test_sink,
|
| 1405 |
+
Send(AllOf(
|
| 1406 |
+
TextMessage(MatchesOstream(comparison_stream)),
|
| 1407 |
+
TextMessage(Eq("0x77 119")),
|
| 1408 |
+
// `std::setiosflags` and `std::resetiosflags` aren't manipulators.
|
| 1409 |
+
// We're unable to distinguish their return type(s) from arbitrary
|
| 1410 |
+
// user-defined types and thus don't suppress the empty str value.
|
| 1411 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "0x77" }
|
| 1412 |
+
value { literal: " " }
|
| 1413 |
+
value { str: "119" }
|
| 1414 |
+
)pb")))));
|
| 1415 |
+
|
| 1416 |
+
test_sink.StartCapturingLogs();
|
| 1417 |
+
LOG(INFO) << std::resetiosflags(std::ios_base::basefield)
|
| 1418 |
+
<< std::setiosflags(std::ios_base::hex) << value << " " //
|
| 1419 |
+
<< std::resetiosflags(std::ios_base::basefield)
|
| 1420 |
+
<< std::setiosflags(std::ios_base::dec) << value;
|
| 1421 |
+
}
|
| 1422 |
+
|
| 1423 |
+
TEST(ManipulatorLogFormatTest, SetBase) {
|
| 1424 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1425 |
+
|
| 1426 |
+
const int value = 0x77;
|
| 1427 |
+
auto comparison_stream = ComparisonStream();
|
| 1428 |
+
comparison_stream << std::setbase(16) << value << " " //
|
| 1429 |
+
<< std::setbase(0) << value;
|
| 1430 |
+
|
| 1431 |
+
EXPECT_CALL(
|
| 1432 |
+
test_sink,
|
| 1433 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1434 |
+
TextMessage(Eq("0x77 119")),
|
| 1435 |
+
// `std::setbase` isn't a manipulator. We're unable to
|
| 1436 |
+
// distinguish its return type from arbitrary user-defined
|
| 1437 |
+
// types and thus don't suppress the empty str value.
|
| 1438 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 1439 |
+
R"pb(value { str: "0x77" }
|
| 1440 |
+
value { literal: " " }
|
| 1441 |
+
value { str: "119" })pb")))));
|
| 1442 |
+
|
| 1443 |
+
test_sink.StartCapturingLogs();
|
| 1444 |
+
LOG(INFO) << std::setbase(16) << value << " " //
|
| 1445 |
+
<< std::setbase(0) << value;
|
| 1446 |
+
}
|
| 1447 |
+
|
| 1448 |
+
TEST(ManipulatorLogFormatTest, SetPrecision) {
|
| 1449 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1450 |
+
|
| 1451 |
+
const double value = 6.022140857e23;
|
| 1452 |
+
auto comparison_stream = ComparisonStream();
|
| 1453 |
+
comparison_stream << std::setprecision(4) << value;
|
| 1454 |
+
|
| 1455 |
+
EXPECT_CALL(
|
| 1456 |
+
test_sink,
|
| 1457 |
+
Send(AllOf(
|
| 1458 |
+
TextMessage(MatchesOstream(comparison_stream)),
|
| 1459 |
+
TextMessage(Eq("6.022e+23")),
|
| 1460 |
+
// `std::setprecision` isn't a manipulator. We're unable to
|
| 1461 |
+
// distinguish its return type from arbitrary user-defined
|
| 1462 |
+
// types and thus don't suppress the empty str value.
|
| 1463 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "6.022e+23" })pb")))));
|
| 1464 |
+
|
| 1465 |
+
test_sink.StartCapturingLogs();
|
| 1466 |
+
LOG(INFO) << std::setprecision(4) << value;
|
| 1467 |
+
}
|
| 1468 |
+
|
| 1469 |
+
TEST(ManipulatorLogFormatTest, SetPrecisionOverflow) {
|
| 1470 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1471 |
+
|
| 1472 |
+
const double value = 6.022140857e23;
|
| 1473 |
+
auto comparison_stream = ComparisonStream();
|
| 1474 |
+
comparison_stream << std::setprecision(200) << value;
|
| 1475 |
+
|
| 1476 |
+
EXPECT_CALL(
|
| 1477 |
+
test_sink,
|
| 1478 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1479 |
+
TextMessage(Eq("602214085700000015187968")),
|
| 1480 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 1481 |
+
R"pb(value { str: "602214085700000015187968" })pb")))));
|
| 1482 |
+
|
| 1483 |
+
test_sink.StartCapturingLogs();
|
| 1484 |
+
LOG(INFO) << std::setprecision(200) << value;
|
| 1485 |
+
}
|
| 1486 |
+
|
| 1487 |
+
TEST(ManipulatorLogFormatTest, SetW) {
|
| 1488 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1489 |
+
|
| 1490 |
+
const int value = 77;
|
| 1491 |
+
auto comparison_stream = ComparisonStream();
|
| 1492 |
+
comparison_stream << std::setw(8) << value;
|
| 1493 |
+
|
| 1494 |
+
EXPECT_CALL(
|
| 1495 |
+
test_sink,
|
| 1496 |
+
Send(AllOf(
|
| 1497 |
+
TextMessage(MatchesOstream(comparison_stream)),
|
| 1498 |
+
TextMessage(Eq(" 77")),
|
| 1499 |
+
// `std::setw` isn't a manipulator. We're unable to
|
| 1500 |
+
// distinguish its return type from arbitrary user-defined
|
| 1501 |
+
// types and thus don't suppress the empty str value.
|
| 1502 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: " 77" })pb")))));
|
| 1503 |
+
|
| 1504 |
+
test_sink.StartCapturingLogs();
|
| 1505 |
+
LOG(INFO) << std::setw(8) << value;
|
| 1506 |
+
}
|
| 1507 |
+
|
| 1508 |
+
TEST(ManipulatorLogFormatTest, Left) {
|
| 1509 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1510 |
+
|
| 1511 |
+
const int value = -77;
|
| 1512 |
+
auto comparison_stream = ComparisonStream();
|
| 1513 |
+
comparison_stream << std::left << std::setw(8) << value;
|
| 1514 |
+
|
| 1515 |
+
EXPECT_CALL(test_sink,
|
| 1516 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1517 |
+
TextMessage(Eq("-77 ")),
|
| 1518 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1519 |
+
str: "-77 "
|
| 1520 |
+
})pb")))));
|
| 1521 |
+
|
| 1522 |
+
test_sink.StartCapturingLogs();
|
| 1523 |
+
LOG(INFO) << std::left << std::setw(8) << value;
|
| 1524 |
+
}
|
| 1525 |
+
|
| 1526 |
+
TEST(ManipulatorLogFormatTest, Right) {
|
| 1527 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1528 |
+
|
| 1529 |
+
const int value = -77;
|
| 1530 |
+
auto comparison_stream = ComparisonStream();
|
| 1531 |
+
comparison_stream << std::right << std::setw(8) << value;
|
| 1532 |
+
|
| 1533 |
+
EXPECT_CALL(test_sink,
|
| 1534 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1535 |
+
TextMessage(Eq(" -77")),
|
| 1536 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1537 |
+
str: " -77"
|
| 1538 |
+
})pb")))));
|
| 1539 |
+
|
| 1540 |
+
test_sink.StartCapturingLogs();
|
| 1541 |
+
LOG(INFO) << std::right << std::setw(8) << value;
|
| 1542 |
+
}
|
| 1543 |
+
|
| 1544 |
+
TEST(ManipulatorLogFormatTest, Internal) {
|
| 1545 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1546 |
+
|
| 1547 |
+
const int value = -77;
|
| 1548 |
+
auto comparison_stream = ComparisonStream();
|
| 1549 |
+
comparison_stream << std::internal << std::setw(8) << value;
|
| 1550 |
+
|
| 1551 |
+
EXPECT_CALL(test_sink,
|
| 1552 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1553 |
+
TextMessage(Eq("- 77")),
|
| 1554 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1555 |
+
str: "- 77"
|
| 1556 |
+
})pb")))));
|
| 1557 |
+
|
| 1558 |
+
test_sink.StartCapturingLogs();
|
| 1559 |
+
LOG(INFO) << std::internal << std::setw(8) << value;
|
| 1560 |
+
}
|
| 1561 |
+
|
| 1562 |
+
TEST(ManipulatorLogFormatTest, SetFill) {
|
| 1563 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1564 |
+
|
| 1565 |
+
const int value = 77;
|
| 1566 |
+
auto comparison_stream = ComparisonStream();
|
| 1567 |
+
comparison_stream << std::setfill('0') << std::setw(8) << value;
|
| 1568 |
+
|
| 1569 |
+
EXPECT_CALL(test_sink,
|
| 1570 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1571 |
+
TextMessage(Eq("00000077")),
|
| 1572 |
+
// `std::setfill` isn't a manipulator. We're
|
| 1573 |
+
// unable to distinguish its return
|
| 1574 |
+
// type from arbitrary user-defined types and
|
| 1575 |
+
// thus don't suppress the empty str value.
|
| 1576 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value {
|
| 1577 |
+
str: "00000077"
|
| 1578 |
+
})pb")))));
|
| 1579 |
+
|
| 1580 |
+
test_sink.StartCapturingLogs();
|
| 1581 |
+
LOG(INFO) << std::setfill('0') << std::setw(8) << value;
|
| 1582 |
+
}
|
| 1583 |
+
|
| 1584 |
+
class FromCustomClass {};
|
| 1585 |
+
std::ostream& operator<<(std::ostream& os, const FromCustomClass&) {
|
| 1586 |
+
return os << "FromCustomClass{}" << std::hex;
|
| 1587 |
+
}
|
| 1588 |
+
|
| 1589 |
+
TEST(ManipulatorLogFormatTest, FromCustom) {
|
| 1590 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1591 |
+
|
| 1592 |
+
FromCustomClass value;
|
| 1593 |
+
auto comparison_stream = ComparisonStream();
|
| 1594 |
+
comparison_stream << value << " " << 0x77;
|
| 1595 |
+
|
| 1596 |
+
EXPECT_CALL(test_sink,
|
| 1597 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1598 |
+
TextMessage(Eq("FromCustomClass{} 0x77")),
|
| 1599 |
+
ENCODED_MESSAGE(EqualsProto(
|
| 1600 |
+
R"pb(value { str: "FromCustomClass{}" }
|
| 1601 |
+
value { literal: " " }
|
| 1602 |
+
value { str: "0x77" })pb")))));
|
| 1603 |
+
|
| 1604 |
+
test_sink.StartCapturingLogs();
|
| 1605 |
+
LOG(INFO) << value << " " << 0x77;
|
| 1606 |
+
}
|
| 1607 |
+
|
| 1608 |
+
class StreamsNothing {};
|
| 1609 |
+
std::ostream& operator<<(std::ostream& os, const StreamsNothing&) { return os; }
|
| 1610 |
+
|
| 1611 |
+
TEST(ManipulatorLogFormatTest, CustomClassStreamsNothing) {
|
| 1612 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1613 |
+
|
| 1614 |
+
StreamsNothing value;
|
| 1615 |
+
auto comparison_stream = ComparisonStream();
|
| 1616 |
+
comparison_stream << value << 77;
|
| 1617 |
+
|
| 1618 |
+
EXPECT_CALL(
|
| 1619 |
+
test_sink,
|
| 1620 |
+
Send(AllOf(TextMessage(MatchesOstream(comparison_stream)),
|
| 1621 |
+
TextMessage(Eq("77")),
|
| 1622 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" })pb")))));
|
| 1623 |
+
|
| 1624 |
+
test_sink.StartCapturingLogs();
|
| 1625 |
+
LOG(INFO) << value << 77;
|
| 1626 |
+
}
|
| 1627 |
+
|
| 1628 |
+
struct PointPercentV {
|
| 1629 |
+
template <typename Sink>
|
| 1630 |
+
friend void AbslStringify(Sink& sink, const PointPercentV& p) {
|
| 1631 |
+
absl::Format(&sink, "(%v, %v)", p.x, p.y);
|
| 1632 |
+
}
|
| 1633 |
+
|
| 1634 |
+
int x = 10;
|
| 1635 |
+
int y = 20;
|
| 1636 |
+
};
|
| 1637 |
+
|
| 1638 |
+
TEST(ManipulatorLogFormatTest, IOManipsDoNotAffectAbslStringify) {
|
| 1639 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1640 |
+
|
| 1641 |
+
PointPercentV p;
|
| 1642 |
+
|
| 1643 |
+
EXPECT_CALL(
|
| 1644 |
+
test_sink,
|
| 1645 |
+
Send(AllOf(
|
| 1646 |
+
TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))),
|
| 1647 |
+
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(10, 20)" })pb")))));
|
| 1648 |
+
|
| 1649 |
+
test_sink.StartCapturingLogs();
|
| 1650 |
+
LOG(INFO) << std::hex << p;
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
+
TEST(StructuredLoggingOverflowTest, TruncatesStrings) {
|
| 1654 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1655 |
+
|
| 1656 |
+
// This message is too long and should be truncated to some unspecified size
|
| 1657 |
+
// no greater than the buffer size but not too much less either. It should be
|
| 1658 |
+
// truncated rather than discarded.
|
| 1659 |
+
EXPECT_CALL(
|
| 1660 |
+
test_sink,
|
| 1661 |
+
Send(AllOf(
|
| 1662 |
+
TextMessage(AllOf(
|
| 1663 |
+
SizeIs(AllOf(Ge(absl::log_internal::kLogMessageBufferSize - 256),
|
| 1664 |
+
Le(absl::log_internal::kLogMessageBufferSize))),
|
| 1665 |
+
Each(Eq('x')))),
|
| 1666 |
+
ENCODED_MESSAGE(HasOneStrThat(AllOf(
|
| 1667 |
+
SizeIs(AllOf(Ge(absl::log_internal::kLogMessageBufferSize - 256),
|
| 1668 |
+
Le(absl::log_internal::kLogMessageBufferSize))),
|
| 1669 |
+
Each(Eq('x'))))))));
|
| 1670 |
+
|
| 1671 |
+
test_sink.StartCapturingLogs();
|
| 1672 |
+
LOG(INFO) << std::string(2 * absl::log_internal::kLogMessageBufferSize, 'x');
|
| 1673 |
+
}
|
| 1674 |
+
|
| 1675 |
+
struct StringLike {
|
| 1676 |
+
absl::string_view data;
|
| 1677 |
+
};
|
| 1678 |
+
std::ostream& operator<<(std::ostream& os, StringLike str) {
|
| 1679 |
+
return os << str.data;
|
| 1680 |
+
}
|
| 1681 |
+
|
| 1682 |
+
TEST(StructuredLoggingOverflowTest, TruncatesInsertionOperators) {
|
| 1683 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1684 |
+
|
| 1685 |
+
// This message is too long and should be truncated to some unspecified size
|
| 1686 |
+
// no greater than the buffer size but not too much less either. It should be
|
| 1687 |
+
// truncated rather than discarded.
|
| 1688 |
+
EXPECT_CALL(
|
| 1689 |
+
test_sink,
|
| 1690 |
+
Send(AllOf(
|
| 1691 |
+
TextMessage(AllOf(
|
| 1692 |
+
SizeIs(AllOf(Ge(absl::log_internal::kLogMessageBufferSize - 256),
|
| 1693 |
+
Le(absl::log_internal::kLogMessageBufferSize))),
|
| 1694 |
+
Each(Eq('x')))),
|
| 1695 |
+
ENCODED_MESSAGE(HasOneStrThat(AllOf(
|
| 1696 |
+
SizeIs(AllOf(Ge(absl::log_internal::kLogMessageBufferSize - 256),
|
| 1697 |
+
Le(absl::log_internal::kLogMessageBufferSize))),
|
| 1698 |
+
Each(Eq('x'))))))));
|
| 1699 |
+
|
| 1700 |
+
test_sink.StartCapturingLogs();
|
| 1701 |
+
LOG(INFO) << StringLike{
|
| 1702 |
+
std::string(2 * absl::log_internal::kLogMessageBufferSize, 'x')};
|
| 1703 |
+
}
|
| 1704 |
+
|
| 1705 |
+
// Returns the size of the largest string that will fit in a `LOG` message
|
| 1706 |
+
// buffer with no prefix.
|
| 1707 |
+
size_t MaxLogFieldLengthNoPrefix() {
|
| 1708 |
+
class StringLengthExtractorSink : public absl::LogSink {
|
| 1709 |
+
public:
|
| 1710 |
+
void Send(const absl::LogEntry& entry) override {
|
| 1711 |
+
CHECK(!size_.has_value());
|
| 1712 |
+
CHECK_EQ(entry.text_message().find_first_not_of('x'),
|
| 1713 |
+
absl::string_view::npos);
|
| 1714 |
+
size_.emplace(entry.text_message().size());
|
| 1715 |
+
}
|
| 1716 |
+
size_t size() const {
|
| 1717 |
+
CHECK(size_.has_value());
|
| 1718 |
+
return *size_;
|
| 1719 |
+
}
|
| 1720 |
+
|
| 1721 |
+
private:
|
| 1722 |
+
absl::optional<size_t> size_;
|
| 1723 |
+
} extractor_sink;
|
| 1724 |
+
LOG(INFO).NoPrefix().ToSinkOnly(&extractor_sink)
|
| 1725 |
+
<< std::string(2 * absl::log_internal::kLogMessageBufferSize, 'x');
|
| 1726 |
+
return extractor_sink.size();
|
| 1727 |
+
}
|
| 1728 |
+
|
| 1729 |
+
TEST(StructuredLoggingOverflowTest, TruncatesStringsCleanly) {
|
| 1730 |
+
const size_t longest_fit = MaxLogFieldLengthNoPrefix();
|
| 1731 |
+
// To log a second value field, we need four bytes: two tag/type bytes and two
|
| 1732 |
+
// sizes. To put any data in the field we need a fifth byte.
|
| 1733 |
+
{
|
| 1734 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1735 |
+
EXPECT_CALL(test_sink,
|
| 1736 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1737 |
+
AllOf(SizeIs(longest_fit), Each(Eq('x'))))),
|
| 1738 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1739 |
+
test_sink.StartCapturingLogs();
|
| 1740 |
+
// x fits exactly, no part of y fits.
|
| 1741 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit, 'x') << "y";
|
| 1742 |
+
}
|
| 1743 |
+
{
|
| 1744 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1745 |
+
EXPECT_CALL(test_sink,
|
| 1746 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1747 |
+
AllOf(SizeIs(longest_fit - 1), Each(Eq('x'))))),
|
| 1748 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1749 |
+
test_sink.StartCapturingLogs();
|
| 1750 |
+
// x fits, one byte from y's header fits but shouldn't be visible.
|
| 1751 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 1, 'x') << "y";
|
| 1752 |
+
}
|
| 1753 |
+
{
|
| 1754 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1755 |
+
EXPECT_CALL(test_sink,
|
| 1756 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1757 |
+
AllOf(SizeIs(longest_fit - 2), Each(Eq('x'))))),
|
| 1758 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1759 |
+
test_sink.StartCapturingLogs();
|
| 1760 |
+
// x fits, two bytes from y's header fit but shouldn't be visible.
|
| 1761 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 2, 'x') << "y";
|
| 1762 |
+
}
|
| 1763 |
+
{
|
| 1764 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1765 |
+
EXPECT_CALL(test_sink,
|
| 1766 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1767 |
+
AllOf(SizeIs(longest_fit - 3), Each(Eq('x'))))),
|
| 1768 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1769 |
+
test_sink.StartCapturingLogs();
|
| 1770 |
+
// x fits, three bytes from y's header fit but shouldn't be visible.
|
| 1771 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 3, 'x') << "y";
|
| 1772 |
+
}
|
| 1773 |
+
{
|
| 1774 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1775 |
+
EXPECT_CALL(test_sink,
|
| 1776 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrAndOneLiteralThat(
|
| 1777 |
+
AllOf(SizeIs(longest_fit - 4), Each(Eq('x'))),
|
| 1778 |
+
IsEmpty())),
|
| 1779 |
+
RawEncodedMessage(Not(AsString(EndsWith("x")))))));
|
| 1780 |
+
test_sink.StartCapturingLogs();
|
| 1781 |
+
// x fits, all four bytes from y's header fit but no data bytes do, so we
|
| 1782 |
+
// encode an empty string.
|
| 1783 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 4, 'x') << "y";
|
| 1784 |
+
}
|
| 1785 |
+
{
|
| 1786 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1787 |
+
EXPECT_CALL(
|
| 1788 |
+
test_sink,
|
| 1789 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrAndOneLiteralThat(
|
| 1790 |
+
AllOf(SizeIs(longest_fit - 5), Each(Eq('x'))), Eq("y"))),
|
| 1791 |
+
RawEncodedMessage(AsString(EndsWith("y"))))));
|
| 1792 |
+
test_sink.StartCapturingLogs();
|
| 1793 |
+
// x fits, y fits exactly.
|
| 1794 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 5, 'x') << "y";
|
| 1795 |
+
}
|
| 1796 |
+
}
|
| 1797 |
+
|
| 1798 |
+
TEST(StructuredLoggingOverflowTest, TruncatesInsertionOperatorsCleanly) {
|
| 1799 |
+
const size_t longest_fit = MaxLogFieldLengthNoPrefix();
|
| 1800 |
+
// To log a second value field, we need four bytes: two tag/type bytes and two
|
| 1801 |
+
// sizes. To put any data in the field we need a fifth byte.
|
| 1802 |
+
{
|
| 1803 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1804 |
+
EXPECT_CALL(test_sink,
|
| 1805 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1806 |
+
AllOf(SizeIs(longest_fit), Each(Eq('x'))))),
|
| 1807 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1808 |
+
test_sink.StartCapturingLogs();
|
| 1809 |
+
// x fits exactly, no part of y fits.
|
| 1810 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit, 'x') << StringLike{"y"};
|
| 1811 |
+
}
|
| 1812 |
+
{
|
| 1813 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1814 |
+
EXPECT_CALL(test_sink,
|
| 1815 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1816 |
+
AllOf(SizeIs(longest_fit - 1), Each(Eq('x'))))),
|
| 1817 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1818 |
+
test_sink.StartCapturingLogs();
|
| 1819 |
+
// x fits, one byte from y's header fits but shouldn't be visible.
|
| 1820 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 1, 'x')
|
| 1821 |
+
<< StringLike{"y"};
|
| 1822 |
+
}
|
| 1823 |
+
{
|
| 1824 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1825 |
+
EXPECT_CALL(test_sink,
|
| 1826 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1827 |
+
AllOf(SizeIs(longest_fit - 2), Each(Eq('x'))))),
|
| 1828 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1829 |
+
test_sink.StartCapturingLogs();
|
| 1830 |
+
// x fits, two bytes from y's header fit but shouldn't be visible.
|
| 1831 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 2, 'x')
|
| 1832 |
+
<< StringLike{"y"};
|
| 1833 |
+
}
|
| 1834 |
+
{
|
| 1835 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1836 |
+
EXPECT_CALL(test_sink,
|
| 1837 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1838 |
+
AllOf(SizeIs(longest_fit - 3), Each(Eq('x'))))),
|
| 1839 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1840 |
+
test_sink.StartCapturingLogs();
|
| 1841 |
+
// x fits, three bytes from y's header fit but shouldn't be visible.
|
| 1842 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 3, 'x')
|
| 1843 |
+
<< StringLike{"y"};
|
| 1844 |
+
}
|
| 1845 |
+
{
|
| 1846 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1847 |
+
EXPECT_CALL(test_sink,
|
| 1848 |
+
Send(AllOf(ENCODED_MESSAGE(HasOneStrThat(
|
| 1849 |
+
AllOf(SizeIs(longest_fit - 4), Each(Eq('x'))))),
|
| 1850 |
+
RawEncodedMessage(AsString(EndsWith("x"))))));
|
| 1851 |
+
test_sink.StartCapturingLogs();
|
| 1852 |
+
// x fits, all four bytes from y's header fit but no data bytes do. We
|
| 1853 |
+
// don't encode an empty string here because every I/O manipulator hits this
|
| 1854 |
+
// codepath and those shouldn't leave empty strings behind.
|
| 1855 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 4, 'x')
|
| 1856 |
+
<< StringLike{"y"};
|
| 1857 |
+
}
|
| 1858 |
+
{
|
| 1859 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 1860 |
+
EXPECT_CALL(
|
| 1861 |
+
test_sink,
|
| 1862 |
+
Send(AllOf(ENCODED_MESSAGE(HasTwoStrsThat(
|
| 1863 |
+
AllOf(SizeIs(longest_fit - 5), Each(Eq('x'))), Eq("y"))),
|
| 1864 |
+
RawEncodedMessage(AsString(EndsWith("y"))))));
|
| 1865 |
+
test_sink.StartCapturingLogs();
|
| 1866 |
+
// x fits, y fits exactly.
|
| 1867 |
+
LOG(INFO).NoPrefix() << std::string(longest_fit - 5, 'x')
|
| 1868 |
+
<< StringLike{"y"};
|
| 1869 |
+
}
|
| 1870 |
+
}
|
| 1871 |
+
|
| 1872 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/log/log_macro_hygiene_test.cc
ADDED
|
@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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 "gmock/gmock.h"
|
| 17 |
+
#include "gtest/gtest.h"
|
| 18 |
+
#include "absl/base/attributes.h"
|
| 19 |
+
#include "absl/base/log_severity.h"
|
| 20 |
+
#include "absl/log/log.h"
|
| 21 |
+
#include "absl/log/scoped_mock_log.h"
|
| 22 |
+
|
| 23 |
+
namespace {
|
| 24 |
+
using ::testing::_;
|
| 25 |
+
using ::testing::Eq;
|
| 26 |
+
|
| 27 |
+
namespace not_absl {
|
| 28 |
+
|
| 29 |
+
class Dummy {
|
| 30 |
+
public:
|
| 31 |
+
Dummy() {}
|
| 32 |
+
|
| 33 |
+
private:
|
| 34 |
+
Dummy(const Dummy&) = delete;
|
| 35 |
+
Dummy& operator=(const Dummy&) = delete;
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
// This line tests that local definitions of INFO, WARNING, ERROR, and
|
| 39 |
+
// etc don't shadow the global ones used by the logging macros. If
|
| 40 |
+
// they do, the LOG() calls in the tests won't compile, catching the
|
| 41 |
+
// bug.
|
| 42 |
+
const Dummy INFO, WARNING, ERROR, FATAL, NUM_SEVERITIES;
|
| 43 |
+
|
| 44 |
+
// These makes sure that the uses of same-named types in the
|
| 45 |
+
// implementation of the logging macros are fully qualified.
|
| 46 |
+
class string {};
|
| 47 |
+
class vector {};
|
| 48 |
+
class LogMessage {};
|
| 49 |
+
class LogMessageFatal {};
|
| 50 |
+
class LogMessageQuietlyFatal {};
|
| 51 |
+
class LogMessageVoidify {};
|
| 52 |
+
class LogSink {};
|
| 53 |
+
class NullStream {};
|
| 54 |
+
class NullStreamFatal {};
|
| 55 |
+
|
| 56 |
+
} // namespace not_absl
|
| 57 |
+
|
| 58 |
+
using namespace not_absl; // NOLINT
|
| 59 |
+
|
| 60 |
+
// Tests for LOG(LEVEL(()).
|
| 61 |
+
|
| 62 |
+
TEST(LogHygieneTest, WorksForQualifiedSeverity) {
|
| 63 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 64 |
+
|
| 65 |
+
::testing::InSequence seq;
|
| 66 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kInfo, _, "To INFO"));
|
| 67 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kWarning, _, "To WARNING"));
|
| 68 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kError, _, "To ERROR"));
|
| 69 |
+
|
| 70 |
+
test_sink.StartCapturingLogs();
|
| 71 |
+
// Note that LOG(LEVEL()) expects the severity as a run-time
|
| 72 |
+
// expression (as opposed to a compile-time constant). Hence we
|
| 73 |
+
// test that :: is allowed before INFO, etc.
|
| 74 |
+
LOG(LEVEL(absl::LogSeverity::kInfo)) << "To INFO";
|
| 75 |
+
LOG(LEVEL(absl::LogSeverity::kWarning)) << "To WARNING";
|
| 76 |
+
LOG(LEVEL(absl::LogSeverity::kError)) << "To ERROR";
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
TEST(LogHygieneTest, WorksWithAlternativeINFOSymbol) {
|
| 80 |
+
const double INFO ABSL_ATTRIBUTE_UNUSED = 7.77;
|
| 81 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 82 |
+
|
| 83 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kInfo, _, "Hello world"));
|
| 84 |
+
|
| 85 |
+
test_sink.StartCapturingLogs();
|
| 86 |
+
LOG(INFO) << "Hello world";
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
TEST(LogHygieneTest, WorksWithAlternativeWARNINGSymbol) {
|
| 90 |
+
const double WARNING ABSL_ATTRIBUTE_UNUSED = 7.77;
|
| 91 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 92 |
+
|
| 93 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kWarning, _, "Hello world"));
|
| 94 |
+
|
| 95 |
+
test_sink.StartCapturingLogs();
|
| 96 |
+
LOG(WARNING) << "Hello world";
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
TEST(LogHygieneTest, WorksWithAlternativeERRORSymbol) {
|
| 100 |
+
const double ERROR ABSL_ATTRIBUTE_UNUSED = 7.77;
|
| 101 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 102 |
+
|
| 103 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kError, _, "Hello world"));
|
| 104 |
+
|
| 105 |
+
test_sink.StartCapturingLogs();
|
| 106 |
+
LOG(ERROR) << "Hello world";
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
TEST(LogHygieneTest, WorksWithAlternativeLEVELSymbol) {
|
| 110 |
+
const double LEVEL ABSL_ATTRIBUTE_UNUSED = 7.77;
|
| 111 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 112 |
+
|
| 113 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kError, _, "Hello world"));
|
| 114 |
+
|
| 115 |
+
test_sink.StartCapturingLogs();
|
| 116 |
+
LOG(LEVEL(absl::LogSeverity::kError)) << "Hello world";
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#define INFO Bogus
|
| 120 |
+
#ifdef NDEBUG
|
| 121 |
+
constexpr bool IsOptimized = false;
|
| 122 |
+
#else
|
| 123 |
+
constexpr bool IsOptimized = true;
|
| 124 |
+
#endif
|
| 125 |
+
|
| 126 |
+
TEST(LogHygieneTest, WorksWithINFODefined) {
|
| 127 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 128 |
+
|
| 129 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kInfo, _, "Hello world"))
|
| 130 |
+
.Times(2 + (IsOptimized ? 2 : 0));
|
| 131 |
+
|
| 132 |
+
test_sink.StartCapturingLogs();
|
| 133 |
+
LOG(INFO) << "Hello world";
|
| 134 |
+
LOG_IF(INFO, true) << "Hello world";
|
| 135 |
+
|
| 136 |
+
DLOG(INFO) << "Hello world";
|
| 137 |
+
DLOG_IF(INFO, true) << "Hello world";
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
#undef INFO
|
| 141 |
+
|
| 142 |
+
#define _INFO Bogus
|
| 143 |
+
TEST(LogHygieneTest, WorksWithUnderscoreINFODefined) {
|
| 144 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 145 |
+
|
| 146 |
+
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kInfo, _, "Hello world"))
|
| 147 |
+
.Times(2 + (IsOptimized ? 2 : 0));
|
| 148 |
+
|
| 149 |
+
test_sink.StartCapturingLogs();
|
| 150 |
+
LOG(INFO) << "Hello world";
|
| 151 |
+
LOG_IF(INFO, true) << "Hello world";
|
| 152 |
+
|
| 153 |
+
DLOG(INFO) << "Hello world";
|
| 154 |
+
DLOG_IF(INFO, true) << "Hello world";
|
| 155 |
+
}
|
| 156 |
+
#undef _INFO
|
| 157 |
+
|
| 158 |
+
TEST(LogHygieneTest, ExpressionEvaluationInLEVELSeverity) {
|
| 159 |
+
auto i = static_cast<int>(absl::LogSeverity::kInfo);
|
| 160 |
+
LOG(LEVEL(++i)) << "hello world"; // NOLINT
|
| 161 |
+
EXPECT_THAT(i, Eq(static_cast<int>(absl::LogSeverity::kInfo) + 1));
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
TEST(LogHygieneTest, ExpressionEvaluationInStreamedMessage) {
|
| 165 |
+
int i = 0;
|
| 166 |
+
LOG(INFO) << ++i;
|
| 167 |
+
EXPECT_THAT(i, 1);
|
| 168 |
+
LOG_IF(INFO, false) << ++i;
|
| 169 |
+
EXPECT_THAT(i, 1);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
// Tests that macros are usable in unbraced switch statements.
|
| 173 |
+
// -----------------------------------------------------------
|
| 174 |
+
|
| 175 |
+
class UnbracedSwitchCompileTest {
|
| 176 |
+
static void Log() {
|
| 177 |
+
switch (0) {
|
| 178 |
+
case 0:
|
| 179 |
+
LOG(INFO);
|
| 180 |
+
break;
|
| 181 |
+
default:
|
| 182 |
+
break;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
};
|
| 186 |
+
|
| 187 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/log/log_modifier_methods_test.cc
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2022 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 <errno.h>
|
| 17 |
+
|
| 18 |
+
#include "gmock/gmock.h"
|
| 19 |
+
#include "gtest/gtest.h"
|
| 20 |
+
#include "absl/log/internal/test_actions.h"
|
| 21 |
+
#include "absl/log/internal/test_helpers.h"
|
| 22 |
+
#include "absl/log/internal/test_matchers.h"
|
| 23 |
+
#include "absl/log/log.h"
|
| 24 |
+
#include "absl/log/log_sink.h"
|
| 25 |
+
#include "absl/log/scoped_mock_log.h"
|
| 26 |
+
#include "absl/strings/match.h"
|
| 27 |
+
#include "absl/strings/string_view.h"
|
| 28 |
+
#include "absl/time/time.h"
|
| 29 |
+
|
| 30 |
+
namespace {
|
| 31 |
+
#if GTEST_HAS_DEATH_TEST
|
| 32 |
+
using ::absl::log_internal::DeathTestExpectedLogging;
|
| 33 |
+
using ::absl::log_internal::DeathTestUnexpectedLogging;
|
| 34 |
+
using ::absl::log_internal::DeathTestValidateExpectations;
|
| 35 |
+
using ::absl::log_internal::DiedOfQFatal;
|
| 36 |
+
#endif
|
| 37 |
+
using ::absl::log_internal::LogSeverity;
|
| 38 |
+
using ::absl::log_internal::Prefix;
|
| 39 |
+
using ::absl::log_internal::SourceBasename;
|
| 40 |
+
using ::absl::log_internal::SourceFilename;
|
| 41 |
+
using ::absl::log_internal::SourceLine;
|
| 42 |
+
using ::absl::log_internal::Stacktrace;
|
| 43 |
+
using ::absl::log_internal::TextMessage;
|
| 44 |
+
using ::absl::log_internal::TextMessageWithPrefix;
|
| 45 |
+
using ::absl::log_internal::TextMessageWithPrefixAndNewline;
|
| 46 |
+
using ::absl::log_internal::TextPrefix;
|
| 47 |
+
using ::absl::log_internal::ThreadID;
|
| 48 |
+
using ::absl::log_internal::Timestamp;
|
| 49 |
+
using ::absl::log_internal::Verbosity;
|
| 50 |
+
|
| 51 |
+
using ::testing::AllOf;
|
| 52 |
+
using ::testing::AnyNumber;
|
| 53 |
+
using ::testing::AnyOf;
|
| 54 |
+
using ::testing::Eq;
|
| 55 |
+
using ::testing::IsEmpty;
|
| 56 |
+
using ::testing::IsFalse;
|
| 57 |
+
using ::testing::Truly;
|
| 58 |
+
|
| 59 |
+
TEST(TailCallsModifiesTest, AtLocationFileLine) {
|
| 60 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 61 |
+
|
| 62 |
+
EXPECT_CALL(
|
| 63 |
+
test_sink,
|
| 64 |
+
Send(AllOf(
|
| 65 |
+
// The metadata should change:
|
| 66 |
+
SourceFilename(Eq("/my/very/very/very_long_source_file.cc")),
|
| 67 |
+
SourceBasename(Eq("very_long_source_file.cc")), SourceLine(Eq(777)),
|
| 68 |
+
// The logged line should change too, even though the prefix must
|
| 69 |
+
// grow to fit the new metadata.
|
| 70 |
+
TextMessageWithPrefix(Truly([](absl::string_view msg) {
|
| 71 |
+
return absl::EndsWith(msg,
|
| 72 |
+
" very_long_source_file.cc:777] hello world");
|
| 73 |
+
})))));
|
| 74 |
+
|
| 75 |
+
test_sink.StartCapturingLogs();
|
| 76 |
+
LOG(INFO).AtLocation("/my/very/very/very_long_source_file.cc", 777)
|
| 77 |
+
<< "hello world";
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
TEST(TailCallsModifiesTest, NoPrefix) {
|
| 81 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 82 |
+
|
| 83 |
+
EXPECT_CALL(test_sink, Send(AllOf(Prefix(IsFalse()), TextPrefix(IsEmpty()),
|
| 84 |
+
TextMessageWithPrefix(Eq("hello world")))));
|
| 85 |
+
|
| 86 |
+
test_sink.StartCapturingLogs();
|
| 87 |
+
LOG(INFO).NoPrefix() << "hello world";
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
TEST(TailCallsModifiesTest, NoPrefixNoMessageNoShirtNoShoesNoService) {
|
| 91 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 92 |
+
|
| 93 |
+
EXPECT_CALL(test_sink,
|
| 94 |
+
Send(AllOf(Prefix(IsFalse()), TextPrefix(IsEmpty()),
|
| 95 |
+
TextMessageWithPrefix(IsEmpty()),
|
| 96 |
+
TextMessageWithPrefixAndNewline(Eq("\n")))));
|
| 97 |
+
test_sink.StartCapturingLogs();
|
| 98 |
+
LOG(INFO).NoPrefix();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
TEST(TailCallsModifiesTest, WithVerbosity) {
|
| 102 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 103 |
+
|
| 104 |
+
EXPECT_CALL(test_sink, Send(Verbosity(Eq(2))));
|
| 105 |
+
|
| 106 |
+
test_sink.StartCapturingLogs();
|
| 107 |
+
LOG(INFO).WithVerbosity(2) << "hello world";
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
TEST(TailCallsModifiesTest, WithVerbosityNoVerbosity) {
|
| 111 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 112 |
+
|
| 113 |
+
EXPECT_CALL(test_sink,
|
| 114 |
+
Send(Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel))));
|
| 115 |
+
|
| 116 |
+
test_sink.StartCapturingLogs();
|
| 117 |
+
LOG(INFO).WithVerbosity(2).WithVerbosity(absl::LogEntry::kNoVerbosityLevel)
|
| 118 |
+
<< "hello world";
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
TEST(TailCallsModifiesTest, WithTimestamp) {
|
| 122 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 123 |
+
|
| 124 |
+
EXPECT_CALL(test_sink, Send(Timestamp(Eq(absl::UnixEpoch()))));
|
| 125 |
+
|
| 126 |
+
test_sink.StartCapturingLogs();
|
| 127 |
+
LOG(INFO).WithTimestamp(absl::UnixEpoch()) << "hello world";
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
TEST(TailCallsModifiesTest, WithThreadID) {
|
| 131 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 132 |
+
|
| 133 |
+
EXPECT_CALL(test_sink,
|
| 134 |
+
Send(AllOf(ThreadID(Eq(absl::LogEntry::tid_t{1234})))));
|
| 135 |
+
|
| 136 |
+
test_sink.StartCapturingLogs();
|
| 137 |
+
LOG(INFO).WithThreadID(1234) << "hello world";
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
TEST(TailCallsModifiesTest, WithMetadataFrom) {
|
| 141 |
+
class ForwardingLogSink : public absl::LogSink {
|
| 142 |
+
public:
|
| 143 |
+
void Send(const absl::LogEntry &entry) override {
|
| 144 |
+
LOG(LEVEL(entry.log_severity())).WithMetadataFrom(entry)
|
| 145 |
+
<< "forwarded: " << entry.text_message();
|
| 146 |
+
}
|
| 147 |
+
} forwarding_sink;
|
| 148 |
+
|
| 149 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 150 |
+
|
| 151 |
+
EXPECT_CALL(
|
| 152 |
+
test_sink,
|
| 153 |
+
Send(AllOf(SourceFilename(Eq("fake/file")), SourceBasename(Eq("file")),
|
| 154 |
+
SourceLine(Eq(123)), Prefix(IsFalse()),
|
| 155 |
+
LogSeverity(Eq(absl::LogSeverity::kWarning)),
|
| 156 |
+
Timestamp(Eq(absl::UnixEpoch())),
|
| 157 |
+
ThreadID(Eq(absl::LogEntry::tid_t{456})),
|
| 158 |
+
TextMessage(Eq("forwarded: hello world")), Verbosity(Eq(7)),
|
| 159 |
+
ENCODED_MESSAGE(
|
| 160 |
+
EqualsProto(R"pb(value { literal: "forwarded: " }
|
| 161 |
+
value { str: "hello world" })pb")))));
|
| 162 |
+
|
| 163 |
+
test_sink.StartCapturingLogs();
|
| 164 |
+
LOG(WARNING)
|
| 165 |
+
.AtLocation("fake/file", 123)
|
| 166 |
+
.NoPrefix()
|
| 167 |
+
.WithTimestamp(absl::UnixEpoch())
|
| 168 |
+
.WithThreadID(456)
|
| 169 |
+
.WithVerbosity(7)
|
| 170 |
+
.ToSinkOnly(&forwarding_sink)
|
| 171 |
+
<< "hello world";
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
TEST(TailCallsModifiesTest, WithPerror) {
|
| 175 |
+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
|
| 176 |
+
|
| 177 |
+
EXPECT_CALL(
|
| 178 |
+
test_sink,
|
| 179 |
+
Send(AllOf(TextMessage(AnyOf(Eq("hello world: Bad file number [9]"),
|
| 180 |
+
Eq("hello world: Bad file descriptor [9]"),
|
| 181 |
+
Eq("hello world: Bad file descriptor [8]"))),
|
| 182 |
+
ENCODED_MESSAGE(
|
| 183 |
+
AnyOf(EqualsProto(R"pb(value { literal: "hello world" }
|
| 184 |
+
value { literal: ": " }
|
| 185 |
+
value { str: "Bad file number" }
|
| 186 |
+
value { literal: " [" }
|
| 187 |
+
value { str: "9" }
|
| 188 |
+
value { literal: "]" })pb"),
|
| 189 |
+
EqualsProto(R"pb(value { literal: "hello world" }
|
| 190 |
+
value { literal: ": " }
|
| 191 |
+
value { str: "Bad file descriptor" }
|
| 192 |
+
value { literal: " [" }
|
| 193 |
+
value { str: "9" }
|
| 194 |
+
value { literal: "]" })pb"),
|
| 195 |
+
EqualsProto(R"pb(value { literal: "hello world" }
|
| 196 |
+
value { literal: ": " }
|
| 197 |
+
value { str: "Bad file descriptor" }
|
| 198 |
+
value { literal: " [" }
|
| 199 |
+
value { str: "8" }
|
| 200 |
+
value { literal: "]" })pb"))))));
|
| 201 |
+
|
| 202 |
+
test_sink.StartCapturingLogs();
|
| 203 |
+
errno = EBADF;
|
| 204 |
+
LOG(INFO).WithPerror() << "hello world";
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
#if GTEST_HAS_DEATH_TEST
|
| 208 |
+
TEST(ModifierMethodDeathTest, ToSinkOnlyQFatal) {
|
| 209 |
+
EXPECT_EXIT(
|
| 210 |
+
{
|
| 211 |
+
absl::ScopedMockLog test_sink(
|
| 212 |
+
absl::MockLogDefault::kDisallowUnexpected);
|
| 213 |
+
|
| 214 |
+
auto do_log = [&test_sink] {
|
| 215 |
+
LOG(QFATAL).ToSinkOnly(&test_sink.UseAsLocalSink()) << "hello world";
|
| 216 |
+
};
|
| 217 |
+
|
| 218 |
+
EXPECT_CALL(test_sink, Send)
|
| 219 |
+
.Times(AnyNumber())
|
| 220 |
+
.WillRepeatedly(DeathTestUnexpectedLogging());
|
| 221 |
+
|
| 222 |
+
EXPECT_CALL(test_sink, Send(AllOf(TextMessage(Eq("hello world")),
|
| 223 |
+
Stacktrace(IsEmpty()))))
|
| 224 |
+
.WillOnce(DeathTestExpectedLogging());
|
| 225 |
+
|
| 226 |
+
test_sink.StartCapturingLogs();
|
| 227 |
+
do_log();
|
| 228 |
+
},
|
| 229 |
+
DiedOfQFatal, DeathTestValidateExpectations());
|
| 230 |
+
}
|
| 231 |
+
#endif
|
| 232 |
+
|
| 233 |
+
} // namespace
|
weight/_dep/abseil-cpp/absl/log/log_sink.cc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "absl/log/log_sink.h"
|
| 16 |
+
|
| 17 |
+
#include "absl/base/config.h"
|
| 18 |
+
|
| 19 |
+
namespace absl {
|
| 20 |
+
ABSL_NAMESPACE_BEGIN
|
| 21 |
+
void LogSink::KeyFunction() const {}
|
| 22 |
+
ABSL_NAMESPACE_END
|
| 23 |
+
} // namespace absl
|