1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

minor changes for clarity

This commit is contained in:
dark64 2020-06-30 12:04:53 +02:00
parent 5850f77e1f
commit 30a38b6403
3 changed files with 19 additions and 17 deletions

View file

@ -282,7 +282,8 @@ fn cli_compile<T: Field>(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<T> = let artifacts: CompilationArtifacts<T> =
compile(source, path, Some(&resolver)).map_err(|e| { compile(source, path, Some(&resolver)).map_err(|e| {
format!( format!(
@ -369,7 +370,8 @@ fn cli_check<T: Field>(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::<T, _>(source, path, Some(&resolver)).map_err(|e| { let _ = check::<T, _>(source, path, Some(&resolver)).map_err(|e| {
format!( format!(
"Check failed:\n\n{}", "Check failed:\n\n{}",
@ -943,7 +945,7 @@ mod tests {
reader.read_to_string(&mut source).unwrap(); reader.read_to_string(&mut source).unwrap();
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").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<Bn128Field> = let _: CompilationArtifacts<Bn128Field> =
compile(source, path, Some(&resolver)).unwrap(); compile(source, path, Some(&resolver)).unwrap();
} }
@ -966,7 +968,7 @@ mod tests {
reader.read_to_string(&mut source).unwrap(); reader.read_to_string(&mut source).unwrap();
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").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<Bn128Field> = let artifacts: CompilationArtifacts<Bn128Field> =
compile(source, path, Some(&resolver)).unwrap(); compile(source, path, Some(&resolver)).unwrap();
@ -997,7 +999,7 @@ mod tests {
reader.read_to_string(&mut source).unwrap(); reader.read_to_string(&mut source).unwrap();
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").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<Bn128Field> = let artifacts: CompilationArtifacts<Bn128Field> =
compile(source, path, Some(&resolver)).unwrap(); compile(source, path, Some(&resolver)).unwrap();

View file

@ -10,7 +10,7 @@ pub struct FileSystemResolver<'a> {
} }
impl<'a> 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 } FileSystemResolver { stdlib_root_path }
} }
} }
@ -67,7 +67,7 @@ mod tests {
let file_path = folder.path().join("bar.zok"); let file_path = folder.path().join("bar.zok");
File::create(file_path.clone()).unwrap(); File::create(file_path.clone()).unwrap();
let fs_resolver = FileSystemResolver::new(""); let fs_resolver = FileSystemResolver::with_stdlib_root("");
let (_, next_location) = fs_resolver let (_, next_location) = fs_resolver
.resolve(file_path.clone(), "./bar.zok".into()) .resolve(file_path.clone(), "./bar.zok".into())
.unwrap(); .unwrap();
@ -76,14 +76,14 @@ mod tests {
#[test] #[test]
fn non_existing_file() { 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()); let res = fs_resolver.resolve("./source.zok".into(), "./rubbish".into());
assert!(res.is_err()); assert!(res.is_err());
} }
#[test] #[test]
fn invalid_location() { 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()); let res = fs_resolver.resolve(",8!-$2abc".into(), "./foo".into());
assert!(res.is_err()); assert!(res.is_err());
} }
@ -95,7 +95,7 @@ mod tests {
let dir_path = folder.path().join("dir"); let dir_path = folder.path().join("dir");
std::fs::create_dir(dir_path.clone()).unwrap(); 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()); let res = fs_resolver.resolve(".".into(), "./dir/".into());
assert!(res.is_err()); assert!(res.is_err());
} }
@ -107,7 +107,7 @@ mod tests {
let file_path = folder.path().join("foo.zok"); let file_path = folder.path().join("foo.zok");
File::create(file_path.clone()).unwrap(); 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()); let res = fs_resolver.resolve(file_path, ".".into());
assert!(res.is_err()); assert!(res.is_err());
} }
@ -129,7 +129,7 @@ mod tests {
writeln!(file, "<user code>").unwrap(); writeln!(file, "<user code>").unwrap();
let stdlib_root_path = zokrates_home_folder.path().to_owned(); 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()); let result = fs_resolver.resolve(file_path, "./bar.zok".into());
assert!(result.is_ok()); assert!(result.is_ok());
// the imported file should be the user's // the imported file should be the user's
@ -153,7 +153,7 @@ mod tests {
writeln!(file, "<user code>").unwrap(); writeln!(file, "<user code>").unwrap();
let stdlib_root_path = zokrates_home_folder.path().to_owned(); 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()); let result = fs_resolver.resolve(file_path.clone(), "bar.zok".into());
assert!(result.is_ok()); assert!(result.is_ok());
// the imported file should be the user's // the imported file should be the user's
@ -173,7 +173,7 @@ mod tests {
let origin_path = source_subfolder.path().join("foo.zok"); let origin_path = source_subfolder.path().join("foo.zok");
File::create(origin_path).unwrap(); File::create(origin_path).unwrap();
let fs_resolver = FileSystemResolver::new(""); let fs_resolver = FileSystemResolver::with_stdlib_root("");
let result = fs_resolver.resolve( let result = fs_resolver.resolve(
source_subfolder.path().to_path_buf().join("foo.zok"), source_subfolder.path().to_path_buf().join("foo.zok"),
"../bar.zok".into(), "../bar.zok".into(),
@ -194,14 +194,14 @@ mod tests {
writeln!(file, "<stdlib code>").unwrap(); writeln!(file, "<stdlib code>").unwrap();
let stdlib_root_path = zokrates_home_folder.path().to_owned(); 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()); let result = fs_resolver.resolve("/path/to/source.zok".into(), "./bar.zok".into());
assert!(result.is_err()); assert!(result.is_err());
} }
#[test] #[test]
fn fail_if_not_found_in_std() { 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()); let result = fs_resolver.resolve("/path/to/source.zok".into(), "bar.zok".into());
assert!(result.is_err()); assert!(result.is_err());
} }

View file

@ -96,7 +96,7 @@ fn compile_and_run<T: Field>(t: Tests) {
let code = std::fs::read_to_string(&t.entry_point).unwrap(); let code = std::fs::read_to_string(&t.entry_point).unwrap();
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").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::<T, _>(code, t.entry_point.clone(), Some(&resolver)).unwrap(); let artifacts = compile::<T, _>(code, t.entry_point.clone(), Some(&resolver)).unwrap();
let bin = artifacts.prog(); let bin = artifacts.prog();