@@ -1102,6 +1102,99 @@ fn main() {
11021102 }
11031103}
11041104
1105+ #[ cfg( test) ]
1106+ mod error_tests {
1107+ use std:: path:: Path ;
1108+
1109+ use super :: * ;
1110+
1111+ use crate :: resolution:: tests:: canon;
1112+ use crate :: resolution:: CanonPath ;
1113+ use crate :: test_utils:: TempWorkspace ;
1114+
1115+ fn dependency_map ( root_dir : & Path , drp : & str , lib_dir : & Path ) -> DependencyMap {
1116+ let mut dependency_map = DependencyMap :: new ( ) ;
1117+
1118+ let context = CanonPath :: canonicalize ( root_dir) . unwrap ( ) ;
1119+ let target = CanonPath :: canonicalize ( lib_dir) . unwrap ( ) ;
1120+
1121+ dependency_map. insert ( context, drp. into ( ) , target) . unwrap ( ) ;
1122+
1123+ dependency_map
1124+ }
1125+
1126+ fn source_file ( path : & Path ) -> SourceFile {
1127+ let content = std:: fs:: read_to_string ( path) . expect ( "Failed to read test file" ) ;
1128+ SourceFile :: new ( path, Arc :: from ( content) )
1129+ }
1130+
1131+ #[ test]
1132+ #[ ignore = "TODO: Bug in Error Handler. Expected to be fixed in a future update to correctly point to dependency source files." ]
1133+ fn dependency_ast_errors_use_dependency_source_file ( ) {
1134+ let ws = TempWorkspace :: new ( "dependency_ast_error_source" ) ;
1135+ let root_dir = ws. create_dir ( "workspace" ) ;
1136+ let lib_dir = ws. create_dir ( "workspace/lib" ) ;
1137+ let main_path = ws. create_file (
1138+ "workspace/main.simf" ,
1139+ "use lib::bad::f;\n fn main() { f(); }\n " ,
1140+ ) ;
1141+ let bad_path = ws. create_file (
1142+ "workspace/lib/bad.simf" ,
1143+ "pub fn f() { let x: u32 = true; }\n " ,
1144+ ) ;
1145+
1146+ let dependencies = dependency_map ( & root_dir, "lib" , & lib_dir) ;
1147+
1148+ let err = TemplateProgram :: new_with_dep ( source_file ( & main_path) , & dependencies)
1149+ . expect_err ( "dependency body has a type error" ) ;
1150+ let dependency_source = canon ( & bad_path) . as_path ( ) . display ( ) . to_string ( ) ;
1151+
1152+ assert ! (
1153+ err. contains( & dependency_source) ,
1154+ "expected diagnostic to point at dependency source {dependency_source}, got:\n {err}"
1155+ ) ;
1156+ }
1157+
1158+ #[ test]
1159+ fn omitted_context_dependency_applies_inside_dependency_files ( ) {
1160+ let ws = TempWorkspace :: new ( "omitted_context_dependency" ) ;
1161+ let lib_dir = ws. create_dir ( "workspace/lib" ) ;
1162+ let main_path = ws. create_file (
1163+ "workspace/main.simf" ,
1164+ "use lib::nested::two;\n fn main() { assert!(jet::eq_32(two(), 2)); }\n " ,
1165+ ) ;
1166+ ws. create_file (
1167+ "workspace/lib/nested.simf" ,
1168+ "use lib::base::one;\n pub fn two() -> u32 {\n let (_, out): (bool, u32) = jet::add_32(one(), 1);\n out\n }\n " ,
1169+ ) ;
1170+ ws. create_file ( "workspace/lib/base.simf" , "pub fn one() -> u32 { 1 }\n " ) ;
1171+
1172+ let dependencies = dependency_map ( & main_path, "lib" , & lib_dir) ;
1173+ let _err = TemplateProgram :: new_with_dep ( source_file ( & main_path) , & dependencies)
1174+ . expect_err ( "omitted-context dependencies" ) ;
1175+ }
1176+
1177+ #[ test]
1178+ fn missing_mapped_module_is_reported_as_file_not_found ( ) {
1179+ let ws = TempWorkspace :: new ( "missing_mapped_module" ) ;
1180+ let root_dir = ws. create_dir ( "workspace" ) ;
1181+ let lib_dir = ws. create_dir ( "workspace/lib" ) ;
1182+ let main_path = ws. create_file (
1183+ "workspace/main.simf" ,
1184+ "use lib::missing::Thing;\n fn main() {}\n " ,
1185+ ) ;
1186+ let dependencies = dependency_map ( & root_dir, "lib" , & lib_dir) ;
1187+
1188+ let err = TemplateProgram :: new_with_dep ( source_file ( & main_path) , & dependencies)
1189+ . expect_err ( "missing imported module should fail" ) ;
1190+
1191+ assert ! (
1192+ err. contains( "missing.simf" ) ,
1193+ "diagnostic should mention the missing module path, got:\n {err}"
1194+ ) ;
1195+ }
1196+ }
1197+
11051198#[ cfg( test) ]
11061199mod functional_tests {
11071200 use crate :: tests:: { run_dependency_test, run_multidep_test} ;
0 commit comments