zstd
The atago project wrote these specs on its own initiative and runs them in its own CI, to exercise atago against a real program. They are not zstd’s official test suite, and the zstd project is not affiliated with atago.
Summary #
1 suite · 15 scenarios
Contents #
- zstd (compression round trips and integrity) — 15 scenarios
- compressing keeps the input and adds one archive
- a compress and decompress round trip restores the bytes exactly
- an empty file survives the round trip
- NUL bytes and high bytes survive the round trip
- the compression level changes the archive, never the content
- –rm removes the input only after a successful compression
- an existing archive is not overwritten
- -f overwrites the archive the refusal protected
- -t accepts a real archive and rejects a corrupt one
- decompressing a corrupt archive leaves no output behind
- a truncated frame fails after decompression has started and leaves nothing
- a missing input fails and names the file
- an unknown option fails without producing output
- the stdin to stdout pipeline round trips
- -l reports one frame and the checksum algorithm
zstd (compression round trips and integrity) #
zstd compresses and decompresses files. A compressor has exactly one promise worth testing: what comes back out is what went in, byte for byte.
Every round trip here is checked with equals_file, which compares the
restored bytes against the original with no newline or encoding
normalization — including the cases that break naive tooling, an empty file
and a file full of NUL bytes. The rest of the suite pins the safety
properties around that: the input is kept unless --rm is asked for, an
existing archive is never silently overwritten, a corrupt frame is rejected
by both -t and decompression, and a failed decompression leaves no partial
output behind. All inputs are written by the spec, so nothing is committed.
Source: test/e2e/thirdparty/zstd/zstd.atago.yaml
Scenario: compressing keeps the input and adds one archive #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created. - The command runs with an isolated home under
${workdir}/.atago-home(HOME/XDG or APPDATA redirected).
Inputs #
Fixture payload.txt:
the quick brown fox
When #
zstd -q payload.txt
Then #
- exit code is
0 - the step changed exactly created
payload.txt.zst, modified nothing, deleted nothing
Scenario: a compress and decompress round trip restores the bytes exactly #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created.
Inputs #
Fixture payload.txt:
line one
line two tabbed
When #
zstd -q payload.txt -o payload.zst
zstd -dq payload.zst -o restored.txt
Then #
- after
zstd -q payload.txt -o payload.zst:- exit code is
0
- exit code is
- after
zstd -dq payload.zst -o restored.txt:- exit code is
0 - file
restored.txtis byte-identical topayload.txt
- exit code is
Scenario: an empty file survives the round trip #
only when zstd --version succeeds
Given #
- Fixture file
empty.txtis created.
When #
zstd -q empty.txt -o empty.zst
zstd -dq empty.zst -o restored.txt
Then #
- after
zstd -q empty.txt -o empty.zst:- exit code is
0
- exit code is
- after
zstd -dq empty.zst -o restored.txt:- exit code is
0 - file
restored.txtis byte-identical toempty.txt
- exit code is
Scenario: NUL bytes and high bytes survive the round trip #
only when zstd --version succeeds
Given #
- Fixture file
binary.datis created.
When #
zstd -q binary.dat -o binary.zst
zstd -dq binary.zst -o restored.dat
Then #
- after
zstd -q binary.dat -o binary.zst:- exit code is
0
- exit code is
- after
zstd -dq binary.zst -o restored.dat:- exit code is
0 - file
restored.datis byte-identical tobinary.dat
- exit code is
Scenario: the compression level changes the archive, never the content #
only when zstd --version succeeds
When #
seq 1 4000 | sed 's/$/ alpha beta gamma delta/' > payload.txt
zstd -1 -q payload.txt -o fast.zst
zstd -19 -q payload.txt -o small.zst
cmp -s fast.zst small.zst
zstd -dq fast.zst -o from-fast.txt
zstd -dq small.zst -o from-small.txt
Then #
- after
seq 1 4000 | sed 's/$/ alpha beta gamma delta/' > payload.txt:- exit code is
0
- exit code is
- after
zstd -1 -q payload.txt -o fast.zst:- exit code is
0
- exit code is
- after
zstd -19 -q payload.txt -o small.zst:- exit code is
0
- exit code is
- after
cmp -s fast.zst small.zst:- exit code is
1
- exit code is
- after
zstd -dq fast.zst -o from-fast.txt:- exit code is
0 - file
from-fast.txtis byte-identical topayload.txt
- exit code is
- after
zstd -dq small.zst -o from-small.txt:- exit code is
0 - file
from-small.txtis byte-identical topayload.txt
- exit code is
Scenario: –rm removes the input only after a successful compression #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created.
Inputs #
Fixture payload.txt:
throwaway
When #
zstd -q --rm payload.txt -o payload.zst
Then #
- exit code is
0 - the step changed exactly created
payload.zst, modified nothing, deletedpayload.txt
Scenario: an existing archive is not overwritten #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created. - Fixture file
payload.zstis created.
Inputs #
Fixture payload.txt:
new data
Fixture payload.zst:
PRECIOUS EXISTING FILE
When #
zstd -q --rm payload.txt -o payload.zst
Then #
- exit code is
1 - stdout is empty
- stderr contains
already exists - the step changed exactly created nothing, modified nothing, deleted nothing
- file
payload.zstcontainsPRECIOUS EXISTING FILE
Scenario: -f overwrites the archive the refusal protected #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created. - Fixture file
payload.zstis created.
Inputs #
Fixture payload.txt:
new data
Fixture payload.zst:
OLD CONTENT
When #
zstd -q -f payload.txt -o payload.zst
zstd -dq payload.zst -o restored.txt
Then #
- after
zstd -q -f payload.txt -o payload.zst:- exit code is
0 - the step changed exactly created nothing, modified
payload.zst, deleted nothing
- exit code is
- after
zstd -dq payload.zst -o restored.txt:- exit code is
0 - file
restored.txtis byte-identical topayload.txt
- exit code is
Scenario: -t accepts a real archive and rejects a corrupt one #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created. - Fixture file
broken.zstis created.
Inputs #
Fixture payload.txt:
integrity matters
Fixture broken.zst:
this is not a zstd frame
When #
zstd -q payload.txt -o good.zst
zstd -t good.zst
zstd -t broken.zst
Then #
- after
zstd -q payload.txt -o good.zst:- exit code is
0
- exit code is
- after
zstd -t good.zst:- exit code is
0
- exit code is
- after
zstd -t broken.zst:- exit code is
1 - stdout is empty
- stderr contains
broken.zst
- exit code is
Scenario: decompressing a corrupt archive leaves no output behind #
only when zstd --version succeeds
Given #
- Fixture file
broken.zstis created.
Inputs #
Fixture broken.zst:
this is not a zstd frame
When #
zstd -dq broken.zst -o restored.txt
Then #
- exit code is
1 - stdout is empty
- file
restored.txtdoes not exist
Scenario: a truncated frame fails after decompression has started and leaves nothing #
only when zstd --version succeeds
When #
seq 1 4000 | sed 's/$/ alpha beta gamma delta/' > payload.txt
zstd -19 -q payload.txt -o whole.zst
head -c 1000 whole.zst > truncated.zst
zstd -dq truncated.zst -o restored.txt
Then #
- after
seq 1 4000 | sed 's/$/ alpha beta gamma delta/' > payload.txt:- exit code is
0
- exit code is
- after
zstd -19 -q payload.txt -o whole.zst:- exit code is
0
- exit code is
- after
head -c 1000 whole.zst > truncated.zst:- exit code is
0
- exit code is
- after
zstd -dq truncated.zst -o restored.txt:- exit code is
1 - stdout is empty
- stderr contains
truncated.zst - file
restored.txtdoes not exist
- exit code is
Scenario: a missing input fails and names the file #
only when zstd --version succeeds
When #
zstd -q no-such-input.txt
Then #
- exit code is
1 - stdout is empty
- stderr contains
no-such-input.txt
Scenario: an unknown option fails without producing output #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created.
Inputs #
Fixture payload.txt:
data
When #
zstd --not-a-real-option payload.txt
Then #
- exit code is
1 - stderr contains
--not-a-real-option - file
payload.txt.zstdoes not exist
Scenario: the stdin to stdout pipeline round trips #
only when zstd --version succeeds
When #
printf 'piped payload\n' | zstd -q | zstd -dq
Then #
- exit code is
0 - stdout equals an exact value
Expected output #
expected stdout:
piped payload
Scenario: -l reports one frame and the checksum algorithm #
only when zstd --version succeeds
Given #
- Fixture file
payload.txtis created.
Inputs #
Fixture payload.txt:
listed archive
When #
zstd -q payload.txt -o listed.zst
zstd -l listed.zst
Then #
- after
zstd -q payload.txt -o listed.zst:- exit code is
0
- exit code is
- after
zstd -l listed.zst:- exit code is
0 - stdout contains
listed.zst,XXH64
- exit code is