mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Implement autoupdate for file_test. (#3043)
I've migrated the toolchain autoupdate scripts here, I just need a little more time to do the explorer side (which I need to check performance, that may require multithreading as we do in the current script). However, this felt substantial enough to share and it means I can handle autoupdate in more of the toolchain, including preparatory work for autoupdate on multi-file tests. Once explorer is done I'll remove the old script.
This commit is contained in:
@@ -7,11 +7,7 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace Carbon::Testing {
|
||||
namespace {
|
||||
@@ -34,10 +30,10 @@ class FileTestBaseTest : public FileTestBase {
|
||||
return Field("content", &TestFile::content, Eq(content));
|
||||
}
|
||||
|
||||
auto RunWithFiles(const llvm::SmallVector<llvm::StringRef>& test_args,
|
||||
const llvm::SmallVector<TestFile>& test_files,
|
||||
llvm::raw_pwrite_stream& stdout,
|
||||
llvm::raw_pwrite_stream& stderr) -> bool override {
|
||||
auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
|
||||
const llvm::SmallVector<TestFile>& test_files,
|
||||
llvm::raw_pwrite_stream& stdout, llvm::raw_pwrite_stream& stderr)
|
||||
-> ErrorOr<bool> override {
|
||||
if (!test_args.empty()) {
|
||||
llvm::ListSeparator sep;
|
||||
stdout << test_args.size() << " args: ";
|
||||
@@ -49,38 +45,46 @@ class FileTestBaseTest : public FileTestBase {
|
||||
|
||||
auto filename = path().filename();
|
||||
if (filename == "args.carbon") {
|
||||
EXPECT_THAT(test_files, ElementsAre(HasFilename("args.carbon")));
|
||||
return true;
|
||||
} else if (filename == "example.carbon") {
|
||||
EXPECT_THAT(test_files, ElementsAre(HasFilename("example.carbon")));
|
||||
int delta_line = 10;
|
||||
stdout << "something\n"
|
||||
"\n"
|
||||
"9: Line delta\n"
|
||||
"8: Negative line delta\n"
|
||||
"+*[]{}\n"
|
||||
"Foo baz\n";
|
||||
<< "\n"
|
||||
<< "example.carbon:" << delta_line + 1 << ": Line delta\n"
|
||||
<< "example.carbon:" << delta_line << ": Negative line delta\n"
|
||||
<< "+*[]{}\n"
|
||||
<< "Foo baz\n";
|
||||
return true;
|
||||
} else if (filename == "fail_example.carbon") {
|
||||
EXPECT_THAT(test_files, ElementsAre(HasFilename("fail_example.carbon")));
|
||||
stderr << "Oops\n";
|
||||
return false;
|
||||
} else if (filename == "two_files.carbon") {
|
||||
int i = 0;
|
||||
for (const auto& file : test_files) {
|
||||
// Prints line numbers to validate per-file.
|
||||
stdout << file.filename << ": " << ++i << "\n";
|
||||
stdout << file.filename << ":2: " << ++i << "\n";
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return ErrorBuilder() << "Unexpected file: " << filename;
|
||||
}
|
||||
}
|
||||
|
||||
auto ValidateRun(const llvm::SmallVector<TestFile>& test_files)
|
||||
-> void override {
|
||||
auto filename = path().filename();
|
||||
if (filename == "two_files.carbon") {
|
||||
EXPECT_THAT(
|
||||
test_files,
|
||||
ElementsAre(
|
||||
AllOf(HasFilename("a.carbon"),
|
||||
HasContent("// CHECK:STDOUT: a.carbon: [[@LINE+0]]\n\n")),
|
||||
HasContent(
|
||||
"// CHECK:STDOUT: a.carbon:[[@LINE+1]]: 1\naaa\n\n")),
|
||||
AllOf(HasFilename("b.carbon"),
|
||||
HasContent("// CHECK:STDOUT: b.carbon: [[@LINE+1]]\n"))));
|
||||
return true;
|
||||
HasContent(
|
||||
"// CHECK:STDOUT: b.carbon:[[@LINE+1]]: 2\nbbb\n"))));
|
||||
} else {
|
||||
ADD_FAILURE() << "Unexpected file: " << filename;
|
||||
return false;
|
||||
EXPECT_THAT(test_files, ElementsAre(HasFilename(filename)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user