remove all of the (now) unnecessary temp file usage in tests

This commit is contained in:
Eh2406 2018-07-26 15:10:48 -04:00
parent acf89e946c
commit 7fc0dffed2
5 changed files with 10 additions and 31 deletions

View File

@ -11,7 +11,6 @@ use support::{execs, main_file, project};
use support::registry::Package; use support::registry::Package;
use support::ChannelChanger; use support::ChannelChanger;
use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
use tempfile;
#[test] #[test]
fn cargo_compile_simple() { fn cargo_compile_simple() {
@ -485,8 +484,7 @@ Caused by:
#[test] #[test]
fn cargo_compile_without_manifest() { fn cargo_compile_without_manifest() {
let tmpdir = tempfile::Builder::new().prefix("cargo").tempdir().unwrap(); let p = project().no_manifest().build();
let p = ProjectBuilder::new(tmpdir.path().to_path_buf()).no_manifest().build();
assert_that( assert_that(
p.cargo("build"), p.cargo("build"),

View File

@ -747,7 +747,6 @@ fn shows_warnings() {
#[test] #[test]
fn warns_if_no_vcs_detected() { fn warns_if_no_vcs_detected() {
let p = project() let p = project()
.use_temp_dir()
.file("src/lib.rs", "pub fn foo() {}") .file("src/lib.rs", "pub fn foo() {}")
.build(); .build();

View File

@ -6,7 +6,6 @@ use std::env;
use cargo::util::ProcessBuilder; use cargo::util::ProcessBuilder;
use support::{cargo_exe, execs, paths}; use support::{cargo_exe, execs, paths};
use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
use tempfile;
fn cargo_process(s: &str) -> ProcessBuilder { fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = support::process(&cargo_exe()); let mut p = support::process(&cargo_exe());
@ -62,12 +61,10 @@ fn simple_bin() {
#[test] #[test]
fn both_lib_and_bin() { fn both_lib_and_bin() {
let td = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
assert_that( assert_that(
cargo_process("init") cargo_process("init")
.arg("--lib") .arg("--lib")
.arg("--bin") .arg("--bin")
.cwd(td.path())
.env("USER", "foo"), .env("USER", "foo"),
execs() execs()
.with_status(101) .with_status(101)
@ -304,21 +301,17 @@ fn simple_git() {
#[test] #[test]
fn auto_git() { fn auto_git() {
let td = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
let foo = &td.path().join("foo");
fs::create_dir_all(&foo).unwrap();
assert_that( assert_that(
cargo_process("init") cargo_process("init")
.arg("--lib") .arg("--lib")
.cwd(foo.clone())
.env("USER", "foo"), .env("USER", "foo"),
execs().with_status(0), execs().with_status(0),
); );
assert_that(&foo.join("Cargo.toml"), existing_file()); assert_that(&paths::root().join("Cargo.toml"), existing_file());
assert_that(&foo.join("src/lib.rs"), existing_file()); assert_that(&paths::root().join("src/lib.rs"), existing_file());
assert_that(&foo.join(".git"), existing_dir()); assert_that(&paths::root().join(".git"), existing_dir());
assert_that(&foo.join(".gitignore"), existing_file()); assert_that(&paths::root().join(".gitignore"), existing_file());
} }
#[test] #[test]

View File

@ -13,7 +13,6 @@ extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate serde_json; extern crate serde_json;
extern crate tar; extern crate tar;
extern crate tempfile;
extern crate toml; extern crate toml;
extern crate url; extern crate url;
#[cfg(windows)] #[cfg(windows)]

View File

@ -96,7 +96,6 @@ use std::usize;
use cargo::util::{ProcessBuilder, ProcessError, Rustc}; use cargo::util::{ProcessBuilder, ProcessError, Rustc};
use cargo; use cargo;
use serde_json::{self, Value}; use serde_json::{self, Value};
use tempfile::TempDir;
use url::Url; use url::Url;
use self::hamcrest as ham; use self::hamcrest as ham;
@ -180,9 +179,8 @@ impl SymlinkBuilder {
} }
} }
pub enum Project { pub struct Project {
Rooted(PathBuf), root: PathBuf
Temp(TempDir),
} }
#[must_use] #[must_use]
@ -206,7 +204,7 @@ impl ProjectBuilder {
pub fn new(root: PathBuf) -> ProjectBuilder { pub fn new(root: PathBuf) -> ProjectBuilder {
ProjectBuilder { ProjectBuilder {
root: Project::Rooted(root), root: Project { root },
files: vec![], files: vec![],
symlinks: vec![], symlinks: vec![],
no_manifest: false, no_manifest: false,
@ -214,7 +212,7 @@ impl ProjectBuilder {
} }
pub fn at<P: AsRef<Path>>(mut self, path: P) -> Self { pub fn at<P: AsRef<Path>>(mut self, path: P) -> Self {
self.root = Project::Rooted(paths::root().join(path)); self.root = Project{root: paths::root().join(path)};
self self
} }
@ -238,11 +236,6 @@ impl ProjectBuilder {
self self
} }
pub fn use_temp_dir(mut self) -> Self {
self.root = Project::Temp(TempDir::new().unwrap());
self
}
pub fn no_manifest(mut self) -> Self { pub fn no_manifest(mut self) -> Self {
self.no_manifest = true; self.no_manifest = true;
self self
@ -286,10 +279,7 @@ impl ProjectBuilder {
impl Project { impl Project {
/// Root of the project, ex: `/path/to/cargo/target/cit/t0/foo` /// Root of the project, ex: `/path/to/cargo/target/cit/t0/foo`
pub fn root(&self) -> PathBuf { pub fn root(&self) -> PathBuf {
match self { self.root.clone()
Project::Rooted(p) => p.clone(),
Project::Temp(t) => t.path().to_path_buf(),
}
} }
/// Project's target dir, ex: `/path/to/cargo/target/cit/t0/foo/target` /// Project's target dir, ex: `/path/to/cargo/target/cit/t0/foo/target`