diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index fdbc644d..9549ad62 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -282,7 +282,8 @@ fn cli_compile(sub_matches: &ArgMatches) -> Result<(), String> { ) }; - let resolver = FileSystemResolver::new(sub_matches.value_of("stdlib-path").unwrap()); + let resolver = + FileSystemResolver::with_stdlib_root(sub_matches.value_of("stdlib-path").unwrap()); let artifacts: CompilationArtifacts = compile(source, path, Some(&resolver)).map_err(|e| { format!( @@ -369,7 +370,8 @@ fn cli_check(sub_matches: &ArgMatches) -> Result<(), String> { ) }; - let resolver = FileSystemResolver::new(sub_matches.value_of("stdlib-path").unwrap()); + let resolver = + FileSystemResolver::with_stdlib_root(sub_matches.value_of("stdlib-path").unwrap()); let _ = check::(source, path, Some(&resolver)).map_err(|e| { format!( "Check failed:\n\n{}", @@ -943,7 +945,7 @@ mod tests { reader.read_to_string(&mut source).unwrap(); let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap(); - let resolver = FileSystemResolver::new(stdlib.to_str().unwrap()); + let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap()); let _: CompilationArtifacts = compile(source, path, Some(&resolver)).unwrap(); } @@ -966,7 +968,7 @@ mod tests { reader.read_to_string(&mut source).unwrap(); let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap(); - let resolver = FileSystemResolver::new(stdlib.to_str().unwrap()); + let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap()); let artifacts: CompilationArtifacts = compile(source, path, Some(&resolver)).unwrap(); @@ -997,7 +999,7 @@ mod tests { reader.read_to_string(&mut source).unwrap(); let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap(); - let resolver = FileSystemResolver::new(stdlib.to_str().unwrap()); + let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap()); let artifacts: CompilationArtifacts = compile(source, path, Some(&resolver)).unwrap(); diff --git a/zokrates_fs_resolver/src/lib.rs b/zokrates_fs_resolver/src/lib.rs index c5dd0196..8d6f5627 100644 --- a/zokrates_fs_resolver/src/lib.rs +++ b/zokrates_fs_resolver/src/lib.rs @@ -10,7 +10,7 @@ pub struct FileSystemResolver<'a> { } impl<'a> FileSystemResolver<'a> { - pub fn new(stdlib_root_path: &'a str) -> Self { + pub fn with_stdlib_root(stdlib_root_path: &'a str) -> Self { FileSystemResolver { stdlib_root_path } } } @@ -67,7 +67,7 @@ mod tests { let file_path = folder.path().join("bar.zok"); File::create(file_path.clone()).unwrap(); - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let (_, next_location) = fs_resolver .resolve(file_path.clone(), "./bar.zok".into()) .unwrap(); @@ -76,14 +76,14 @@ mod tests { #[test] fn non_existing_file() { - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let res = fs_resolver.resolve("./source.zok".into(), "./rubbish".into()); assert!(res.is_err()); } #[test] fn invalid_location() { - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let res = fs_resolver.resolve(",8!-$2abc".into(), "./foo".into()); assert!(res.is_err()); } @@ -95,7 +95,7 @@ mod tests { let dir_path = folder.path().join("dir"); std::fs::create_dir(dir_path.clone()).unwrap(); - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let res = fs_resolver.resolve(".".into(), "./dir/".into()); assert!(res.is_err()); } @@ -107,7 +107,7 @@ mod tests { let file_path = folder.path().join("foo.zok"); File::create(file_path.clone()).unwrap(); - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let res = fs_resolver.resolve(file_path, ".".into()); assert!(res.is_err()); } @@ -129,7 +129,7 @@ mod tests { writeln!(file, "").unwrap(); let stdlib_root_path = zokrates_home_folder.path().to_owned(); - let fs_resolver = FileSystemResolver::new(stdlib_root_path.to_str().unwrap()); + let fs_resolver = FileSystemResolver::with_stdlib_root(stdlib_root_path.to_str().unwrap()); let result = fs_resolver.resolve(file_path, "./bar.zok".into()); assert!(result.is_ok()); // the imported file should be the user's @@ -153,7 +153,7 @@ mod tests { writeln!(file, "").unwrap(); let stdlib_root_path = zokrates_home_folder.path().to_owned(); - let fs_resolver = FileSystemResolver::new(stdlib_root_path.to_str().unwrap()); + let fs_resolver = FileSystemResolver::with_stdlib_root(stdlib_root_path.to_str().unwrap()); let result = fs_resolver.resolve(file_path.clone(), "bar.zok".into()); assert!(result.is_ok()); // the imported file should be the user's @@ -173,7 +173,7 @@ mod tests { let origin_path = source_subfolder.path().join("foo.zok"); File::create(origin_path).unwrap(); - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let result = fs_resolver.resolve( source_subfolder.path().to_path_buf().join("foo.zok"), "../bar.zok".into(), @@ -194,14 +194,14 @@ mod tests { writeln!(file, "").unwrap(); let stdlib_root_path = zokrates_home_folder.path().to_owned(); - let fs_resolver = FileSystemResolver::new(stdlib_root_path.to_str().unwrap()); + let fs_resolver = FileSystemResolver::with_stdlib_root(stdlib_root_path.to_str().unwrap()); let result = fs_resolver.resolve("/path/to/source.zok".into(), "./bar.zok".into()); assert!(result.is_err()); } #[test] fn fail_if_not_found_in_std() { - let fs_resolver = FileSystemResolver::new(""); + let fs_resolver = FileSystemResolver::with_stdlib_root(""); let result = fs_resolver.resolve("/path/to/source.zok".into(), "bar.zok".into()); assert!(result.is_err()); } diff --git a/zokrates_test/src/lib.rs b/zokrates_test/src/lib.rs index 8d7d5162..878fe952 100644 --- a/zokrates_test/src/lib.rs +++ b/zokrates_test/src/lib.rs @@ -96,7 +96,7 @@ fn compile_and_run(t: Tests) { let code = std::fs::read_to_string(&t.entry_point).unwrap(); let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap(); - let resolver = FileSystemResolver::new(stdlib.to_str().unwrap()); + let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap()); let artifacts = compile::(code, t.entry_point.clone(), Some(&resolver)).unwrap(); let bin = artifacts.prog();