diff --git a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt index 6a2aca303d..ed968953a2 100644 --- a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt +++ b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt @@ -49,7 +49,7 @@ object ArgsHelper { } fun evaluateFilePath(filePath: String): String { - var file = filePath.trim().replaceFirst("~", System.getProperty("user.home")) + var file = filePath.trim().replaceFirst(Regex("^~"), System.getProperty("user.home")) file = substituteEnvVars(file) // avoid File(..).canonicalPath since that will resolve symlinks file = Paths.get(file).toAbsolutePath().normalize().toString() @@ -180,7 +180,10 @@ object ArgsHelper { val matcher = envRegex.matcher(text) while (matcher.find()) { val envName = matcher.group(1) - val envValue = System.getenv(envName) ?: "" + val envValue = System.getenv(envName) + if (envValue == null) { + println("WARNING: $envName not found") + } matcher.appendReplacement(buffer, envValue) } matcher.appendTail(buffer) diff --git a/test_runner/src/test/kotlin/ftl/args/ArgsHelperFilePathTest.kt b/test_runner/src/test/kotlin/ftl/args/ArgsHelperFilePathTest.kt index 577e02d553..7e45d7fef4 100644 --- a/test_runner/src/test/kotlin/ftl/args/ArgsHelperFilePathTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/ArgsHelperFilePathTest.kt @@ -59,9 +59,73 @@ class ArgsHelperFilePathTest { Truth.assertThat(actual).isEqualTo(expected) } + @Test + fun evaluateRelativeFilePath() { + val expected = makeTmpFile("/tmp/app-debug.apk") + val testApkPath = "~/../../../../../../../../../tmp/app-debug.apk" + val actual = ArgsHelper.evaluateFilePath(testApkPath) + + Truth.assertThat(actual).isEqualTo(expected) + } + + @Test + fun evaluateRelativeAndWildCardsInFilePath() { + makeTmpFile("/tmp/tmp1/tmp2/tmp3/tmp4/tmp5/tmp6/tmp7/tmp8/tmp9/app-debug.apk") + val expected = makeTmpFile("/tmp/tmp1/tmp2/tmp3/tmp4/tmp5/tmp6/tmp7/tmp8/tmp9/tmp10/app-debug.apk") + val inputPath = "~/../../../../../../../../../tmp/tmp1/**/tmp4/**/tmp7/*/tmp9/*/app*debug.apk" + val actual = ArgsHelper.evaluateFilePath(inputPath) + + Truth.assertThat(actual).isEqualTo(expected) + } + + @Test + fun evaluateWildCardsInFilePath() { + val expected = makeTmpFile("/tmp/tmp1/tmp2/tmp3/tmp4/tmp5/tmp6/tmp7/tmp8/tmp9/app-debug.apk") + makeTmpFile("/tmp/tmp1/tmp2/tmp3/tmp4/tmp5/tmp6/tmp7/tmp8/tmp9/tmp10/app-debug.apk") + val inputPath = "/tmp/**/tmp4/**/tmp8/*/app*debug.apk" + val actual = ArgsHelper.evaluateFilePath(inputPath) + + Truth.assertThat(actual).isEqualTo(expected) + } + + + @Test(expected = RuntimeException::class) + fun wildCardsInFileNameWithMultipleMatches() { + makeTmpFile("/tmp/tmp1/app-debug.apk") + makeTmpFile("/tmp/tmp1/app---debug.apk") + val inputPath = "/tmp/tmp1/app*debug.apk" + ArgsHelper.evaluateFilePath(inputPath) + } + + + @Test(expected = RuntimeException::class) + fun wildCardsInFilePathWithMultipleMatches() { + makeTmpFile("/tmp/tmp1/tmp2/tmp3/app-debug.apk") + makeTmpFile("/tmp/tmp1/tmp2/tmp3/tmp4/app-debug.apk") + val inputPath = "~/../../../../../../../../../tmp/**/tmp2/**/app*debug.apk" + ArgsHelper.evaluateFilePath(inputPath) + } + + @Test + fun evaluateMultipleEnvVarsInFilePath() { + val expected = makeTmpFile("/tmp/tmp/random.xctestrun") + environmentVariables.set("TMP_DIR", "tmp") + environmentVariables.set("RANDOM_FILE", "random") + val inputPath = "/\$TMP_DIR/\$TMP_DIR/\$RANDOM_FILE.xctestrun" + val actual = ArgsHelper.evaluateFilePath(inputPath) + + Truth.assertThat(actual).isEqualTo(expected) + } + @Test(expected = java.nio.file.NoSuchFileException::class) fun evaluateInvalidFilePath() { val testApkPath = "~/flank_test_app/invalid_path/app-debug-*.xctestrun" ArgsHelper.evaluateFilePath(testApkPath) } + + @Test(expected = java.nio.file.NoSuchFileException::class) + fun evaluateInvalidFilePathWithTilde() { + val testApkPath = "~/flank_test_app/~/invalid_path/app-debug-*.xctestrun" + ArgsHelper.evaluateFilePath(testApkPath) + } } diff --git a/test_runner/src/test/kotlin/ftl/args/ArgsHelperTest.kt b/test_runner/src/test/kotlin/ftl/args/ArgsHelperTest.kt index 7f0e5dd6c0..1eb9702c0c 100644 --- a/test_runner/src/test/kotlin/ftl/args/ArgsHelperTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/ArgsHelperTest.kt @@ -238,7 +238,7 @@ class ArgsHelperTest { .isEqualTo(ArgsHelper.evaluateFilePath(testApkPath)) } - @Test(expected = RuntimeException::class) + @Test(expected = java.nio.file.NoSuchFileException::class) fun evaluateInvalidFilePath() { val testApkPath = "~/flank_test_app/invalid_path/app-debug-*.xctestrun" ArgsHelper.evaluateFilePath(testApkPath)