Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for LazyByteString invariants are missing #564

Closed
sjakobi opened this issue Dec 8, 2022 · 0 comments
Closed

Tests for LazyByteString invariants are missing #564

sjakobi opened this issue Dec 8, 2022 · 0 comments

Comments

@sjakobi
Copy link
Member

sjakobi commented Dec 8, 2022

-- | The data type invariant:
-- Every ByteString is either 'Empty' or consists of non-null 'S.ByteString's.
-- All functions must preserve this, and the QC properties must check this.
--
invariant :: ByteString -> Bool
invariant Empty = True
invariant (Chunk (S.BS _ len) cs) = len > 0 && invariant cs
-- | In a form that checks the invariant lazily.
checkInvariant :: ByteString -> ByteString
checkInvariant Empty = Empty
checkInvariant (Chunk c@(S.BS _ len) cs)
| len > 0 = Chunk c (checkInvariant cs)
| otherwise = error $ "Data.ByteString.Lazy: invariant violation:"
++ show (Chunk c cs)

Despite the comment about QC properties, there seem to be no tests that apply invariant or checkInvariant to the output of LazyByteString-producing functions.

clyring added a commit to clyring/bytestring that referenced this issue Dec 8, 2022
Bodigrim pushed a commit to Bodigrim/bytestring that referenced this issue May 28, 2023
* Thoroughly check the no-empty-chunks invariant in CI

Fixes haskell#564.

* Avoid even temporary empty chunks in lazy foldl1

* Fiddle with formatting and documentation

This also removes deriving Typeable, which does nothing since ghc-7.10.

* Re-insert reference to invariant-checking functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant