minor changes for clarity
This commit is contained in:
parent
5850f77e1f
commit
30a38b6403
3 changed files with 19 additions and 17 deletions
|
@ -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> =
|
||||
compile(source, path, Some(&resolver)).map_err(|e| {
|
||||
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| {
|
||||
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<Bn128Field> =
|
||||
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<Bn128Field> =
|
||||
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<Bn128Field> =
|
||||
compile(source, path, Some(&resolver)).unwrap();
|
||||
|
|
|
@ -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, "<user code>").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, "<user code>").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, "<stdlib code>").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());
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn compile_and_run<T: Field>(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::<T, _>(code, t.entry_point.clone(), Some(&resolver)).unwrap();
|
||||
|
||||
let bin = artifacts.prog();
|
||||
|
|
Loading…
Reference in a new issue