Skip to content

Commit

Permalink
refact(watch): print files that changed in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Profpatsch committed Apr 14, 2024
1 parent 0c39606 commit f69b612
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,17 @@ mod tests {
}

/// Assert no watcher event happens until the timeout
fn assert_none_within(watch: &Watch, timeout: Duration) -> bool {
watch.rx.recv_timeout(timeout).is_err()
fn assert_none_within(watch: &Watch, timeout: Duration) {
let res = watch.rx.recv_timeout(timeout);
match res {
Err(_) => return,
Ok(watch_result) => {
panic!(
"expected no file change notification for; but these files changed: {:?}",
watch_result
);
}
}
}

/// Returns true iff the given file has changed
Expand Down Expand Up @@ -431,7 +440,7 @@ mod tests {
// platforms.
//
// If we do receive any notifications, our test is broken.
assert!(assert_none_within(watcher, WATCHER_TIMEOUT));
assert_none_within(watcher, WATCHER_TIMEOUT);
}

#[test]
Expand Down Expand Up @@ -469,7 +478,7 @@ mod tests {
assert_file_changed_within(&watcher, "baz", WATCHER_TIMEOUT);

expect_bash(r#"echo 1 > "$1/foo/bar""#, [t]);
assert!(assert_none_within(&watcher, WATCHER_TIMEOUT));
assert_none_within(&watcher, WATCHER_TIMEOUT);
}

#[test]
Expand Down Expand Up @@ -506,15 +515,15 @@ mod tests {

// bar is not watched, expect error
expect_bash(r#"echo 1 > "$1/bar""#, [t]);
assert!(assert_none_within(&watcher, WATCHER_TIMEOUT));
assert_none_within(&watcher, WATCHER_TIMEOUT);

// Rename bar to foo, expect a notification
expect_bash(r#"mv "$1/bar" "$1/foo""#, [t]);
assert_file_changed_within(&watcher, "foo", WATCHER_TIMEOUT);

// Do it a second time
expect_bash(r#"echo 1 > "$1/bar""#, [t]);
assert!(assert_none_within(&watcher, WATCHER_TIMEOUT));
assert_none_within(&watcher, WATCHER_TIMEOUT);

// Rename bar to foo, expect a notification
expect_bash(r#"mv "$1/bar" "$1/foo""#, [t]);
Expand Down

0 comments on commit f69b612

Please sign in to comment.