mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Experiment with multiple input files in CLI tests
This commit is contained in:
parent
b64e0b3ce4
commit
f07ffb58f2
1 changed files with 42 additions and 47 deletions
|
@ -20,7 +20,7 @@ mod cli_run {
|
||||||
use roc_test_utils::assert_multiline_str_eq;
|
use roc_test_utils::assert_multiline_str_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
|
@ -101,23 +101,17 @@ mod cli_run {
|
||||||
assert_eq!(out.status.success(), expects_success_exit_code);
|
assert_eq!(out.status.success(), expects_success_exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_roc_on<'a, I: IntoIterator<Item = &'a str>>(
|
fn run_roc_on<'a, IA: IntoIterator<Item = &'a str>, IF: IntoIterator<Item = &'a str>>(
|
||||||
file: &'a Path,
|
file: &'a Path,
|
||||||
args: I,
|
args: IA,
|
||||||
stdin: &[&str],
|
stdin: &[&str],
|
||||||
input_file: Option<PathBuf>,
|
input_files: IF,
|
||||||
) -> Out {
|
) -> Out {
|
||||||
let compile_out = match input_file {
|
let compile_out = run_roc(
|
||||||
Some(input_file) => run_roc(
|
|
||||||
args.into_iter()
|
args.into_iter()
|
||||||
.chain([file.to_str().unwrap(), input_file.to_str().unwrap()]),
|
.chain(iter::once(file.to_str().unwrap()).chain(input_files)),
|
||||||
stdin,
|
stdin,
|
||||||
),
|
);
|
||||||
None => run_roc(
|
|
||||||
args.into_iter().chain(iter::once(file.to_str().unwrap())),
|
|
||||||
stdin,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
if !compile_out.stderr.is_empty() &&
|
if !compile_out.stderr.is_empty() &&
|
||||||
// If there is any stderr, it should be reporting the runtime and that's it!
|
// If there is any stderr, it should be reporting the runtime and that's it!
|
||||||
|
@ -135,12 +129,12 @@ mod cli_run {
|
||||||
compile_out
|
compile_out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_output_with_stdin(
|
fn check_output_with_stdin<'a, I: IntoIterator<Item = &'a str>>(
|
||||||
file: &Path,
|
file: &'a Path,
|
||||||
stdin: &[&str],
|
stdin: &[&str],
|
||||||
executable_filename: &str,
|
executable_filename: &str,
|
||||||
flags: &[&str],
|
flags: &[&'a str],
|
||||||
input_file: Option<PathBuf>,
|
input_files: I,
|
||||||
expected_ending: &str,
|
expected_ending: &str,
|
||||||
use_valgrind: bool,
|
use_valgrind: bool,
|
||||||
) {
|
) {
|
||||||
|
@ -160,12 +154,13 @@ mod cli_run {
|
||||||
run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], None);
|
run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], None);
|
||||||
|
|
||||||
if use_valgrind && ALLOW_VALGRIND {
|
if use_valgrind && ALLOW_VALGRIND {
|
||||||
let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file {
|
let (valgrind_out, raw_xml) =
|
||||||
|
if let Some(ref input_file) = input_files.into_iter().next() {
|
||||||
run_with_valgrind(
|
run_with_valgrind(
|
||||||
stdin.clone().iter().copied(),
|
stdin.clone().iter().copied(),
|
||||||
&[
|
&[
|
||||||
file.with_file_name(executable_filename).to_str().unwrap(),
|
file.with_file_name(executable_filename).to_str().unwrap(),
|
||||||
input_file.clone().to_str().unwrap(),
|
input_file.clone(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -210,11 +205,11 @@ mod cli_run {
|
||||||
}
|
}
|
||||||
|
|
||||||
valgrind_out
|
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(
|
run_cmd(
|
||||||
file.with_file_name(executable_filename).to_str().unwrap(),
|
file.with_file_name(executable_filename).to_str().unwrap(),
|
||||||
stdin.iter().copied(),
|
stdin.iter().copied(),
|
||||||
&[input_file.to_str().unwrap()],
|
&[input_file],
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
run_cmd(
|
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(
|
CliMode::RocRun => run_roc_on(
|
||||||
file,
|
file,
|
||||||
iter::once(CMD_RUN).chain(flags.clone()),
|
iter::once(CMD_RUN).chain(flags.clone()),
|
||||||
stdin,
|
stdin,
|
||||||
input_file.clone(),
|
input_files,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -318,7 +313,7 @@ mod cli_run {
|
||||||
}
|
}
|
||||||
"hello-gui" | "breakout" => {
|
"hello-gui" | "breakout" => {
|
||||||
// Since these require opening a window, we do `roc build` on them but don't run them.
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +326,7 @@ mod cli_run {
|
||||||
example.stdin,
|
example.stdin,
|
||||||
example.executable_filename,
|
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.expected_ending,
|
||||||
example.use_valgrind,
|
example.use_valgrind,
|
||||||
);
|
);
|
||||||
|
@ -344,7 +339,7 @@ mod cli_run {
|
||||||
example.stdin,
|
example.stdin,
|
||||||
example.executable_filename,
|
example.executable_filename,
|
||||||
&[OPTIMIZE_FLAG],
|
&[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.expected_ending,
|
||||||
example.use_valgrind,
|
example.use_valgrind,
|
||||||
);
|
);
|
||||||
|
@ -357,7 +352,7 @@ mod cli_run {
|
||||||
example.stdin,
|
example.stdin,
|
||||||
example.executable_filename,
|
example.executable_filename,
|
||||||
&[LINKER_FLAG, "legacy"],
|
&[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.expected_ending,
|
||||||
example.use_valgrind,
|
example.use_valgrind,
|
||||||
);
|
);
|
||||||
|
@ -564,7 +559,7 @@ mod cli_run {
|
||||||
benchmark.stdin,
|
benchmark.stdin,
|
||||||
benchmark.executable_filename,
|
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.expected_ending,
|
||||||
benchmark.use_valgrind,
|
benchmark.use_valgrind,
|
||||||
);
|
);
|
||||||
|
@ -574,7 +569,7 @@ mod cli_run {
|
||||||
benchmark.stdin,
|
benchmark.stdin,
|
||||||
benchmark.executable_filename,
|
benchmark.executable_filename,
|
||||||
&[OPTIMIZE_FLAG],
|
&[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.expected_ending,
|
||||||
benchmark.use_valgrind,
|
benchmark.use_valgrind,
|
||||||
);
|
);
|
||||||
|
@ -863,7 +858,7 @@ mod cli_run {
|
||||||
&[],
|
&[],
|
||||||
"multi-dep-str",
|
"multi-dep-str",
|
||||||
&[],
|
&[],
|
||||||
None,
|
iter::empty(),
|
||||||
"I am Dep2.str2\n",
|
"I am Dep2.str2\n",
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
@ -877,7 +872,7 @@ mod cli_run {
|
||||||
&[],
|
&[],
|
||||||
"multi-dep-str",
|
"multi-dep-str",
|
||||||
&[OPTIMIZE_FLAG],
|
&[OPTIMIZE_FLAG],
|
||||||
None,
|
iter::empty(),
|
||||||
"I am Dep2.str2\n",
|
"I am Dep2.str2\n",
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
@ -891,7 +886,7 @@ mod cli_run {
|
||||||
&[],
|
&[],
|
||||||
"multi-dep-thunk",
|
"multi-dep-thunk",
|
||||||
&[],
|
&[],
|
||||||
None,
|
iter::empty(),
|
||||||
"I am Dep2.value2\n",
|
"I am Dep2.value2\n",
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
@ -905,7 +900,7 @@ mod cli_run {
|
||||||
&[],
|
&[],
|
||||||
"multi-dep-thunk",
|
"multi-dep-thunk",
|
||||||
&[OPTIMIZE_FLAG],
|
&[OPTIMIZE_FLAG],
|
||||||
None,
|
iter::empty(),
|
||||||
"I am Dep2.value2\n",
|
"I am Dep2.value2\n",
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue