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) #

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.txt is 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.txt is 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
  • after zstd -dq payload.zst -o restored.txt:
    • exit code is 0
    • file restored.txt is byte-identical to payload.txt

Scenario: an empty file survives the round trip #

only when zstd --version succeeds

Given #

  • Fixture file empty.txt is 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
  • after zstd -dq empty.zst -o restored.txt:
    • exit code is 0
    • file restored.txt is byte-identical to empty.txt

Scenario: NUL bytes and high bytes survive the round trip #

only when zstd --version succeeds

Given #

  • Fixture file binary.dat is 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
  • after zstd -dq binary.zst -o restored.dat:
    • exit code is 0
    • file restored.dat is byte-identical to binary.dat

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
  • after zstd -1 -q payload.txt -o fast.zst:
    • exit code is 0
  • after zstd -19 -q payload.txt -o small.zst:
    • exit code is 0
  • after cmp -s fast.zst small.zst:
    • exit code is 1
  • after zstd -dq fast.zst -o from-fast.txt:
    • exit code is 0
    • file from-fast.txt is byte-identical to payload.txt
  • after zstd -dq small.zst -o from-small.txt:
    • exit code is 0
    • file from-small.txt is byte-identical to payload.txt

Scenario: –rm removes the input only after a successful compression #

only when zstd --version succeeds

Given #

  • Fixture file payload.txt is 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, deleted payload.txt

Scenario: an existing archive is not overwritten #

only when zstd --version succeeds

Given #

  • Fixture file payload.txt is created.
  • Fixture file payload.zst is 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.zst contains PRECIOUS EXISTING FILE

Scenario: -f overwrites the archive the refusal protected #

only when zstd --version succeeds

Given #

  • Fixture file payload.txt is created.
  • Fixture file payload.zst is 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
  • after zstd -dq payload.zst -o restored.txt:
    • exit code is 0
    • file restored.txt is byte-identical to payload.txt

Scenario: -t accepts a real archive and rejects a corrupt one #

only when zstd --version succeeds

Given #

  • Fixture file payload.txt is created.
  • Fixture file broken.zst is 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
  • after zstd -t good.zst:
    • exit code is 0
  • after zstd -t broken.zst:
    • exit code is 1
    • stdout is empty
    • stderr contains broken.zst

Scenario: decompressing a corrupt archive leaves no output behind #

only when zstd --version succeeds

Given #

  • Fixture file broken.zst is 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.txt does 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
  • after zstd -19 -q payload.txt -o whole.zst:
    • exit code is 0
  • after head -c 1000 whole.zst > truncated.zst:
    • exit code is 0
  • after zstd -dq truncated.zst -o restored.txt:
    • exit code is 1
    • stdout is empty
    • stderr contains truncated.zst
    • file restored.txt does not exist

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.txt is 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.zst does 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.txt is 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
  • after zstd -l listed.zst:
    • exit code is 0
    • stdout contains listed.zst, XXH64