Replace some calls to brev crate (#410)

This commit is contained in:
Casey Rodarmor 2019-04-16 22:06:28 -07:00 committed by GitHub
parent 792b7a249c
commit eb3ae2d093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 39 deletions

View File

@ -509,7 +509,6 @@ impl<'a> Parser<'a> {
mod test { mod test {
use super::*; use super::*;
use crate::testing::parse_success; use crate::testing::parse_success;
use brev;
macro_rules! summary_test { macro_rules! summary_test {
($name:ident, $input:expr, $expected:expr $(,)*) => { ($name:ident, $input:expr, $expected:expr $(,)*) => {
@ -1127,7 +1126,7 @@ f y=(`echo hello` + x) +z=("foo" + "bar"):"#,
let mut justfiles = vec![]; let mut justfiles = vec![];
let mut current = None; let mut current = None;
for line in brev::slurp("README.adoc").lines() { for line in fs::read_to_string("README.adoc").unwrap().lines() {
if let Some(mut justfile) = current { if let Some(mut justfile) = current {
if line == "```" { if line == "```" {
justfiles.push(justfile); justfiles.push(justfile);

View File

@ -22,18 +22,6 @@ fn edit<P: convert::AsRef<ffi::OsStr>>(path: P) -> ! {
} }
} }
trait Slurp {
fn slurp(&mut self) -> Result<String, io::Error>;
}
impl Slurp for fs::File {
fn slurp(&mut self) -> io::Result<String> {
let mut destination = String::new();
self.read_to_string(&mut destination)?;
Ok(destination)
}
}
pub fn run() { pub fn run() {
#[cfg(windows)] #[cfg(windows)]
enable_ansi_support().ok(); enable_ansi_support().ok();
@ -274,9 +262,7 @@ pub fn run() {
edit(justfile); edit(justfile);
} }
text = fs::File::open(justfile) text = fs::read_to_string(justfile)
.unwrap_or_else(|error| die!("Error opening justfile: {}", error))
.slurp()
.unwrap_or_else(|error| die!("Error reading justfile: {}", error)); .unwrap_or_else(|error| die!("Error reading justfile: {}", error));
if let Err(error) = env::set_current_dir(&directory) { if let Err(error) = env::set_current_dir(&directory) {
@ -323,10 +309,8 @@ pub fn run() {
edit(name); edit(name);
} }
text = fs::File::open(name) text =
.unwrap_or_else(|error| die!("Error opening justfile: {}", error)) fs::read_to_string(name).unwrap_or_else(|error| die!("Error reading justfile: {}", error));
.slurp()
.unwrap_or_else(|error| die!("Error reading justfile: {}", error));
} }
let justfile = Parser::parse(&text).unwrap_or_else(|error| { let justfile = Parser::parse(&text).unwrap_or_else(|error| {

View File

@ -56,11 +56,11 @@ fn integration_test(
let mut justfile_path = tmp.path().to_path_buf(); let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile"); justfile_path.push("justfile");
brev::dump(justfile_path, justfile); fs::write(justfile_path, justfile).unwrap();
let mut dotenv_path = tmp.path().to_path_buf(); let mut dotenv_path = tmp.path().to_path_buf();
dotenv_path.push(".env"); dotenv_path.push(".env");
brev::dump(dotenv_path, "DOTENV_KEY=dotenv-value"); fs::write(dotenv_path, "DOTENV_KEY=dotenv-value").unwrap();
let mut child = Command::new(&executable_path("just")) let mut child = Command::new(&executable_path("just"))
.current_dir(tmp.path()) .current_dir(tmp.path())

View File

@ -2,6 +2,7 @@
mod unix { mod unix {
use executable_path::executable_path; use executable_path::executable_path;
use std::{ use std::{
fs,
process::Command, process::Command,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -23,7 +24,7 @@ mod unix {
let mut justfile_path = tmp.path().to_path_buf(); let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile"); justfile_path.push("justfile");
brev::dump(justfile_path, justfile); fs::write(justfile_path, justfile).unwrap();
let start = Instant::now(); let start = Instant::now();

View File

@ -1,7 +1,5 @@
use executable_path::executable_path; use executable_path::executable_path;
use std::path::Path; use std::{fs, path::Path, process, str};
use std::process;
use std::str;
use tempdir::TempDir; use tempdir::TempDir;
#[cfg(unix)] #[cfg(unix)]
@ -34,14 +32,15 @@ fn test_invocation_directory() {
let mut justfile_path = tmp.path().to_path_buf(); let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile"); justfile_path.push("justfile");
brev::dump( fs::write(
justfile_path, justfile_path,
"default:\n @cd {{invocation_directory()}}\n @echo {{invocation_directory()}}", "default:\n @cd {{invocation_directory()}}\n @echo {{invocation_directory()}}",
); )
.unwrap();
let mut subdir = tmp.path().to_path_buf(); let mut subdir = tmp.path().to_path_buf();
subdir.push("subdir"); subdir.push("subdir");
brev::mkdir(&subdir); fs::create_dir(&subdir).unwrap();
let output = process::Command::new(&executable_path("just")) let output = process::Command::new(&executable_path("just"))
.current_dir(&subdir) .current_dir(&subdir)

View File

@ -26,7 +26,7 @@ fn test_justfile_search() {
.expect("test justfile search: failed to create temporary directory"); .expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf(); let mut path = tmp.path().to_path_buf();
path.push("justfile"); path.push("justfile");
brev::dump(&path, "default:\n\techo ok"); fs::write(&path, "default:\n\techo ok").unwrap();
path.pop(); path.pop();
path.push("a"); path.push("a");
@ -47,7 +47,7 @@ fn test_capitalized_justfile_search() {
.expect("test justfile search: failed to create temporary directory"); .expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf(); let mut path = tmp.path().to_path_buf();
path.push("Justfile"); path.push("Justfile");
brev::dump(&path, "default:\n\techo ok"); fs::write(&path, "default:\n\techo ok").unwrap();
path.pop(); path.pop();
path.push("a"); path.push("a");
@ -68,16 +68,16 @@ fn test_capitalization_priority() {
.expect("test justfile search: failed to create temporary directory"); .expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf(); let mut path = tmp.path().to_path_buf();
path.push("justfile"); path.push("justfile");
brev::dump(&path, "default:\n\techo ok"); fs::write(&path, "default:\n\techo ok").unwrap();
path.pop(); path.pop();
path.push("Justfile"); path.push("Justfile");
brev::dump(&path, "default:\n\techo fail"); fs::write(&path, "default:\n\techo fail").unwrap();
path.pop(); path.pop();
// if we see "default\n\techo fail" in `justfile` then we're running // if we see "default\n\techo fail" in `justfile` then we're running
// in a case insensitive filesystem, so just bail // in a case insensitive filesystem, so just bail
path.push("justfile"); path.push("justfile");
if brev::slurp(&path) == "default:\n\techo fail" { if fs::read_to_string(&path).unwrap() == "default:\n\techo fail" {
return; return;
} }
path.pop(); path.pop();
@ -100,14 +100,14 @@ fn test_upwards_path_argument() {
.expect("test justfile search: failed to create temporary directory"); .expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf(); let mut path = tmp.path().to_path_buf();
path.push("justfile"); path.push("justfile");
brev::dump(&path, "default:\n\techo ok"); fs::write(&path, "default:\n\techo ok").unwrap();
path.pop(); path.pop();
path.push("a"); path.push("a");
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory"); fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
path.push("justfile"); path.push("justfile");
brev::dump(&path, "default:\n\techo bad"); fs::write(&path, "default:\n\techo bad").unwrap();
path.pop(); path.pop();
search_test(&path, &["../"]); search_test(&path, &["../"]);
@ -120,14 +120,14 @@ fn test_downwards_path_argument() {
.expect("test justfile search: failed to create temporary directory"); .expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf(); let mut path = tmp.path().to_path_buf();
path.push("justfile"); path.push("justfile");
brev::dump(&path, "default:\n\techo bad"); fs::write(&path, "default:\n\techo bad").unwrap();
path.pop(); path.pop();
path.push("a"); path.push("a");
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory"); fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
path.push("justfile"); path.push("justfile");
brev::dump(&path, "default:\n\techo ok"); fs::write(&path, "default:\n\techo ok").unwrap();
path.pop(); path.pop();
path.pop(); path.pop();