set_program_phase_raii_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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(SetProgramPhaseRaiiTest, Simple) {
  10. TraceStream trace_stream;
  11. trace_stream.set_current_phase(ProgramPhase::Unknown);
  12. {
  13. SetProgramPhase set_prog_phase(trace_stream, ProgramPhase::Execution);
  14. EXPECT_TRUE(trace_stream.current_phase() == ProgramPhase::Execution);
  15. }
  16. EXPECT_TRUE(trace_stream.current_phase() == ProgramPhase::Unknown);
  17. }
  18. TEST(SetProgramPhaseRaiiTest, UpdatePhase) {
  19. TraceStream trace_stream;
  20. trace_stream.set_current_phase(ProgramPhase::Unknown);
  21. {
  22. SetProgramPhase set_prog_phase(trace_stream, ProgramPhase::Execution);
  23. EXPECT_TRUE(trace_stream.current_phase() == ProgramPhase::Execution);
  24. set_prog_phase.update_phase(ProgramPhase::TypeChecking);
  25. EXPECT_TRUE(trace_stream.current_phase() == ProgramPhase::TypeChecking);
  26. }
  27. EXPECT_TRUE(trace_stream.current_phase() == ProgramPhase::Unknown);
  28. }
  29. } // namespace
  30. } // namespace Carbon