This commit is contained in:
Richard Feldman 2020-07-28 22:57:23 -04:00
parent 931c558b5a
commit 5643c4b921
3 changed files with 763 additions and 767 deletions

File diff suppressed because it is too large Load diff

View file

@ -29,29 +29,6 @@ pub fn test_home() -> ModuleId {
ModuleIds::default().get_or_insert(&"Test".into())
}
/// Without a larger-than-default stack size, some tests
/// run out of stack space in debug builds (but don't in --release builds)
#[allow(dead_code)]
const THREAD_STACK_SIZE: usize = 4 * 1024 * 1024;
pub fn test_async<F: std::future::Future>(future: F) -> F::Output {
use tokio::runtime::Builder;
// Create the runtime
let mut rt = Builder::new()
.thread_name("tokio-thread-for-tests")
.thread_stack_size(THREAD_STACK_SIZE)
// DEBUG: Replace this with .basic_scheduler() to make tests run single-threaded on the main thread.
// Doing this makes assertion failures easier to read, but means
// the tests can't reveal concurrency bugs, so leave this off by default!
.threaded_scheduler()
.build()
.expect("Error initializing Tokio runtime.");
// Spawn the root task
rt.block_on(future)
}
#[allow(dead_code)]
pub fn infer_expr(
subs: Subs,

View file

@ -13,7 +13,7 @@ mod helpers;
#[cfg(test)]
mod test_load {
use crate::helpers::{fixtures_dir, test_async};
use crate::helpers::fixtures_dir;
use inlinable_string::InlinableString;
use roc_can::def::Declaration::*;
use roc_can::def::Def;
@ -27,7 +27,7 @@ mod test_load {
// HELPERS
async fn load_fixture(
fn load_fixture(
dir_name: &str,
module_name: &str,
subs_by_module: SubsByModule,
@ -39,8 +39,7 @@ mod test_load {
src_dir,
filename,
subs_by_module,
)
.await;
);
let loaded_module = loaded.expect("Test module failed to load");
assert_eq!(loaded_module.can_problems, Vec::new());
@ -129,15 +128,12 @@ mod test_load {
let subs_by_module = MutMap::default();
let src_dir = fixtures_dir().join("interface_with_deps");
let filename = src_dir.join("Primary.roc");
test_async(async {
let loaded = load(
&roc_builtins::std::standard_stdlib(),
src_dir,
filename,
subs_by_module,
)
.await;
);
let mut loaded_module = loaded.expect("Test module failed to load");
@ -160,14 +156,12 @@ mod test_load {
assert_eq!(expected_name, &InlinableString::from("Primary"));
assert_eq!(def_count, 10);
});
}
#[test]
fn load_unit() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module = load_fixture("no_deps", "Unit", subs_by_module).await;
let loaded_module = load_fixture("no_deps", "Unit", subs_by_module);
expect_types(
loaded_module,
@ -175,15 +169,12 @@ mod test_load {
"unit" => "Unit",
},
);
});
}
#[test]
fn import_alias() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module =
load_fixture("interface_with_deps", "ImportAlias", subs_by_module).await;
let loaded_module = load_fixture("interface_with_deps", "ImportAlias", subs_by_module);
expect_types(
loaded_module,
@ -191,15 +182,12 @@ mod test_load {
"unit" => "Dep1.Unit",
},
);
});
}
#[test]
fn load_and_typecheck() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module =
load_fixture("interface_with_deps", "WithBuiltins", subs_by_module).await;
let loaded_module = load_fixture("interface_with_deps", "WithBuiltins", subs_by_module);
expect_types(
loaded_module,
@ -214,15 +202,12 @@ mod test_load {
"fromDep2" => "Float",
},
);
});
}
#[test]
fn iface_quicksort() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module =
load_fixture("interface_with_deps", "Quicksort", subs_by_module).await;
let loaded_module = load_fixture("interface_with_deps", "Quicksort", subs_by_module);
expect_types(
loaded_module,
@ -232,14 +217,12 @@ mod test_load {
"quicksort" => "List (Num a), Int, Int -> List (Num a)",
},
);
});
}
#[test]
fn app_quicksort() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module = load_fixture("app_with_deps", "Quicksort", subs_by_module).await;
let loaded_module = load_fixture("app_with_deps", "Quicksort", subs_by_module);
expect_types(
loaded_module,
@ -249,14 +232,12 @@ mod test_load {
"quicksort" => "List (Num a), Int, Int -> List (Num a)",
},
);
});
}
#[test]
fn load_astar() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module = load_fixture("interface_with_deps", "AStar", subs_by_module).await;
let loaded_module = load_fixture("interface_with_deps", "AStar", subs_by_module);
expect_types(
loaded_module,
@ -269,14 +250,12 @@ mod test_load {
"astar" => "(position, position -> Float), (position -> Set position), position, Model position -> [ Err [ KeyNotFound ]*, Ok (List position) ]*",
},
);
});
}
#[test]
fn load_principal_types() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module = load_fixture("no_deps", "Principal", subs_by_module).await;
let loaded_module = load_fixture("no_deps", "Principal", subs_by_module);
expect_types(
loaded_module,
@ -285,15 +264,12 @@ mod test_load {
"identity" => "a -> a",
},
);
});
}
#[test]
fn iface_dep_types() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module =
load_fixture("interface_with_deps", "Primary", subs_by_module).await;
let loaded_module = load_fixture("interface_with_deps", "Primary", subs_by_module);
expect_types(
loaded_module,
@ -310,14 +286,12 @@ mod test_load {
"withDefault" => "Res.Res a *, a -> a",
},
);
});
}
#[test]
fn app_dep_types() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module = load_fixture("app_with_deps", "Primary", subs_by_module).await;
let loaded_module = load_fixture("app_with_deps", "Primary", subs_by_module);
expect_types(
loaded_module,
@ -334,14 +308,12 @@ mod test_load {
"withDefault" => "Res.Res a *, a -> a",
},
);
});
}
#[test]
fn imported_dep_regression() {
test_async(async {
let subs_by_module = MutMap::default();
let loaded_module = load_fixture("interface_with_deps", "OneDep", subs_by_module).await;
let loaded_module = load_fixture("interface_with_deps", "OneDep", subs_by_module);
expect_types(
loaded_module,
@ -349,17 +321,15 @@ mod test_load {
"str" => "Str",
},
);
});
}
// #[test]
// fn load_records() {
// test_async(async {
// use roc::types::{ErrorType, Mismatch, Problem, TypeExt};
// let subs_by_module = MutMap::default();
// let loaded_module =
// load_fixture("interface_with_deps", "Records", subs_by_module).await;
// load_fixture("interface_with_deps", "Records", subs_by_module);
// // NOTE: `a` here is unconstrained, so unifies with <type error>
// let expected_types = hashmap! {
@ -409,6 +379,5 @@ mod test_load {
// assert_eq!((&symbol, expected_type), (&symbol, &actual_str.as_str()));
// }
// }
// });
// }
}