Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow blob, tilde and env vars in app paths #386

Merged
merged 15 commits into from
Nov 16, 2018

Conversation

sravanmedarapu
Copy link
Contributor

@sravanmedarapu sravanmedarapu commented Nov 11, 2018

app, test and xctestrun-file values in Flank config should support below formats along with current formats.

  1. tilda expansion(~)
  2. environment variable expansion
  3. globbing with * and **
Ex: 
app: ~/repo/app-*.apk
xctestrun-file: $DERIVED_DATA/**/*. xctestrun

Fix #336

@codecov-io
Copy link

codecov-io commented Nov 11, 2018

Codecov Report

Merging #386 into master will increase coverage by 0.07%.
The diff coverage is 82.6%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #386      +/-   ##
============================================
+ Coverage      79.9%   79.98%   +0.07%     
- Complexity      483      490       +7     
============================================
  Files            66       67       +1     
  Lines          1553     1594      +41     
  Branches        234      241       +7     
============================================
+ Hits           1241     1275      +34     
- Misses          173      177       +4     
- Partials        139      142       +3

bootstraponline and others added 3 commits November 11, 2018 13:01
Fixed failing tests

Added unit tests
Add ArgsFileVisitor

Fix paths
Copy link
Contributor

@bootstraponline bootstraponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JUnit coverage for edge cases in ArgsHelperFilePath (/**/, /*/, /tmp, etc.) will help improve confidence that the code is working as intended.

@@ -45,6 +48,24 @@ object ArgsHelper {
}
}

fun evaluateFilePath(filePath: String): String {
var file = filePath.trim().replaceFirst("~", System.getProperty("user.home"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ should be replaced only if it's the first character in the string
https://stackoverflow.com/a/7163455

the regex should be ^~, we should add a JUnit test for this (for both the happy path and failure case).

~/tmp should be replaced
/tmp/~ should not be replaced

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably need more testing around paths with /**/ and /*/

i'm not sure splitting by /**/ works for all cases


// https://stackoverflow.com/a/2821201/2450315
private val envRegex = Pattern.compile("\\$([a-zA-Z_]+[a-zA-Z0-9_]*)")
private fun substituteEnvVars(text: String): String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check this works for duplicate environment variables via more JUnit tests. There are probably other edge cases as well. For example the ${HOME} syntax which we should probably document as unsupported.

$HOME/$HOME/tmp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably WARN but not fail for duplicate env variables. The warning is to notify the user that he's duplicated an env variable. Not failing, in case its intentional.

Regardless, I don't think we should handle custom env vars. That would likely be a pain to maintain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash doesn't warn on duplicates. I'm using bash as the model for the parsing logic.

val matcher = envRegex.matcher(text)
while (matcher.find()) {
val envName = matcher.group(1)
val envValue = System.getenv(envName) ?: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise an error/warning here? Silently ignoring un-found env variables seems like a bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is standard behavior in Bash, that's how environment variables work sadly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed on slack, printing a warning makes sense.

file = Paths.get(file).toAbsolutePath().normalize().toString()

// Avoid walking the folder's parent dir if we know it exists already.
if (File(file).exists()) return file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we also printed this value to console. Something like - Resolved app file path - "$file".
Under a conditional. if (filePath != file).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be printed already when the args are printed to stdout at the start of a test run.

# Conflicts:
#	test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
#	test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
#	test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
}

@Test
fun tmpTest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be deleted.

@bootstraponline bootstraponline merged commit 25980b1 into Flank:master Nov 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants