Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Refactor integration tests: #157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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