Fix dependency namespacing in 'checks' tests.
We were mixing module names and package names in a very weird way but it was somehow working. However, the generated ASTs would vastly differ from what we would typically get from running those tests on a standard project -- which defies a bit the purpose of those tests. Signed-off-by: KtorZ <matthias.benkort@gmail.com>
This commit is contained in:
parent
81713d93a0
commit
79a7d80c7f
|
@ -11,15 +11,23 @@ use crate::{
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
const DEFAULT_MODULE_NAME: &str = "my_module";
|
||||||
|
const DEFAULT_PACKAGE: &str = "test/project";
|
||||||
|
|
||||||
fn parse(source_code: &str) -> UntypedModule {
|
fn parse(source_code: &str) -> UntypedModule {
|
||||||
|
parse_as(source_code, DEFAULT_MODULE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_as(source_code: &str, name: &str) -> UntypedModule {
|
||||||
let kind = ModuleKind::Lib;
|
let kind = ModuleKind::Lib;
|
||||||
let (ast, _) = parser::module(source_code, kind).expect("Failed to parse module");
|
let (mut ast, _) = parser::module(source_code, kind).expect("Failed to parse module");
|
||||||
|
ast.name = name.to_string();
|
||||||
ast
|
ast
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_module(
|
fn check_module(
|
||||||
ast: UntypedModule,
|
ast: UntypedModule,
|
||||||
extra: Vec<(String, UntypedModule)>,
|
extra: Vec<UntypedModule>,
|
||||||
kind: ModuleKind,
|
kind: ModuleKind,
|
||||||
tracing: Tracing,
|
tracing: Tracing,
|
||||||
) -> Result<(Vec<Warning>, TypedModule), (Vec<Warning>, Error)> {
|
) -> Result<(Vec<Warning>, TypedModule), (Vec<Warning>, Error)> {
|
||||||
|
@ -31,27 +39,32 @@ fn check_module(
|
||||||
module_types.insert("aiken".to_string(), builtins::prelude(&id_gen));
|
module_types.insert("aiken".to_string(), builtins::prelude(&id_gen));
|
||||||
module_types.insert("aiken/builtin".to_string(), builtins::plutus(&id_gen));
|
module_types.insert("aiken/builtin".to_string(), builtins::plutus(&id_gen));
|
||||||
|
|
||||||
for (package, module) in extra {
|
for module in extra {
|
||||||
let mut warnings = vec![];
|
let mut warnings = vec![];
|
||||||
|
|
||||||
|
if module.name == DEFAULT_MODULE_NAME {
|
||||||
|
panic!("passed extra modules with default name! Use 'parse_as' to define tests instead of 'parse'.");
|
||||||
|
}
|
||||||
|
|
||||||
let typed_module = module
|
let typed_module = module
|
||||||
.infer(
|
.infer(
|
||||||
&id_gen,
|
&id_gen,
|
||||||
kind,
|
kind,
|
||||||
&package,
|
DEFAULT_PACKAGE,
|
||||||
&module_types,
|
&module_types,
|
||||||
Tracing::All(TraceLevel::Verbose),
|
Tracing::All(TraceLevel::Verbose),
|
||||||
&mut warnings,
|
&mut warnings,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.expect("extra dependency did not compile");
|
.expect("extra dependency did not compile");
|
||||||
module_types.insert(package.clone(), typed_module.type_info.clone());
|
|
||||||
|
module_types.insert(typed_module.name.clone(), typed_module.type_info.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = ast.infer(
|
let result = ast.infer(
|
||||||
&id_gen,
|
&id_gen,
|
||||||
kind,
|
kind,
|
||||||
"test/project",
|
DEFAULT_PACKAGE,
|
||||||
&module_types,
|
&module_types,
|
||||||
tracing,
|
tracing,
|
||||||
&mut warnings,
|
&mut warnings,
|
||||||
|
@ -76,7 +89,7 @@ fn check_with_verbosity(
|
||||||
|
|
||||||
fn check_with_deps(
|
fn check_with_deps(
|
||||||
ast: UntypedModule,
|
ast: UntypedModule,
|
||||||
extra: Vec<(String, UntypedModule)>,
|
extra: Vec<UntypedModule>,
|
||||||
) -> Result<(Vec<Warning>, TypedModule), (Vec<Warning>, Error)> {
|
) -> Result<(Vec<Warning>, TypedModule), (Vec<Warning>, Error)> {
|
||||||
check_module(ast, extra, ModuleKind::Lib, Tracing::verbose())
|
check_module(ast, extra, ModuleKind::Lib, Tracing::verbose())
|
||||||
}
|
}
|
||||||
|
@ -2358,7 +2371,7 @@ fn forbid_importing_or_using_opaque_constructors() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
use foo/thing.{Thing, Foo}
|
use thing.{Thing, Foo}
|
||||||
|
|
||||||
fn bar(thing: Thing) {
|
fn bar(thing: Thing) {
|
||||||
expect Foo(a) = thing
|
expect Foo(a) = thing
|
||||||
|
@ -2367,15 +2380,12 @@ fn forbid_importing_or_using_opaque_constructors() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
check_with_deps(
|
check_with_deps(parse(source_code), vec![(parse_as(dependency, "thing"))],),
|
||||||
parse(source_code),
|
|
||||||
vec![("foo/thing".to_string(), parse(dependency))],
|
|
||||||
),
|
|
||||||
Err((_, Error::UnknownModuleField { .. })),
|
Err((_, Error::UnknownModuleField { .. })),
|
||||||
));
|
));
|
||||||
|
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
use foo/thing.{Thing}
|
use thing.{Thing}
|
||||||
|
|
||||||
fn bar(thing: Thing) {
|
fn bar(thing: Thing) {
|
||||||
expect Foo(a) = thing
|
expect Foo(a) = thing
|
||||||
|
@ -2384,10 +2394,7 @@ fn forbid_importing_or_using_opaque_constructors() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
check_with_deps(
|
check_with_deps(parse(source_code), vec![(parse_as(dependency, "thing"))],),
|
||||||
parse(source_code),
|
|
||||||
vec![("foo/thing".to_string(), parse(dependency))],
|
|
||||||
),
|
|
||||||
Err((_, Error::UnknownTypeConstructor { .. })),
|
Err((_, Error::UnknownTypeConstructor { .. })),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue