mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-25 16:31:10 +00:00
Lex now prints its yaml as: ``` - filename: name tokens: [ ... ] ``` New support in file_test allows the `filename` marker at the top to define the default file number for later lines, meaning multi-file output from lexing is now associated with the appropriate file. Similar support will probably also apply to lowering, semir, and other places that print a filename once for the full dump. This hammers a bit at how line number replacements work in file_test, allowing stacking them so that lex errors and stdout can both be line-associated properly. I've tried to make the autoupdate more frequently work in one pass, now also taking into account the file index when doing line replacements. There are still some issues with EndOfFile that it may be good to discuss: because CHECK lines are appended to the end of the file now, and the EndOfFile token points at the last line including comments, new lex tests now take two runs to autoupdate (because without CHECK lines, the EndOfFile points at a content line, which content is then inserted after). Note that removing CHECK lines from the test is not a solution: autoupdate also started inserting blank lines, which breaks this for a similar reason. One solution here might be to not have EndOfFile associate with a line or column, which has been a bit of an issue regardless. Also fixes a small issue with toolchain's autoupdate script.
46 lines
1.6 KiB
C++
46 lines
1.6 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
|
|
|
|
#ifndef CARBON_TESTING_FILE_TEST_AUTOUPDATE_H_
|
|
#define CARBON_TESTING_FILE_TEST_AUTOUPDATE_H_
|
|
|
|
#include <filesystem>
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "re2/re2.h"
|
|
#include "testing/file_test/line.h"
|
|
|
|
namespace Carbon::Testing {
|
|
|
|
struct FileTestLineNumberReplacement {
|
|
bool has_file;
|
|
|
|
// The line replacement. The pattern should match lines. If has_file, pattern
|
|
// should have a file and line group; otherwise, only a line group, but
|
|
// default_file_re should be provided.
|
|
//
|
|
// Uses shared_ptr for storage in SmallVector.
|
|
std::shared_ptr<RE2> re;
|
|
|
|
// line_formatv should provide {0} to substitute with [[@LINE...]] deltas.
|
|
std::string line_formatv;
|
|
};
|
|
|
|
// Automatically updates CHECKs in the provided file. Returns true if updated.
|
|
auto AutoupdateFileTest(
|
|
const std::filesystem::path& file_test_path, llvm::StringRef input_content,
|
|
const llvm::SmallVector<llvm::StringRef>& filenames,
|
|
int autoupdate_line_number,
|
|
const llvm::SmallVector<llvm::SmallVector<FileTestLine>>& non_check_lines,
|
|
llvm::StringRef stdout, llvm::StringRef stderr,
|
|
const std::optional<RE2>& default_file_re,
|
|
const llvm::SmallVector<FileTestLineNumberReplacement>&
|
|
line_number_replacements,
|
|
std::function<void(std::string&)> do_extra_check_replacements) -> bool;
|
|
|
|
} // namespace Carbon::Testing
|
|
|
|
#endif // CARBON_TESTING_FILE_TEST_AUTOUPDATE_H_
|