Skip to content
Open
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[
"zip",
"bz",
"bz2",
"bz3",
"gz",
"lz4",
"xz",
Expand Down Expand Up @@ -406,6 +407,40 @@ mod tests {
);
}

/// `bz3` is a supported extension, so the suggestion must insert `.tar` *before* it.
/// Regression: `bz3` was missing from `SUPPORTED_EXTENSIONS`, so the walk skipped it and
/// suggested `linux.bz3.tar.gz`, which `ouch` then rejects for a misplaced archive format.
#[test]
fn builds_suggestion_for_bzip3_extension() {
assert_eq!(
build_archive_file_suggestion(Path::new("linux.bz3"), ".tar").as_deref(),
Some("linux.tar.bz3")
);
assert_eq!(
build_archive_file_suggestion(Path::new("linux.bz3.gz"), ".tar").as_deref(),
Some("linux.tar.bz3.gz")
);
}

/// Every non-archive extension that `slice_to_extension` accepts must be listed in
/// `SUPPORTED_EXTENSIONS`, otherwise the suggestion walk skips it and proposes a path
/// `ouch` itself rejects. This is what let `bz3` go missing.
/// Archive-first aliases such as `tgz` and `tbz3` live in `SUPPORTED_ALIASES` instead.
#[test]
fn every_standalone_parsable_extension_is_supported() {
for ext in PRETTY_SUPPORTED_EXTENSIONS.split(", ") {
let parsed =
slice_to_extension(ext.as_bytes()).unwrap_or_else(|| panic!("'{ext}' is advertised but not parsable"));
if parsed.compression_formats == [CompressionFormat::Tar] {
continue;
}

@marcospb19 marcospb19 Aug 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, why are we skipping tar here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing, and you are right to ask. tar is itself in SUPPORTED_EXTENSIONS, so that guard was skipping a case that already passed the assertion. It was dead weight and it narrowed the test for no reason.

Removed in 23ff69e. The loop now covers tar as well, so dropping it from the list fails too:

'tar' is advertised and parsable but missing from SUPPORTED_EXTENSIONS

Before the change, that mutation passed. bz3 is still caught, which was the original point. Sorry for the slow reply on this one.

assert!(
SUPPORTED_EXTENSIONS.contains(&ext),
"'{ext}' is advertised and parsable but missing from SUPPORTED_EXTENSIONS"
);
}
}

#[test]
fn test_extension_parsing_with_multiple_archive_formats() {
assert!(separate_known_extensions_from_name("file.tar.zip".as_ref()).is_err());
Expand Down