Get checkstyle tests passing.

Fix up the checkstyle test so they pass. There is still an issue with
the content, but I think that is caused by a problem with how diffs are
being calculated presently.
This commit is contained in:
Mark Story 2016-01-20 00:07:01 -05:00
parent d8c6f5954a
commit 9c275833fc
2 changed files with 12 additions and 23 deletions

View File

@ -65,7 +65,7 @@ fn coverage_tests() {
#[test]
fn checkstyle_test() {
let filename = "tests/target/fn-single-line.rs".to_string();
let filename = "tests/source/fn-single-line.rs".to_string();
let expected = "tests/writemode/checkstyle.xml";
let output = run_rustfmt(filename.clone(), WriteMode::Checkstyle);
@ -78,12 +78,12 @@ fn checkstyle_test() {
.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");
let compare = make_diff(&expected_text, &output, DIFF_CONTEXT_SIZE);
if compare.len() > 0 {
let mut failures = HashMap::new();
failures.insert(filename, compare);
print_mismatches(failures);
assert!(false, "Text does not match expected output");
}
}
@ -183,21 +183,10 @@ pub fn run_rustfmt(filename: String, write_mode: WriteMode) -> String {
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()
let mut out = Vec::new();
let file_map = format(Path::new(&filename), &config, write_mode);
let _ = filemap::write_all_files(&file_map, &mut out, write_mode, &config);
String::from_utf8(out).unwrap()
}
pub fn idempotent_check(filename: String,

View File

@ -1,2 +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: &amp;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() -&gt; String {`" /><error line="22" severity="warning" message="Should be ` &quot;yay&quot;`" /><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() -&gt; Vec&lt;i32&gt; {`" /><error line="60" severity="warning" message="Should be ` vec![]`" /><error line="60" severity="warning" message="Should be `}`" /></file></checkstyle>
<checkstyle version="4.3"><file name="tests/source/fn-single-line.rs"><error line="1" severity="warning" message="Should be `fn foo_expr() { 1 }`" /><error line="1" severity="warning" message="Should be `fn foo_stmt() { foo(); }`" /><error line="1" severity="warning" message="Should be `fn foo_decl_local() { let z = 5; }`" /><error line="1" severity="warning" message="Should be `fn foo_decl_item(x: &amp;mut i32) { x = 3; }`" /><error line="1" severity="warning" message="Should be `fn empty() {}`" /><error line="1" severity="warning" message="Should be `fn foo_return() -&gt; String { &quot;yay&quot; }`" /><error line="1" severity="warning" message="Should be `fn foo_where() -&gt; T`" /><error line="1" severity="warning" message="Should be ` where T: Sync`" /><error line="1" severity="warning" message="Should be `{`" /><error line="50" severity="warning" message="Should be `fn lots_of_space() { 1 }`" /><error line="57" severity="warning" message="Should be ` fn dummy(&amp;self) {}`" /><error line="57" severity="warning" message="Should be `trait CoolerTypes {`" /><error line="57" severity="warning" message="Should be ` fn dummy(&amp;self) {}`" /><error line="57" severity="warning" message="Should be `fn Foo&lt;T&gt;() where T: Bar {}`" /><error line="57" severity="warning" message="Should be ``" /></file></checkstyle>