use std::io::Write;
use std::path::Path;
- use tempdir::TempDir;
+ use tempfile::{self, TempDir};
use dir::IgnoreBuilder;
use gitignore::Gitignore;
}
}
+ fn tmpdir(prefix: &str) -> TempDir {
+ tempfile::Builder::new().prefix(prefix).tempdir().unwrap()
+ }
+
#[test]
fn explicit_ignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join("not-an-ignore"), "foo\n!bar");
let (gi, err) = Gitignore::new(td.path().join("not-an-ignore"));
#[test]
fn git_exclude() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
mkdirp(td.path().join(".git/info"));
wfile(td.path().join(".git/info/exclude"), "foo\n!bar");
#[test]
fn gitignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
mkdirp(td.path().join(".git"));
wfile(td.path().join(".gitignore"), "foo\n!bar");
#[test]
fn gitignore_no_git() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".gitignore"), "foo\n!bar");
let (ig, err) = IgnoreBuilder::new().build().add_child(td.path());
#[test]
fn ignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".ignore"), "foo\n!bar");
let (ig, err) = IgnoreBuilder::new().build().add_child(td.path());
#[test]
fn custom_ignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
let custom_ignore = ".customignore";
wfile(td.path().join(custom_ignore), "foo\n!bar");
// Tests that a custom ignore file will override an .ignore.
#[test]
fn custom_ignore_over_ignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
let custom_ignore = ".customignore";
wfile(td.path().join(".ignore"), "foo");
wfile(td.path().join(custom_ignore), "!foo");
// Tests that earlier custom ignore files have lower precedence than later.
#[test]
fn custom_ignore_precedence() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
let custom_ignore1 = ".customignore1";
let custom_ignore2 = ".customignore2";
wfile(td.path().join(custom_ignore1), "foo");
// Tests that an .ignore will override a .gitignore.
#[test]
fn ignore_over_gitignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".gitignore"), "foo");
wfile(td.path().join(".ignore"), "!foo");
// Tests that exclude has lower precedent than both .ignore and .gitignore.
#[test]
fn exclude_lowest() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".gitignore"), "!foo");
wfile(td.path().join(".ignore"), "!bar");
mkdirp(td.path().join(".git/info"));
#[test]
fn errored() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".gitignore"), "f**oo");
let (_, err) = IgnoreBuilder::new().build().add_child(td.path());
#[test]
fn errored_both() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".gitignore"), "f**oo");
wfile(td.path().join(".ignore"), "fo**o");
#[test]
fn errored_partial() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
mkdirp(td.path().join(".git"));
wfile(td.path().join(".gitignore"), "f**oo\nbar");
#[test]
fn errored_partial_and_ignore() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
wfile(td.path().join(".gitignore"), "f**oo\nbar");
wfile(td.path().join(".ignore"), "!bar");
#[test]
fn not_present_empty() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
let (_, err) = IgnoreBuilder::new().build().add_child(td.path());
assert!(err.is_none());
fn stops_at_git_dir() {
// This tests that .gitignore files beyond a .git barrier aren't
// matched, but .ignore files are.
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
mkdirp(td.path().join(".git"));
mkdirp(td.path().join("foo/.git"));
wfile(td.path().join(".gitignore"), "foo");
#[test]
fn absolute_parent() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
mkdirp(td.path().join(".git"));
mkdirp(td.path().join("foo"));
wfile(td.path().join(".gitignore"), "bar");
#[test]
fn absolute_parent_anchored() {
- let td = TempDir::new("ignore-test-").unwrap();
+ let td = tmpdir("ignore-test-");
mkdirp(td.path().join(".git"));
mkdirp(td.path().join("src/llvm"));
wfile(td.path().join(".gitignore"), "/llvm/\nfoo");