Files
carbon-lang/toolchain/lexer/lexer_file_test.cpp
T
Jon Ross-Perkins b5167b2d69 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.
2023-08-02 21:32:21 +00:00

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: +(\d+))",
// The `{{{{` becomes `{{`.
.sub_for_formatv = "line: {{{{ *}}{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