Run filecheck on `text`, using directives extracted from `context`.
(text: &str, context: &Context)
| 111 | |
| 112 | /// Run filecheck on `text`, using directives extracted from `context`. |
| 113 | pub fn run_filecheck(text: &str, context: &Context) -> anyhow::Result<()> { |
| 114 | log::debug!( |
| 115 | "Filecheck Input:\n\ |
| 116 | =======================\n\ |
| 117 | {text}\n\ |
| 118 | =======================" |
| 119 | ); |
| 120 | let checker = build_filechecker(context)?; |
| 121 | if checker |
| 122 | .check(text, NO_VARIABLES) |
| 123 | .context("filecheck failed")? |
| 124 | { |
| 125 | Ok(()) |
| 126 | } else { |
| 127 | // Filecheck mismatch. Emit an explanation as output. |
| 128 | let (_, explain) = checker |
| 129 | .explain(text, NO_VARIABLES) |
| 130 | .context("filecheck explain failed")?; |
| 131 | anyhow::bail!( |
| 132 | "filecheck failed for function on line {}:\n{}{}", |
| 133 | context.details.location.line_number, |
| 134 | checker, |
| 135 | explain |
| 136 | ); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /// Build a filechecker using the directives in the file preamble and the function's comments. |
| 141 | pub fn build_filechecker(context: &Context) -> anyhow::Result<Checker> { |