Use explicit dir in cli_run tests

This commit is contained in:
Richard Feldman 2020-10-31 22:25:27 -04:00
parent a6b57aea87
commit 1f183769c4

View file

@ -15,21 +15,10 @@ mod cli_run {
example_file, extract_valgrind_errors, run_cmd, run_roc, run_with_valgrind, example_file, extract_valgrind_errors, run_cmd, run_roc, run_with_valgrind,
}; };
use serial_test::serial; use serial_test::serial;
use std::path::Path;
fn check_output( fn check_output(file: &Path, flags: &[&str], expected_ending: &str, use_valgrind: bool) {
folder: &str, let compile_out = run_roc(&[&["build", file.to_str().unwrap()], flags].concat());
file: &str,
flags: &[&str],
expected_ending: &str,
use_valgrind: bool,
) {
let compile_out = run_roc(
&[
&["build", example_file(folder, file).to_str().unwrap()],
flags,
]
.concat(),
);
if !compile_out.stderr.is_empty() { if !compile_out.stderr.is_empty() {
panic!(compile_out.stderr); panic!(compile_out.stderr);
} }
@ -37,14 +26,14 @@ mod cli_run {
let out = if use_valgrind { let out = if use_valgrind {
let (valgrind_out, raw_xml) = let (valgrind_out, raw_xml) =
run_with_valgrind(&[example_file(folder, "app").to_str().unwrap()]); run_with_valgrind(&[file.with_file_name("app").to_str().unwrap()]);
let memory_errors = extract_valgrind_errors(&raw_xml); let memory_errors = extract_valgrind_errors(&raw_xml);
if !memory_errors.is_empty() { if !memory_errors.is_empty() {
panic!("{:?}", memory_errors); panic!("{:?}", memory_errors);
} }
valgrind_out valgrind_out
} else { } else {
run_cmd(example_file(folder, "app").to_str().unwrap(), &[]) run_cmd(file.with_file_name("app").to_str().unwrap(), &[])
}; };
if !&out.stdout.ends_with(expected_ending) { if !&out.stdout.ends_with(expected_ending) {
panic!( panic!(
@ -59,8 +48,7 @@ mod cli_run {
#[serial(hello_world)] #[serial(hello_world)]
fn run_hello_world() { fn run_hello_world() {
check_output( check_output(
"hello-world", &example_file("hello-world", "Hello.roc"),
"Hello.roc",
&[], &[],
"Hello, World!!!!!!!!!!!!!\n", "Hello, World!!!!!!!!!!!!!\n",
true, true,
@ -71,8 +59,7 @@ mod cli_run {
#[serial(hello_world)] #[serial(hello_world)]
fn run_hello_world_optimized() { fn run_hello_world_optimized() {
check_output( check_output(
"hello-world", &example_file("hello-world", "Hello.roc"),
"Hello.roc",
&[], &[],
"Hello, World!!!!!!!!!!!!!\n", "Hello, World!!!!!!!!!!!!!\n",
true, true,
@ -83,8 +70,7 @@ mod cli_run {
#[serial(quicksort)] #[serial(quicksort)]
fn run_quicksort_not_optimized() { fn run_quicksort_not_optimized() {
check_output( check_output(
"quicksort", &example_file("quicksort", "Quicksort.roc"),
"Quicksort.roc",
&[], &[],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
false, false,
@ -95,8 +81,7 @@ mod cli_run {
#[serial(quicksort)] #[serial(quicksort)]
fn run_quicksort_optimized() { fn run_quicksort_optimized() {
check_output( check_output(
"quicksort", &example_file("quicksort", "Quicksort.roc"),
"Quicksort.roc",
&["--optimize"], &["--optimize"],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
false, false,
@ -109,8 +94,7 @@ mod cli_run {
#[ignore] #[ignore]
fn run_quicksort_valgrind() { fn run_quicksort_valgrind() {
check_output( check_output(
"quicksort", &example_file("quicksort", "Quicksort.roc"),
"Quicksort.roc",
&[], &[],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
true, true,
@ -123,8 +107,7 @@ mod cli_run {
#[ignore] #[ignore]
fn run_quicksort_optimized_valgrind() { fn run_quicksort_optimized_valgrind() {
check_output( check_output(
"quicksort", &example_file("quicksort", "Quicksort.roc"),
"Quicksort.roc",
&["--optimize"], &["--optimize"],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
true, true,
@ -135,8 +118,7 @@ mod cli_run {
#[serial(multi_module)] #[serial(multi_module)]
fn run_multi_module() { fn run_multi_module() {
check_output( check_output(
"multi-module", &example_file("multi-module", "Quicksort.roc"),
"Quicksort.roc",
&[], &[],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
false, false,
@ -147,8 +129,7 @@ mod cli_run {
#[serial(multi_module)] #[serial(multi_module)]
fn run_multi_module_optimized() { fn run_multi_module_optimized() {
check_output( check_output(
"multi-module", &example_file("multi-module", "Quicksort.roc"),
"Quicksort.roc",
&["--optimize"], &["--optimize"],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
false, false,
@ -161,8 +142,7 @@ mod cli_run {
#[ignore] #[ignore]
fn run_multi_module_valgrind() { fn run_multi_module_valgrind() {
check_output( check_output(
"multi-module", &example_file("multi-module", "Quicksort.roc"),
"Quicksort.roc",
&[], &[],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
true, true,
@ -175,8 +155,7 @@ mod cli_run {
#[ignore] #[ignore]
fn run_multi_module_optimized_valgrind() { fn run_multi_module_optimized_valgrind() {
check_output( check_output(
"multi-module", &example_file("multi-module", "Quicksort.roc"),
"Quicksort.roc",
&["--optimize"], &["--optimize"],
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
true, true,