Skip to content
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: 15 additions & 0 deletions rust/tests/cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ fn history(home: &Path) -> Vec<Value> {
.collect()
}

#[test]
fn a_command_that_took_under_a_millisecond_compares_equal_to_one_that_took_longer() {
let quick = r#"<command index="1" exit_code="1" at="2026-10-17T01:58:14+09:00">"#;
let slower =
r#"<command index="1" exit_code="1" duration="1ms" at="2026-10-17T02:00:00+09:00">"#;
let longer =
r#"<command index="1" exit_code="1" duration="1.5s" at="2026-10-17T02:00:00+09:00">"#;
assert_eq!(normalise(quick), normalise(slower));
assert_eq!(normalise(quick), normalise(longer));
assert_eq!(
normalise(quick),
r#"<command index="1" exit_code="1" at="<TIME>">"#
);
}

#[test]
fn output_from_both_streams_is_shown_and_stored_and_the_exit_code_passes_through() {
let home = tempfile::tempdir().unwrap();
Expand Down
6 changes: 4 additions & 2 deletions rust/tests/capture_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ pub fn require_parity() {
}

/// What a command printed, with the parts that legitimately differ between two runs
/// replaced: timestamps, durations, relative times.
/// replaced: timestamps, durations, relative times. A `duration` attribute is dropped, not
/// masked, because both builds store whole milliseconds and omit the attribute at 0, so two
/// runs of a command that takes about a millisecond can differ in whether it is there at all.
pub fn normalise(text: &str) -> String {
let patterns = [
(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d[+-]\d\d:\d\d", "<TIME>"),
(r#"duration="[^"]*""#, r#"duration="<D>""#),
(r#" duration="[^"]*""#, ""),
(r"\(\d+ \w+ ago\)", "(<AGO>)"),
];
let mut out = text.replace("\r\n", "\n");
Expand Down
Loading