mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Add tests for env var passing
This commit is contained in:
parent
5d8f04575e
commit
73210469db
4 changed files with 47 additions and 23 deletions
|
@ -93,7 +93,11 @@ mod cli_run {
|
|||
}
|
||||
|
||||
fn check_compile_error(file: &Path, flags: &[&str], expected: &str) {
|
||||
let compile_out = run_roc([CMD_CHECK, file.to_str().unwrap()].iter().chain(flags), &[]);
|
||||
let compile_out = run_roc(
|
||||
[CMD_CHECK, file.to_str().unwrap()].iter().chain(flags),
|
||||
&[],
|
||||
&[],
|
||||
);
|
||||
let err = compile_out.stdout.trim();
|
||||
let err = strip_colors(err);
|
||||
|
||||
|
@ -105,7 +109,7 @@ mod cli_run {
|
|||
}
|
||||
|
||||
fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) {
|
||||
let out = run_roc([CMD_FORMAT, file.to_str().unwrap(), CHECK_FLAG], &[]);
|
||||
let out = run_roc([CMD_FORMAT, file.to_str().unwrap(), CHECK_FLAG], &[], &[]);
|
||||
|
||||
assert_eq!(out.status.success(), expects_success_exit_code);
|
||||
}
|
||||
|
@ -115,6 +119,7 @@ mod cli_run {
|
|||
args: I,
|
||||
stdin: &[&str],
|
||||
app_args: &[String],
|
||||
env: &[(&str, &str)],
|
||||
) -> Out {
|
||||
let compile_out = run_roc(
|
||||
// converting these all to String avoids lifetime issues
|
||||
|
@ -123,6 +128,7 @@ mod cli_run {
|
|||
.chain([file.to_str().unwrap().to_string(), "--".to_string()])
|
||||
.chain(app_args.iter().cloned()),
|
||||
stdin,
|
||||
env,
|
||||
);
|
||||
|
||||
let ignorable = "🔨 Rebuilding platform...\n";
|
||||
|
@ -166,7 +172,13 @@ mod cli_run {
|
|||
|
||||
let out = match cli_mode {
|
||||
CliMode::RocBuild => {
|
||||
run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], &[]);
|
||||
run_roc_on(
|
||||
file,
|
||||
iter::once(CMD_BUILD).chain(flags.clone()),
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
);
|
||||
|
||||
if use_valgrind && ALLOW_VALGRIND {
|
||||
let mut valgrind_args = vec![file
|
||||
|
@ -223,25 +235,18 @@ mod cli_run {
|
|||
}
|
||||
CliMode::Roc => {
|
||||
if !extra_env.is_empty() {
|
||||
// TODO: environment is not currently forwarded by Roc to the target
|
||||
// binary, so this would fail!
|
||||
// TODO: `roc` and `roc dev` are currently buggy for `env.roc`
|
||||
continue;
|
||||
}
|
||||
run_roc_on(file, flags.clone(), stdin, app_args)
|
||||
}
|
||||
CliMode::RocRun => {
|
||||
if !extra_env.is_empty() {
|
||||
// TODO: environment is not currently forwarded by Roc to the target
|
||||
// binary, so this would fail!
|
||||
continue;
|
||||
}
|
||||
run_roc_on(
|
||||
file,
|
||||
iter::once(CMD_RUN).chain(flags.clone()),
|
||||
stdin,
|
||||
app_args,
|
||||
)
|
||||
run_roc_on(file, flags.clone(), stdin, app_args, extra_env)
|
||||
}
|
||||
CliMode::RocRun => run_roc_on(
|
||||
file,
|
||||
iter::once(CMD_RUN).chain(flags.clone()),
|
||||
stdin,
|
||||
app_args,
|
||||
extra_env,
|
||||
),
|
||||
};
|
||||
|
||||
if !&out.stdout.ends_with(expected_ending) {
|
||||
|
@ -344,7 +349,7 @@ mod cli_run {
|
|||
// Since these require things the build system often doesn't have
|
||||
// (e.g. GUIs open a window, Ruby needs ruby installed, WASM needs a browser)
|
||||
// we do `roc build` on them but don't run them.
|
||||
run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], &[]);
|
||||
run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], &[], &[]);
|
||||
return;
|
||||
}
|
||||
"swiftui" | "rocLovesSwift" => {
|
||||
|
@ -352,7 +357,7 @@ mod cli_run {
|
|||
eprintln!("WARNING: skipping testing example {} because it only works on MacOS.", example.filename);
|
||||
return;
|
||||
} else {
|
||||
run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], &[]);
|
||||
run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], &[], &[]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ fn exec_bench_w_input<T: Measurement>(
|
|||
let compile_out = run_roc(
|
||||
["build", OPTIMIZE_FLAG, file.to_str().unwrap()],
|
||||
&[stdin_str],
|
||||
&[],
|
||||
);
|
||||
|
||||
if !compile_out.stderr.is_empty() && compile_out.stderr != "🔨 Rebuilding platform...\n" {
|
||||
|
|
|
@ -22,7 +22,7 @@ pub struct Out {
|
|||
pub status: ExitStatus,
|
||||
}
|
||||
|
||||
pub fn run_roc<I, S>(args: I, stdin_vals: &[&str]) -> Out
|
||||
pub fn run_roc<I, S>(args: I, stdin_vals: &[&str], extra_env: &[(&str, &str)]) -> Out
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
|
@ -62,7 +62,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
run_with_stdin(&roc_binary_path, args, stdin_vals)
|
||||
run_with_stdin_and_env(&roc_binary_path, args, stdin_vals, extra_env)
|
||||
}
|
||||
|
||||
pub fn run_glue<I, S>(args: I) -> Out
|
||||
|
@ -118,6 +118,19 @@ pub fn strip_colors(str: &str) -> String {
|
|||
}
|
||||
|
||||
pub fn run_with_stdin<I, S>(path: &Path, args: I, stdin_vals: &[&str]) -> Out
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
run_with_stdin_and_env(path, args, stdin_vals, &[])
|
||||
}
|
||||
|
||||
pub fn run_with_stdin_and_env<I, S>(
|
||||
path: &Path,
|
||||
args: I,
|
||||
stdin_vals: &[&str],
|
||||
extra_env: &[(&str, &str)],
|
||||
) -> Out
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
|
@ -128,6 +141,10 @@ where
|
|||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
for (k, v) in extra_env {
|
||||
cmd.env(k, v);
|
||||
}
|
||||
|
||||
let mut child = cmd
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
|
|
|
@ -215,6 +215,7 @@ mod glue_cli_run {
|
|||
.map(|arg| arg.to_string())
|
||||
.chain([app_file.to_str().unwrap().to_string()]),
|
||||
&[],
|
||||
&[],
|
||||
);
|
||||
|
||||
let ignorable = "🔨 Rebuilding platform...\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue