blob: c9139e361756e76a1819d4a4c163aa78dc3c4f5c [file] [log] [blame]
Roland Bockd662a2d2022-07-12 20:55:271// Copyright 2022 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/check_is_test.h"
6
7#include "base/check.h"
8#include "base/logging.h"
9
10namespace {
11bool g_this_is_a_test = false;
12}
13
14namespace base::internal {
15void check_is_test_impl() {
16 CHECK(g_this_is_a_test);
17}
18} // namespace base::internal
19
20namespace base::test {
21// base/test/allow_check_is_test_to_be_called.h declares
22// `AllowCheckIsTestToBeCalled`, but is only allowed to be included in test
23// code.
24// We therefore have to also mark the symbol as exported here.
25BASE_EXPORT void AllowCheckIsTestToBeCalled() {
26 LOG(WARNING) << "Allowing special test code paths";
27 // This CHECK ensures that `AllowCheckIsTestToBeCalled` is called just once.
28 // Since it is called in `base::TestSuite`, this should effectivly prevent
29 // calls to AllowCheckIsTestToBeCalled in production code (assuming that code
30 // has unit test coverage).
31 //
32 // This is just in case someone ignores the fact that this function in the
33 // `base::test` namespace and ends on "ForTesting".
34 CHECK(!g_this_is_a_test)
35 << "AllowCheckIsTestToBeCalled must not be called more than once";
36
37 g_this_is_a_test = true;
38}
39
40} // namespace base::test