Files
carbon-lang/explorer/parse_and_execute/parse_and_execute_test.cpp
T
Richard SmithandJon Ross-Perkins ea60e4f491 Track the file kind on SourceLocation rather than computing it from the file name. (#2999)
This will be more correct if a user file is named prelude.carbon, and
reduces the explorer runtime by about 10% by removing a string
comparison from the check for whether trace output is enabled.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-07-19 23:07:53 +00:00

48 lines
1.3 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "explorer/parse_and_execute/parse_and_execute.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace Carbon::Testing {
namespace {
using ::testing::Eq;
using ::testing::MatchesRegex;
TEST(ParseAndExecuteTest, Recursion) {
std::string source = R"(
package Test api;
fn Main() -> i32 {
return
)";
// A high depth that's expected to complete in a few seconds.
static constexpr int Depth = 50000;
for (int i = 0; i < Depth; ++i) {
source += "if true then\n";
}
source += "1\n";
for (int i = 0; i < Depth; ++i) {
source += "else 0\n";
}
source += R"(
;
}
)";
TraceStream trace_stream;
auto err =
ParseAndExecute("explorer/data/prelude.carbon", "test.carbon", source,
/*parser_debug=*/false, &trace_stream, &llvm::nulls());
ASSERT_FALSE(err.ok());
// Don't expect any particular source location for the error.
EXPECT_THAT(err.error().message(),
MatchesRegex("RUNTIME ERROR:.* stack overflow: too many "
"interpreter actions on stack"));
}
} // namespace
} // namespace Carbon::Testing