-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,3 +363,65 @@ fn file_types() -> Result<()> { | |
|
||
Ok(()) | ||
} | ||
|
||
/// Abort the run if a hook fails. | ||
#[test] | ||
fn fail_fast() -> Result<()> { | ||
let context = TestContext::new(); | ||
|
||
context.init_project(); | ||
|
||
let cwd = context.workdir(); | ||
cwd.child("file.txt").write_str("Hello, world! ")?; | ||
cwd.child("json.json").write_str("{}\n ")?; | ||
cwd.child("main.py").write_str(r#"print "abc" "#)?; | ||
|
||
// Global files and exclude. | ||
context | ||
.workdir() | ||
.child(".pre-commit-config.yaml") | ||
.write_str(indoc::indoc! {r#" | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
fail_fast: false | ||
types: [ "json" ] | ||
- id: trailing-whitespace | ||
fail_fast: true | ||
- id: trailing-whitespace | ||
- id: trailing-whitespace | ||
"# | ||
})?; | ||
|
||
Command::new("git") | ||
.arg("add") | ||
.arg(".") | ||
.current_dir(cwd) | ||
.assert() | ||
.success(); | ||
|
||
cmd_snapshot!(context.filters(), context.run(), @r#" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
Cloning https://github.com/pre-commit/[email protected] | ||
Installing environment for https://github.com/pre-commit/[email protected] | ||
trim trailing whitespace.................................................Failed | ||
- hook id: trailing-whitespace | ||
- exit code: 1 | ||
- files were modified by this hook | ||
Fixing json.json | ||
trim trailing whitespace.................................................Failed | ||
- hook id: trailing-whitespace | ||
- exit code: 1 | ||
- files were modified by this hook | ||
Fixing file.txt | ||
Fixing main.py | ||
----- stderr ----- | ||
"#); | ||
|
||
Ok(()) | ||
} |