Skip to content

Commit

Permalink
Merge pull request #408 from renatocaval/master
Browse files Browse the repository at this point in the history
fixes how giter8 deals with scripted test
  • Loading branch information
eed3si9n authored Aug 30, 2019
2 parents 48de2e2 + a46d5dd commit 1e55a9f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
5 changes: 2 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ ThisBuild / scmInfo := Some(
// posterous title needs to be giter8, so both app and root are named giter8
lazy val root = (project in file("."))
.enablePlugins(TravisSitePlugin, NoPublish)
.disablePlugins(ScriptedPlugin)
.aggregate(app, lib, scaffold, plugin)
.settings(
name := "giter8",
Expand All @@ -45,7 +44,7 @@ lazy val root = (project in file("."))
)

lazy val app = (project in file("app"))
.disablePlugins(BintrayPlugin, ScriptedPlugin)
.disablePlugins(BintrayPlugin)
.enablePlugins(ConscriptPlugin, BuildInfoPlugin, SonatypePublish)
.dependsOn(lib)
.settings(
Expand Down Expand Up @@ -131,7 +130,7 @@ lazy val plugin = (project in file("plugin"))
)

lazy val lib = (project in file("library"))
.disablePlugins(BintrayPlugin, ScriptedPlugin)
.disablePlugins(BintrayPlugin)
.enablePlugins(SonatypePublish)
.settings(crossSbt)
.settings(
Expand Down
3 changes: 2 additions & 1 deletion plugin/src/main/scala-sbt-1.0/sbt/sbtgiter8/SBTCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package sbtgiter8
object SBTCompat extends ScriptedCompat

trait ScriptedCompat {
val finalScriptName = "test.script"
val scriptedSettings = sbt.ScriptedPlugin.projectSettings
val sbtLauncher = sbt.ScriptedPlugin.autoImport.sbtLauncher
val sbtTestDirectory = sbt.ScriptedPlugin.autoImport.sbtTestDirectory
Expand All @@ -31,6 +32,6 @@ trait ScriptedCompat {
val scriptedLaunchOpts = sbt.ScriptedPlugin.autoImport.scriptedLaunchOpts
val scriptedRun = sbt.ScriptedPlugin.autoImport.scriptedRun
val scriptedSbt = sbt.ScriptedPlugin.autoImport.scriptedSbt
val scriptedTask = sbt.ScriptedPlugin.scriptedTask
val scriptedTask = sbt.ScriptedPlugin.autoImport.scripted
val scriptedTests = sbt.ScriptedPlugin.autoImport.scriptedTests
}
32 changes: 22 additions & 10 deletions plugin/src/main/scala/Giter8Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ object Giter8Plugin extends sbt.AutoPlugin {
} else Nil

// copy test script or generate one
val script = new File(out, "test")
// the final script should always be called "test.script"
// no matter how it was originally called by user
val script = new File(out, finalScriptName)
if (ts.exists) IO.copyFile(ts, script)
else IO.write(script, """>test""")

Expand All @@ -141,15 +143,25 @@ object Giter8Plugin extends sbt.AutoPlugin {
val dir = (sourceDirectory in Test).value
val metadir = (baseDirectory in LocalRootProject).value / "project"
val file0 = dir / "g8" / "test"
val files = List(
file0,
dir / "g8" / "giter8.test",
dir / "g8" / "g8.test",
metadir / "test",
metadir / "giter8.test",
metadir / "g8.test"
)
files.find(_.exists).getOrElse(file0)

// we should only use file0 if its an exisiting file
// if it exists and is a dir we should fallback to test.script
val defaultTestScript =
if (file0.isDirectory) dir / "g8" / "test.script"
else file0

val files = List(file0,
dir / "g8" / "test.script",
dir / "g8" / "giter8.test",
dir / "g8" / "g8.test",
metadir / "test",
metadir / "test.script",
metadir / "giter8.test",
metadir / "g8.test")

files
.find(_.isFile)
.getOrElse(defaultTestScript)
},
scriptedBufferLog in (Test, g8) := true
)
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions plugin/src/sbt-test/giter8/simple/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enablePlugins(ScriptedPlugin)

scriptedBufferLog in (Test, g8) := false

TaskKey[Unit]("writeInvalidFile") := {
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/sbt-test/giter8/without-name/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

enablePlugins(ScriptedPlugin)

scriptedBufferLog in (Test, g8) := false

val javaVmArgs: List[String] = {
Expand Down

0 comments on commit 1e55a9f

Please sign in to comment.