2015-05-28 12:23:07 -05:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
extern crate rustfmt;
|
|
|
|
extern crate diff;
|
|
|
|
extern crate regex;
|
2015-08-30 13:47:46 -05:00
|
|
|
extern crate term;
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2015-09-10 17:27:22 -05:00
|
|
|
use std::collections::HashMap;
|
2015-05-28 12:23:07 -05:00
|
|
|
use std::fs;
|
|
|
|
use std::io::{self, Read, BufRead, BufReader};
|
2016-04-02 16:32:24 -05:00
|
|
|
use std::path::{Path, PathBuf};
|
2015-09-17 13:21:06 -05:00
|
|
|
|
2015-05-28 12:23:07 -05:00
|
|
|
use rustfmt::*;
|
2016-01-21 21:09:01 -06:00
|
|
|
use rustfmt::filemap::{write_system_newlines, FileMap};
|
2016-04-04 18:02:22 -05:00
|
|
|
use rustfmt::config::{Config, ReportTactic};
|
2015-09-10 17:27:22 -05:00
|
|
|
use rustfmt::rustfmt_diff::*;
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2016-02-01 22:40:45 -06:00
|
|
|
const DIFF_CONTEXT_SIZE: usize = 3;
|
2015-08-30 13:47:46 -05:00
|
|
|
|
2015-05-28 12:23:07 -05:00
|
|
|
fn get_path_string(dir_entry: io::Result<fs::DirEntry>) -> String {
|
2016-01-31 11:58:38 -06:00
|
|
|
let path = dir_entry.expect("Couldn't get DirEntry").path();
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2016-01-31 11:58:38 -06:00
|
|
|
path.to_str().expect("Couldn't stringify path").to_owned()
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
|
2015-06-23 06:26:04 -05:00
|
|
|
// Integration tests. The files in the tests/source are formatted and compared
|
|
|
|
// to their equivalent in tests/target. The target file and config can be
|
2016-11-02 23:22:16 -05:00
|
|
|
// overridden by annotations in the source file. The input and output must match
|
2015-06-23 06:26:04 -05:00
|
|
|
// exactly.
|
|
|
|
// FIXME(#28) would be good to check for error messages and fail on them, or at
|
|
|
|
// least report.
|
2015-05-28 12:23:07 -05:00
|
|
|
#[test]
|
|
|
|
fn system_tests() {
|
2015-09-17 13:21:06 -05:00
|
|
|
// Get all files in the tests/source directory.
|
2016-01-31 11:58:38 -06:00
|
|
|
let files = fs::read_dir("tests/source").expect("Couldn't read source dir");
|
2015-09-17 13:21:06 -05:00
|
|
|
// Turn a DirEntry into a String that represents the relative path to the
|
|
|
|
// file.
|
2015-05-28 12:23:07 -05:00
|
|
|
let files = files.map(get_path_string);
|
2016-04-04 18:02:22 -05:00
|
|
|
let (_reports, count, fails) = check_files(files);
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2015-09-17 13:21:06 -05:00
|
|
|
// Display results.
|
2015-06-23 06:26:04 -05:00
|
|
|
println!("Ran {} system tests.", count);
|
|
|
|
assert!(fails == 0, "{} system tests failed", fails);
|
|
|
|
}
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2015-10-23 09:42:07 -05:00
|
|
|
// Do the same for tests/coverage-source directory
|
|
|
|
// the only difference is the coverage mode
|
|
|
|
#[test]
|
|
|
|
fn coverage_tests() {
|
2016-04-04 18:02:22 -05:00
|
|
|
let files = fs::read_dir("tests/coverage/source").expect("Couldn't read source dir");
|
2015-10-23 09:42:07 -05:00
|
|
|
let files = files.map(get_path_string);
|
2016-04-04 18:02:22 -05:00
|
|
|
let (_reports, count, fails) = check_files(files);
|
2015-10-23 09:42:07 -05:00
|
|
|
|
|
|
|
println!("Ran {} tests in coverage mode.", count);
|
|
|
|
assert!(fails == 0, "{} tests failed", fails);
|
|
|
|
}
|
|
|
|
|
2016-01-17 22:06:00 -06:00
|
|
|
#[test]
|
|
|
|
fn checkstyle_test() {
|
2016-04-04 18:02:22 -05:00
|
|
|
let filename = "tests/writemode/source/fn-single-line.rs";
|
|
|
|
let expected_filename = "tests/writemode/target/checkstyle.xml";
|
|
|
|
assert_output(filename, expected_filename);
|
2016-01-21 21:09:01 -06:00
|
|
|
}
|
|
|
|
|
2016-01-17 22:06:00 -06:00
|
|
|
|
2016-01-21 21:09:01 -06:00
|
|
|
// Helper function for comparing the results of rustfmt
|
|
|
|
// to a known output file generated by one of the write modes.
|
2016-04-04 18:02:22 -05:00
|
|
|
fn assert_output(source: &str, expected_filename: &str) {
|
|
|
|
let config = read_config(&source);
|
2016-04-02 16:32:24 -05:00
|
|
|
let (file_map, _report) = format_file(source, &config);
|
2016-02-05 14:59:41 -06:00
|
|
|
|
2016-01-21 21:09:01 -06:00
|
|
|
// Populate output by writing to a vec.
|
|
|
|
let mut out = vec![];
|
2016-02-05 14:59:41 -06:00
|
|
|
let _ = filemap::write_all_files(&file_map, &mut out, &config);
|
2016-01-21 21:09:01 -06:00
|
|
|
let output = String::from_utf8(out).unwrap();
|
|
|
|
|
2016-01-31 11:58:38 -06:00
|
|
|
let mut expected_file = fs::File::open(&expected_filename).expect("Couldn't open target");
|
2016-01-17 22:06:00 -06:00
|
|
|
let mut expected_text = String::new();
|
|
|
|
expected_file.read_to_string(&mut expected_text)
|
2016-04-22 02:03:36 -05:00
|
|
|
.expect("Failed reading target");
|
2016-01-17 22:06:00 -06:00
|
|
|
|
2016-01-19 23:07:01 -06:00
|
|
|
let compare = make_diff(&expected_text, &output, DIFF_CONTEXT_SIZE);
|
|
|
|
if compare.len() > 0 {
|
|
|
|
let mut failures = HashMap::new();
|
2016-01-21 21:09:01 -06:00
|
|
|
failures.insert(source.to_string(), compare);
|
2016-01-19 23:07:01 -06:00
|
|
|
print_mismatches(failures);
|
|
|
|
assert!(false, "Text does not match expected output");
|
2016-01-17 22:06:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 06:26:04 -05:00
|
|
|
// Idempotence tests. Files in tests/target are checked to be unaltered by
|
|
|
|
// rustfmt.
|
|
|
|
#[test]
|
|
|
|
fn idempotence_tests() {
|
2015-09-17 13:21:06 -05:00
|
|
|
// Get all files in the tests/target directory.
|
|
|
|
let files = fs::read_dir("tests/target")
|
2016-04-22 01:53:39 -05:00
|
|
|
.expect("Couldn't read target dir")
|
|
|
|
.map(get_path_string);
|
2016-04-04 18:02:22 -05:00
|
|
|
let (_reports, count, fails) = check_files(files);
|
2015-09-17 13:21:06 -05:00
|
|
|
|
|
|
|
// Display results.
|
|
|
|
println!("Ran {} idempotent tests.", count);
|
|
|
|
assert!(fails == 0, "{} idempotent tests failed", fails);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run rustfmt on itself. This operation must be idempotent. We also check that
|
|
|
|
// no warnings are emitted.
|
|
|
|
#[test]
|
|
|
|
fn self_tests() {
|
|
|
|
let files = fs::read_dir("src/bin")
|
2016-04-22 01:53:39 -05:00
|
|
|
.expect("Couldn't read src dir")
|
|
|
|
.chain(fs::read_dir("tests").expect("Couldn't read tests dir"))
|
|
|
|
.map(get_path_string);
|
2015-09-17 13:21:06 -05:00
|
|
|
// Hack because there's no `IntoIterator` impl for `[T; N]`.
|
2015-06-23 06:26:04 -05:00
|
|
|
let files = files.chain(Some("src/lib.rs".to_owned()).into_iter());
|
2016-06-12 03:38:03 -05:00
|
|
|
let files = files.chain(Some("build.rs".to_owned()).into_iter());
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2016-04-04 18:02:22 -05:00
|
|
|
let (reports, count, fails) = check_files(files);
|
2015-09-17 13:21:06 -05:00
|
|
|
let mut warnings = 0;
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2015-09-17 13:21:06 -05:00
|
|
|
// Display results.
|
|
|
|
println!("Ran {} self tests.", count);
|
|
|
|
assert!(fails == 0, "{} self tests failed", fails);
|
|
|
|
|
|
|
|
for format_report in reports {
|
|
|
|
println!("{}", format_report);
|
|
|
|
warnings += format_report.warning_count();
|
|
|
|
}
|
|
|
|
|
2015-09-23 18:15:08 -05:00
|
|
|
assert!(warnings == 0,
|
|
|
|
"Rustfmt's code generated {} warnings",
|
|
|
|
warnings);
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
|
2016-04-11 11:49:56 -05:00
|
|
|
#[test]
|
|
|
|
fn stdin_formatting_smoke_test() {
|
|
|
|
let input = Input::Text("fn main () {}".to_owned());
|
|
|
|
let config = Config::default();
|
2016-05-15 04:41:05 -05:00
|
|
|
let (error_summary, file_map, _report) = format_input::<io::Stdout>(input, &config, None)
|
|
|
|
.unwrap();
|
2016-04-14 18:51:50 -05:00
|
|
|
assert!(error_summary.has_no_errors());
|
2016-05-15 04:41:05 -05:00
|
|
|
for &(ref file_name, ref text) in &file_map {
|
|
|
|
if file_name == "stdin" {
|
|
|
|
assert!(text.to_string() == "fn main() {}\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic!("no stdin");
|
2016-04-11 11:49:56 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 18:51:50 -05:00
|
|
|
#[test]
|
|
|
|
fn format_lines_errors_are_reported() {
|
|
|
|
let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap();
|
|
|
|
let input = Input::Text(format!("fn {}() {{}}", long_identifier));
|
|
|
|
let config = Config::default();
|
2016-05-15 04:41:05 -05:00
|
|
|
let (error_summary, _file_map, _report) = format_input::<io::Stdout>(input, &config, None)
|
|
|
|
.unwrap();
|
2016-04-14 18:51:50 -05:00
|
|
|
assert!(error_summary.has_formatting_errors());
|
|
|
|
}
|
|
|
|
|
2015-05-28 12:23:07 -05:00
|
|
|
// For each file, run rustfmt and collect the output.
|
|
|
|
// Returns the number of files checked and the number of failures.
|
2016-04-04 18:02:22 -05:00
|
|
|
fn check_files<I>(files: I) -> (Vec<FormatReport>, u32, u32)
|
2015-05-28 12:23:07 -05:00
|
|
|
where I: Iterator<Item = String>
|
|
|
|
{
|
|
|
|
let mut count = 0;
|
|
|
|
let mut fails = 0;
|
2015-09-17 13:21:06 -05:00
|
|
|
let mut reports = vec![];
|
2015-05-28 12:23:07 -05:00
|
|
|
|
|
|
|
for file_name in files.filter(|f| f.ends_with(".rs")) {
|
|
|
|
println!("Testing '{}'...", file_name);
|
2015-09-17 13:21:06 -05:00
|
|
|
|
2016-04-04 18:02:22 -05:00
|
|
|
match idempotent_check(file_name) {
|
2015-09-17 13:21:06 -05:00
|
|
|
Ok(report) => reports.push(report),
|
|
|
|
Err(msg) => {
|
|
|
|
print_mismatches(msg);
|
|
|
|
fails += 1;
|
|
|
|
}
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
2015-09-17 13:21:06 -05:00
|
|
|
|
2015-05-28 12:23:07 -05:00
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:21:06 -05:00
|
|
|
(reports, count, fails)
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
|
2015-08-30 13:47:46 -05:00
|
|
|
fn print_mismatches(result: HashMap<String, Vec<Mismatch>>) {
|
|
|
|
let mut t = term::stdout().unwrap();
|
|
|
|
|
|
|
|
for (file_name, diff) in result {
|
2015-09-23 18:15:08 -05:00
|
|
|
print_diff(diff,
|
|
|
|
|line_num| format!("\nMismatch at {}:{}:", file_name, line_num));
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
2015-08-30 13:47:46 -05:00
|
|
|
|
2016-04-07 22:51:06 -05:00
|
|
|
t.reset().unwrap();
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
|
2016-04-04 18:02:22 -05:00
|
|
|
fn read_config(filename: &str) -> Config {
|
2016-01-17 22:06:00 -06:00
|
|
|
let sig_comments = read_significant_comments(&filename);
|
2016-08-09 15:11:27 -05:00
|
|
|
// Look for a config file... If there is a 'config' property in the significant comments, use
|
|
|
|
// that. Otherwise, if there are no significant comments at all, look for a config file with
|
|
|
|
// the same name as the test file.
|
2016-08-08 16:13:45 -05:00
|
|
|
let mut config = if !sig_comments.is_empty() {
|
|
|
|
get_config(sig_comments.get("config").map(|x| &(*x)[..]))
|
|
|
|
} else {
|
2016-08-09 15:10:48 -05:00
|
|
|
get_config(Path::new(filename)
|
|
|
|
.with_extension("toml")
|
|
|
|
.file_name()
|
|
|
|
.and_then(std::ffi::OsStr::to_str))
|
|
|
|
};
|
2016-01-17 22:06:00 -06:00
|
|
|
|
|
|
|
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;
|
2016-04-02 15:41:25 -05:00
|
|
|
|
2016-01-21 21:09:01 -06:00
|
|
|
config
|
|
|
|
}
|
2016-01-17 22:06:00 -06:00
|
|
|
|
2016-04-02 16:32:24 -05:00
|
|
|
fn format_file<P: Into<PathBuf>>(filename: P, config: &Config) -> (FileMap, FormatReport) {
|
|
|
|
let input = Input::File(filename.into());
|
2016-05-15 04:41:05 -05:00
|
|
|
let (_error_summary, file_map, report) = format_input::<io::Stdout>(input, &config, None)
|
|
|
|
.unwrap();
|
2016-04-14 18:51:50 -05:00
|
|
|
return (file_map, report);
|
2016-01-17 22:06:00 -06:00
|
|
|
}
|
|
|
|
|
2016-04-04 18:02:22 -05:00
|
|
|
pub fn idempotent_check(filename: String) -> Result<FormatReport, HashMap<String, Vec<Mismatch>>> {
|
2015-08-19 14:41:19 -05:00
|
|
|
let sig_comments = read_significant_comments(&filename);
|
2016-04-04 18:02:22 -05:00
|
|
|
let config = read_config(&filename);
|
2016-04-02 16:32:24 -05:00
|
|
|
let (file_map, format_report) = format_file(filename, &config);
|
2015-09-17 13:21:06 -05:00
|
|
|
|
2016-01-12 17:12:48 -06:00
|
|
|
let mut write_result = HashMap::new();
|
2016-05-15 04:41:05 -05:00
|
|
|
for &(ref filename, ref text) in &file_map {
|
2016-01-12 17:12:48 -06:00
|
|
|
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.clone(), one_result);
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:21:06 -05:00
|
|
|
let target = sig_comments.get("target").map(|x| &(*x)[..]);
|
|
|
|
|
2016-04-04 18:02:22 -05:00
|
|
|
handle_result(write_result, target).map(|_| format_report)
|
2015-09-17 13:21:06 -05:00
|
|
|
}
|
2015-08-19 14:41:19 -05:00
|
|
|
|
2016-08-09 15:11:27 -05:00
|
|
|
// Reads test config file using the supplied (optional) file name. If there's no file name or the
|
|
|
|
// file doesn't exist, just return the default config. Otherwise, the file must be read
|
|
|
|
// successfully.
|
2015-09-17 13:21:06 -05:00
|
|
|
fn get_config(config_file: Option<&str>) -> Config {
|
2015-07-31 18:21:44 -05:00
|
|
|
let config_file_name = match config_file {
|
2015-09-17 13:21:06 -05:00
|
|
|
None => return Default::default(),
|
2015-07-31 18:21:44 -05:00
|
|
|
Some(file_name) => {
|
|
|
|
let mut full_path = "tests/config/".to_owned();
|
|
|
|
full_path.push_str(&file_name);
|
2016-08-08 16:13:45 -05:00
|
|
|
if !Path::new(&full_path).exists() {
|
|
|
|
return Default::default();
|
|
|
|
};
|
2015-07-31 18:21:44 -05:00
|
|
|
full_path
|
|
|
|
}
|
|
|
|
};
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2016-01-31 11:58:38 -06:00
|
|
|
let mut def_config_file = fs::File::open(config_file_name).expect("Couldn't open config");
|
2015-05-28 12:23:07 -05:00
|
|
|
let mut def_config = String::new();
|
2016-01-31 11:58:38 -06:00
|
|
|
def_config_file.read_to_string(&mut def_config).expect("Couldn't read config");
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2015-09-17 13:21:06 -05:00
|
|
|
Config::from_toml(&def_config)
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
|
2015-08-19 14:41:19 -05:00
|
|
|
// Reads significant comments of the form: // rustfmt-key: value
|
|
|
|
// into a hash map.
|
|
|
|
fn read_significant_comments(file_name: &str) -> HashMap<String, String> {
|
2016-01-31 11:58:38 -06:00
|
|
|
let file = fs::File::open(file_name).expect(&format!("Couldn't read file {}", file_name));
|
2015-05-28 12:23:07 -05:00
|
|
|
let reader = BufReader::new(file);
|
2015-08-19 14:41:19 -05:00
|
|
|
let pattern = r"^\s*//\s*rustfmt-([^:]+):\s*(\S+)";
|
2016-01-31 11:58:38 -06:00
|
|
|
let regex = regex::Regex::new(&pattern).expect("Failed creating pattern 1");
|
2015-05-28 12:23:07 -05:00
|
|
|
|
2015-08-19 14:41:19 -05:00
|
|
|
// Matches lines containing significant comments or whitespace.
|
2015-09-10 17:52:57 -05:00
|
|
|
let line_regex = regex::Regex::new(r"(^\s*$)|(^\s*//\s*rustfmt-[^:]+:\s*\S+)")
|
2016-04-22 01:53:39 -05:00
|
|
|
.expect("Failed creating pattern 2");
|
2015-05-28 12:23:07 -05:00
|
|
|
|
|
|
|
reader.lines()
|
2016-04-22 02:03:36 -05:00
|
|
|
.map(|line| line.expect("Failed getting line"))
|
|
|
|
.take_while(|line| line_regex.is_match(&line))
|
|
|
|
.filter_map(|line| {
|
|
|
|
regex.captures_iter(&line).next().map(|capture| {
|
|
|
|
(capture.at(1).expect("Couldn't unwrap capture").to_owned(),
|
|
|
|
capture.at(2).expect("Couldn't unwrap capture").to_owned())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect()
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compare output to input.
|
2015-08-19 14:41:19 -05:00
|
|
|
// TODO: needs a better name, more explanation.
|
2015-09-17 13:21:06 -05:00
|
|
|
fn handle_result(result: HashMap<String, String>,
|
2016-04-04 18:02:22 -05:00
|
|
|
target: Option<&str>)
|
2015-09-17 13:21:06 -05:00
|
|
|
-> Result<(), HashMap<String, Vec<Mismatch>>> {
|
2015-05-28 12:23:07 -05:00
|
|
|
let mut failures = HashMap::new();
|
|
|
|
|
|
|
|
for (file_name, fmt_text) in result {
|
2015-08-19 14:41:19 -05:00
|
|
|
// If file is in tests/source, compare to file with same name in tests/target.
|
2016-04-04 18:02:22 -05:00
|
|
|
let target = get_target(&file_name, target);
|
2016-01-31 11:58:38 -06:00
|
|
|
let mut f = fs::File::open(&target).expect("Couldn't open target");
|
2015-05-28 12:23:07 -05:00
|
|
|
|
|
|
|
let mut text = String::new();
|
2016-01-31 11:58:38 -06:00
|
|
|
f.read_to_string(&mut text).expect("Failed reading target");
|
2015-09-17 13:21:06 -05:00
|
|
|
|
2015-05-28 12:23:07 -05:00
|
|
|
if fmt_text != text {
|
2015-09-10 17:27:22 -05:00
|
|
|
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
|
2016-02-11 19:59:13 -06:00
|
|
|
assert!(!diff.is_empty(),
|
|
|
|
"Empty diff? Maybe due to a missing a newline at the end of a file?");
|
2015-08-30 13:47:46 -05:00
|
|
|
failures.insert(file_name, diff);
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
}
|
2015-08-30 13:47:46 -05:00
|
|
|
|
2015-09-17 13:21:06 -05:00
|
|
|
if failures.is_empty() {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(failures)
|
2015-05-28 12:23:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map source file paths to their target paths.
|
2016-04-04 18:02:22 -05:00
|
|
|
fn get_target(file_name: &str, target: Option<&str>) -> String {
|
|
|
|
if file_name.contains("source") {
|
|
|
|
let target_file_name = file_name.replace("source", "target");
|
|
|
|
if let Some(replace_name) = target {
|
|
|
|
Path::new(&target_file_name)
|
|
|
|
.with_file_name(replace_name)
|
|
|
|
.into_os_string()
|
|
|
|
.into_string()
|
|
|
|
.unwrap()
|
|
|
|
} else {
|
|
|
|
target_file_name
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
2015-05-28 12:23:07 -05:00
|
|
|
} else {
|
2016-04-04 18:02:22 -05:00
|
|
|
// This is either and idempotence check or a self check
|
2015-05-28 12:23:07 -05:00
|
|
|
file_name.to_owned()
|
|
|
|
}
|
|
|
|
}
|
2015-12-28 05:53:34 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rustfmt_diff_make_diff_tests() {
|
|
|
|
let diff = make_diff("a\nb\nc\nd", "a\ne\nc\nd", 3);
|
|
|
|
assert_eq!(diff,
|
|
|
|
vec![Mismatch {
|
|
|
|
line_number: 1,
|
|
|
|
lines: vec![DiffLine::Context("a".into()),
|
|
|
|
DiffLine::Resulting("b".into()),
|
|
|
|
DiffLine::Expected("e".into()),
|
|
|
|
DiffLine::Context("c".into()),
|
|
|
|
DiffLine::Context("d".into())],
|
|
|
|
}]);
|
|
|
|
}
|
2016-08-09 20:21:04 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rustfmt_diff_no_diff_test() {
|
|
|
|
let diff = make_diff("a\nb\nc\nd", "a\nb\nc\nd", 3);
|
|
|
|
assert_eq!(diff, vec![]);
|
|
|
|
}
|