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

fixes how giter8 deals with scripted test #408

Merged
merged 2 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally thought this was a bug, but the final script is always called "test". That's what allows users to have scripts called "giter8.test" or "g8.test".

Unfortunately that conflicts with Play applications using default Play layout (see sbt/sbt#630).

Since, sbt 1.2.1, scripted tests recognize "test.script" as a valid script name. We can workaround this situation by forcing it to be "test.script" when using sbt 1.x.

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",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how "giter8.test" and "g8.test" could possibly be used. If we add such a file, for instace, giter8 will pick it, but it won't work with sbt-scripted because it only accepts "test" or "test.script".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, now I see why "giter8.test" and "g8.test" can work. The user can define the test in such a file, but then when it gets run, the content of the file is copied to out / "test" (as seen here).

In the end, the test script is always copied to a file called "test". The 'fix' I did here make it impossible to use "giter8.test" or "g8.test", because it makes the final script to be named as such which sbt-scripted won't recognize.

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