set_file_context_raii_test.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include <gmock/gmock.h>
  5. #include <gtest/gtest.h>
  6. #include "explorer/base/trace_stream.h"
  7. namespace Carbon {
  8. namespace {
  9. TEST(SetFileContextRaiiTest, UpdateFileContext) {
  10. TraceStream trace_stream;
  11. trace_stream.set_stream(&llvm::nulls());
  12. trace_stream.set_allowed_phases({ProgramPhase::All});
  13. trace_stream.set_allowed_file_kinds({FileKind::Main});
  14. {
  15. SetFileContext set_file_ctx(
  16. trace_stream,
  17. SourceLocation("example/prelude.carbon", 9, FileKind::Prelude));
  18. EXPECT_FALSE(trace_stream.is_enabled());
  19. set_file_ctx.update_source_loc(
  20. SourceLocation("example/main.carbon", 9, FileKind::Main));
  21. EXPECT_TRUE(trace_stream.is_enabled());
  22. set_file_ctx.update_source_loc(
  23. SourceLocation("example/import.carbon", 9, FileKind::Import));
  24. EXPECT_FALSE(trace_stream.is_enabled());
  25. }
  26. // The trace stream should be enabled when we're not in any particular file.
  27. EXPECT_TRUE(trace_stream.is_enabled());
  28. }
  29. } // namespace
  30. } // namespace Carbon