From 8be1d1926e3dde13c3e25cc0322fcd65e32206b2 Mon Sep 17 00:00:00 2001 From: Bryce Van Dyk Date: Thu, 8 Oct 2015 01:10:07 +1300 Subject: [PATCH] Fix path issue with tests on Windows The code that manipulates paths to try and find files in the target dir was not handling windows file seperators correctly. The code has been updated to use the path module, and hopefully will play nicer across operating systems. --- tests/system.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/system.rs b/tests/system.rs index 346bbcd9123..b6dee149ed1 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -16,6 +16,7 @@ use std::collections::HashMap; use std::fs; use std::io::{self, Read, BufRead, BufReader}; +use std::path::Path; use rustfmt::*; use rustfmt::config::{Config, ReportTactic}; @@ -232,8 +233,19 @@ fn handle_result(result: HashMap, // Map source file paths to their target paths. fn get_target(file_name: &str, target: Option<&str>) -> String { - if file_name.starts_with("tests/source/") { - let base = target.unwrap_or(file_name.trim_left_matches("tests/source/")); + let file_path = Path::new(file_name); + let source_path_prefix = Path::new("tests/source/"); + if file_path.starts_with(source_path_prefix) { + let mut components = file_path.components(); + // Can't skip(2) as the resulting iterator can't as_path() + components.next(); + components.next(); + + let new_target = match components.as_path().to_str() { + Some(string) => string, + None => file_name, + }; + let base = target.unwrap_or(new_target); format!("tests/target/{}", base) } else { -- 2.44.0