Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always exit with error when custom maskfile is not found #25

Merged
merged 1 commit into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fn main() {

let maskfile = find_maskfile();
if maskfile.is_err() {
println!("{} no maskfile.md found", "WARNING:".yellow());
// If the maskfile can't be found, at least parse for --version or --help
cli_app.get_matches();
return;
Expand Down Expand Up @@ -55,6 +54,20 @@ fn find_maskfile() -> Result<String, String> {

let maskfile = mask::loader::read_maskfile(maskfile_path);

if maskfile.is_err() {
if let Some(p) = maskfile_path.to_str() {
// Check if this is a custom maskfile
if p != "./maskfile.md" {
// Exit with an error it's not found
eprintln!("{} specified maskfile not found", "ERROR:".red());
std::process::exit(1);
} else {
// Just log a warning and let the process continue
println!("{} no maskfile.md found", "WARNING:".yellow());
}
}
}

maskfile
}

Expand Down
59 changes: 52 additions & 7 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ fn specifying_a_maskfile_in_a_different_dir() {
.success();
}

mod when_no_maskfile_found {
// Using current_dir(".github") to make sure the default maskfile.md can't be found
mod when_no_maskfile_found_in_current_directory {
use super::*;

#[test]
fn logs_warning_about_missing_file() {
common::run_mask(&PathBuf::from("./nonexistent.md"))
fn logs_warning_about_missing_maskfile_when_its_not_custom() {
common::run_mask(&PathBuf::from("./maskfile.md"))
.current_dir(".github")
.assert()
.stdout(contains(format!(
"{} no maskfile.md found",
Expand All @@ -41,7 +43,8 @@ mod when_no_maskfile_found {

#[test]
fn exits_without_error_for_help() {
common::run_mask(&PathBuf::from("./nonexistent.md"))
common::run_mask(&PathBuf::from("./maskfile.md"))
.current_dir(".github")
.command("--help")
.assert()
.stdout(contains("USAGE:"))
Expand All @@ -50,7 +53,8 @@ mod when_no_maskfile_found {

#[test]
fn exits_without_error_for_version() {
common::run_mask(&PathBuf::from("./nonexistent.md"))
common::run_mask(&PathBuf::from("./maskfile.md"))
.current_dir(".github")
.command("--version")
.assert()
.stdout(contains(format!("{} {}", crate_name!(), crate_version!())))
Expand All @@ -59,10 +63,51 @@ mod when_no_maskfile_found {

#[test]
fn exits_with_error_for_any_other_command() {
common::run_mask(&PathBuf::from("./maskfile.md"))
.current_dir(".github")
.command("nothing")
.assert()
.stderr(contains("error: Found argument 'nothing' which wasn't expected, or isn't valid in this context"))
.failure();
}
}

mod when_custom_specified_maskfile_not_found {
use super::*;

#[test]
fn exits_with_error_for_help() {
common::run_mask(&PathBuf::from("./nonexistent.md"))
.command("yasss")
.command("--help")
.assert()
.stderr(contains("error: Found argument 'yasss' which wasn't expected, or isn't valid in this context"))
.stderr(contains(format!(
"{} specified maskfile not found",
"ERROR:".red()
)))
.failure();
}

#[test]
fn exits_with_error_for_version() {
common::run_mask(&PathBuf::from("./nonexistent.md"))
.command("--version")
.assert()
.stderr(contains(format!(
"{} specified maskfile not found",
"ERROR:".red()
)))
.failure();
}

#[test]
fn exits_with_error_for_any_other_command() {
common::run_mask(&PathBuf::from("./nonexistent.md"))
.command("what")
.assert()
.stderr(contains(format!(
"{} specified maskfile not found",
"ERROR:".red()
)))
.failure();
}
}
Expand Down