diff --git a/src/commands/test.rs b/src/commands/test.rs index e3e8620..1c4897e 100644 --- a/src/commands/test.rs +++ b/src/commands/test.rs @@ -128,8 +128,8 @@ fn run_tests( }; if output.status.success() { - let ans_str = ans.trim().replace("\r\n", "\n"); - let out_str = stdout.trim().replace("\r\n", "\n"); + let ans_str = reformat_ans_str(&ans); + let out_str = reformat_ans_str(&stdout); if ans_str == out_str { println!("{}", CHECKBOX); @@ -175,3 +175,7 @@ fn run_tests( Ok(()) } + +fn reformat_ans_str(s: &str) -> String { + s.replace("\r\n", "\n").lines().map(str::trim).collect() +} diff --git a/src/lang.rs b/src/lang.rs index ec81127..a158396 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -1,14 +1,9 @@ use crate::StdErr; +use std::env::consts::EXE_EXTENSION; use std::fmt; use std::path::PathBuf; use Language::*; -#[cfg(target_os = "windows")] -const EXEC_EXT: &str = "exe"; - -#[cfg(not(target_os = "windows"))] -const EXEC_EXT: &str = ""; - #[derive(PartialEq, Eq, Hash, Debug, Copy, Clone)] pub enum Language { Haskell, @@ -75,10 +70,10 @@ impl Language { .map(|v| v.iter().map(|s| s.to_string()).collect::>()); let exec_path = match self { - Haskell => path.with_extension(EXEC_EXT), + Haskell => path.with_extension(EXE_EXTENSION), Java => path.with_extension(""), Python => path.to_owned(), - Rust => path.with_extension(EXEC_EXT), + Rust => path.with_extension(EXE_EXTENSION), Unknown => PathBuf::new(), };