Skip to content

Commit ba447d2

Browse files
committed
Add integration test
Ref #469
1 parent a11e01b commit ba447d2

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- stage: test
1515
env: SBT_VERSION=1.2.8
1616
jdk: openjdk8
17-
script: sbt "-no-colors" "^^ $SBT_VERSION" ";publishLocal;scalafmtCheckAll;plugin/scripted;scaffold/scripted;lib/test;app/compile"
17+
script: sbt "-no-colors" "^^ $SBT_VERSION" ";publishLocal;scalafmtCheckAll;launcher/test;plugin/scripted;scaffold/scripted;lib/test;app/compile"
1818
- name: "Scala 2.13"
1919
script:
2020
- sbt "++ 2.13.2" app/test lib/test

build.sbt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Dependencies._
22
import CrossVersion.partialVersion
33

4-
val g8version = "0.13.0-SNAPSHOT"
4+
val g8version = "0.13.1-SNAPSHOT"
55

66
val javaVmArgs: List[String] = {
77
import scala.collection.JavaConverters._
@@ -187,8 +187,15 @@ lazy val launcher = (project in file("launcher"))
187187
description := "Command line tool to apply templates defined on GitHub",
188188
name := "giter8-launcher",
189189
crossScalaVersions := List(scala212, scala213),
190-
libraryDependencies += coursier,
191-
run / fork := true
190+
libraryDependencies ++= Seq(
191+
coursier,
192+
verify % Test,
193+
sbtIo % Test
194+
),
195+
testFrameworks += new TestFramework("verify.runner.Framework"),
196+
run / fork := true,
197+
Test / fork := true,
198+
Test / javaOptions ++= Seq(s"""-DG8_HOME=${target.value / "home"}""")
192199
// assemblyMergeStrategy in assembly := {
193200
// case "plugin.properties" => MergeStrategy.concat
194201
// case "module-info.class" => MergeStrategy.discard

launcher/src/main/scala/LauncherMain.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.net.URLClassLoader
44
import java.io.{BufferedInputStream, File, FileInputStream}
55
import java.util.Properties
66
import java.lang.reflect.InvocationTargetException
7-
import java.nio.file.Files
7+
import java.nio.file.{Files, StandardCopyOption}
88

99
object LauncherMain extends Runner with App {
1010
java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.SEVERE)
@@ -35,7 +35,7 @@ class LauncherProcessor extends Processor {
3535
(if (forceOverwrite) Vector("-f") else Vector()) ++
3636
(outputDirectory match { case Some(out) => Vector("-o", out.toString); case _ => Vector() })
3737
val giter8Files = giter8Artifacts(g8v)
38-
virtuallyRun(giter8Files, virtualArgument)
38+
virtuallyRun(giter8Files, virtualArgument, workingDirectory)
3939
Right("")
4040
}
4141

@@ -67,7 +67,7 @@ class LauncherProcessor extends Processor {
6767
}
6868
downloadedJars map { downloaded =>
6969
val t = bootDir / downloaded.getName
70-
Files.copy(downloaded.toPath, t.toPath).toFile
70+
Files.copy(downloaded.toPath, t.toPath, StandardCopyOption.REPLACE_EXISTING).toFile
7171
}
7272
}
7373
// push launcher JAR to the end of classpath to avoid Scala version clash
@@ -83,9 +83,9 @@ class LauncherProcessor extends Processor {
8383
}
8484

8585
// uses classloader trick to run
86-
def virtuallyRun(files: Seq[File], args: Seq[String]): Unit = {
86+
def virtuallyRun(files: Seq[File], args: Seq[String], workingDirectory: File): Unit = {
8787
val cl = new URLClassLoader(files.map(_.toURL).toArray, null)
88-
call("giter8.Giter8", "run", cl)(classOf[Array[String]])(args.toArray)
88+
call("giter8.Giter8", "run", cl)(classOf[Array[String]], classOf[File])(args.toArray, workingDirectory)
8989
}
9090

9191
def giter8Version(templateDir: File): Option[String] = {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package testpkg
2+
3+
import giter8._
4+
import verify._
5+
import java.io.File
6+
import sbt.io.IO
7+
8+
object LauncherTest extends BasicTestSuite {
9+
lazy val launcher = new Runner {
10+
def run(args: Array[String], workingDirectory: File): Int = {
11+
run(args, workingDirectory, new LauncherProcessor)
12+
}
13+
}
14+
implicit private class RichFile(file: File) {
15+
def /(child: String): File = new File(file, child)
16+
}
17+
18+
test("runs scala/scala-seed.g8") {
19+
IO.withTemporaryDirectory { dir =>
20+
launcher.run(Array("scala/scala-seed.g8", "--name=hello"), dir)
21+
assert((dir / "hello" / "build.sbt").exists)
22+
}
23+
}
24+
}

project/Dependencies.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ object Dependencies {
2121
val scalacheck = "org.scalacheck" %% "scalacheck" % "1.14.3"
2222
val scalatest = "org.scalatest" %% "scalatest" % "3.2.0"
2323
val scalamock = "org.scalamock" %% "scalamock" % "4.4.0"
24+
val verify = "com.eed3si9n.verify" %% "verify" % "0.2.0"
2425
val sbtIo = "org.scala-sbt" %% "io" % "1.3.4"
2526
val scala212 = "2.12.11"
2627
val scala213 = "2.13.2"

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.3.10
1+
sbt.version=1.2.8

0 commit comments

Comments
 (0)