aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/build/build.scala4
-rw-r--r--test/empty-build-file/Main.scala5
-rw-r--r--test/empty-build-file/build/build.scala0
-rw-r--r--test/empty-build/Main.scala5
-rw-r--r--test/empty-build/build/build/dummy0
-rw-r--r--test/forgot-extend/build/build.scala2
-rw-r--r--test/library-test/Foo.scala4
-rw-r--r--test/library-test/build/build.scala25
-rw-r--r--test/multi-build/build/build.scala7
-rw-r--r--test/multi-build/code.scala5
-rw-r--r--test/multi-build/sub1/code.scala4
-rw-r--r--test/multi-build/sub2/code.scala4
-rw-r--r--test/no-build-file/Main.scala5
-rw-r--r--test/no-build-file/build/foo.scala0
-rw-r--r--test/nothing/placeholder0
-rw-r--r--test/simple-fixed-cbt/Main.scala6
-rw-r--r--test/simple-fixed-cbt/build/build.scala14
-rw-r--r--test/simple-fixed/Main.scala6
-rw-r--r--test/simple-fixed/build/build.scala29
-rw-r--r--test/simple/Main.scala6
-rw-r--r--test/simple/build/build.scala43
-rw-r--r--test/test.scala262
22 files changed, 436 insertions, 0 deletions
diff --git a/test/build/build.scala b/test/build/build.scala
new file mode 100644
index 0000000..5a138fb
--- /dev/null
+++ b/test/build/build.scala
@@ -0,0 +1,4 @@
+import cbt._
+class Build(val context: cbt.Context) extends BaseBuild{
+ override def dependencies = super.dependencies :+ context.cbtDependency
+}
diff --git a/test/empty-build-file/Main.scala b/test/empty-build-file/Main.scala
new file mode 100644
index 0000000..19d4beb
--- /dev/null
+++ b/test/empty-build-file/Main.scala
@@ -0,0 +1,5 @@
+object Main{
+ def main( args: Array[String] ): Unit = {
+ println( Console.GREEN ++ "Hello World" ++ Console.RESET )
+ }
+}
diff --git a/test/empty-build-file/build/build.scala b/test/empty-build-file/build/build.scala
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/empty-build-file/build/build.scala
diff --git a/test/empty-build/Main.scala b/test/empty-build/Main.scala
new file mode 100644
index 0000000..19d4beb
--- /dev/null
+++ b/test/empty-build/Main.scala
@@ -0,0 +1,5 @@
+object Main{
+ def main( args: Array[String] ): Unit = {
+ println( Console.GREEN ++ "Hello World" ++ Console.RESET )
+ }
+}
diff --git a/test/empty-build/build/build/dummy b/test/empty-build/build/build/dummy
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/empty-build/build/build/dummy
diff --git a/test/forgot-extend/build/build.scala b/test/forgot-extend/build/build.scala
new file mode 100644
index 0000000..9181a5d
--- /dev/null
+++ b/test/forgot-extend/build/build.scala
@@ -0,0 +1,2 @@
+import cbt._
+class Build(val context: Context)
diff --git a/test/library-test/Foo.scala b/test/library-test/Foo.scala
new file mode 100644
index 0000000..75c0780
--- /dev/null
+++ b/test/library-test/Foo.scala
@@ -0,0 +1,4 @@
+package lib_test
+object Foo{
+ def bar = "Hello, Foo Bar"
+}
diff --git a/test/library-test/build/build.scala b/test/library-test/build/build.scala
new file mode 100644
index 0000000..d07e58e
--- /dev/null
+++ b/test/library-test/build/build.scala
@@ -0,0 +1,25 @@
+import cbt._
+
+// cbt:https://github.com/cvogt/cbt.git#bf4ea112fe668fb7e2e95a2baca4989b16384783
+class Build(val context: Context) extends BaseBuild with PackageJars{
+ def groupId = "cbt.test"
+ def defaultVersion = "0.1"
+ def name = "library-test"
+
+ override def dependencies =
+ super.dependencies ++ // don't forget super.dependencies here for scala-library, etc.
+ Seq(
+ // source dependency
+ // DirectoryDependency( projectDirectory ++ "/subProject" )
+ ) ++
+ // pick resolvers explicitly for individual dependencies (and their transitive dependencies)
+ Resolver( mavenCentral, sonatypeReleases ).bind(
+ // CBT-style Scala dependencies
+ // ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" )
+ // MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" )
+
+ // SBT-style dependencies
+ // "com.lihaoyi" %% "ammonite-ops" % "0.5.5"
+ // "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5"
+ )
+}
diff --git a/test/multi-build/build/build.scala b/test/multi-build/build/build.scala
new file mode 100644
index 0000000..5576a3d
--- /dev/null
+++ b/test/multi-build/build/build.scala
@@ -0,0 +1,7 @@
+import cbt._
+class Build(val context: Context) extends BaseBuild{
+ override def dependencies = Seq(
+ DirectoryDependency(projectDirectory++"/sub1"),
+ DirectoryDependency(projectDirectory++"/sub2")
+ ) ++ super.dependencies
+}
diff --git a/test/multi-build/code.scala b/test/multi-build/code.scala
new file mode 100644
index 0000000..3fe85ad
--- /dev/null
+++ b/test/multi-build/code.scala
@@ -0,0 +1,5 @@
+object Main extends App{
+ println("root here")
+ println(Foo(5))
+ println(Bar("test"))
+}
diff --git a/test/multi-build/sub1/code.scala b/test/multi-build/sub1/code.scala
new file mode 100644
index 0000000..b2d5deb
--- /dev/null
+++ b/test/multi-build/sub1/code.scala
@@ -0,0 +1,4 @@
+case class Foo(i: Int)
+object Main extends App{
+ println("sub1 here")
+} \ No newline at end of file
diff --git a/test/multi-build/sub2/code.scala b/test/multi-build/sub2/code.scala
new file mode 100644
index 0000000..1ec6ebf
--- /dev/null
+++ b/test/multi-build/sub2/code.scala
@@ -0,0 +1,4 @@
+case class Bar(s: String)
+object Main extends App{
+ println("sub1 here")
+}
diff --git a/test/no-build-file/Main.scala b/test/no-build-file/Main.scala
new file mode 100644
index 0000000..19d4beb
--- /dev/null
+++ b/test/no-build-file/Main.scala
@@ -0,0 +1,5 @@
+object Main{
+ def main( args: Array[String] ): Unit = {
+ println( Console.GREEN ++ "Hello World" ++ Console.RESET )
+ }
+}
diff --git a/test/no-build-file/build/foo.scala b/test/no-build-file/build/foo.scala
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/no-build-file/build/foo.scala
diff --git a/test/nothing/placeholder b/test/nothing/placeholder
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/nothing/placeholder
diff --git a/test/simple-fixed-cbt/Main.scala b/test/simple-fixed-cbt/Main.scala
new file mode 100644
index 0000000..75f9349
--- /dev/null
+++ b/test/simple-fixed-cbt/Main.scala
@@ -0,0 +1,6 @@
+import lib_test.Foo
+import org.eclipse.jgit.lib.Ref
+import com.spotify.missinglink.ArtifactLoader
+object Main extends App{
+ println(Foo.bar)
+}
diff --git a/test/simple-fixed-cbt/build/build.scala b/test/simple-fixed-cbt/build/build.scala
new file mode 100644
index 0000000..1d0640d
--- /dev/null
+++ b/test/simple-fixed-cbt/build/build.scala
@@ -0,0 +1,14 @@
+import cbt._
+
+// cbt:https://github.com/cvogt/cbt.git#bf4ea112fe668fb7e2e95a2baca4989b16384783
+class Build(val context: cbt.Context) extends PackageJars{
+ override def dependencies = super.dependencies ++ Seq(
+ DirectoryDependency( context.cbtHome ++ "/test/library-test" )
+ ) ++ Resolver( mavenCentral ).bind(
+ MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"),
+ MavenDependency("com.spotify", "missinglink-core", "0.1.1")
+ )
+ def groupId: String = "cbt.test"
+ def defaultVersion: String = "0.1"
+ def name: String = "simple-fixed-cbt"
+} \ No newline at end of file
diff --git a/test/simple-fixed/Main.scala b/test/simple-fixed/Main.scala
new file mode 100644
index 0000000..75f9349
--- /dev/null
+++ b/test/simple-fixed/Main.scala
@@ -0,0 +1,6 @@
+import lib_test.Foo
+import org.eclipse.jgit.lib.Ref
+import com.spotify.missinglink.ArtifactLoader
+object Main extends App{
+ println(Foo.bar)
+}
diff --git a/test/simple-fixed/build/build.scala b/test/simple-fixed/build/build.scala
new file mode 100644
index 0000000..a2bd584
--- /dev/null
+++ b/test/simple-fixed/build/build.scala
@@ -0,0 +1,29 @@
+import cbt._
+
+class Build(context: cbt.Context) extends BasicBuild(context){
+ override def dependencies = (
+ super.dependencies
+ ++
+ Seq(
+ GitDependency("https://github.com/cvogt/cbt.git", "908e05e296974fe67d8aaf9f094d97ff986905af", Some("test/library-test"))
+ )
+ ++
+ Resolver(mavenCentral).bind(
+ ScalaDependency("com.typesafe.play", "play-json", "2.4.4"),
+ MavenDependency("joda-time", "joda-time", "2.9.2"),
+ // the below tests pom inheritance with dependencyManagement and variable substitution for pom properties
+ MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"),
+ // the below tests pom inheritance with variable substitution for pom xml tag contents
+ MavenDependency("com.spotify", "missinglink-core", "0.1.1")
+ )
+ ++
+ Resolver(
+ mavenCentral,
+ bintray("tpolecat"),
+ sonatypeSnapshots
+ ).bind(
+ "org.cvogt" %% "play-json-extensions" % "0.8.0",
+ "ai.x" %% "lens" % "1.0.0"
+ )
+ )
+}
diff --git a/test/simple/Main.scala b/test/simple/Main.scala
new file mode 100644
index 0000000..75f9349
--- /dev/null
+++ b/test/simple/Main.scala
@@ -0,0 +1,6 @@
+import lib_test.Foo
+import org.eclipse.jgit.lib.Ref
+import com.spotify.missinglink.ArtifactLoader
+object Main extends App{
+ println(Foo.bar)
+}
diff --git a/test/simple/build/build.scala b/test/simple/build/build.scala
new file mode 100644
index 0000000..586daca
--- /dev/null
+++ b/test/simple/build/build.scala
@@ -0,0 +1,43 @@
+import cbt._
+
+class Build(val context: cbt.Context) extends BaseBuild{
+ override def dependencies = (
+ super.dependencies
+ ++
+ Seq(
+ GitDependency("https://github.com/cvogt/cbt.git", "908e05e296974fe67d8aaf9f094d97ff986905af", Some("test/library-test"))
+ ) ++
+ // FIXME: make the below less verbose
+ Resolver( mavenCentral ).bind(
+ ScalaDependency("com.typesafe.play", "play-json", "2.4.4"),
+ MavenDependency("joda-time", "joda-time", "2.9.2"),
+ // the below tests pom inheritance with dependencyManagement and variable substitution for pom properties
+ MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"),
+ // the below tests pom inheritance with variable substitution for pom xml tag contents
+ MavenDependency("com.spotify", "missinglink-core", "0.1.1"),
+ // the below tests pom inheritance with variable substitution being parts of strings
+ MavenDependency("cc.factorie","factorie_2.11","1.2")
+ // the dependency below uses a maven version range. Currently not supported.
+ // TODO: put in a proper error message for version range not supported
+ //MavenDependency("com.github.nikita-volkov", "sext", "0.2.4")
+ // currently breaks with can't find https://repo1.maven.org/maven2/org/apache/avro/avro-mapred/1.7.7/avro-mapred-1.7.7-hadoop2.pom.sha1
+ // org.apache.spark:spark-sql_2.11:1.6.1
+ // currently fails, let's see if because of a bug
+ // io.spray:spray-http:1.3.3
+ ) ++
+ Resolver( new java.net.URL("http://maven.spikemark.net/roundeights") ).bind(
+ // Check that lower case checksums work
+ ScalaDependency("com.roundeights","hasher","1.2.0")
+ ) ++
+ Resolver(
+ mavenCentral,
+ bintray("tpolecat"),
+ sonatypeSnapshots
+ ).bind(
+ "org.cvogt" %% "play-json-extensions" % "0.8.0",
+ "ai.x" %% "lens" % "1.0.0"
+ )
+ )
+
+ def printArgs = context.args.mkString(" ")
+}
diff --git a/test/test.scala b/test/test.scala
new file mode 100644
index 0000000..5b4a4af
--- /dev/null
+++ b/test/test.scala
@@ -0,0 +1,262 @@
+package cbt
+package test
+import java.util.concurrent.ConcurrentHashMap
+import java.io.File
+import java.nio.file._
+import java.net.URL
+
+// micro framework
+object Main{
+ def main(_args: Array[String]): Unit = {
+ val start = System.currentTimeMillis
+ val args = new Stage1ArgsParser(_args.toVector)
+ implicit val logger: Logger = new Logger(args.enabledLoggers, System.currentTimeMillis)
+ val lib = new Lib(logger)
+ val cbtHome = new File(System.getenv("CBT_HOME"))
+
+ var successes = 0
+ var failures = 0
+ def assertException[T:scala.reflect.ClassTag](msg: String = "")(code: => Unit)(implicit logger: Logger) = {
+ try{
+ code
+ assert(false, msg)
+ }catch{ case _:AssertionError => }
+ }
+ def assert(condition: Boolean, msg: String = "")(implicit logger: Logger) = {
+ scala.util.Try{
+ Predef.assert(condition, "["++msg++"]")
+ }.map{ _ =>
+ print(".")
+ successes += 1
+ }.recover{
+ case e: AssertionError =>
+ println("FAILED")
+ e.printStackTrace
+ failures += 1
+ }.get
+ }
+
+ def runCbt(path: String, _args: Seq[String])(implicit logger: Logger): Result = {
+ import java.io._
+ val allArgs: Seq[String] = ((cbtHome.string ++ "/cbt") +: "direct" +: (_args ++ args.propsRaw))
+ logger.test(allArgs.toString)
+ val pb = new ProcessBuilder( allArgs :_* )
+ pb.directory(cbtHome ++ ("/test/" ++ path))
+ val p = pb.start
+ val berr = new BufferedReader(new InputStreamReader(p.getErrorStream));
+ val bout = new BufferedReader(new InputStreamReader(p.getInputStream));
+ import collection.JavaConversions._
+ val err = Stream.continually(berr.readLine()).takeWhile(_ != null).mkString("\n")
+ val out = Stream.continually(bout.readLine()).takeWhile(_ != null).mkString("\n")
+ p.waitFor
+ Result(p.exitValue == 0, out, err)
+ }
+ case class Result(exit0: Boolean, out: String, err: String)
+ def assertSuccess(res: Result, msg: => String)(implicit logger: Logger) = {
+ assert(res.exit0, msg ++ res.toString)
+ }
+
+ // tests
+ def usage(path: String)(implicit logger: Logger) = {
+ val usageString = "Methods provided by CBT"
+ val res = runCbt(path, Seq())
+ logger.test(res.toString)
+ val debugToken = "usage " ++ path ++ " "
+ assertSuccess(res,debugToken)
+ assert(res.out == "", debugToken ++ res.toString)
+ assert(res.err contains usageString, debugToken ++ res.toString)
+ }
+ def compile(path: String)(implicit logger: Logger) = task("compile", path)
+ def task(name: String, path: String)(implicit logger: Logger) = {
+ val res = runCbt(path, Seq(name))
+ val debugToken = name ++ " " ++ path ++ " "
+ assertSuccess(res,debugToken)
+ res
+ // assert(res.err == "", res.err) // FIXME: enable this
+ }
+
+ def clean(path: String)(implicit logger: Logger) = {
+ val res = runCbt(path, Seq("clean", "dry-run", "force"))
+ val debugToken = "\n"++lib.red("Deleting") ++ " " ++ (cbtHome ++("/test/"++path++"/target")).toPath.toAbsolutePath.toString++"\n"
+ val debugToken2 = "\n"++lib.red("Deleting") ++ " " ++ (cbtHome ++("/test/"++path)).toPath.toAbsolutePath.toString++"\n"
+ assertSuccess(res,debugToken)
+ assert(res.out == "", debugToken ++ " " ++ res.toString)
+ assert(res.err.contains(debugToken), debugToken ++ " " ++ res.toString)
+ assert(
+ !res.err.contains(debugToken2),
+ "Tried to delete too much: " ++ debugToken2 ++ " " ++ res.toString
+ )
+ res.err.split("\n").filter(_.startsWith(lib.red("Deleting"))).foreach{ line =>
+ assert(
+ line.size >= debugToken2.trim.size,
+ "Tried to delete too much: " ++ line ++" debugToken2: " ++ debugToken2
+ )
+ }
+ }
+
+ logger.test( "Running tests " ++ _args.toList.toString )
+
+ val cache = cbtHome ++ "/cache"
+ val mavenCache = cache ++ "/maven"
+ val cbtHasChanged = true
+ def Resolver(urls: URL*) = MavenResolver(cbtHasChanged, mavenCache, urls: _*)
+
+ {
+ val noContext = ContextImplementation(
+ cbtHome ++ "/test/nothing",
+ cbtHome,
+ Array(),
+ Array(),
+ start,
+ cbtHasChanged,
+ null,
+ null,
+ new ConcurrentHashMap[String,AnyRef],
+ new ConcurrentHashMap[AnyRef,ClassLoader],
+ cache,
+ cbtHome,
+ cbtHome,
+ cbtHome ++ "/compatibilityTarget",
+ null
+ )
+
+ val b = new BasicBuild(noContext){
+ override def dependencies =
+ Resolver(mavenCentral).bind(
+ MavenDependency("net.incongru.watchservice","barbary-watchservice","1.0"),
+ MavenDependency("net.incongru.watchservice","barbary-watchservice","1.0")
+ )
+ }
+ val cp = b.classpath
+ assert(cp.strings.distinct == cp.strings, "duplicates in classpath: " ++ cp.string)
+ }
+
+ // test that messed up artifacts crash with an assertion (which should tell the user what's up)
+ assertException[AssertionError](){
+ Resolver(mavenCentral).bindOne( MavenDependency("com.jcraft", "jsch", " 0.1.53") ).classpath
+ }
+ assertException[AssertionError](){
+ Resolver(mavenCentral).bindOne( MavenDependency("com.jcraft", null, "0.1.53") ).classpath
+ }
+ assertException[AssertionError](){
+ Resolver(mavenCentral).bindOne( MavenDependency("com.jcraft", "", " 0.1.53") ).classpath
+ }
+ assertException[AssertionError](){
+ Resolver(mavenCentral).bindOne( MavenDependency("com.jcraft%", "jsch", " 0.1.53") ).classpath
+ }
+ assertException[AssertionError](){
+ Resolver(mavenCentral).bindOne( MavenDependency("", "jsch", " 0.1.53") ).classpath
+ }
+
+ (
+ (
+ if(System.getenv("CIRCLECI") == null){
+ // tenporarily disable on circleci as it seems to have trouble reliably
+ // downloading from bintray
+ Dependencies(
+ Resolver( bintray("tpolecat") ).bind(
+ lib.ScalaDependency("org.tpolecat","tut-core","0.4.2", scalaMajorVersion="2.11")
+ )
+ ).classpath.strings
+ } else Nil
+ ) ++
+ Dependencies(
+ Resolver( sonatypeReleases ).bind(
+ MavenDependency("org.cvogt","scala-extensions_2.11","0.5.1")
+ )
+ ).classpath.strings
+ ++
+ Dependencies(
+ Resolver( mavenCentral ).bind(
+ MavenDependency("ai.x","lens_2.11","1.0.0")
+ )
+ ).classpath.strings
+ ).foreach{
+ path => assert(new File(path).exists, path)
+ }
+
+ usage("nothing")
+ compile("nothing")
+ //clean("nothing")
+ usage("multi-build")
+ compile("multi-build")
+ clean("multi-build")
+ usage("simple")
+ compile("simple")
+ clean("simple")
+ usage("simple-fixed")
+ compile("simple-fixed")
+
+ compile("../plugins/sbt_layout")
+ compile("../plugins/scalafmt")
+ compile("../plugins/scalajs")
+ compile("../plugins/scalariform")
+ compile("../plugins/scalatest")
+ compile("../plugins/wartremover")
+ compile("../plugins/uber-jar")
+ compile("../examples/scalafmt-example")
+ compile("../examples/scalariform-example")
+ compile("../examples/scalatest-example")
+ compile("../examples/scalajs-react-example/js")
+ compile("../examples/scalajs-react-example/jvm")
+ compile("../examples/multi-project-example")
+ if(sys.props("java.version").startsWith("1.7")){
+ System.err.println("\nskipping dotty tests on Java 7")
+ } else {
+ compile("../examples/dotty-example")
+ task("run","../examples/dotty-example")
+ task("doc","../examples/dotty-example")
+ }
+ task("fastOptJS","../examples/scalajs-react-example/js")
+ task("fullOptJS","../examples/scalajs-react-example/js")
+ compile("../examples/uber-jar-example")
+
+ {
+ val res = task("docJar","simple-fixed-cbt")
+ assert( res.out endsWith "simple-fixed-cbt_2.11-0.1-javadoc.jar", res.out )
+ assert( res.err contains "model contains", res.err )
+ assert( res.err endsWith "documentable templates", res.err )
+ }
+
+ {
+ val res = runCbt("simple", Seq("printArgs","1","2","3"))
+ assert(res.exit0)
+ assert(res.out == "1 2 3", res.out)
+ }
+
+ {
+ val res = runCbt("../examples/build-info-example", Seq("run"))
+ assert(res.exit0)
+ assert(res.out contains "version: 0.1", res.out)
+ }
+
+ {
+ val res = runCbt("forgot-extend", Seq("run"))
+ assert(!res.exit0)
+ assert(res.err contains "Build cannot be cast to cbt.BuildInterface", res.err)
+ }
+
+ {
+ val res = runCbt("no-build-file", Seq("run"))
+ assert(!res.exit0)
+ assert(res.err contains "No file build.scala (lower case) found in", res.err)
+ }
+
+ {
+ val res = runCbt("empty-build-file", Seq("run"))
+ assert(!res.exit0)
+ assert(res.err contains "You need to define a class Build in build.scala in", res.err)
+ }
+
+ {
+ val res = runCbt("../examples/wartremover-example", Seq("compile"))
+ assert(!res.exit0)
+ assert(res.err.contains("var is disabled"), res.out)
+ assert(res.err.contains("null is disabled"), res.out)
+ }
+
+ System.err.println(" DONE!")
+ System.err.println( successes.toString ++ " succeeded, "++ failures.toString ++ " failed" )
+ if(failures > 0) System.exit(1) else System.exit(0)
+ }
+}