Skip to content

Commit

Permalink
Dispense with separate conserve_testsupport crate.
Browse files Browse the repository at this point in the history
Now the library's built as a library, blackbox tests can reach code in
there.
  • Loading branch information
sourcefrog committed Dec 11, 2016
1 parent f1e7af9 commit 33ccb8b
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 93 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -33,6 +32,3 @@ time = "^0"
default = []
sync = [] # Flush changes to disk.
bench = [] # Build benchmarks (nightly compiler only)

[workspace]
members = ["testsupport"]
3 changes: 1 addition & 2 deletions src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ extern crate time;
#[cfg(feature="bench")]
extern crate test;

extern crate conserve_testsupport;

// Conserve implementation modules.
mod apath;
mod archive;
Expand Down
2 changes: 1 addition & 1 deletion src/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
58 changes: 56 additions & 2 deletions src/testfixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
5 changes: 2 additions & 3 deletions tests/blackbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,8 +17,8 @@ use std::str;

use spectral::prelude::*;

use conserve_testsupport::TreeFixture;

extern crate conserve;
use conserve::testfixtures::TreeFixture;


#[test]
Expand Down
4 changes: 2 additions & 2 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 0 additions & 4 deletions testsupport/Cargo.lock

This file was deleted.

7 changes: 0 additions & 7 deletions testsupport/Cargo.toml

This file was deleted.

65 changes: 0 additions & 65 deletions testsupport/src/lib.rs

This file was deleted.

0 comments on commit 33ccb8b

Please sign in to comment.