parse_and_execute_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. TraceStream trace_stream;
  30. auto err =
  31. ParseAndExecute("explorer/data/prelude.carbon", "test.carbon", source,
  32. /*parser_debug=*/false, &trace_stream, &llvm::nulls());
  33. ASSERT_FALSE(err.ok());
  34. EXPECT_THAT(err.error().message(),
  35. Eq("RUNTIME ERROR: overflow:1: stack overflow: too many "
  36. "interpreter actions on stack"));
  37. }
  38. } // namespace
  39. } // namespace Carbon::Testing