diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 7b4024ce0a..92a326e2f1 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -20,7 +20,7 @@ mod cli_run { use roc_test_utils::assert_multiline_str_eq; use serial_test::serial; use std::iter; - use std::path::{Path, PathBuf}; + use std::path::Path; use strum::IntoEnumIterator; use strum_macros::EnumIter; @@ -101,23 +101,17 @@ mod cli_run { assert_eq!(out.status.success(), expects_success_exit_code); } - fn run_roc_on<'a, I: IntoIterator>( + fn run_roc_on<'a, IA: IntoIterator, IF: IntoIterator>( file: &'a Path, - args: I, + args: IA, stdin: &[&str], - input_file: Option, + input_files: IF, ) -> Out { - let compile_out = match input_file { - Some(input_file) => run_roc( - args.into_iter() - .chain([file.to_str().unwrap(), input_file.to_str().unwrap()]), - stdin, - ), - None => run_roc( - args.into_iter().chain(iter::once(file.to_str().unwrap())), - stdin, - ), - }; + let compile_out = run_roc( + args.into_iter() + .chain(iter::once(file.to_str().unwrap()).chain(input_files)), + stdin, + ); if !compile_out.stderr.is_empty() && // If there is any stderr, it should be reporting the runtime and that's it! @@ -135,12 +129,12 @@ mod cli_run { compile_out } - fn check_output_with_stdin( - file: &Path, + fn check_output_with_stdin<'a, I: IntoIterator>( + file: &'a Path, stdin: &[&str], executable_filename: &str, - flags: &[&str], - input_file: Option, + flags: &[&'a str], + input_files: I, expected_ending: &str, use_valgrind: bool, ) { @@ -160,20 +154,21 @@ mod cli_run { run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], None); if use_valgrind && ALLOW_VALGRIND { - let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file { - run_with_valgrind( - stdin.clone().iter().copied(), - &[ - file.with_file_name(executable_filename).to_str().unwrap(), - input_file.clone().to_str().unwrap(), - ], - ) - } else { - run_with_valgrind( - stdin.clone().iter().copied(), - &[file.with_file_name(executable_filename).to_str().unwrap()], - ) - }; + let (valgrind_out, raw_xml) = + if let Some(ref input_file) = input_files.into_iter().next() { + run_with_valgrind( + stdin.clone().iter().copied(), + &[ + file.with_file_name(executable_filename).to_str().unwrap(), + input_file.clone(), + ], + ) + } else { + run_with_valgrind( + stdin.clone().iter().copied(), + &[file.with_file_name(executable_filename).to_str().unwrap()], + ) + }; if valgrind_out.status.success() { let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { @@ -210,11 +205,11 @@ mod cli_run { } valgrind_out - } else if let Some(ref input_file) = input_file { + } else if let Some(ref input_file) = input_files.into_iter().next() { run_cmd( file.with_file_name(executable_filename).to_str().unwrap(), stdin.iter().copied(), - &[input_file.to_str().unwrap()], + &[input_file], ) } else { run_cmd( @@ -224,12 +219,12 @@ mod cli_run { ) } } - CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_file.clone()), + CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_files), CliMode::RocRun => run_roc_on( file, iter::once(CMD_RUN).chain(flags.clone()), stdin, - input_file.clone(), + input_files, ), }; @@ -318,7 +313,7 @@ mod cli_run { } "hello-gui" | "breakout" => { // Since these require opening a window, we do `roc build` on them but don't run them. - run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], None); + run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], iter::empty()); return; } @@ -331,7 +326,7 @@ mod cli_run { example.stdin, example.executable_filename, &[], - example.input_file.and_then(|file| Some(example_file(dir_name, file))), + example.input_file.and_then(|file| example_file(dir_name, file).to_str()), example.expected_ending, example.use_valgrind, ); @@ -344,7 +339,7 @@ mod cli_run { example.stdin, example.executable_filename, &[OPTIMIZE_FLAG], - example.input_file.and_then(|file| Some(example_file(dir_name, file))), + example.input_file.and_then(|file| example_file(dir_name, file).to_str()), example.expected_ending, example.use_valgrind, ); @@ -357,7 +352,7 @@ mod cli_run { example.stdin, example.executable_filename, &[LINKER_FLAG, "legacy"], - example.input_file.and_then(|file| Some(example_file(dir_name, file))), + example.input_file.and_then(|file| example_file(dir_name, file).to_str()), example.expected_ending, example.use_valgrind, ); @@ -564,7 +559,7 @@ mod cli_run { benchmark.stdin, benchmark.executable_filename, &[], - benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), + benchmark.input_file.and_then(|file| examples_dir("benchmarks").join(file).to_str()), benchmark.expected_ending, benchmark.use_valgrind, ); @@ -574,7 +569,7 @@ mod cli_run { benchmark.stdin, benchmark.executable_filename, &[OPTIMIZE_FLAG], - benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), + benchmark.input_file.and_then(|file| examples_dir("benchmarks").join(file).to_str()), benchmark.expected_ending, benchmark.use_valgrind, ); @@ -863,7 +858,7 @@ mod cli_run { &[], "multi-dep-str", &[], - None, + iter::empty(), "I am Dep2.str2\n", true, ); @@ -877,7 +872,7 @@ mod cli_run { &[], "multi-dep-str", &[OPTIMIZE_FLAG], - None, + iter::empty(), "I am Dep2.str2\n", true, ); @@ -891,7 +886,7 @@ mod cli_run { &[], "multi-dep-thunk", &[], - None, + iter::empty(), "I am Dep2.value2\n", true, ); @@ -905,7 +900,7 @@ mod cli_run { &[], "multi-dep-thunk", &[OPTIMIZE_FLAG], - None, + iter::empty(), "I am Dep2.value2\n", true, );