Skip to content

Commit f848d2b

Browse files
committed
Accept marker-only changes in RewriteTest instead of failing with empty diff
After #7202, `ChangeDependencyGroupIdAndArtifactId` updates `JavaSourceSet` markers on Java files when dependency coordinates change. These marker-only changes produce Results with identical before/after text, which `RewriteTest` previously treated as errors ("An empty diff was generated"). Instead of failing, silently accept Results where the printed text is unchanged. This allows recipes to update markers (e.g. classpath metadata) without requiring downstream tests to add explicit `after` text for every Java source spec. The `afterRecipe` callback still fires with the updated tree, so tests that need to verify marker changes (like `updatesJavaSourceSetMarkerOnJavaFiles`) continue to work. Fixes #7349
1 parent 317e4b9 commit f848d2b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

rewrite-test/src/main/java/org/openrewrite/test/RewriteTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,16 @@ default void rewriteRun(Consumer<RecipeSpec> spec, SourceSpec<?>... sourceSpecs)
562562
boolean isRemote = result.getAfter() instanceof Remote;
563563
if (!isRemote && Objects.equals(result.getBefore().getSourcePath(), result.getAfter().getSourcePath()) &&
564564
Objects.equals(before, actualAfter)) {
565-
fail("An empty diff was generated. The recipe incorrectly changed a reference without changing its contents.");
565+
// Marker-only changes (e.g. JavaSourceSet updates from dependency
566+
// coordinate changes) produce Results with identical text. Accept
567+
// these silently rather than treating them as errors.
568+
allResults.remove(result);
569+
try {
570+
//noinspection unchecked
571+
((Consumer<SourceFile>) sourceSpec.afterRecipe).accept(result.getAfter());
572+
} catch (ClassCastException ignored) {
573+
}
574+
continue nextSourceFile;
566575
}
567576

568577
assert result.getBefore() != null;

0 commit comments

Comments
 (0)