Skip to content

Commit

Permalink
[split] scrooge: use scalatest, remove specs
Browse files Browse the repository at this point in the history
RB_ID=263371
  • Loading branch information
David Helder authored and CI committed Jan 9, 2014
1 parent 03ca491 commit 08a5d46
Show file tree
Hide file tree
Showing 27 changed files with 1,711 additions and 1,394 deletions.
6 changes: 0 additions & 6 deletions demos/scrooge-maven-demo/pom.xml
Expand Up @@ -72,12 +72,6 @@
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs_2.9.1</artifactId>
<version>1.6.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
Expand Down
@@ -1,17 +1,21 @@
package com.twitter.example

import org.specs.SpecificationWithJUnit
import org.junit.runner.RunWith
import org.scalatest.WordSpec
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.MustMatchers
import com.twitter.mydemo.renamed.User

class DemoSpec extends SpecificationWithJUnit {
@RunWith(classOf[JUnitRunner])
class DemoSpec extends WordSpec with MustMatchers {
def printUser(user: User) {println("User %s, id %d".format(user.name, user.id))}

"generated finagle service" should {
"server and client" in {
val server = DemoServer.buildServer()
val client = DemoClient.buildClient(server.localAddress)
client.createUser("Tyrion")().name mustEqual("Tyrion")
client.createUser("Jon")().name mustEqual("Jon")
client.createUser("Tyrion")().name must be("Tyrion")
client.createUser("Jon")().name must be("Jon")
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions project/Build.scala
Expand Up @@ -79,12 +79,7 @@ object Scrooge extends Build {
otherResolvers += m2Repo,

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" %"1.9.1" % "test",
"org.scala-tools.testing" %% "specs" % "1.6.9" % "test" cross CrossVersion.binaryMapped {
case "2.9.2" => "2.9.1"
case "2.10.0" => "2.10"
case x => x
},
"org.scalatest" %% "scalatest" % "1.9.1" % "test",
"junit" % "junit" % "4.8.1" % "test"
),
resolvers += "twitter-repo" at "http://maven.twttr.com",
Expand Down
12 changes: 6 additions & 6 deletions scrooge-generator/pom.xml
Expand Up @@ -56,12 +56,6 @@
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs_2.9.1</artifactId>
<version>1.6.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
Expand All @@ -80,6 +74,12 @@
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.2</artifactId>
<version>1.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
Expand Down
Expand Up @@ -48,7 +48,7 @@ object Main {
val oldGenMap = new mutable.HashMap[String, File]
if (newGenMap.size != oldGenMap.size) {
println("Wrong number of files generated")
exit(1)
sys.exit(1)
}
FileUtils.getFiles(new File(compiler.destFolder), "**/*.java", "") foreach { s =>
val file = s.asInstanceOf[File]
Expand Down
23 changes: 11 additions & 12 deletions scrooge-generator/src/test/scala/com/twitter/scrooge/ASTSpec.scala
@@ -1,18 +1,18 @@
package com.twitter.scrooge.ast

import org.specs.SpecificationWithJUnit
import com.twitter.scrooge.testutil.Spec

class ASTSpec extends SpecificationWithJUnit {
class ASTSpec extends Spec {
"Namespace" should {
"generate correct namespace from java" in {
val doc = Document(Seq(Namespace("java", Identifier("com.twitter.oatmeal"))), Nil)
doc.namespace("java").isDefined must beTrue
doc.namespace("java").get.fullName mustEqual ("com.twitter.oatmeal")
doc.namespace("java").isDefined must be(true)
doc.namespace("java").get.fullName must be("com.twitter.oatmeal")
}

"reject undefined namespace" in {
val doc = Document(Seq(Namespace("warble", Identifier("com.twitter.oatmeal"))), Nil)
doc.namespace("garble") mustEqual None
doc.namespace("garble") must be(None)
}

"map namespaces" in {
Expand All @@ -21,8 +21,8 @@ class ASTSpec extends SpecificationWithJUnit {
val rbOatmealNs = Namespace("rb", Identifier("Oatmeal"))
val doc = Document(Seq(javaOatmealNs, rbOatmealNs), Nil)
val namespaceMap = Map(javaOatmealNs.id.fullName -> javaGranolaNs.id.fullName)
doc.mapNamespaces(namespaceMap) mustEqual
Document(Seq(javaGranolaNs, rbOatmealNs), Nil)
doc.mapNamespaces(namespaceMap) must be(
Document(Seq(javaGranolaNs, rbOatmealNs), Nil))
}

"map namespaces recursively" in {
Expand All @@ -31,10 +31,9 @@ class ASTSpec extends SpecificationWithJUnit {
val doc1 = Document(Seq(javaOatmealNs), Nil)
val doc2 = Document(Seq(javaOatmealNs, Include("other", doc1)), Nil)
val namespaceMap = Map(javaOatmealNs.id.fullName -> javaGranolaNs.id.fullName)
doc2.mapNamespaces(namespaceMap) must beLike {
doc2.mapNamespaces(namespaceMap) match {
case Document(Seq(javaGranolaNs, Include(_, included)), Nil) =>
included mustEqual Document(Seq(javaGranolaNs), Nil)
true
included must be(Document(Seq(javaGranolaNs), Nil))
}
}
}
Expand Down Expand Up @@ -68,15 +67,15 @@ class ASTSpec extends SpecificationWithJUnit {
simpleCases foreach {
case (input, (expected, _)) =>
val sid = SimpleID(input)
sid.toCamelCase.name mustEqual expected
sid.toCamelCase.name must be(expected)
}
}

"title case conversion" in {
simpleCases foreach {
case (input, (_, expected)) =>
val sid = SimpleID(input)
sid.toTitleCase.name mustEqual expected
sid.toTitleCase.name must be(expected)
}
}
}
Expand Down
Expand Up @@ -2,10 +2,9 @@ package com.twitter.scrooge

import java.io.{FileWriter, File}
import scala.io.Source
import org.specs.SpecificationWithJUnit
import com.twitter.scrooge.testutil.TempDirectory
import com.twitter.scrooge.testutil.{Spec, TempDirectory}

class MainSpec extends SpecificationWithJUnit {
class MainSpec extends Spec {
"Scrooge Main" should {
"gen file mapping with absolute paths" in {
val inDir = TempDirectory.create(None)
Expand Down Expand Up @@ -51,6 +50,6 @@ struct Point {
input.getPath + " -> " + buildPath(outDir.getPath, "MyTest", "Constants.scala") + "\n" +
input.getPath + " -> " + buildPath(outDir.getPath, "MyTest", "Direction.scala") + "\n" +
input.getPath + " -> " + buildPath(outDir.getPath, "MyTest", "Point.scala")+ "\n"
manifestString mustEqual expected
manifestString must be(expected)
}
}
@@ -1,48 +1,48 @@
package com.twitter.scrooge

import com.twitter.scrooge.testutil.Spec
import org.apache.thrift.protocol.TType
import org.specs.SpecificationWithJUnit
import scala.collection.{Map, Set}
import thrift.test._

// This is a cross project test and I feel bad for putting it here
// but scrooge-generator already has all the infrastructure to do
// generation and testing and anyway requires scrooge-runtime for
// tests.
class ThriftStructMetaDataSpec extends SpecificationWithJUnit {
class ThriftStructMetaDataSpec extends Spec {
"Provide useful metadata" in {
val s = XtructColl(Map(1 -> 2L), Seq("test"), Set(10.toByte), 123)
val metaData = XtructColl.metaData

assert(metaData.codecClass == XtructColl.getClass) // mustEqual doesn't work here
metaData.structClassName mustEqual "thrift.test.XtructColl"
metaData.structName mustEqual "XtructColl"
metaData.structClass mustEqual classOf[XtructColl]
metaData.structClassName must be("thrift.test.XtructColl")
metaData.structName must be("XtructColl")
metaData.structClass must be(classOf[XtructColl])

val Seq(f1, f2, f3, f4) = metaData.fields.sortBy(_.id)

f1.name mustEqual "a_map"
f1.id mustEqual 1
f1.`type` mustEqual TType.MAP
f1.manifest mustEqual Some(implicitly[Manifest[Map[Int, Long]]])
f1.getValue[Map[Int, Long]](s) mustEqual Map(1 -> 2L)

f2.name mustEqual "a_list"
f2.id mustEqual 2
f2.`type` mustEqual TType.LIST
f2.manifest mustEqual Some(implicitly[Manifest[Seq[String]]])
f2.getValue[Seq[String]](s) mustEqual Seq("test")

f3.name mustEqual "a_set"
f3.id mustEqual 3
f3.`type` mustEqual TType.SET
f3.manifest mustEqual Some(implicitly[Manifest[Set[Byte]]])
f3.getValue[Set[Byte]](s) mustEqual Set(10.toByte)

f4.name mustEqual "non_col"
f4.id mustEqual 4
f4.`type` mustEqual TType.I32
f4.manifest mustEqual Some(implicitly[Manifest[Int]])
f4.getValue[Int](s) mustEqual 123
f1.name must be("a_map")
f1.id must be(1)
f1.`type` must be(TType.MAP)
f1.manifest must be(Some(implicitly[Manifest[Map[Int, Long]]]))
f1.getValue[Map[Int, Long]](s) must be(Map(1 -> 2L))

f2.name must be("a_list")
f2.id must be(2)
f2.`type` must be(TType.LIST)
f2.manifest must be(Some(implicitly[Manifest[Seq[String]]]))
f2.getValue[Seq[String]](s) must be(Seq("test"))

f3.name must be("a_set")
f3.id must be(3)
f3.`type` must be(TType.SET)
f3.manifest must be(Some(implicitly[Manifest[Set[Byte]]]))
f3.getValue[Set[Byte]](s) must be(Set(10.toByte))

f4.name must be("non_col")
f4.id must be(4)
f4.`type` must be(TType.I32)
f4.manifest must be(Some(implicitly[Manifest[Int]]))
f4.getValue[Int](s) must be(123)
}
}
@@ -1,7 +1,7 @@
package com.twitter.scrooge.backend

import org.specs.SpecificationWithJUnit
import com.twitter.scrooge.frontend.ResolvedDocument
import com.twitter.scrooge.testutil.Spec

class TestGeneratorFactory extends GeneratorFactory {
val lang = "test"
Expand All @@ -13,11 +13,11 @@ class TestGeneratorFactory extends GeneratorFactory {
): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, generationDate, experimentFlags)
}

class GeneratorFactorySpec extends SpecificationWithJUnit {
class GeneratorFactorySpec extends Spec {
"GeneratorFactory" should {
"be loadable" in {
val generator = Generator("test", Map.empty[String, ResolvedDocument], "", "", Seq.empty[String])
generator must haveClass[ScalaGenerator]
generator.isInstanceOf[ScalaGenerator] must be(true)
}
}
}
@@ -1,18 +1,18 @@
package com.twitter.scrooge.backend

import org.specs.SpecificationWithJUnit
import com.twitter.scrooge.testutil.Spec
import org.apache.thrift.protocol.TBinaryProtocol
import org.apache.thrift.transport.TMemoryBuffer

class ImmutableStructSpec extends SpecificationWithJUnit {
class ImmutableStructSpec extends Spec {

"Scala objects" should {
import thrift.test._
"encode and decode" in {
val protocol = new TBinaryProtocol(new TMemoryBuffer(10000))
val originalBonk = Bonk("This is Bonk message", 13)
Bonk.encode(originalBonk, protocol)
Bonk.decode(protocol) mustEqual(originalBonk)
Bonk.decode(protocol) must be(originalBonk)
}

"deep copy" in {
Expand Down Expand Up @@ -49,10 +49,10 @@ class ImmutableStructSpec extends SpecificationWithJUnit {
structThing = xtructSwapped
)
)
copied.x1 mustEqual(nested.x1)
copied.x2.structThing must_!=(nested.x2.structThing) //swapped
copied.x2 must_!=(nested.x2)
copied.x3 mustEqual(nested.x3)
copied.x1 must be(nested.x1)
copied.x2.structThing must not be(nested.x2.structThing) //swapped
copied.x2 must not be(nested.x2)
copied.x3 must be(nested.x3)
}
}

Expand All @@ -62,7 +62,7 @@ class ImmutableStructSpec extends SpecificationWithJUnit {
val protocol = new TBinaryProtocol(new TMemoryBuffer(10000))
val originalBonk = new Bonk("This is Bonk message", 13)
Bonk.encode(originalBonk, protocol)
Bonk.decode(protocol) mustEqual(originalBonk)
Bonk.decode(protocol) must be(originalBonk)
}

"deep copy" in {
Expand Down Expand Up @@ -96,13 +96,13 @@ class ImmutableStructSpec extends SpecificationWithJUnit {
.x2(xtruct2.copy().structThing(xtructSwapped).build())
.build()

copied.getX1 mustEqual(nested.getX1)
copied.getX2.getStructThing must_!=(nested.getX2.getStructThing) //swapped
copied.getX2 must_!=(nested.getX2)
copied.getX3 mustEqual(nested.getX3)
copied.getX1 must be(nested.getX1)
copied.getX2.getStructThing must not be(nested.getX2.getStructThing) //swapped
copied.getX2 must not be(nested.getX2)
copied.getX3 must be(nested.getX3)

val copiedPartial = nested.copy().unsetX2().build()
copiedPartial.isSetX2 must beFalse
copiedPartial.isSetX2 must be(false)
}
}
}

0 comments on commit 08a5d46

Please sign in to comment.