Change explorer's file_test to support argument passing to main. (#3032)

This shifts explorer's file_test to use ExplorerMain in order to be able
to pass arguments similar to how the command line would. It also means
that various output wrapping done by the command line is shared, no
longer copied by file_test.

In order to help make this work, I plugged vfs::FileSystem into
explorer, similar to how we're doing this on the toolchain side (might
try to share more code later). I was having trouble getting an overlay
working, I think due to how paths are specified -- but due to the issues
in fixing this, I'm just loading the prelude into the InMemoryFilesystem
for now.

Under this approach, I'm unifying more of the file versus string
handling. I think we should shift towards an approach where, like
toolchain code, anyone trying to use Explorer should use a vfs
implementation to supply code. This should reduce the number of distinct
code paths which we're maintaining/testing.

Short-term, this allows the trace testdata to be merged into file_test
with less special casing, using ARGS:. Long-term, it means that the
file_test knows the ARGS to pass to generate checks to match against,
which is the direction I'm planning for autoupdate.
This commit is contained in:
Jon Ross-Perkins
2023-07-28 15:29:51 +00:00
committed by GitHub
parent 3f24aa28b7
commit 9e03d5efe2
18 changed files with 167 additions and 139 deletions
@@ -10,10 +10,16 @@
namespace Carbon::Testing {
namespace {
using ::testing::Eq;
using ::testing::MatchesRegex;
TEST(ParseAndExecuteTest, Recursion) {
llvm::vfs::InMemoryFileSystem fs;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> prelude =
llvm::MemoryBuffer::getFile("explorer/data/prelude.carbon");
ASSERT_FALSE(prelude.getError()) << prelude.getError().message();
ASSERT_TRUE(fs.addFile("prelude.carbon", /*ModificationTime=*/0,
std::move(*prelude)));
std::string source = R"(
package Test api;
fn Main() -> i32 {
@@ -32,9 +38,12 @@ TEST(ParseAndExecuteTest, Recursion) {
;
}
)";
ASSERT_TRUE(fs.addFile("test.carbon", /*ModificationTime=*/0,
llvm::MemoryBuffer::getMemBuffer(source)));
TraceStream trace_stream;
auto err =
ParseAndExecute("explorer/data/prelude.carbon", "test.carbon", source,
ParseAndExecute(fs, "prelude.carbon", "test.carbon",
/*parser_debug=*/false, &trace_stream, &llvm::nulls());
ASSERT_FALSE(err.ok());
// Don't expect any particular source location for the error.