Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,7 @@ tasks:
generates:
- acceptance/bundle/refschema/out.fields.txt
cmds:
- cmd: go test ./acceptance -run TestAccept/bundle/refschema -update &> /dev/null
ignore_error: true # -update returns non-zero exit code on changes
- go test ./acceptance -run TestAccept/bundle/refschema -update

generate-schema:
desc: Generate bundle JSON schema
Expand Down
28 changes: 21 additions & 7 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,35 +899,49 @@ func doComparison(t *testing.T, repls testdiff.ReplacementsContext, dirRef, dirN
valueNew = repls.Replace(valueNew)
}

// In update mode, regenerating the reference files is the goal: each branch below
// writes or removes the reference and returns without failing the test. Genuine
// problems still fail — read errors (via tryReading above), write errors (via
// require/testutil), and the both-missing case above.

// The test did not produce an expected output file.
if okRef && !okNew {
t.Errorf("Missing output file: %s", relPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would not removing t.Errorf be enough? (for cleaner diff)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to keep the old logical blocks

if testdiff.OverwriteMode {
// The test no longer produces this output; drop the stale reference.
t.Logf("Removing output file: %s", relPath)
require.NoError(t, os.Remove(pathRef))
return
}
t.Errorf("Missing output file: %s", relPath)
return
}

// The test produced an unexpected output file.
if !okRef && okNew {
if testdiff.OverwriteMode {
t.Logf("Writing output file: %s", relPath)
testutil.WriteFile(t, pathRef, valueNew)
return
}
t.Errorf("Unexpected output file: %s\npathRef: %s\npathNew: %s", relPath, pathRef, pathNew)
if shouldShowDiff(pathNew, valueNew) {
testdiff.AssertEqualTexts(t, pathRef, pathNew, valueRef, valueNew)
}
if testdiff.OverwriteMode {
t.Logf("Writing output file: %s", relPath)
return
}

// In update mode, overwrite on any difference rather than calling
// AssertEqualTexts, which would mark the test failed.
if testdiff.OverwriteMode {
if valueRef != valueNew {
t.Logf("Overwriting existing output file: %s", relPath)
testutil.WriteFile(t, pathRef, valueNew)
}
return
}

// Compare the reference and new values.
equal := testdiff.AssertEqualTexts(t, pathRef, pathNew, valueRef, valueNew)
if !equal && testdiff.OverwriteMode {
t.Logf("Overwriting existing output file: %s", relPath)
testutil.WriteFile(t, pathRef, valueNew)
}

if VerboseTest && !equal && printedRepls != nil && !*printedRepls {
*printedRepls = true
Expand Down
Loading