3eefe03c51
A few notes: 1) Oilpan is a generic library, meaning that it can work with arbitrary user types. The library is split in type-aware (include/) and type-erased (src/) parts. The former comprises a lot of code that still needs to be defended with dchecks; 2) Macros are prefixed with CPPGC_, so that they don't clash in the user code with similar macros from other libraries; 3) The macros simply forward requests to V8 so that dcheck handlers can be configured uniformly; 4) The CL doesn't contain CHECK_EQ and friends, but they can be added later if needed. Bug: chromium:1056170 Change-Id: I68e6f663247705233eaf030384164d81e53071e1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2148774 Commit-Queue: Anton Bikineev <bikineev@chromium.org> Reviewed-by: Omer Katz <omerkatz@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#67129}
80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <string>
|
|
|
|
#include "include/cppgc/internal/logging.h"
|
|
#include "include/cppgc/source-location.h"
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace cppgc {
|
|
namespace internal {
|
|
|
|
namespace {
|
|
// GCC < 9 has a bug due to which calling non-constexpr functions are not
|
|
// allowed even on constexpr path:
|
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67026.
|
|
#if !defined(__GNUC__) || defined(__clang__)
|
|
constexpr int CheckInConstexpr(int a) {
|
|
CPPGC_DCHECK(a > 0);
|
|
CPPGC_CHECK(a > 0);
|
|
return a;
|
|
}
|
|
#endif
|
|
} // namespace
|
|
|
|
TEST(LoggingTest, Pass) {
|
|
CPPGC_DCHECK(true);
|
|
CPPGC_CHECK(true);
|
|
}
|
|
|
|
TEST(LoggingTest, Fail) {
|
|
#if DEBUG
|
|
EXPECT_DEATH_IF_SUPPORTED(CPPGC_DCHECK(false), "");
|
|
#endif
|
|
EXPECT_DEATH_IF_SUPPORTED(CPPGC_CHECK(false), "");
|
|
}
|
|
|
|
TEST(LoggingTest, DontReportUnused) {
|
|
int a = 1;
|
|
CPPGC_DCHECK(a);
|
|
}
|
|
|
|
#if !defined(__GNUC__) || defined(__clang__)
|
|
TEST(LoggingTest, ConstexprContext) {
|
|
constexpr int a = CheckInConstexpr(1);
|
|
CPPGC_DCHECK(a);
|
|
}
|
|
#endif
|
|
|
|
#if DEBUG && !defined(OFFICIAL_BUILD)
|
|
TEST(LoggingTest, Message) {
|
|
using ::testing::ContainsRegex;
|
|
EXPECT_DEATH_IF_SUPPORTED(CPPGC_DCHECK(5 == 7),
|
|
ContainsRegex("failed.*5 == 7"));
|
|
EXPECT_DEATH_IF_SUPPORTED(CPPGC_CHECK(5 == 7),
|
|
ContainsRegex("failed.*5 == 7"));
|
|
}
|
|
|
|
#if CPPGC_SUPPORTS_SOURCE_LOCATION
|
|
TEST(LoggingTest, SourceLocation) {
|
|
using ::testing::AllOf;
|
|
using ::testing::HasSubstr;
|
|
constexpr auto loc = SourceLocation::Current();
|
|
EXPECT_DEATH_IF_SUPPORTED(CPPGC_DCHECK(false),
|
|
AllOf(HasSubstr(loc.FileName()),
|
|
HasSubstr(std::to_string(loc.Line() + 3))));
|
|
EXPECT_DEATH_IF_SUPPORTED(CPPGC_CHECK(false),
|
|
AllOf(HasSubstr(loc.FileName()),
|
|
HasSubstr(std::to_string(loc.Line() + 6))));
|
|
}
|
|
#endif // CPPGC_SUPPORTS_SOURCE_LOCATION
|
|
|
|
#endif // DEBUG
|
|
|
|
} // namespace internal
|
|
} // namespace cppgc
|