diff --git a/Taskfile.yml b/Taskfile.yml index 0bd2325546..47b0c306c3 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -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 diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index f6ec0805fb..2c8b7f712e 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -899,35 +899,44 @@ func doComparison(t *testing.T, repls testdiff.ReplacementsContext, dirRef, dirN valueNew = repls.Replace(valueNew) } - // The test did not produce an expected output file. - if okRef && !okNew { - t.Errorf("Missing output file: %s", relPath) - if testdiff.OverwriteMode { + // In update mode, (re)generating the reference files is the goal, so applying + // a change is success, not failure. Write or remove the reference file to match + // what the test produced, then return without marking the test failed. Genuine + // problems still fail the run: read errors (reported by tryReading above) and + // write errors (via require/testutil below). + if testdiff.OverwriteMode { + switch { + case okRef && !okNew: + // The test no longer produces this output; drop the stale reference. t.Logf("Removing output file: %s", relPath) require.NoError(t, os.Remove(pathRef)) + case !okRef && okNew: + t.Logf("Writing output file: %s", relPath) + testutil.WriteFile(t, pathRef, valueNew) + case valueRef != valueNew: + t.Logf("Overwriting existing output file: %s", relPath) + testutil.WriteFile(t, pathRef, valueNew) } return } + // The test did not produce an expected output file. + if okRef && !okNew { + t.Errorf("Missing output file: %s", relPath) + return + } + // The test produced an unexpected output file. if !okRef && okNew { 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) - 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