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

View File

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

View File

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

View File

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

View File

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