mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Start tests for checkstyle.
They don't yet pass, I've clearly misunderstood the existing tests.
This commit is contained in:
parent
5632831bd1
commit
66d4faf53f
@ -63,6 +63,30 @@ fn coverage_tests() {
|
||||
assert!(fails == 0, "{} tests failed", fails);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkstyle_test() {
|
||||
let filename = "tests/target/fn-single-line.rs".to_string();
|
||||
let expected = "tests/writemode/checkstyle.xml";
|
||||
|
||||
let output = run_rustfmt(filename.clone(), WriteMode::Checkstyle);
|
||||
|
||||
let mut expected_file = fs::File::open(&expected)
|
||||
.ok()
|
||||
.expect("Couldn't open target.");
|
||||
let mut expected_text = String::new();
|
||||
expected_file.read_to_string(&mut expected_text)
|
||||
.ok()
|
||||
.expect("Failed reading target.");
|
||||
|
||||
let mut failures = HashMap::new();
|
||||
if expected_text != output {
|
||||
let diff = make_diff(&expected_text, &output, DIFF_CONTEXT_SIZE);
|
||||
failures.insert(filename, diff);
|
||||
// print_mismatches(failures);
|
||||
// assert!(false, "Text does not match expected output");
|
||||
}
|
||||
}
|
||||
|
||||
// Idempotence tests. Files in tests/target are checked to be unaltered by
|
||||
// rustfmt.
|
||||
#[test]
|
||||
@ -145,6 +169,37 @@ fn print_mismatches(result: HashMap<String, Vec<Mismatch>>) {
|
||||
assert!(t.reset().unwrap());
|
||||
}
|
||||
|
||||
pub fn run_rustfmt(filename: String, write_mode: WriteMode) -> String {
|
||||
let sig_comments = read_significant_comments(&filename);
|
||||
let mut config = get_config(sig_comments.get("config").map(|x| &(*x)[..]));
|
||||
|
||||
for (key, val) in &sig_comments {
|
||||
if key != "target" && key != "config" {
|
||||
config.override_value(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
// Don't generate warnings for to-do items.
|
||||
config.report_todo = ReportTactic::Never;
|
||||
|
||||
// Simulate run()
|
||||
let mut file_map = format(Path::new(&filename), &config, write_mode);
|
||||
// TODO this writes directly to stdout making it impossible to test :(
|
||||
let write_result = filemap::write_all_files(&file_map, write_mode, &config);
|
||||
let res = write_result.unwrap();
|
||||
String::new()
|
||||
|
||||
// for (filename, text) in file_map.iter() {
|
||||
// let mut v = Vec::new();
|
||||
// // Won't panic, as we're not doing any IO.
|
||||
// write_system_newlines(&mut v, text, &config).unwrap();
|
||||
// // Won't panic, we are writing correct utf8.
|
||||
// let one_result = String::from_utf8(v).unwrap();
|
||||
// write_result.insert(filename, one_result);
|
||||
// }
|
||||
// write_result.remove(&filename).unwrap().to_owned()
|
||||
}
|
||||
|
||||
pub fn idempotent_check(filename: String,
|
||||
write_mode: WriteMode)
|
||||
-> Result<FormatReport, HashMap<String, Vec<Mismatch>>> {
|
||||
|
2
tests/writemode/checkstyle.xml
Normal file
2
tests/writemode/checkstyle.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<checkstyle version="4.3"><file name="tests/target/fn-single-line.rs"><error line="1" severity="warning" message="Should be `fn foo_expr() {`" /><error line="1" severity="warning" message="Should be ` 1`" /><error line="1" severity="warning" message="Should be `}`" /><error line="1" severity="warning" message="Should be `fn foo_stmt() {`" /><error line="1" severity="warning" message="Should be ` foo();`" /><error line="1" severity="warning" message="Should be `}`" /><error line="1" severity="warning" message="Should be `fn foo_decl_local() {`" /><error line="1" severity="warning" message="Should be ` let z = 5;`" /><error line="1" severity="warning" message="Should be `}`" /><error line="1" severity="warning" message="Should be `fn foo_decl_item(x: &mut i32) {`" /><error line="1" severity="warning" message="Should be ` x = 3;`" /><error line="1" severity="warning" message="Should be `}`" /><error line="22" severity="warning" message="Should be `fn foo_return() -> String {`" /><error line="22" severity="warning" message="Should be ` "yay"`" /><error line="22" severity="warning" message="Should be `}`" /><error line="60" severity="warning" message="Should be `fn lots_of_space() {`" /><error line="60" severity="warning" message="Should be ` 1`" /><error line="60" severity="warning" message="Should be `}`" /><error line="60" severity="warning" message="Should be `fn mac() -> Vec<i32> {`" /><error line="60" severity="warning" message="Should be ` vec![]`" /><error line="60" severity="warning" message="Should be `}`" /></file></checkstyle>
|
Loading…
Reference in New Issue
Block a user