-
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.
Add tests for
types
, types_or
, exclude_types
- Loading branch information
Showing
3 changed files
with
80 additions
and
10 deletions.
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
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 |
---|---|---|
|
@@ -199,6 +199,7 @@ fn skips() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
/// Test global `files`, `exclude`, and hook level `files`, `exclude`. | ||
#[test] | ||
fn files_and_exclude() -> Result<()> { | ||
let context = TestContext::new(); | ||
|
@@ -264,7 +265,7 @@ fn files_and_exclude() -> Result<()> { | |
- id: trailing-whitespace | ||
files: valid.json | ||
- id: end-of-file-fixer | ||
exclude: (valid.json|file.txt) | ||
exclude: (valid.json|main.py) | ||
- id: check-json | ||
" | ||
})?; | ||
|
@@ -285,17 +286,80 @@ fn files_and_exclude() -> Result<()> { | |
- exit code: 1 | ||
- files were modified by this hook | ||
Fixing valid.json | ||
fix end of files.........................................................Failed | ||
- hook id: end-of-file-fixer | ||
fix end of files.........................................................Passed | ||
check json...............................................................Passed | ||
----- stderr ----- | ||
"#); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Test selecting files by type, `types`, `types_or`, and `exclude_types`. | ||
#[test] | ||
fn file_types() -> 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 | ||
types: [ "json" ] | ||
- id: trailing-whitespace | ||
types_or: [ "json", "python" ] | ||
- id: trailing-whitespace | ||
exclude_types: [ "json" ] | ||
- id: trailing-whitespace | ||
types: [ "json" ] | ||
exclude_types: [ "json" ] | ||
"# | ||
})?; | ||
|
||
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 main.py | ||
check json...............................................................Passed | ||
trim trailing whitespace.................................................Failed | ||
- hook id: trailing-whitespace | ||
- exit code: 1 | ||
- files were modified by this hook | ||
Fixing file.txt | ||
trim trailing whitespace.............................(no files to check)Skipped | ||
----- stderr ----- | ||
"#); | ||
|
||
Ok(()) | ||
} | ||
|
||
// TODO: test `types`, `types_or`, `exclude_types` |