From b4702228eb3c1b85acfe90302a5703caf8c28ea0 Mon Sep 17 00:00:00 2001 From: Mexator Date: Tue, 10 Sep 2024 14:37:24 +0300 Subject: [PATCH] Restore test for single quote path literals --- .../dropbox/focus/CreateFocusSettingsTask.kt | 2 +- .../com/dropbox/focus/FocusPluginTest.kt | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt b/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt index fe558a8..705ab6a 100644 --- a/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt +++ b/focus-gradle-plugin/src/main/kotlin/com/dropbox/focus/CreateFocusSettingsTask.kt @@ -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(",") diff --git a/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt b/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt index ce1fe08..3f1e609 100644 --- a/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt +++ b/focus-gradle-plugin/src/test/kotlin/com/dropbox/focus/FocusPluginTest.kt @@ -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 @@ -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") @@ -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(