Skip to content

Commit

Permalink
Replace some calls to brev crate (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Apr 17, 2019
1 parent 792b7a2 commit eb3ae2d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
3 changes: 1 addition & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ impl<'a> Parser<'a> {
mod test {
use super::*;
use crate::testing::parse_success;
use brev;

macro_rules! summary_test {
($name:ident, $input:expr, $expected:expr $(,)*) => {
Expand Down Expand Up @@ -1127,7 +1126,7 @@ f y=(`echo hello` + x) +z=("foo" + "bar"):"#,
let mut justfiles = vec![];
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 line == "```" {
justfiles.push(justfile);
Expand Down
22 changes: 3 additions & 19 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
#[cfg(windows)]
enable_ansi_support().ok();
Expand Down Expand Up @@ -274,9 +262,7 @@ pub fn run() {
edit(justfile);
}

text = fs::File::open(justfile)
.unwrap_or_else(|error| die!("Error opening justfile: {}", error))
.slurp()
text = fs::read_to_string(justfile)
.unwrap_or_else(|error| die!("Error reading justfile: {}", error));

if let Err(error) = env::set_current_dir(&directory) {
Expand Down Expand Up @@ -323,10 +309,8 @@ pub fn run() {
edit(name);
}

text = fs::File::open(name)
.unwrap_or_else(|error| die!("Error opening justfile: {}", error))
.slurp()
.unwrap_or_else(|error| die!("Error reading justfile: {}", error));
text =
fs::read_to_string(name).unwrap_or_else(|error| die!("Error reading justfile: {}", error));
}

let justfile = Parser::parse(&text).unwrap_or_else(|error| {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ fn integration_test(

let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile");
brev::dump(justfile_path, justfile);
fs::write(justfile_path, justfile).unwrap();

let mut dotenv_path = tmp.path().to_path_buf();
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"))
.current_dir(tmp.path())
Expand Down
3 changes: 2 additions & 1 deletion tests/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
mod unix {
use executable_path::executable_path;
use std::{
fs,
process::Command,
time::{Duration, Instant},
};
Expand All @@ -23,7 +24,7 @@ mod unix {

let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile");
brev::dump(justfile_path, justfile);
fs::write(justfile_path, justfile).unwrap();

let start = Instant::now();

Expand Down
11 changes: 5 additions & 6 deletions tests/invocation_directory.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use executable_path::executable_path;
use std::path::Path;
use std::process;
use std::str;
use std::{fs, path::Path, process, str};
use tempdir::TempDir;

#[cfg(unix)]
Expand Down Expand Up @@ -34,14 +32,15 @@ fn test_invocation_directory() {

let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile");
brev::dump(
fs::write(
justfile_path,
"default:\n @cd {{invocation_directory()}}\n @echo {{invocation_directory()}}",
);
)
.unwrap();

let mut subdir = tmp.path().to_path_buf();
subdir.push("subdir");
brev::mkdir(&subdir);
fs::create_dir(&subdir).unwrap();

let output = process::Command::new(&executable_path("just"))
.current_dir(&subdir)
Expand Down
18 changes: 9 additions & 9 deletions tests/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_justfile_search() {
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(&path, "default:\n\techo ok");
fs::write(&path, "default:\n\techo ok").unwrap();
path.pop();

path.push("a");
Expand All @@ -47,7 +47,7 @@ fn test_capitalized_justfile_search() {
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("Justfile");
brev::dump(&path, "default:\n\techo ok");
fs::write(&path, "default:\n\techo ok").unwrap();
path.pop();

path.push("a");
Expand All @@ -68,16 +68,16 @@ fn test_capitalization_priority() {
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(&path, "default:\n\techo ok");
fs::write(&path, "default:\n\techo ok").unwrap();
path.pop();
path.push("Justfile");
brev::dump(&path, "default:\n\techo fail");
fs::write(&path, "default:\n\techo fail").unwrap();
path.pop();

// if we see "default\n\techo fail" in `justfile` then we're running
// in a case insensitive filesystem, so just bail
path.push("justfile");
if brev::slurp(&path) == "default:\n\techo fail" {
if fs::read_to_string(&path).unwrap() == "default:\n\techo fail" {
return;
}
path.pop();
Expand All @@ -100,14 +100,14 @@ fn test_upwards_path_argument() {
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(&path, "default:\n\techo ok");
fs::write(&path, "default:\n\techo ok").unwrap();
path.pop();

path.push("a");
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");

path.push("justfile");
brev::dump(&path, "default:\n\techo bad");
fs::write(&path, "default:\n\techo bad").unwrap();
path.pop();

search_test(&path, &["../"]);
Expand All @@ -120,14 +120,14 @@ fn test_downwards_path_argument() {
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(&path, "default:\n\techo bad");
fs::write(&path, "default:\n\techo bad").unwrap();
path.pop();

path.push("a");
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");

path.push("justfile");
brev::dump(&path, "default:\n\techo ok");
fs::write(&path, "default:\n\techo ok").unwrap();
path.pop();
path.pop();

Expand Down

0 comments on commit eb3ae2d

Please sign in to comment.