1 #pragma once 2 3 #include <torch/csrc/Export.h> 4 #include <memory> 5 #include <string> 6 7 namespace torch { 8 namespace jit { 9 10 struct Graph; 11 12 namespace testing { 13 14 struct FileCheckImpl; 15 16 struct FileCheck { 17 public: 18 TORCH_API explicit FileCheck(); 19 TORCH_API ~FileCheck(); 20 21 // Run FileCheck against test string 22 TORCH_API void run(const std::string& test_string); 23 24 // Run FileCheck against dump of graph IR 25 TORCH_API void run(const Graph& graph); 26 27 // Parsing input checks string and run against test string / dump of graph IR 28 TORCH_API void run( 29 const std::string& input_checks_string, 30 const std::string& test_string); 31 TORCH_API void run( 32 const std::string& input_checks_string, 33 const Graph& graph); 34 35 // Checks that the string occurs, starting at the end of the most recent match 36 TORCH_API FileCheck* check(const std::string& str); 37 38 // Checks that the string does not occur between the previous match and next 39 // match. Consecutive check_nots test against the same previous match and next 40 // match 41 TORCH_API FileCheck* check_not(const std::string& str); 42 43 // Checks that the string occurs on the same line as the previous match 44 TORCH_API FileCheck* check_same(const std::string& str); 45 46 // Checks that the string occurs on the line immediately following the 47 // previous match 48 TORCH_API FileCheck* check_next(const std::string& str); 49 50 // Checks that the string occurs count number of times, starting at the end 51 // of the previous match. If exactly is true, checks that there are exactly 52 // count many matches 53 TORCH_API FileCheck* check_count( 54 const std::string& str, 55 size_t count, 56 bool exactly = false); 57 58 // A series of consecutive check_dags get turned into a group of checks 59 // which can appear in any order relative to each other. The checks begin 60 // at the end of the previous match, and the match for the check_dag group 61 // is the minimum match of all individual checks to the maximum match of all 62 // individual checks. 63 TORCH_API FileCheck* check_dag(const std::string& str); 64 65 // Checks that source token is highlighted in str (usually an error message). 66 TORCH_API FileCheck* check_source_highlighted(const std::string& str); 67 68 // Checks that the regex matched string occurs, starting at the end of the 69 // most recent match 70 TORCH_API FileCheck* check_regex(const std::string& str); 71 72 // reset checks 73 TORCH_API void reset(); 74 75 private: 76 bool has_run = false; 77 std::unique_ptr<FileCheckImpl> fcImpl; 78 }; 79 } // namespace testing 80 } // namespace jit 81 } // namespace torch 82