diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java index 3ece85c099b30a..20a299f6ae0bd7 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java @@ -1776,4 +1776,40 @@ public void testSingleVersionOverridePatches() throws Exception { "ccc", InterimModule.DepSpec.fromModuleKey(ModuleKey.create("ccc", Version.parse("2.0")))); } + + @Test + public void testSingleVersionOverridePatches_failsOnRename() throws Exception { + FakeRegistry registry = registryFactory.newFakeRegistry("/foo"); + ModuleFileFunction.REGISTRIES.set(differencer, ImmutableSet.of(registry.getUrl())); + ModuleKey bbb = createModuleKey("bbb", "1.0"); + registry.addModule(bbb, "module(name='bbb',version='1.0')"); + + scratch.file("BUILD"); + scratch.file( + "patch.diff", + """ + diff --git a/MODULE.bazel b/MODULE.bazel.bak + similarity index 55% + rename from MODULE.bazel + rename to MODULE.bazel.bak + index 3f855b5..949dd15 100644 + """); + + var moduleFileKey = + ModuleFileValue.key( + bbb, + SingleVersionOverride.create( + Version.EMPTY, + "", + ImmutableList.of(Label.parseCanonicalUnchecked("//:patch.diff")), + ImmutableList.of(), + 1)); + EvaluationResult result = + evaluator.evaluate(ImmutableList.of(moduleFileKey), evaluationContext); + assertThat(result.hasError()).isTrue(); + assertThat(result.getError().getException()) + .hasMessageThat() + .isEqualTo( + "error applying single_version_override patch /workspace/patch.diff to module file: Renaming is not supported when applying a patch to the single file /module/MODULE.bazel."); + } }