autoupdate.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TESTING_FILE_TEST_AUTOUPDATE_H_
  5. #define CARBON_TESTING_FILE_TEST_AUTOUPDATE_H_
  6. #include <filesystem>
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "llvm/ADT/StringRef.h"
  9. #include "testing/file_test/line.h"
  10. namespace Carbon::Testing {
  11. struct FileTestLineNumberReplacement {
  12. bool has_file;
  13. // The line replacement. The pattern should match lines. If has_file, pattern
  14. // should have a file and line group; otherwise, only a line group.
  15. std::string pattern;
  16. // line_formatv should provide {0} to substitute with [[@LINE...]] deltas.
  17. std::string line_formatv;
  18. };
  19. // Automatically updates CHECKs in the provided file. Returns true if updated.
  20. auto AutoupdateFileTest(
  21. const std::filesystem::path& file_test_path, llvm::StringRef input_content,
  22. const llvm::SmallVector<llvm::StringRef>& filenames,
  23. int autoupdate_line_number,
  24. llvm::SmallVector<llvm::SmallVector<FileTestLine>>& non_check_lines,
  25. llvm::StringRef stdout, llvm::StringRef stderr,
  26. FileTestLineNumberReplacement line_number_replacement,
  27. std::function<void(std::string&)> do_extra_check_replacements) -> bool;
  28. } // namespace Carbon::Testing
  29. #endif // CARBON_TESTING_FILE_TEST_AUTOUPDATE_H_