From b5b950150fa55afe1cb3d172fb2d4a4ce5dc739c Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Sat, 11 Nov 2017 13:02:04 +0100 Subject: [PATCH] Make tests run on non-windows machines Hardcoding the windows path separator isn't a good idea for portability :) --- tests/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index a496796..46abc68 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -14,7 +14,8 @@ use nom::*; use std::collections::HashMap; fn all_sample_m3u_playlists() -> Vec { - fs::read_dir("sample-playlists\\").unwrap() + let path: std::path::PathBuf = ["sample-playlists"].iter().collect(); + fs::read_dir(path.to_str().unwrap()).unwrap() .filter_map(Result::ok) .map(|dir| dir.path()) .filter(|path| path.extension().map_or(false, |ext| ext == "m3u8")) @@ -23,13 +24,14 @@ fn all_sample_m3u_playlists() -> Vec { fn getm3u(path: &str) -> String { let mut buf = String::new(); - let mut file = fs::File::open(path).expect("Can't find m3u8."); + let mut file = fs::File::open(path).expect(&format!("Can't find m3u8: {}", path)); let u = file.read_to_string(&mut buf).expect("Can't read file"); buf } fn get_sample_playlist(name: &str) -> String { - getm3u(&(String::from("sample-playlists\\") + name)) + let path: std::path::PathBuf = ["sample-playlists", name].iter().collect(); + getm3u(path.to_str().unwrap()) } // ----------------------------------------------------------------------------------------------- @@ -389,4 +391,4 @@ fn create_and_parse_media_playlist_full() { }); let playlist_parsed = print_create_and_parse_playlist(&mut playlist_original); assert_eq!(playlist_original, playlist_parsed); -} \ No newline at end of file +}