diff --git a/compiler/testData/cli/jvm/duplicateSourcesInModule.xml b/compiler/testData/cli/jvm/duplicateSourcesInModule.xml index ce4f16a0fdc..409ec1db942 100644 --- a/compiler/testData/cli/jvm/duplicateSourcesInModule.xml +++ b/compiler/testData/cli/jvm/duplicateSourcesInModule.xml @@ -1,6 +1,6 @@ - - - + + + - \ No newline at end of file + diff --git a/compiler/testData/cli/jvm/nonexistentPathInModule.xml b/compiler/testData/cli/jvm/nonexistentPathInModule.xml index 1ddd1289d9a..15459bf5184 100644 --- a/compiler/testData/cli/jvm/nonexistentPathInModule.xml +++ b/compiler/testData/cli/jvm/nonexistentPathInModule.xml @@ -1,6 +1,6 @@ - - - + + + diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java b/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java index 5d41d96929c..1e1af36c1ce 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java @@ -49,6 +49,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir { private static final String TESTDATA_DIR = "$TESTDATA_DIR$"; private static final String EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX = "-Xargfile="; + private static final String BUILD_FILE_ARGUMENT_PREFIX = "-Xbuild-file="; public static Pair executeCompilerGrabOutput(@NotNull CLITool compiler, @NotNull List args) { StringBuilder output = new StringBuilder(); @@ -200,29 +201,38 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir { String argWithTestPathsReplaced = replaceTestPaths(argWithColonsReplaced, testDataDir, tempDir); + if (arg.startsWith(BUILD_FILE_ARGUMENT_PREFIX)) { + return createTempFileWithPathsReplaced(argWithTestPathsReplaced, BUILD_FILE_ARGUMENT_PREFIX, ".xml", testDataDir, tempDir); + } + if (arg.startsWith(EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX)) { - return mockArgfile(argWithTestPathsReplaced, testDataDir, tempDir); - } - else { - return argWithTestPathsReplaced; + return createTempFileWithPathsReplaced( + argWithTestPathsReplaced, EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX, "", testDataDir, tempDir + ); } + + return argWithTestPathsReplaced; } - // Create new temp. argfile with all test paths replaced and return argfile-argument pointing to that file - private static String mockArgfile(@NotNull String argfileArgument, @NotNull String testDataDir, @NotNull String tempDir) { - String argfilePath = kotlin.text.StringsKt.substringAfter(argfileArgument, EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX, argfileArgument); - File argfile = new File(argfilePath); + // Create new temporary file with all test paths replaced and return the new argument value with the new file path + @NotNull + private static String createTempFileWithPathsReplaced( + @NotNull String argument, + @NotNull String argumentPrefix, + @NotNull String tempFileSuffix, + @NotNull String testDataDir, + @NotNull String tempDir + ) { + String filePath = kotlin.text.StringsKt.substringAfter(argument, argumentPrefix, argument); + File file = new File(filePath); + if (!file.exists()) return argument; - if (argfile.exists()) { - File mockArgfile = FilesKt.createTempFile(argfile.getAbsolutePath(), "", new File(tempDir)); - String oldArgfileContent = FilesKt.readText(argfile, Charsets.UTF_8); - String newArgfileContent = replaceTestPaths(oldArgfileContent, testDataDir, tempDir); - FilesKt.writeText(mockArgfile, newArgfileContent, Charsets.UTF_8); - return EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX + mockArgfile.getAbsolutePath(); - } else { - return argfileArgument; - } + File result = FilesKt.createTempFile(file.getAbsolutePath(), tempFileSuffix, new File(tempDir)); + String oldContent = FilesKt.readText(file, Charsets.UTF_8); + String newContent = replaceTestPaths(oldContent, testDataDir, tempDir); + FilesKt.writeText(result, newContent, Charsets.UTF_8); + return argumentPrefix + result.getAbsolutePath(); } private static String replaceTestPaths(@NotNull String str, @NotNull String testDataDir, @NotNull String tempDir) {