parse_and_execute_test.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. TEST(ParseAndExecuteTest, Recursion) {
  11. std::string source = R"(
  12. package Test api;
  13. fn Main() -> i32 {
  14. return
  15. )";
  16. // A high depth that's expected to complete in a few seconds.
  17. static constexpr int Depth = 50000;
  18. for (int i = 0; i < Depth; ++i) {
  19. source += "if true then\n";
  20. }
  21. source += "1\n";
  22. for (int i = 0; i < Depth; ++i) {
  23. source += "else 0\n";
  24. }
  25. source += R"(
  26. ;
  27. }
  28. )";
  29. auto err = ParseAndExecute("explorer/data/prelude.carbon", source);
  30. ASSERT_FALSE(err.ok());
  31. EXPECT_THAT(err.error().message(),
  32. Eq("RUNTIME ERROR: overflow:1: stack overflow: too many "
  33. "interpreter actions on stack"));
  34. }
  35. } // namespace
  36. } // namespace Carbon::Testing