From dc6c19d7ef58e55fd4ddbd611527c5d3bd7b8301 Mon Sep 17 00:00:00 2001 From: Kartik Patodi Date: Wed, 18 Oct 2017 09:54:18 +0530 Subject: [PATCH] Normalize files that are gotten from FileUtil.createTempDirectory It's required to avoid getting different paths inside tools (compiler, ant etc) and in tests. --- .../jetbrains/kotlin/test/KotlinTestUtils.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java index 4f8a8d5a551..60c8ff37a7c 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -389,20 +389,27 @@ public class KotlinTestUtils { @NotNull public static File tmpDirForTest(TestCase test) throws IOException { - File answer = FileUtil.createTempDirectory(test.getClass().getSimpleName(), test.getName()); + File answer = normalizeFile(FileUtil.createTempDirectory(test.getClass().getSimpleName(), test.getName())); deleteOnShutdown(answer); return answer; } @NotNull public static File tmpDir(String name) throws IOException { - // we should use this form. otherwise directory will be deleted on each test - File answer = FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, ""); + // We should use this form. otherwise directory will be deleted on each test. + File answer = normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, "")); deleteOnShutdown(answer); return answer; } - public static void deleteOnShutdown(File file) { + private static File normalizeFile(File file) throws IOException { + // Get canonical file to be sure that it's the same as inside the compiler, + // for example, on Windows, if a canonical path contains any space from FileUtil.createTempDirectory we will get + // a File with short names (8.3) in its path and it will break some normalization passes in tests. + return file.getCanonicalFile(); + } + + private static void deleteOnShutdown(File file) { if (filesToDelete.isEmpty()) { ShutDownTracker.getInstance().registerShutdownTask(() -> ShutDownTracker.invokeAndWait(true, true, () -> { for (File victim : filesToDelete) {