mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:20:11 +01:00
To filter based on file contexts, you can use `-trace_file_context=...` flag along with `--trace_file=...` flag. These are the following options you can pass to the `-trace_file_context=...` flag (you can also pass them as list by separating them with comma). 1. `main`: Include trace output for file containing the main function. 2. `prelude`: Include trace output for prelude. 3. `import`: Include trace output for imports. 4. `include`: Include trace output for all. If the flag isn't used or non of the options are passed, by default only main file context is traced. File contexts are distinguished based upon the source location by passing the source location to `TraceStream::is_enabled(..)` as arguments. If no arguments are passed, file context is `FileContext::Unknown` and for now it will add the trace from unknown file context. Note: `import` option currently doesn't work as imports aren't supported yet. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
48 lines
1.6 KiB
C++
48 lines
1.6 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 {
|
|
|
|
// TODO: write test cases to distinguish between file context of main file and
|
|
// an import once imports are supported.
|
|
|
|
TEST(SetFileContextRaiiTest, Simple) {
|
|
TraceStream trace_stream;
|
|
{
|
|
SetFileContext set_file_ctx(trace_stream,
|
|
SourceLocation("example/main.carbon", 9));
|
|
EXPECT_TRUE(trace_stream.file_context() == FileContext::Main);
|
|
}
|
|
|
|
// Considering the file context for a trace stream is FileContext::Unknown by
|
|
// default, as the default value of source location in a trace stream is
|
|
// std::nullopt.
|
|
EXPECT_TRUE(trace_stream.file_context() == FileContext::Unknown);
|
|
}
|
|
|
|
TEST(SetFileContextRaiiTest, UpdateFileContext) {
|
|
TraceStream trace_stream;
|
|
{
|
|
SetFileContext set_file_ctx(trace_stream,
|
|
SourceLocation("example/prelude.carbon", 9));
|
|
EXPECT_TRUE(trace_stream.file_context() == FileContext::Prelude);
|
|
set_file_ctx.update_source_loc(SourceLocation("example/main.carbon", 9));
|
|
EXPECT_TRUE(trace_stream.file_context() == FileContext::Main);
|
|
}
|
|
|
|
// Considering the file context for a trace stream is FileContext::Unknown by
|
|
// default, as the default value of source location in a trace stream is
|
|
// std::nullopt.
|
|
EXPECT_TRUE(trace_stream.file_context() == FileContext::Unknown);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace Carbon::Testing
|