don't read config twice during tests

This commit is contained in:
Aleksey Kladov 2016-04-02 23:41:25 +03:00
parent 84fb2f402e
commit 255231d9ed

View File

@ -74,12 +74,8 @@ fn checkstyle_test() {
// Helper function for comparing the results of rustfmt
// to a known output file generated by one of the write modes.
fn assert_output(source: &str, expected_filename: &str, write_mode: Option<WriteMode>) {
let file_map = run_rustfmt(source.to_string(), write_mode);
let mut config = read_config(&source);
if let Some(write_mode) = write_mode {
config.write_mode = write_mode;
}
let config = read_config(&source, write_mode);
let file_map = run_rustfmt(source.to_string(), &config);
// Populate output by writing to a vec.
let mut out = vec![];
@ -180,7 +176,7 @@ fn print_mismatches(result: HashMap<String, Vec<Mismatch>>) {
assert!(t.reset().unwrap());
}
fn read_config(filename: &str) -> Config {
fn read_config(filename: &str, write_mode: Option<WriteMode>) -> Config {
let sig_comments = read_significant_comments(&filename);
let mut config = get_config(sig_comments.get("config").map(|x| &(*x)[..]));
@ -192,15 +188,16 @@ fn read_config(filename: &str) -> Config {
// Don't generate warnings for to-do items.
config.report_todo = ReportTactic::Never;
if let Some(mode) = write_mode {
config.write_mode = mode
}
config
}
// Simulate run()
fn run_rustfmt(filename: String, write_mode: Option<WriteMode>) -> FileMap {
let mut config = read_config(&filename);
if let Some(write_mode) = write_mode {
config.write_mode = write_mode;
}
fn run_rustfmt(filename: String, config: &Config) -> FileMap {
format(Path::new(&filename), &config)
}
@ -208,8 +205,8 @@ pub fn idempotent_check(filename: String,
write_mode: Option<WriteMode>)
-> Result<FormatReport, HashMap<String, Vec<Mismatch>>> {
let sig_comments = read_significant_comments(&filename);
let config = read_config(&filename);
let mut file_map = run_rustfmt(filename, write_mode);
let config = read_config(&filename, write_mode);
let mut file_map = run_rustfmt(filename, &config);
let format_report = fmt_lines(&mut file_map, &config);
let mut write_result = HashMap::new();