Files
carbon-lang/explorer/base/set_file_context_raii_test.cpp
T
Geoff Romer e3d3122f1d Move tests to the namespace of the code under test (#3244)
Rationale: this convention avoids forcing closely-related code to be far
apart in the namespace hierarchy, and vice versa. By the same token, it
makes the namespace hierarchy more consistent with the directory
hierarchy.
2023-09-18 22:05:14 +00:00

38 lines
1.2 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "explorer/base/trace_stream.h"
namespace Carbon {
namespace {
TEST(SetFileContextRaiiTest, UpdateFileContext) {
TraceStream trace_stream;
trace_stream.set_stream(&llvm::nulls());
trace_stream.set_allowed_phases({ProgramPhase::All});
trace_stream.set_allowed_file_kinds({FileKind::Main});
{
SetFileContext set_file_ctx(
trace_stream,
SourceLocation("example/prelude.carbon", 9, FileKind::Prelude));
EXPECT_FALSE(trace_stream.is_enabled());
set_file_ctx.update_source_loc(
SourceLocation("example/main.carbon", 9, FileKind::Main));
EXPECT_TRUE(trace_stream.is_enabled());
set_file_ctx.update_source_loc(
SourceLocation("example/import.carbon", 9, FileKind::Import));
EXPECT_FALSE(trace_stream.is_enabled());
}
// The trace stream should be enabled when we're not in any particular file.
EXPECT_TRUE(trace_stream.is_enabled());
}
} // namespace
} // namespace Carbon