mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-22 12:39:52 +03:00
adds tests for outputfile
This commit is contained in:
parent
ed8ff4468c
commit
044dc96e58
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1269,6 +1269,7 @@ dependencies = [
|
||||
"snarkvm-gadgets",
|
||||
"snarkvm-r1cs",
|
||||
"snarkvm-utilities",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -114,6 +114,9 @@ default-features = false
|
||||
version = "0.2.1"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.tempfile]
|
||||
version = "3.0.4"
|
||||
|
||||
[features]
|
||||
default = [ ]
|
||||
ci_skip = [ "leo-ast/ci_skip" ]
|
||||
|
@ -21,9 +21,6 @@ pub enum OutputFileError {
|
||||
#[error("{}: {}", _0, _1)]
|
||||
Crate(&'static str, String),
|
||||
|
||||
#[error("creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
||||
#[error("Cannot read from the provided file path - {:?}", _0)]
|
||||
FileReadError(PathBuf),
|
||||
|
||||
|
@ -42,19 +42,6 @@ impl OutputFile {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exists_at(&self, path: &Path) -> bool {
|
||||
let path = self.setup_file_path(path);
|
||||
path.exists()
|
||||
}
|
||||
|
||||
/// Reads the output register variables from the given file path if it exists.
|
||||
pub fn read_from(&self, path: &Path) -> Result<String, OutputFileError> {
|
||||
let path = self.setup_file_path(path);
|
||||
|
||||
let output = fs::read_to_string(&path).map_err(|_| OutputFileError::FileReadError(path.into_owned()))?;
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
/// Writes output to a file.
|
||||
pub fn write(&self, path: &Path, bytes: &[u8]) -> Result<(), OutputFileError> {
|
||||
// create output file
|
||||
@ -88,3 +75,26 @@ impl OutputFile {
|
||||
path
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_output_file {
|
||||
use crate::{OutputFile, OUTPUTS_DIRECTORY_NAME};
|
||||
use std::{error::Error, fs};
|
||||
|
||||
#[test]
|
||||
fn test_all() -> Result<(), Box<dyn Error>> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
let file = OutputFile::new("test");
|
||||
let path = dir.path();
|
||||
|
||||
assert!(file.write(path, Default::default()).is_err());
|
||||
assert!(file.remove(path)? == false);
|
||||
|
||||
fs::create_dir(dir.path().join(OUTPUTS_DIRECTORY_NAME))?;
|
||||
|
||||
assert!(file.write(path, Default::default()).is_ok());
|
||||
assert!(file.remove(path)? == true);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user