Skip to content

Commit

Permalink
NOISSUE - Refactor integration tests:
Browse files Browse the repository at this point in the history
* Group tests by category
* Pull out shared methods

Signed-off-by: joshmc <[email protected]>
  • Loading branch information
jmcconnell26 committed Dec 3, 2020
1 parent 31e66fa commit 524f608
Show file tree
Hide file tree
Showing 16 changed files with 1,104 additions and 1,056 deletions.
44 changes: 44 additions & 0 deletions cargo-geiger/tests/context/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::env;
use std::path::{Path, PathBuf};
use tempfile::TempDir;
use url::Url;

pub struct Context {
_dir: TempDir,
pub path: PathBuf,
}

impl Context {
pub fn new() -> Self {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let src_path = Path::new(&manifest_dir).join("../test_crates");
let dir = TempDir::new().unwrap();
let copy_options = fs_extra::dir::CopyOptions {
content_only: true,
..Default::default()
};
fs_extra::dir::copy(&src_path, dir.path(), &copy_options)
.expect("Failed to copy tests");
let path = dir
.path()
.canonicalize()
.expect("Failed to canonicalize temporary path");
// Canonicalizing on Windows returns a UNC path (starting with `\\?\`).
// `cargo build` (as of 1.47.0) fails to use an overriding path dependency if the manifest
// given to `cargo build` is a UNC path. Roudtripping to URL gets rid of the UNC prefix.
let path = if cfg!(windows) {
Url::from_file_path(path)
.expect("URL from path must succeed")
.to_file_path()
.expect("Roundtripping path to URL must succeed")
} else {
path
};
let _dir = dir;
Context { _dir, path }
}

pub fn crate_dir(&self, name: &str) -> PathBuf {
self.path.join(name)
}
}
Loading

0 comments on commit 524f608

Please sign in to comment.