Skip to content

Commit

Permalink
rust: Adjust EKO::close
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Aug 20, 2024
1 parent 44fc971 commit ea6fd0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions crates/dekoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ impl EKO {
}

/// Write content back to an archive and destroy working directory.
pub fn close(&self, allow_overwrite: bool) -> Result<()> {
self.write(allow_overwrite, true)
pub fn close(&self) -> Result<()> {
self.write(false, true)
}

/// Write content back to an archive and destroy working directory.
pub fn overwrite_and_close(&self) -> Result<()> {
self.write(true, true)
}

/// Write content back to an archive.
Expand Down
16 changes: 13 additions & 3 deletions crates/dekoder/tests/test_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ fn v015tar() -> PathBuf {
src
}

#[test]
fn open() {
let src = v015tar();
let dst = assert_fs::TempDir::new().unwrap();
// open
let _ = EKO::edit(src.to_owned(), dst.to_owned()).unwrap();
let metadata = dst.child("metadata.yaml");
metadata.assert(predicate::path::exists());
}

#[test]
fn save_as_other() {
let src = v015tar();
Expand All @@ -21,7 +31,7 @@ fn save_as_other() {
// write to somewhere else
let tarb = assert_fs::NamedTempFile::new("v0.15b.tar").unwrap();
eko.set_tar_path(tarb.to_owned());
eko.close(true).unwrap();
eko.overwrite_and_close().unwrap();
tarb.assert(predicate::path::exists());
}

Expand All @@ -41,7 +51,7 @@ fn has_operator() {
// it is the one
assert!(ep.equals(eko.available_operators()[0], 64));
assert!(eko.has_operator(&ep, 64));
eko.close(false).unwrap();
eko.close().unwrap();
}

#[test]
Expand All @@ -58,5 +68,5 @@ fn load_operator() {
let mut op = Operator::zeros();
eko.load_operator(&ep, 64, &mut op).unwrap();
assert!(op.op.dim().0 > 0);
eko.close(false).unwrap();
eko.close().unwrap();
}

0 comments on commit ea6fd0d

Please sign in to comment.