Files
carbon-lang/explorer/common/set_file_context_raii_test.cpp
T
Richard SmithandJon Ross-Perkins ea60e4f491 Track the file kind on SourceLocation rather than computing it from the file name. (#2999)
This will be more correct if a user file is named prelude.carbon, and
reduces the explorer runtime by about 10% by removing a string
comparison from the check for whether trace output is enabled.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-07-19 23:07:53 +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/common/trace_stream.h"
namespace Carbon::Testing {
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::Testing