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..a5f503af05 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -899,24 +899,42 @@ 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) 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 @@ -924,10 +942,6 @@ func doComparison(t *testing.T, repls testdiff.ReplacementsContext, dirRef, dirN // 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