Skip to content

Commit 7fc0dff

Browse files
committed
remove all of the (now) unnecessary temp file usage in tests
1 parent acf89e9 commit 7fc0dff

File tree

5 files changed

+10
-31
lines changed

5 files changed

+10
-31
lines changed

tests/testsuite/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use support::{execs, main_file, project};
1111
use support::registry::Package;
1212
use support::ChannelChanger;
1313
use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
14-
use tempfile;
1514

1615
#[test]
1716
fn cargo_compile_simple() {
@@ -485,8 +484,7 @@ Caused by:
485484

486485
#[test]
487486
fn cargo_compile_without_manifest() {
488-
let tmpdir = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
489-
let p = ProjectBuilder::new(tmpdir.path().to_path_buf()).no_manifest().build();
487+
let p = project().no_manifest().build();
490488

491489
assert_that(
492490
p.cargo("build"),

tests/testsuite/fix.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ fn shows_warnings() {
747747
#[test]
748748
fn warns_if_no_vcs_detected() {
749749
let p = project()
750-
.use_temp_dir()
751750
.file("src/lib.rs", "pub fn foo() {}")
752751
.build();
753752

tests/testsuite/init.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::env;
66
use cargo::util::ProcessBuilder;
77
use support::{cargo_exe, execs, paths};
88
use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
9-
use tempfile;
109

1110
fn cargo_process(s: &str) -> ProcessBuilder {
1211
let mut p = support::process(&cargo_exe());
@@ -62,12 +61,10 @@ fn simple_bin() {
6261

6362
#[test]
6463
fn both_lib_and_bin() {
65-
let td = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
6664
assert_that(
6765
cargo_process("init")
6866
.arg("--lib")
6967
.arg("--bin")
70-
.cwd(td.path())
7168
.env("USER", "foo"),
7269
execs()
7370
.with_status(101)
@@ -304,21 +301,17 @@ fn simple_git() {
304301

305302
#[test]
306303
fn auto_git() {
307-
let td = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
308-
let foo = &td.path().join("foo");
309-
fs::create_dir_all(&foo).unwrap();
310304
assert_that(
311305
cargo_process("init")
312306
.arg("--lib")
313-
.cwd(foo.clone())
314307
.env("USER", "foo"),
315308
execs().with_status(0),
316309
);
317310

318-
assert_that(&foo.join("Cargo.toml"), existing_file());
319-
assert_that(&foo.join("src/lib.rs"), existing_file());
320-
assert_that(&foo.join(".git"), existing_dir());
321-
assert_that(&foo.join(".gitignore"), existing_file());
311+
assert_that(&paths::root().join("Cargo.toml"), existing_file());
312+
assert_that(&paths::root().join("src/lib.rs"), existing_file());
313+
assert_that(&paths::root().join(".git"), existing_dir());
314+
assert_that(&paths::root().join(".gitignore"), existing_file());
322315
}
323316

324317
#[test]

tests/testsuite/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extern crate serde_derive;
1313
#[macro_use]
1414
extern crate serde_json;
1515
extern crate tar;
16-
extern crate tempfile;
1716
extern crate toml;
1817
extern crate url;
1918
#[cfg(windows)]

tests/testsuite/support/mod.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ use std::usize;
9696
use cargo::util::{ProcessBuilder, ProcessError, Rustc};
9797
use cargo;
9898
use serde_json::{self, Value};
99-
use tempfile::TempDir;
10099
use url::Url;
101100

102101
use self::hamcrest as ham;
@@ -180,9 +179,8 @@ impl SymlinkBuilder {
180179
}
181180
}
182181

183-
pub enum Project {
184-
Rooted(PathBuf),
185-
Temp(TempDir),
182+
pub struct Project {
183+
root: PathBuf
186184
}
187185

188186
#[must_use]
@@ -206,15 +204,15 @@ impl ProjectBuilder {
206204

207205
pub fn new(root: PathBuf) -> ProjectBuilder {
208206
ProjectBuilder {
209-
root: Project::Rooted(root),
207+
root: Project { root },
210208
files: vec![],
211209
symlinks: vec![],
212210
no_manifest: false,
213211
}
214212
}
215213

216214
pub fn at<P: AsRef<Path>>(mut self, path: P) -> Self {
217-
self.root = Project::Rooted(paths::root().join(path));
215+
self.root = Project{root: paths::root().join(path)};
218216
self
219217
}
220218

@@ -238,11 +236,6 @@ impl ProjectBuilder {
238236
self
239237
}
240238

241-
pub fn use_temp_dir(mut self) -> Self {
242-
self.root = Project::Temp(TempDir::new().unwrap());
243-
self
244-
}
245-
246239
pub fn no_manifest(mut self) -> Self {
247240
self.no_manifest = true;
248241
self
@@ -286,10 +279,7 @@ impl ProjectBuilder {
286279
impl Project {
287280
/// Root of the project, ex: `/path/to/cargo/target/cit/t0/foo`
288281
pub fn root(&self) -> PathBuf {
289-
match self {
290-
Project::Rooted(p) => p.clone(),
291-
Project::Temp(t) => t.path().to_path_buf(),
292-
}
282+
self.root.clone()
293283
}
294284

295285
/// Project's target dir, ex: `/path/to/cargo/target/cit/t0/foo/target`

0 commit comments

Comments
 (0)