mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 16:00:33 +00:00
This migrates explorer tests to file_test, using the new --autoupdate functionality. Per discussion, the trace tests that were using "not" output are mostly migrated to checking full output. The main exception is tests that were including trace output from the prelude: the prelude output is pretty long (multiple MB already) and I think it wasn't the intent to include, only trace output from the small program. This is the remaining use of lit support, so the supporting libraries are also removed here.
47 lines
1.3 KiB
C++
47 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 <string>
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "re2/re2.h"
|
|
#include "toolchain/driver/driver_file_test_base.h"
|
|
|
|
namespace Carbon::Testing {
|
|
namespace {
|
|
|
|
class LexerFileTest : public DriverFileTestBase {
|
|
public:
|
|
explicit LexerFileTest(std::filesystem::path path)
|
|
: DriverFileTestBase(std::move(path)),
|
|
end_of_file_re_((R"((EndOfFile.*column: )( *\d+))")) {}
|
|
|
|
auto GetDefaultArgs() -> llvm::SmallVector<std::string> override {
|
|
return {"dump", "tokens", "%s"};
|
|
}
|
|
|
|
auto GetLineNumberReplacement(llvm::ArrayRef<llvm::StringRef> /*filenames*/)
|
|
-> LineNumberReplacement override {
|
|
return {.has_file = false,
|
|
.pattern = R"(line: (\s*\d+))",
|
|
// The `{{{{` becomes `{{`.
|
|
.line_formatv = "{{{{ *}}{0}"};
|
|
}
|
|
|
|
auto DoExtraCheckReplacements(std::string& check_line) -> void override {
|
|
// Ignore the resulting column of EndOfFile because it's often the end of
|
|
// the CHECK comment.
|
|
RE2::Replace(&check_line, end_of_file_re_, R"(\1{{ *\\d+}})");
|
|
}
|
|
|
|
private:
|
|
RE2 end_of_file_re_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
CARBON_FILE_TEST_FACTORY(LexerFileTest);
|
|
|
|
} // namespace Carbon::Testing
|