Support multiple modules in uitest

This commit is contained in:
Ayaz Hafiz 2023-04-12 11:35:33 -05:00
parent 0ec0568ef9
commit 014ec8c092
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 192 additions and 30 deletions

View file

@ -44,8 +44,9 @@ fn promote_expr_to_module(src: &str) -> String {
buffer
}
pub fn run_load_and_infer(
pub fn run_load_and_infer<'a>(
src: &str,
dependencies: impl IntoIterator<Item = (&'a str, &'a str)>,
no_promote: bool,
) -> Result<(LoadedModule, String), std::io::Error> {
use tempfile::tempdir;
@ -65,6 +66,11 @@ pub fn run_load_and_infer(
let loaded = {
let dir = tempdir()?;
for (file, source) in dependencies {
std::fs::write(dir.path().join(format!("{file}.roc")), source)?;
}
let filename = PathBuf::from("Test.roc");
let file_path = dir.path().join(filename);
let result = roc_load::load_and_typecheck_str(
@ -338,7 +344,11 @@ impl InferredProgram {
}
}
pub fn infer_queries(src: &str, options: InferOptions) -> Result<InferredProgram, Box<dyn Error>> {
pub fn infer_queries<'a>(
src: &str,
dependencies: impl IntoIterator<Item = (&'a str, &'a str)>,
options: InferOptions,
) -> Result<InferredProgram, Box<dyn Error>> {
let (
LoadedModule {
module_id: home,
@ -351,7 +361,7 @@ pub fn infer_queries(src: &str, options: InferOptions) -> Result<InferredProgram
..
},
src,
) = run_load_and_infer(src, options.no_promote)?;
) = run_load_and_infer(src, dependencies, options.no_promote)?;
let declarations = declarations_by_id.remove(&home).unwrap();
let subs = solved.inner_mut();