Skip to content

Commit

Permalink
Restore test for single quote path literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Mexator committed Sep 10, 2024
1 parent 23a8b15 commit b470222
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class CreateFocusSettingsTask : DefaultTask() {
// language=groovy
writer.append(
"""
File f = new File("${modulesToDirMapFile.get().asFile.absolutePath}")
File f = new File('${modulesToDirMapFile.get().asFile.absolutePath}')
if (f.exists()) {
f.eachLine { line ->
var values = line.split(",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.dropbox.focus

import com.google.common.truth.Truth.assertThat
import java.io.File
import java.util.regex.Pattern
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.Before
Expand Down Expand Up @@ -66,6 +67,21 @@ class FocusPluginTest {
assertThat(firstRun.output).contains("as it does not exist.")
}

@Test
fun allPathLiteralsAreSingleQuote() {
val fixtureRoot = File("src/test/projects/happy-path")
gradleRunner
.withArguments(":module:focus")
.runFixture(fixtureRoot) { build() }

val focusFileContent =
File("src/test/projects/happy-path/build/notnowhere/build/focus.settings.gradle").readText()
// has at least one single-quote path literal
assertThat(focusFileContent).matches(Pattern.compile(""".*new File\('.*'\).*""", Pattern.DOTALL))
// no double-quote path literals
assertThat(focusFileContent).doesNotMatch(Pattern.compile(""".*new File\(".*"\).*""", Pattern.DOTALL))
}

@Test
fun happyPath_CsvCreated() {
val fixtureRoot = File("src/test/projects/happy-path")
Expand All @@ -91,7 +107,7 @@ class FocusPluginTest {
val csvFilePath = File("src/test/projects/happy-path/build/notnowhere/build/moduleToDirMap.csv").absolutePath
val focusFileContent = File("src/test/projects/happy-path/build/notnowhere/build/focus.settings.gradle").readText()
// language=groovy
assertThat(focusFileContent).contains("""File f = new File("$csvFilePath")""")
assertThat(focusFileContent).contains("""File f = new File('$csvFilePath')""")
}

private fun GradleRunner.runFixture(
Expand Down

0 comments on commit b470222

Please sign in to comment.