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:
+4
-4
@@ -1,6 +1,6 @@
|
||||
<modules>
|
||||
<module name="name" outputDir="whatever" type="java-production">
|
||||
<sources path="duplicateSourcesInModule.kt"/>
|
||||
<sources path="duplicateSourcesInModule.kt"/>
|
||||
<module name="name" outputDir="$TEMP_DIR$/whatever" type="java-production">
|
||||
<sources path="$TESTDATA_DIR$/duplicateSourcesInModule.kt"/>
|
||||
<sources path="$TESTDATA_DIR$/duplicateSourcesInModule.kt"/>
|
||||
</module>
|
||||
</modules>
|
||||
</modules>
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
<modules>
|
||||
<module name="name" outputDir="whatever" type="java-production">
|
||||
<sources path="nonexistentFile.kt"/>
|
||||
<sources path="some/nonexistent/dir/"/>
|
||||
<module name="name" outputDir="$TEMP_DIR$/whatever" type="java-production">
|
||||
<sources path="$TESTDATA_DIR$/nonexistentFile.kt"/>
|
||||
<sources path="$TESTDATA_DIR$/some/nonexistent/dir/"/>
|
||||
</module>
|
||||
</modules>
|
||||
|
||||
@@ -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<String, ExitCode> executeCompilerGrabOutput(@NotNull CLITool<?> compiler, @NotNull List<String> 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) {
|
||||
|
||||
Reference in New Issue
Block a user