diff --git a/Cargo.toml b/Cargo.toml index 8a5f4825..0e0dee55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ blake2-rfc = "^0" brotli2 = "^0" clap = "~2.19" clippy = {version = "*", optional = true} -conserve_testsupport = {path = "testsupport", version = "0.3.0"} error-chain = "~0.7.1" isatty = "0.1" log = "^0" @@ -33,6 +32,3 @@ time = "^0" default = [] sync = [] # Flush changes to disk. bench = [] # Build benchmarks (nightly compiler only) - -[workspace] -members = ["testsupport"] diff --git a/src/backup.rs b/src/backup.rs index ada73f20..027c15ef 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -115,8 +115,7 @@ mod tests { use super::backup; use super::super::index; use super::super::report::Report; - use super::super::testfixtures::{ScratchArchive}; - use conserve_testsupport::TreeFixture; + use super::super::testfixtures::{ScratchArchive, TreeFixture}; #[cfg(unix)] #[test] diff --git a/src/lib.rs b/src/lib.rs index f608ab93..26d214c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,8 +28,6 @@ extern crate time; #[cfg(feature="bench")] extern crate test; -extern crate conserve_testsupport; - // Conserve implementation modules. mod apath; mod archive; diff --git a/src/restore.rs b/src/restore.rs index 932679e4..b526d00a 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -135,7 +135,7 @@ mod tests { use super::super::backup::backup; use super::super::report::Report; use super::super::testfixtures::ScratchArchive; - use conserve_testsupport::TreeFixture; + use super::super::testfixtures::TreeFixture; fn setup_archive() -> ScratchArchive { let af = ScratchArchive::new(); diff --git a/src/sources.rs b/src/sources.rs index ef58b6c8..3ab0eeb9 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -202,7 +202,7 @@ mod tests { use super::*; use super::super::report::Report; - use conserve_testsupport::TreeFixture; + use super::super::testfixtures::TreeFixture; #[test] fn simple_directory() { diff --git a/src/testfixtures.rs b/src/testfixtures.rs index 4f182560..f5eb8137 100644 --- a/src/testfixtures.rs +++ b/src/testfixtures.rs @@ -7,12 +7,14 @@ /// Fixtures that create directories will be automatically deleted when the object /// is deleted. +use std::fs; +use std::io::Write; use std::ops::Deref; -use std::path::{Path}; +use std::path::{Path, PathBuf}; use tempdir; -use super::{Archive}; +use super::Archive; /// A temporary archive. pub struct ScratchArchive { @@ -49,3 +51,55 @@ impl Deref for ScratchArchive { &self.archive } } + + +/// A temporary tree for running a test. +/// +/// Created in a temporary directory and automatically disposed when done. +pub struct TreeFixture { + pub root: PathBuf, + _tempdir: tempdir::TempDir, // held only for cleanup +} + +impl TreeFixture { + pub fn new() -> TreeFixture { + let tempdir = tempdir::TempDir::new("conserve_TreeFixture").unwrap(); + let root = tempdir.path().to_path_buf(); + TreeFixture { + _tempdir: tempdir, + root: root, + } + } + + pub fn path(self: &TreeFixture) -> &Path { + &self.root + } + + pub fn create_file(self: &TreeFixture, relative_path: &str) { + let full_path = self.root.join(relative_path); + let mut f = fs::File::create(&full_path).unwrap(); + f.write_all(b"contents").unwrap(); + } + + pub fn create_dir(self: &TreeFixture, relative_path: &str) { + fs::create_dir(self.root.join(relative_path)).unwrap(); + } + + #[cfg(unix)] + pub fn create_symlink(self: &TreeFixture, relative_path: &str, target: &str) { + use std::os::unix::fs as unix_fs; + + unix_fs::symlink(target, self.root.join(relative_path)).unwrap(); + } + + /// Symlinks are just not present on Windows. + #[cfg(windows)] + pub fn create_symlink(self: &TreeFixture, _relative_path: &str, _target: &str) { + } +} + +impl Default for TreeFixture { + fn default() -> Self { + Self::new() + } +} diff --git a/tests/blackbox.rs b/tests/blackbox.rs index 2f455943..c6b7e260 100644 --- a/tests/blackbox.rs +++ b/tests/blackbox.rs @@ -4,7 +4,6 @@ /// Run conserve CLI as a subprocess and test it. -extern crate conserve_testsupport; #[macro_use] extern crate spectral; extern crate tempdir; @@ -18,8 +17,8 @@ use std::str; use spectral::prelude::*; -use conserve_testsupport::TreeFixture; - +extern crate conserve; +use conserve::testfixtures::TreeFixture; #[test] diff --git a/tests/integration.rs b/tests/integration.rs index f9ec404f..a5a9cfbe 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -3,14 +3,14 @@ extern crate tempdir; extern crate conserve; -extern crate conserve_testsupport; use conserve::backup; use conserve::index; use conserve::report::Report; use conserve::Restore; use conserve::testfixtures::{ScratchArchive}; -use conserve_testsupport::TreeFixture; +use conserve::testfixtures::TreeFixture; + #[test] pub fn simple_backup() { diff --git a/testsupport/Cargo.lock b/testsupport/Cargo.lock deleted file mode 100644 index 001b3fa8..00000000 --- a/testsupport/Cargo.lock +++ /dev/null @@ -1,4 +0,0 @@ -[root] -name = "testsupport" -version = "0.1.0" - diff --git a/testsupport/Cargo.toml b/testsupport/Cargo.toml deleted file mode 100644 index 4dc9768a..00000000 --- a/testsupport/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "conserve_testsupport" -version = "0.3.0" -authors = ["Martin Pool "] - -[dependencies] -tempdir = "^0" diff --git a/testsupport/src/lib.rs b/testsupport/src/lib.rs deleted file mode 100644 index d9453f5a..00000000 --- a/testsupport/src/lib.rs +++ /dev/null @@ -1,65 +0,0 @@ -// Conserve backup system. -// Copyright 2016 Martin Pool. - - -/// Utilities to set up test environments. -/// -/// Fixtures that create directories will be automatically deleted when the object -/// is deleted. - -extern crate tempdir; - -use std::fs; -use std::io::Write; -use std::path::{Path, PathBuf}; - -/// A temporary tree for running a test. -/// -/// Created in a temporary directory and automatically disposed when done. -pub struct TreeFixture { - pub root: PathBuf, - _tempdir: tempdir::TempDir, // held only for cleanup -} - -impl TreeFixture { - pub fn new() -> TreeFixture { - let tempdir = tempdir::TempDir::new("conserve_TreeFixture").unwrap(); - let root = tempdir.path().to_path_buf(); - TreeFixture { - _tempdir: tempdir, - root: root, - } - } - - pub fn path(self: &TreeFixture) -> &Path { - &self.root - } - - pub fn create_file(self: &TreeFixture, relative_path: &str) { - let full_path = self.root.join(relative_path); - let mut f = fs::File::create(&full_path).unwrap(); - f.write_all(b"contents").unwrap(); - } - - pub fn create_dir(self: &TreeFixture, relative_path: &str) { - fs::create_dir(self.root.join(relative_path)).unwrap(); - } - - #[cfg(unix)] - pub fn create_symlink(self: &TreeFixture, relative_path: &str, target: &str) { - use std::os::unix::fs as unix_fs; - - unix_fs::symlink(target, self.root.join(relative_path)).unwrap(); - } - - /// Symlinks are just not present on Windows. - #[cfg(windows)] - pub fn create_symlink(self: &TreeFixture, _relative_path: &str, _target: &str) { - } -} - -impl Default for TreeFixture { - fn default() -> Self { - Self::new() - } -}