Repository: casey/just
Pull request #892 (2021-07-03 21:14:44)

Remove test-utilities crate


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 28ba1e6b..b40c296e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -216,7 +216,7 @@ dependencies = [
  "strum_macros",
  "target",
  "tempfile",
- "test-utilities",
+ "temptree",
  "unicode-width",
  "which",
  "yaml-rust",
@@ -530,20 +530,21 @@ dependencies = [
 ]
 
 [[package]]
-name = "termcolor"
-version = "1.1.2"
+name = "temptree"
+version = "0.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
+checksum = "f2b41283c421539cd57fda2bdae139a0e08992dba973cd4ba859765c867ad591"
 dependencies = [
- "winapi-util",
+ "tempfile",
 ]
 
 [[package]]
-name = "test-utilities"
-version = "0.0.0"
+name = "termcolor"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
 dependencies = [
- "just",
- "tempfile",
+ "winapi-util",
 ]
 
 [[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 275f9d98..234c22dd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -46,12 +46,10 @@ features = ["derive"]
 [dev-dependencies]
 executable-path   = "1.0.0"
 pretty_assertions = "0.7.0"
+temptree          = "0.0.0"
 which             = "4.0.0"
 yaml-rust         = "0.4.5"
 
-[dev-dependencies.test-utilities]
-path = "test-utilities"
-
 [features]
 # No features are active by default.
 default = []
diff --git a/src/search.rs b/src/search.rs
index 6671b477..1b95a52f 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -197,7 +197,7 @@ impl Search {
 #[cfg(test)]
 mod tests {
   use super::*;
-  use test_utilities::tmptree;
+  use temptree::temptree;
 
   #[test]
   fn not_found() {
@@ -305,7 +305,7 @@ mod tests {
 
   #[test]
   fn justfile_symlink_parent() {
-    let tmp = tmptree! {
+    let tmp = temptree! {
       src: "",
       sub: {},
     };


Test patch:
diff --git a/src/testing.rs b/src/testing.rs
index bbf7d298..0bb92537 100644
--- a/src/testing.rs
+++ b/src/testing.rs
@@ -31,7 +31,12 @@ pub(crate) fn search(config: &Config) -> Search {
   }
 }
 
-pub(crate) use test_utilities::tempdir;
+pub(crate) fn tempdir() -> tempfile::TempDir {
+  tempfile::Builder::new()
+    .prefix("just-test-tempdir")
+    .tempdir()
+    .expect("failed to create temporary directory")
+}
 
 macro_rules! analysis_error {
   (
diff --git a/test-utilities/Cargo.toml b/test-utilities/Cargo.toml
deleted file mode 100644
index 90971de0..00000000
--- a/test-utilities/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name    = "test-utilities"
-version = "0.0.0"
-authors = ["Casey Rodarmor <casey@rodarmor.com>"]
-edition = "2018"
-publish = false
-
-[dependencies]
-tempfile = "3"
-just = { path = ".." }
diff --git a/test-utilities/src/lib.rs b/test-utilities/src/lib.rs
deleted file mode 100644
index 414cae11..00000000
--- a/test-utilities/src/lib.rs
+++ /dev/null
@@ -1,149 +0,0 @@
-use std::{collections::HashMap, fs, path::Path, process::Output};
-
-pub fn tempdir() -> tempfile::TempDir {
-  tempfile::Builder::new()
-    .prefix("just-test-tempdir")
-    .tempdir()
-    .expect("failed to create temporary directory")
-}
-
-pub fn assert_success(output: &Output) {
-  if !output.status.success() {
-    eprintln!("stderr: {}", String::from_utf8_lossy(&output.stderr));
-    eprintln!("stdout: {}", String::from_utf8_lossy(&output.stdout));
-    panic!("{}", output.status);
-  }
-}
-
-pub fn assert_stdout(output: &Output, stdout: &str) {
-  assert_success(output);
-  assert_eq!(String::from_utf8_lossy(&output.stdout), stdout);
-}
-
-pub enum Entry {
-  File {
-    contents: &'static str,
-  },
-  Dir {
-    entries: HashMap<&'static str, Entry>,
-  },
-}
-
-impl Entry {
-  fn instantiate(self, path: &Path) {
-    match self {
-      Entry::File { contents } => fs::write(path, contents).expect("Failed to write tempfile"),
-      Entry::Dir { entries } => {
-        fs::create_dir(path).expect("Failed to create tempdir");
-
-        for (name, entry) in entries {
-          entry.instantiate(&path.join(name));
-        }
-      },
-    }
-  }
-
-  pub fn instantiate_base(base: &Path, entries: HashMap<&'static str, Entry>) {
-    for (name, entry) in entries {
-      entry.instantiate(&base.join(name));
-    }
-  }
-}
-
-#[macro_export]
-macro_rules! entry {
-  {
-    {
-      $($contents:tt)*
-    }
-  } => {
-    $crate::Entry::Dir{entries: $crate::entries!($($contents)*)}
-  };
-  {
-    $contents:expr
-  } => {
-    $crate::Entry::File{contents: $contents}
-  };
-}
-
-#[macro_export]
-macro_rules! entries {
-  {
-  } => {
-    std::collections::HashMap::new()
-  };
-  {
-    $($name:tt : $contents:tt,)*
-  } => {
-    {
-      use std::collections::HashMap;
-      let mut entries: HashMap<&'static str, $crate::Entry> = HashMap::new();
-
-      $(
-        entries.insert($crate::name!($name), $crate::entry!($contents));
-      )*
-
-      entries
-    }
-  }
-}
-
-#[macro_export]
-macro_rules! name {
-  {
-    $name:ident
-  } => {
-    stringify!($name)
-  };
-  {
-    $name:literal
-  } => {
-    $name
-  };
-}
-
-#[macro_export]
-macro_rules! tmptree {
-  {
-    $($contents:tt)*
-  } => {
-    {
-      let tempdir = $crate::tempdir();
-
-      let entries = $crate::entries!($($contents)*);
-
-      $crate::Entry::instantiate_base(&tempdir.path(), entries);
-
-      tempdir
-    }
-  }
-}
-
-#[cfg(test)]
-mod tests {
-  use super::*;
-
-  #[test]
-  fn tmptree_file() {
-    let tmpdir = tmptree! {
-      foo: "bar",
-    };
-
-    let contents = fs::read_to_string(tmpdir.path().join("foo")).unwrap();
-
-    assert_eq!(contents, "bar");
-  }
-
-  #[test]
-  fn tmptree_dir() {
-    let tmpdir = tmptree! {
-      foo: {
-        bar: "baz",
-      },
-    };
-
-    let contents = fs::read_to_string(tmpdir.path().join("foo/bar")).unwrap();
-
-    assert_eq!(contents, "baz");
-  }
-}
diff --git a/tests/assert_stdout.rs b/tests/assert_stdout.rs
new file mode 100644
index 00000000..05f2b9b9
--- /dev/null
+++ b/tests/assert_stdout.rs
@@ -0,0 +1,6 @@
+use crate::common::*;
+
+pub(crate) fn assert_stdout(output: &Output, stdout: &str) {
+  assert_success(output);
+  assert_eq!(String::from_utf8_lossy(&output.stdout), stdout);
+}
diff --git a/tests/assert_success.rs b/tests/assert_success.rs
new file mode 100644
index 00000000..0f4ddab5
--- /dev/null
+++ b/tests/assert_success.rs
@@ -0,0 +1,9 @@
+use crate::common::*;
+
+pub(crate) fn assert_success(output: &Output) {
+  if !output.status.success() {
+    eprintln!("stderr: {}", String::from_utf8_lossy(&output.stderr));
+    eprintln!("stdout: {}", String::from_utf8_lossy(&output.stdout));
+    panic!("{}", output.status);
+  }
+}
diff --git a/tests/choose.rs b/tests/choose.rs
index f6c5b626..0d990873 100644
--- a/tests/choose.rs
+++ b/tests/choose.rs
@@ -115,7 +115,7 @@ test! {
 
 #[test]
 fn default() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "foo:\n echo foo\n",
   };
 
diff --git a/tests/common.rs b/tests/common.rs
index 96d03d51..96b0d17d 100644
--- a/tests/common.rs
+++ b/tests/common.rs
@@ -1,17 +1,22 @@
 pub(crate) use std::{
   collections::BTreeMap,
   env::{self, consts::EXE_SUFFIX},
+  error::Error,
   fs,
   io::Write,
   iter,
   path::Path,
-  process::{Command, Stdio},
+  process::{Command, Output, Stdio},
   str,
 };
 
 pub(crate) use executable_path::executable_path;
 pub(crate) use just::unindent;
 pub(crate) use libc::{EXIT_FAILURE, EXIT_SUCCESS};
-pub(crate) use test_utilities::{assert_stdout, tempdir, tmptree};
+pub(crate) use temptree::temptree;
 pub(crate) use which::which;
 pub(crate) use yaml_rust::YamlLoader;
+
+pub(crate) use crate::{
+  assert_stdout::assert_stdout, assert_success::assert_success, tempdir::tempdir,
+};
diff --git a/tests/completions.rs b/tests/completions.rs
index 4b172cf7..79132382 100644
--- a/tests/completions.rs
+++ b/tests/completions.rs
@@ -1,11 +1,8 @@
-use std::process::Command;
-
-use executable_path::executable_path;
-use tempfile::tempdir;
+use crate::common::*;
 
 #[test]
 fn output() {
-  let tempdir = tempdir().unwrap();
+  let tempdir = tempdir();
 
   let output = Command::new(executable_path("just"))
     .arg("--completions")
diff --git a/tests/dotenv.rs b/tests/dotenv.rs
index 69646909..94701c8e 100644
--- a/tests/dotenv.rs
+++ b/tests/dotenv.rs
@@ -1,11 +1,8 @@
-use executable_path::executable_path;
-use std::{process, str};
-
-use test_utilities::tmptree;
+use crate::common::*;
 
 #[test]
 fn dotenv() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     ".env": "KEY=ROOT",
     sub: {
       ".env": "KEY=SUB",
@@ -15,7 +12,7 @@ fn dotenv() {
 
   let binary = executable_path("just");
 
-  let output = process::Command::new(binary)
+  let output = Command::new(binary)
     .current_dir(tmp.path())
     .arg("sub/default")
     .output()
diff --git a/tests/edit.rs b/tests/edit.rs
index 9dcbc7b1..78e77d3a 100644
--- a/tests/edit.rs
+++ b/tests/edit.rs
@@ -5,7 +5,7 @@ const JUSTFILE: &str = "Yooooooo, hopefully this never becomes valid syntax.";
 /// Test that --edit doesn't require a valid justfile
 #[test]
 fn invalid_justfile() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
   };
 
@@ -29,7 +29,7 @@ fn invalid_justfile() {
 /// Test that editor is $VISUAL, $EDITOR, or "vim" in that order
 #[test]
 fn editor_precedence() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
   };
 
@@ -83,7 +83,7 @@ fn editor_precedence() {
 #[cfg(unix)]
 #[test]
 fn editor_working_directory() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
     child: {},
     editor: "#!/usr/bin/env sh\ncat $1\npwd",
diff --git a/tests/examples.rs b/tests/examples.rs
index adfc2a19..9d3e2720 100644
--- a/tests/examples.rs
+++ b/tests/examples.rs
@@ -1,7 +1,4 @@
-use std::{fs, process::Command};
-
-use executable_path::executable_path;
-use test_utilities::assert_success;
+use crate::common::*;
 
 #[test]
 fn examples() {
diff --git a/tests/init.rs b/tests/init.rs
index 74ea28eb..efcbc6ae 100644
--- a/tests/init.rs
+++ b/tests/init.rs
@@ -1,8 +1,4 @@
-use std::{fs, process::Command};
-
-use executable_path::executable_path;
-
-use test_utilities::{tempdir, tmptree};
+use crate::common::*;
 
 const EXPECTED: &str = "default:\n\techo 'Hello, world!'\n";
 
@@ -47,7 +43,7 @@ fn exists() {
 
 #[test]
 fn invocation_directory() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     ".git": {},
   };
 
@@ -67,7 +63,7 @@ fn invocation_directory() {
 
 #[test]
 fn parent_dir() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     ".git": {},
     sub: {},
   };
@@ -88,7 +84,7 @@ fn parent_dir() {
 
 #[test]
 fn alternate_marker() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     "_darcs": {},
   };
 
@@ -108,7 +104,7 @@ fn alternate_marker() {
 
 #[test]
 fn search_directory() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     sub: {
       ".git": {},
     },
@@ -131,7 +127,7 @@ fn search_directory() {
 
 #[test]
 fn justfile() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     sub: {
       ".git": {},
     },
@@ -155,7 +151,7 @@ fn justfile() {
 
 #[test]
 fn justfile_and_working_directory() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     sub: {
       ".git": {},
     },
diff --git a/tests/interrupts.rs b/tests/interrupts.rs
index 7b68452f..9842d86e 100644
--- a/tests/interrupts.rs
+++ b/tests/interrupts.rs
@@ -1,13 +1,8 @@
 #[cfg(unix)]
 mod unix {
-  use executable_path::executable_path;
-  use just::unindent;
-  use std::{
-    fs,
-    process::Command,
-    time::{Duration, Instant},
-  };
-  use test_utilities::tempdir;
+  use crate::common::*;
+
+  use std::time::{Duration, Instant};
 
   fn kill(process_id: u32) {
     unsafe {
diff --git a/tests/invocation_directory.rs b/tests/invocation_directory.rs
index f819513c..1215bc27 100644
--- a/tests/invocation_directory.rs
+++ b/tests/invocation_directory.rs
@@ -1,7 +1,4 @@
-use std::{fs, path::Path, process, str};
-
-use executable_path::executable_path;
-use test_utilities::tempdir;
+use crate::common::*;
 
 #[cfg(unix)]
 fn convert_native_path(path: &Path) -> String {
@@ -15,7 +12,7 @@ fn convert_native_path(path: &Path) -> String {
 #[cfg(windows)]
 fn convert_native_path(path: &Path) -> String {
   // Translate path from windows style to unix style
-  let mut cygpath = process::Command::new("cygpath");
+  let mut cygpath = Command::new("cygpath");
   cygpath.arg("--unix");
   cygpath.arg(path);
 
@@ -51,7 +48,7 @@ fn test_invocation_directory() {
   subdir.push("subdir");
   fs::create_dir(&subdir).unwrap();
 
-  let output = process::Command::new(&executable_path("just"))
+  let output = Command::new(&executable_path("just"))
     .current_dir(&subdir)
     .args(&["--shell", "sh"])
     .output()
diff --git a/tests/lib.rs b/tests/lib.rs
index 237279bc..a9e60db3 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -1,7 +1,10 @@
 #[macro_use]
 mod test;
 
+mod assert_stdout;
+mod assert_success;
 mod common;
+mod tempdir;
 
 mod choose;
 mod command;
diff --git a/tests/readme.rs b/tests/readme.rs
index 4df6aaae..a89fd876 100644
--- a/tests/readme.rs
+++ b/tests/readme.rs
@@ -1,7 +1,4 @@
-use std::{fs, process::Command};
-
-use executable_path::executable_path;
-use test_utilities::{assert_success, tempdir};
+use crate::common::*;
 
 #[test]
 fn readme() {
diff --git a/tests/search.rs b/tests/search.rs
index 3603f05e..eb4a5f66 100644
--- a/tests/search.rs
+++ b/tests/search.rs
@@ -1,12 +1,9 @@
-use executable_path::executable_path;
-use std::{path, process, str};
+use crate::common::*;
 
-use test_utilities::tmptree;
-
-fn search_test<P: AsRef<path::Path>>(path: P, args: &[&str]) {
+fn search_test<P: AsRef<Path>>(path: P, args: &[&str]) {
   let binary = executable_path("just");
 
-  let output = process::Command::new(binary)
+  let output = Command::new(binary)
     .current_dir(path)
     .args(args)
     .output()
@@ -23,7 +20,7 @@ fn search_test<P: AsRef<path::Path>>(path: P, args: &[&str]) {
 
 #[test]
 fn test_justfile_search() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo ok",
     a: {
       b: {
@@ -39,7 +36,7 @@ fn test_justfile_search() {
 
 #[test]
 fn test_capitalized_justfile_search() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     Justfile: "default:\n\techo ok",
     a: {
       b: {
@@ -55,7 +52,7 @@ fn test_capitalized_justfile_search() {
 
 #[test]
 fn test_upwards_path_argument() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo ok",
     a: {
       justfile: "default:\n\techo bad",
@@ -68,7 +65,7 @@ fn test_upwards_path_argument() {
 
 #[test]
 fn test_downwards_path_argument() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo bad",
     a: {
       justfile: "default:\n\techo ok",
@@ -87,7 +84,7 @@ fn test_downwards_path_argument() {
 
 #[test]
 fn test_upwards_multiple_path_argument() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo ok",
     a: {
       b: {
@@ -103,7 +100,7 @@ fn test_upwards_multiple_path_argument() {
 
 #[test]
 fn test_downwards_multiple_path_argument() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo bad",
     a: {
       b: {
@@ -124,7 +121,7 @@ fn test_downwards_multiple_path_argument() {
 
 #[test]
 fn single_downards() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo ok",
     child: {},
   };
@@ -136,7 +133,7 @@ fn single_downards() {
 
 #[test]
 fn single_upwards() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: "default:\n\techo ok",
     child: {},
   };
diff --git a/tests/shell.rs b/tests/shell.rs
index 412cb886..fb2e00e2 100644
--- a/tests/shell.rs
+++ b/tests/shell.rs
@@ -1,8 +1,4 @@
-use std::{process::Command, str};
-
-use executable_path::executable_path;
-
-use test_utilities::{assert_stdout, tmptree};
+use crate::common::*;
 
 const JUSTFILE: &str = "
 expression := `EXPRESSION`
@@ -17,7 +13,7 @@ recipe default=`DEFAULT`:
 #[test]
 #[cfg_attr(windows, ignore)]
 fn flag() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
     shell: "#!/usr/bin/env bash\necho \"$@\"",
   };
@@ -56,7 +52,7 @@ recipe:
 #[test]
 #[cfg_attr(unix, ignore)]
 fn cmd() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE_CMD,
   };
 
@@ -85,7 +81,7 @@ recipe:
 #[test]
 #[cfg_attr(unix, ignore)]
 fn powershell() {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE_POWERSHELL,
   };
 
diff --git a/tests/tempdir.rs b/tests/tempdir.rs
new file mode 100644
index 00000000..fb6c82ca
--- /dev/null
+++ b/tests/tempdir.rs
@@ -0,0 +1,6 @@
+pub(crate) fn tempdir() -> tempfile::TempDir {
+  tempfile::Builder::new()
+    .prefix("just-test-tempdir")
+    .tempdir()
+    .expect("failed to create temporary directory")
+}
diff --git a/tests/test.rs b/tests/test.rs
index 4b708979..7d86de64 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1,7 +1,5 @@
 use crate::common::*;
 
-pub(crate) use pretty_assertions::assert_eq;
-
 macro_rules! test {
   (
     name:     $name:ident,
diff --git a/tests/working_directory.rs b/tests/working_directory.rs
index c003a7bb..c43252e5 100644
--- a/tests/working_directory.rs
+++ b/tests/working_directory.rs
@@ -1,7 +1,4 @@
-use std::{error::Error, process::Command};
-
-use executable_path::executable_path;
-use test_utilities::tmptree;
+use crate::common::*;
 
 const JUSTFILE: &str = r#"
 foo := `cat data`
@@ -24,7 +21,7 @@ const WANT: &str = "shebang: OK\nexpression: OK\ndefault: OK\nlinewise: OK\n";
 /// `--justfile` but not `--working-directory`
 #[test]
 fn justfile_without_working_directory() -> Result<(), Box<dyn Error>> {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
     data: DATA,
   };
@@ -50,7 +47,7 @@ fn justfile_without_working_directory() -> Result<(), Box<dyn Error>> {
 /// `--justfile` but not `--working-directory`, and justfile path has no parent
 #[test]
 fn justfile_without_working_directory_relative() -> Result<(), Box<dyn Error>> {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
     data: DATA,
   };
@@ -77,7 +74,7 @@ fn justfile_without_working_directory_relative() -> Result<(), Box<dyn Error>> {
 /// found
 #[test]
 fn change_working_directory_to_search_justfile_parent() -> Result<(), Box<dyn Error>> {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
     data: DATA,
     subdir: {},
@@ -103,7 +100,7 @@ fn change_working_directory_to_search_justfile_parent() -> Result<(), Box<dyn Er
 /// `--justfile` but not `--working-directory`
 #[test]
 fn justfile_and_working_directory() -> Result<(), Box<dyn Error>> {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     justfile: JUSTFILE,
     sub: {
       data: DATA,
@@ -133,7 +130,7 @@ fn justfile_and_working_directory() -> Result<(), Box<dyn Error>> {
 /// `--justfile` but not `--working-directory`
 #[test]
 fn search_dir_child() -> Result<(), Box<dyn Error>> {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     child: {
       justfile: JUSTFILE,
       data: DATA,
@@ -161,7 +158,7 @@ fn search_dir_child() -> Result<(), Box<dyn Error>> {
 /// `--justfile` but not `--working-directory`
 #[test]
 fn search_dir_parent() -> Result<(), Box<dyn Error>> {
-  let tmp = tmptree! {
+  let tmp = temptree! {
     child: {
     },
     justfile: JUSTFILE,