blob: 3d30bd3861152f8597163140bf348dea46bd701e [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001// Copyright 2017 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// This test serves primarily as a compilation test for base/raw_logging.h.
16// Raw logging testing is covered by logging_unittest.cc, which is not as
17// portable as this test.
18
19#include "absl/base/internal/raw_logging.h"
20
21#include <tuple>
22
23#include "gtest/gtest.h"
24#include "absl/strings/str_cat.h"
25
26namespace {
27
28TEST(RawLoggingCompilationTest, Log) {
29 ABSL_RAW_LOG(INFO, "RAW INFO: %d", 1);
30 ABSL_RAW_LOG(INFO, "RAW INFO: %d %d", 1, 2);
31 ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d", 1, 2, 3);
32 ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d", 1, 2, 3, 4);
33 ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d %d", 1, 2, 3, 4, 5);
34 ABSL_RAW_LOG(WARNING, "RAW WARNING: %d", 1);
35 ABSL_RAW_LOG(ERROR, "RAW ERROR: %d", 1);
36}
37
38TEST(RawLoggingCompilationTest, PassingCheck) {
39 ABSL_RAW_CHECK(true, "RAW CHECK");
40}
41
42// Not all platforms support output from raw log, so we don't verify any
43// particular output for RAW check failures (expecting the empty string
44// accomplishes this). This test is primarily a compilation test, but we
45// are verifying process death when EXPECT_DEATH works for a platform.
46const char kExpectedDeathOutput[] = "";
47
48TEST(RawLoggingDeathTest, FailingCheck) {
49 EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_CHECK(1 == 0, "explanation"),
50 kExpectedDeathOutput);
51}
52
53TEST(RawLoggingDeathTest, LogFatal) {
54 EXPECT_DEATH_IF_SUPPORTED(ABSL_RAW_LOG(FATAL, "my dog has fleas"),
55 kExpectedDeathOutput);
56}
57
58TEST(InternalLog, CompilationTest) {
59 ABSL_INTERNAL_LOG(INFO, "Internal Log");
60 std::string log_msg = "Internal Log";
61 ABSL_INTERNAL_LOG(INFO, log_msg);
62
63 ABSL_INTERNAL_LOG(INFO, log_msg + " 2");
64
65 float d = 1.1f;
66 ABSL_INTERNAL_LOG(INFO, absl::StrCat("Internal log ", 3, " + ", d));
67}
68
69TEST(InternalLogDeathTest, FailingCheck) {
70 EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_CHECK(1 == 0, "explanation"),
71 kExpectedDeathOutput);
72}
73
74TEST(InternalLogDeathTest, LogFatal) {
75 EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_LOG(FATAL, "my dog has fleas"),
76 kExpectedDeathOutput);
77}
78
79} // namespace