Minor, use TEMP_DIR/TESTDATA_DIR in CLI tests on xml build files
Otherwise the "outputDir" in these tests was treated as relative to the
project root, and starting from 63b4302cea, running these tests resulted
in the "whatever" directory being created in the project root
This commit is contained in:
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module name="name" outputDir="whatever" type="java-production">
|
<module name="name" outputDir="$TEMP_DIR$/whatever" type="java-production">
|
||||||
<sources path="duplicateSourcesInModule.kt"/>
|
<sources path="$TESTDATA_DIR$/duplicateSourcesInModule.kt"/>
|
||||||
<sources path="duplicateSourcesInModule.kt"/>
|
<sources path="$TESTDATA_DIR$/duplicateSourcesInModule.kt"/>
|
||||||
</module>
|
</module>
|
||||||
</modules>
|
</modules>
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module name="name" outputDir="whatever" type="java-production">
|
<module name="name" outputDir="$TEMP_DIR$/whatever" type="java-production">
|
||||||
<sources path="nonexistentFile.kt"/>
|
<sources path="$TESTDATA_DIR$/nonexistentFile.kt"/>
|
||||||
<sources path="some/nonexistent/dir/"/>
|
<sources path="$TESTDATA_DIR$/some/nonexistent/dir/"/>
|
||||||
</module>
|
</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
|||||||
private static final String TESTDATA_DIR = "$TESTDATA_DIR$";
|
private static final String TESTDATA_DIR = "$TESTDATA_DIR$";
|
||||||
|
|
||||||
private static final String EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX = "-Xargfile=";
|
private static final String EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX = "-Xargfile=";
|
||||||
|
private static final String BUILD_FILE_ARGUMENT_PREFIX = "-Xbuild-file=";
|
||||||
|
|
||||||
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLITool<?> compiler, @NotNull List<String> args) {
|
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLITool<?> compiler, @NotNull List<String> args) {
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
@@ -200,29 +201,38 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
|||||||
|
|
||||||
String argWithTestPathsReplaced = replaceTestPaths(argWithColonsReplaced, testDataDir, tempDir);
|
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)) {
|
if (arg.startsWith(EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX)) {
|
||||||
return mockArgfile(argWithTestPathsReplaced, testDataDir, tempDir);
|
return createTempFileWithPathsReplaced(
|
||||||
}
|
argWithTestPathsReplaced, EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX, "", testDataDir, tempDir
|
||||||
else {
|
);
|
||||||
return argWithTestPathsReplaced;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return argWithTestPathsReplaced;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new temp. argfile with all test paths replaced and return argfile-argument pointing to that file
|
// Create new temporary file with all test paths replaced and return the new argument value with the new file path
|
||||||
private static String mockArgfile(@NotNull String argfileArgument, @NotNull String testDataDir, @NotNull String tempDir) {
|
@NotNull
|
||||||
String argfilePath = kotlin.text.StringsKt.substringAfter(argfileArgument, EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX, argfileArgument);
|
private static String createTempFileWithPathsReplaced(
|
||||||
File argfile = new File(argfilePath);
|
@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 result = FilesKt.createTempFile(file.getAbsolutePath(), tempFileSuffix, new File(tempDir));
|
||||||
File mockArgfile = FilesKt.createTempFile(argfile.getAbsolutePath(), "", new File(tempDir));
|
String oldContent = FilesKt.readText(file, Charsets.UTF_8);
|
||||||
String oldArgfileContent = FilesKt.readText(argfile, Charsets.UTF_8);
|
String newContent = replaceTestPaths(oldContent, testDataDir, tempDir);
|
||||||
String newArgfileContent = replaceTestPaths(oldArgfileContent, testDataDir, tempDir);
|
FilesKt.writeText(result, newContent, Charsets.UTF_8);
|
||||||
FilesKt.writeText(mockArgfile, newArgfileContent, Charsets.UTF_8);
|
|
||||||
return EXPERIMENTAL_ARGFILE_ARGUMENT_PREFIX + mockArgfile.getAbsolutePath();
|
|
||||||
} else {
|
|
||||||
return argfileArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return argumentPrefix + result.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String replaceTestPaths(@NotNull String str, @NotNull String testDataDir, @NotNull String tempDir) {
|
private static String replaceTestPaths(@NotNull String str, @NotNull String testDataDir, @NotNull String tempDir) {
|
||||||
|
|||||||
Reference in New Issue
Block a user