parse_and_execute_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "explorer/parse_and_execute/parse_and_execute.h"
  5. #include <gmock/gmock.h>
  6. #include <gtest/gtest.h>
  7. namespace Carbon::Testing {
  8. namespace {
  9. using ::testing::Eq;
  10. using ::testing::MatchesRegex;
  11. TEST(ParseAndExecuteTest, Recursion) {
  12. std::string source = R"(
  13. package Test api;
  14. fn Main() -> i32 {
  15. return
  16. )";
  17. // A high depth that's expected to complete in a few seconds.
  18. static constexpr int Depth = 50000;
  19. for (int i = 0; i < Depth; ++i) {
  20. source += "if true then\n";
  21. }
  22. source += "1\n";
  23. for (int i = 0; i < Depth; ++i) {
  24. source += "else 0\n";
  25. }
  26. source += R"(
  27. ;
  28. }
  29. )";
  30. TraceStream trace_stream;
  31. auto err =
  32. ParseAndExecute("explorer/data/prelude.carbon", "test.carbon", source,
  33. /*parser_debug=*/false, &trace_stream, &llvm::nulls());
  34. ASSERT_FALSE(err.ok());
  35. // Don't expect any particular source location for the error.
  36. EXPECT_THAT(err.error().message(),
  37. MatchesRegex("RUNTIME ERROR:.* stack overflow: too many "
  38. "interpreter actions on stack"));
  39. }
  40. } // namespace
  41. } // namespace Carbon::Testing