Skip to content

Commit

Permalink
Fix single glob splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Nov 16, 2018
1 parent 6211c0f commit 3dd27d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/ArgsFileVisitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class ArgsFileVisitor(glob: String) : SimpleFileVisitor<Path>() {

companion object {
private const val RECURSE = "/**"
private const val SINGLE_GLOB = "/*"
}

@Throws(java.nio.file.NoSuchFileException::class)
fun walk(searchPath: Path): List<Path> {
val searchString = searchPath.toString()
// /Users/tmp/code/flank/test_app/** => /Users/tmp/code/flank/test_app/
val beforeGlob = Paths.get(searchString.substringBefore(RECURSE))
val beforeGlob = Paths.get(searchString.substringBefore(SINGLE_GLOB))
// must not follow links when resolving paths or /tmp turns into /private/tmp
val realPath = beforeGlob.toRealPath(LinkOption.NOFOLLOW_LINKS)

Expand Down
11 changes: 6 additions & 5 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object ArgsHelper {

fun evaluateFilePath(filePath: String): String {
var file = filePath.trim().replaceFirst(Regex("^~"), System.getProperty("user.home"))
file = substituteEnvVars(file)
file = evaluateEnvVars(file)
// avoid File(..).canonicalPath since that will resolve symlinks
file = Paths.get(file).toAbsolutePath().normalize().toString()

Expand All @@ -63,7 +63,8 @@ object ArgsHelper {
} else if (filePaths.isEmpty()) {
Utils.fatalError("'$file' not found ($filePath)")
}
return filePaths[0].toAbsolutePath().toString()

return filePaths.first().toAbsolutePath().normalize().toString()
}

fun assertGcsFileExists(uri: String) {
Expand Down Expand Up @@ -175,16 +176,16 @@ object ArgsHelper {

// https://stackoverflow.com/a/2821201/2450315
private val envRegex = Pattern.compile("\\$([a-zA-Z_]+[a-zA-Z0-9_]*)")
private fun substituteEnvVars(text: String): String {
private fun evaluateEnvVars(text: String): String {
val buffer = StringBuffer()
val matcher = envRegex.matcher(text)
while (matcher.find()) {
val envName = matcher.group(1)
val envValue = System.getenv(envName)
val envValue: String? = System.getenv(envName)
if (envValue == null) {
println("WARNING: $envName not found")
}
matcher.appendReplacement(buffer, envValue)
matcher.appendReplacement(buffer, envValue ?: "")
}
matcher.appendTail(buffer)
return buffer.toString()
Expand Down
5 changes: 3 additions & 2 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.junit.contrib.java.lang.system.SystemOutRule
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import java.io.File
import ftl.test.util.TestHelper.absolutePath

@RunWith(FlankTestRunner::class)
class AndroidArgsFileTest {
Expand All @@ -43,8 +44,8 @@ class AndroidArgsFileTest {
private val testName = "class com.example.app.ExampleUiTest#testPasses"
private val directoryToPull = "/sdcard/screenshots"

private val appApkAbsolutePath = File(appApkLocal).absolutePath
private val testApkAbsolutePath = File(testApkLocal).absolutePath
private val appApkAbsolutePath = appApkLocal.absolutePath()
private val testApkAbsolutePath = testApkLocal.absolutePath()
// NOTE: Change working dir to '%MODULE_WORKING_DIR%' in IntelliJ to match gradle for this test to pass.
@Test
fun localConfigLoadsSuccessfully() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ class ArgsHelperFilePathTest {
Truth.assertThat(actual).isEqualTo(expected)
}

@Test
fun evaluateSingleGlobBeforeDouble() {
val expected = makeTmpFile("/tmp/tmp1/tmp2/singleglob/app-debug.apk")
val inputPath = "/tmp/*/**/singleglob/app-debug.apk"
val actual = ArgsHelper.evaluateFilePath(inputPath)

Truth.assertThat(actual).isEqualTo(expected)
}

@Test
fun evaluateRelativeAndWildCardsInFilePath() {
makeTmpFile("/tmp/tmp1/tmp2/tmp3/tmp4/tmp5/tmp6/tmp7/tmp8/tmp9/app-debug.apk")
Expand Down

0 comments on commit 3dd27d4

Please sign in to comment.