Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Nov 21, 2024
1 parent ce14163 commit 7fa8c33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
22 changes: 2 additions & 20 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,6 @@ impl TestContext {

/// Initialize a sample project for pre-commit.
pub fn init_project(&self) {
// TODO: Clone some repositories used in the tests.
// if !self.cache_dir.join("pre-commit-hooks") {
// Command::new("git")
// .arg("clone")
// .arg("https://github.com/pre-commit/pre-commit-hooks")
// .arg("--depth=1")
// .arg("--branch=v5.0.0")
// .current_dir(&self.cache_dir)
// .assert()
// .success();
// }
//
// fs_extra::dir::copy(
// self.cache_dir.join("pre-commit-hooks"),
// self.home_dir.join("pre-commit-hooks"),
// &fs_extra::dir::CopyOptions::new(),
// )?;

// Write some common files.

Command::new("git")
.arg("init")
.current_dir(&self.temp_dir)
Expand Down Expand Up @@ -260,6 +240,8 @@ pub const INSTA_FILTERS: &[(&str, &str)] = &[
r"Caused by: .* \(os error 2\)",
"Caused by: No such file or directory (os error 2)",
),
// Time seconds
(r"(\d+\.)?\d+s", "[TIME]"),
];

#[allow(unused_macros)]
Expand Down
14 changes: 10 additions & 4 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,25 @@ fn staged_files_only() -> Result<()> {
.child("file.txt")
.write_str("Hello world again!")?;

cmd_snapshot!(context.filters(), context.run(), @r#"
let filters: Vec<_> = context
.filters()
.into_iter()
.chain([(r"/\d+-\d+.patch", "/[TIME]-[PID].patch")])
.collect();

cmd_snapshot!(filters, context.run(), @r#"
success: true
exit_code: 0
----- stdout -----
trailing-whitespace......................................................Passed
- hook id: trailing-whitespace
- duration: 0.03s
- duration: [TIME]
Hello, world!
----- stderr -----
Non-staged changes detected, saving to `[HOME]/1732196801370-22887.patch`
Non-staged changes detected, saving to `[HOME]/[TIME]-[PID].patch`
Restored working tree changes from `[HOME]/1732196801370-22887.patch`
Restored working tree changes from `[HOME]/[TIME]-[PID].patch`
"#);

let content = context.read("file.txt");
Expand Down

0 comments on commit 7fa8c33

Please sign in to comment.