From 8620ee09b54c409803899a8f436f32aeb3718a67 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 2 Oct 2019 15:02:10 +0200 Subject: [PATCH] [test framework] an attempt to better guess target path for files copied into test project (IDEA-223901) GitOrigin-RevId: ed184e44e72b41c52d51b00d3a989dd72883b54e --- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index d8e26edeade2..dbd52ce8eefa 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -129,6 +129,8 @@ import org.jetbrains.annotations.TestOnly; import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -347,7 +349,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig if (candidate.isAbsolute()) { sourceFile = candidate; if (targetPath == sourcePath) { - targetPath = PathUtil.getFileName(sourcePath); + Path testDataPathObj = Paths.get(testDataPath), targetPathObj = Paths.get(targetPath); + if (targetPathObj.startsWith(testDataPathObj)) { + targetPath = testDataPathObj.relativize(targetPathObj).toString(); + } + else { + targetPath = targetPathObj.getFileName().toString(); + } Logger.getInstance(getClass()).warn("Absolute target path '" + sourcePath + "' trimmed to '" + targetPath + "'"); } }