Skip to content

Commit 03e8934

Browse files
committed
Auto merge of #5810 - Eh2406:test-fix, r=alexcrichton
now that we respect gitignore tests can be simplified There are a lot of test that used a tempfile to avoid the fact that cargo would not init a git in the test folder. (or because they were copy/pasted from one that did.) Now that #5733 landed we can remove them all.
2 parents dab09a0 + 7fc0dff commit 03e8934

File tree

6 files changed

+32
-47
lines changed

6 files changed

+32
-47
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/new.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use cargo::util::ProcessBuilder;
77
use support::process;
88
use support::{execs, paths};
99
use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
10-
use tempfile;
1110

1211
fn cargo_process(s: &str) -> ProcessBuilder {
1312
let mut p = support::cargo_process();
@@ -110,27 +109,22 @@ fn both_lib_and_bin() {
110109

111110
#[test]
112111
fn simple_git() {
113-
// Run inside a temp directory so that cargo will initialize a git repo.
114-
// If this ran inside paths::root() it would detect that we are already
115-
// inside a git repo and skip the initialization.
116-
let td = tempfile::Builder::new().prefix("cargo").tempdir().unwrap();
117112
assert_that(
118113
cargo_process("new")
119114
.arg("--lib")
120115
.arg("foo")
121-
.cwd(td.path())
122116
.env("USER", "foo"),
123117
execs().with_status(0),
124118
);
125119

126-
assert_that(td.path(), existing_dir());
127-
assert_that(&td.path().join("foo/Cargo.toml"), existing_file());
128-
assert_that(&td.path().join("foo/src/lib.rs"), existing_file());
129-
assert_that(&td.path().join("foo/.git"), existing_dir());
130-
assert_that(&td.path().join("foo/.gitignore"), existing_file());
120+
assert_that(&paths::root(), existing_dir());
121+
assert_that(&paths::root().join("foo/Cargo.toml"), existing_file());
122+
assert_that(&paths::root().join("foo/src/lib.rs"), existing_file());
123+
assert_that(&paths::root().join("foo/.git"), existing_dir());
124+
assert_that(&paths::root().join("foo/.gitignore"), existing_file());
131125

132126
assert_that(
133-
cargo_process("build").cwd(&td.path().join("foo")),
127+
cargo_process("build").cwd(&paths::root().join("foo")),
134128
execs().with_status(0),
135129
);
136130
}
@@ -476,6 +470,9 @@ fn subpackage_no_git() {
476470
execs().with_status(0),
477471
);
478472

473+
assert_that(&paths::root().join("foo/.git"), existing_dir());
474+
assert_that(&paths::root().join("foo/.gitignore"), existing_file());
475+
479476
let subpackage = paths::root().join("foo").join("components");
480477
fs::create_dir(&subpackage).unwrap();
481478
assert_that(
@@ -502,10 +499,19 @@ fn subpackage_git_with_gitignore() {
502499
execs().with_status(0),
503500
);
504501

505-
let gitignore = paths::root().join("foo").join(".gitignore");
502+
assert_that(
503+
&paths::root().join("foo/.git"),
504+
existing_dir(),
505+
);
506+
assert_that(
507+
&paths::root().join("foo/.gitignore"),
508+
existing_file(),
509+
);
510+
511+
let gitignore = paths::root().join("foo/.gitignore");
506512
fs::write(gitignore, b"components").unwrap();
507513

508-
let subpackage = paths::root().join("foo").join("components");
514+
let subpackage = paths::root().join("foo/components");
509515
fs::create_dir(&subpackage).unwrap();
510516
assert_that(
511517
cargo_process("new")
@@ -515,11 +521,11 @@ fn subpackage_git_with_gitignore() {
515521
);
516522

517523
assert_that(
518-
&paths::root().join("foo").join("components").join("subcomponent").join(".git"),
524+
&paths::root().join("foo/components/subcomponent/.git"),
519525
existing_dir(),
520526
);
521527
assert_that(
522-
&paths::root().join("foo").join("components").join("subcomponent").join(".gitignore"),
528+
&paths::root().join("foo/components/subcomponent/.gitignore"),
523529
existing_file(),
524530
);
525531

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)