]> Witch of Git - ivy/blob - src/bin/filecheck.rs
[tools] Add tools/lit.py
[ivy] / src / bin / filecheck.rs
1 use filecheck;
2 use std::{io::prelude::*, process};
3
4 fn main() {
5 let fname = match std::env::args().nth(1) {
6 Some(fname) => fname,
7 None => {
8 println!("Usage: filecheck <pattern-file>");
9 process::exit(1);
10 }
11 };
12
13 let text = match std::fs::read_to_string(&fname) {
14 Ok(text) => text,
15 Err(err) => {
16 println!("Error: failed to read '{}':\n{}", fname, err);
17 process::exit(1);
18 }
19 };
20
21 let checker = match filecheck::CheckerBuilder::new().text(&text) {
22 Ok(builder) => builder.finish(),
23 Err(err) => {
24 println!("Error parsing check directives: {}", err);
25 process::exit(1);
26 }
27 };
28
29 let mut buffer = String::new();
30 if let Err(err) = std::io::stdin().read_to_string(&mut buffer) {
31 println!("Error reading from stdin: {}", err);
32 process::exit(1);
33 }
34
35 let (success, explanation) = match checker.explain(&buffer, &()) {
36 Ok(res) => res,
37 Err(err) => {
38 println!("Error checking: {}", err);
39 process::exit(1);
40 }
41 };
42
43 if !success {
44 println!("{}", explanation);
45 process::exit(1);
46 }
47 }