mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
148 lines
4.3 KiB
Rust
148 lines
4.3 KiB
Rust
// #[macro_use]
|
|
extern crate pretty_assertions;
|
|
|
|
extern crate bumpalo;
|
|
extern crate inlinable_string;
|
|
extern crate roc_collections;
|
|
extern crate roc_load;
|
|
extern crate roc_module;
|
|
|
|
mod helpers;
|
|
|
|
#[cfg(test)]
|
|
mod cli_run {
|
|
use crate::helpers::{example_file, extract_valgrind_errors, run_roc, run_with_valgrind, Out};
|
|
use serial_test::serial;
|
|
|
|
fn check_hello_world_output(out: Out) {
|
|
if !out.stderr.is_empty() {
|
|
panic!(out.stderr);
|
|
}
|
|
assert!(out.status.success());
|
|
|
|
let (valgrind_out, raw_xml) =
|
|
run_with_valgrind(&[example_file("hello-world", "app").to_str().unwrap()]);
|
|
|
|
let ending = "Hello, World!!!!!!!!!!!!!\n";
|
|
if !&valgrind_out.stdout.ends_with(ending) {
|
|
panic!(
|
|
"expected output to end with {:?} but instead got {:#?}",
|
|
ending, valgrind_out
|
|
);
|
|
}
|
|
let memory_errors = extract_valgrind_errors(&raw_xml);
|
|
if !memory_errors.is_empty() {
|
|
panic!("{:?}", memory_errors);
|
|
}
|
|
assert!(valgrind_out.status.success());
|
|
}
|
|
|
|
#[test]
|
|
#[serial(hello_world)]
|
|
fn run_hello_world() {
|
|
check_hello_world_output(run_roc(&[
|
|
"build",
|
|
example_file("hello-world", "Hello.roc").to_str().unwrap(),
|
|
]));
|
|
}
|
|
|
|
#[test]
|
|
#[serial(hello_world)]
|
|
fn run_hello_world_optimized() {
|
|
check_hello_world_output(run_roc(&[
|
|
"build",
|
|
"--optimize",
|
|
example_file("hello-world", "Hello.roc").to_str().unwrap(),
|
|
]));
|
|
}
|
|
|
|
fn check_quicksort_output(out: Out) {
|
|
if !out.stderr.is_empty() {
|
|
panic!(out.stderr);
|
|
}
|
|
assert!(out.status.success());
|
|
|
|
let (valgrind_out, raw_xml) =
|
|
run_with_valgrind(&[example_file("quicksort", "app").to_str().unwrap()]);
|
|
let ending = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n";
|
|
if !&valgrind_out.stdout.ends_with(ending) {
|
|
panic!(
|
|
"expected output to end with {:?} but instead got {:#?}",
|
|
ending, valgrind_out
|
|
);
|
|
}
|
|
let memory_errors = extract_valgrind_errors(&raw_xml);
|
|
if !memory_errors.is_empty() {
|
|
panic!("{:?}", memory_errors);
|
|
}
|
|
assert!(valgrind_out.status.success());
|
|
}
|
|
|
|
#[test]
|
|
#[serial(quicksort)]
|
|
// TODO: Stop ignoring this test once we are correctly freeing the RocList even when in dev build.
|
|
#[ignore]
|
|
fn run_quicksort() {
|
|
check_quicksort_output(run_roc(&[
|
|
"build",
|
|
example_file("quicksort", "Quicksort.roc").to_str().unwrap(),
|
|
]));
|
|
}
|
|
|
|
#[test]
|
|
#[serial(quicksort)]
|
|
fn run_quicksort_optimized() {
|
|
check_quicksort_output(run_roc(&[
|
|
"build",
|
|
"--optimize",
|
|
example_file("quicksort", "Quicksort.roc").to_str().unwrap(),
|
|
]));
|
|
}
|
|
|
|
fn check_muti_module_output(out: Out) {
|
|
if !out.stderr.is_empty() {
|
|
panic!(out.stderr);
|
|
}
|
|
assert!(out.status.success());
|
|
|
|
let (valgrind_out, raw_xml) =
|
|
run_with_valgrind(&[example_file("multi-module", "app").to_str().unwrap()]);
|
|
let ending = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n";
|
|
if !&valgrind_out.stdout.ends_with(ending) {
|
|
panic!(
|
|
"expected output to end with {:?} but instead got {:#?}",
|
|
ending, valgrind_out
|
|
);
|
|
}
|
|
let memory_errors = extract_valgrind_errors(&raw_xml);
|
|
if !memory_errors.is_empty() {
|
|
panic!("{:?}", memory_errors);
|
|
}
|
|
assert!(valgrind_out.status.success());
|
|
}
|
|
|
|
#[test]
|
|
#[serial(multi_module)]
|
|
// TODO: Stop ignoring this test once we are correctly freeing the RocList even when in dev build.
|
|
#[ignore]
|
|
fn run_multi_module() {
|
|
check_muti_module_output(run_roc(&[
|
|
"run",
|
|
example_file("multi-module", "Quicksort.roc")
|
|
.to_str()
|
|
.unwrap(),
|
|
]));
|
|
}
|
|
|
|
#[test]
|
|
#[serial(multi_module)]
|
|
fn run_multi_module_optimized() {
|
|
check_muti_module_output(run_roc(&[
|
|
"run",
|
|
example_file("multi-module", "Quicksort.roc")
|
|
.to_str()
|
|
.unwrap(),
|
|
"--optimize",
|
|
]));
|
|
}
|
|
}
|