mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-19 09:01:14 +01:00
file-formats: let the codec decide whether JXL reads (#2278)
Every workspace gate with `--all-features` has been failing since #2135 taught craft-image-codecs to read JPEG XL behind a `jxl` feature. The capability test asserted that JXL read is `Unsupported`, full stop. With that codec feature on, `capabilities()` forwards the codec's own answer of `Available`. The assertion then fails. This crate cannot read that feature through `cfg!`. The feature belongs to a dependency. A workspace build turns it on without this crate selecting anything. An equality against either value is therefore wrong in some build. The test now asks the codec the same question the code asks it. It compares the two answers. A build whose codec reads JXL must report `Available`. One whose codec does not must report `Unsupported`. The mapping has to exist either way. A missing codec therefore fails an assertion of its own. The comparison is never quietly skipped. Without `raster-codecs` there is no codec to ask. The answer is `Unsupported`. Verified at 1.100.0 on Linux. `cargo test -p craft-file-formats -p craft-image-codecs --all-features --locked` runs the case that was failing and passes. The same test passes with `-p craft-file-formats --all-features` and with `--no-default-features`. clippy with `--all-targets --all-features -D warnings` is clean. `cargo fmt --check` is clean. Making `capabilities()` ignore the codec's read flag fails the test. That is what the comparison is for. The HEIF and deep-EXR failures in that package need the pinned corpus. My checkout has not fetched it.
This commit is contained in:
1 parent
56847b14ad
commit
56c3c833bb
1 file changed
+10
-1
@@ -26,8 +26,17 @@ fn known_formats_separate_build_disabled_and_unsupported_operations() {
|
||||
#[cfg(not(feature = "raster-codecs"))]
|
||||
assert_eq!(jpeg.read, Availability::BuildDisabled);
|
||||
|
||||
// Whether this build reads JPEG XL is craft-image-codecs' `jxl` feature to decide, and this
|
||||
// crate cannot see that through `cfg!`: a workspace build turns it on without this crate
|
||||
// selecting anything, which is how a plain equality here failed every `--all-features` gate.
|
||||
// The codec's own answer is the one to check against, so a wrong read status is still caught.
|
||||
#[cfg(feature = "raster-codecs")]
|
||||
assert!(matches!(Format::Jxl.capabilities().read, Availability::Available | Availability::Unsupported));
|
||||
{
|
||||
let codec = Format::Jxl.raster_codec();
|
||||
assert!(codec.is_some(), "JXL is handled by craft-image-codecs and must map to one of its formats");
|
||||
let expected = if codec.is_some_and(|codec| codec.caps().read) { Availability::Available } else { Availability::Unsupported };
|
||||
assert_eq!(Format::Jxl.capabilities().read, expected);
|
||||
}
|
||||
#[cfg(not(feature = "raster-codecs"))]
|
||||
assert_eq!(Format::Jxl.capabilities().read, Availability::Unsupported);
|
||||
#[cfg(not(feature = "raster-codecs"))]
|
||||
|
||||
Reference in new issue
Block a user