Skip to content

A @data_provider test shares one snapshot across all its values #1185

Description

@Chemaclass

Problem

An unnamed snapshot is named after the test function, and a @data_provider
runs that function once per value — so every value compares against the same
file:

function provide_values() { echo "alpha"; echo "beta"; }

# @data_provider provide_values
function test_shared() { assert_match_snapshot "value is $1"; }

The first value creates the snapshot; the second fails with
Expected to match the snapshot even though nothing about it is wrong. The
message is accurate about the symptom and silent about the cause.

What I changed, and what I did not

Documented the interaction in docs/assertions.md, pointing at
assert_match_named_snapshot "$1" for one file per value.

I tried putting the hint in the failure message and reverted it: the
renderer has no signal for "this test ran with provider arguments".
_BASHUNIT_CURRENT_TEST_INTERPOLATED_NAME looked like one but is only set for
::N::-style interpolated titles, so the hint never fired. Exposing such a
signal is a design change rather than a message fix, and it is the maintainer's
call.

Giving each value its own snapshot file would be the other fix, and a bigger
one: it would orphan every snapshot already on disk.

An acceptance test now pins the current behaviour either way.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions