summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-06-19 10:38:50 -0700
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-06-19 10:38:50 -0700
commite2b4db06f20894b6f14b929c1d2c7f15e1af68ee (patch)
treeda05f3c2cd1615675765e851603cf85740ba3564
parent97271ef9f75296d6b3b5ef10ec361c70591a6a27 (diff)
parent173e709017f5cd489e5526bec92da8dc904fc436 (diff)
downloadscala-e2b4db06f20894b6f14b929c1d2c7f15e1af68ee.tar.gz
scala-e2b4db06f20894b6f14b929c1d2c7f15e1af68ee.tar.bz2
scala-e2b4db06f20894b6f14b929c1d2c7f15e1af68ee.zip
Merge pull request #2657 from gkossakowski/junit-master
Merge JUnit support into master
-rwxr-xr-xbuild.xml60
-rw-r--r--src/eclipse/README.md3
-rw-r--r--src/eclipse/test-junit/.classpath12
-rw-r--r--src/eclipse/test-junit/.project35
-rw-r--r--test/files/run/WeakHashSetTest.scala174
-rw-r--r--test/junit/scala/reflect/internal/util/WeakHashSetTest.scala171
-rw-r--r--test/junit/scala/tools/nsc/SampleTest.scala17
7 files changed, 296 insertions, 176 deletions
diff --git a/build.xml b/build.xml
index ea213d2d6e..2af335d6ab 100755
--- a/build.xml
+++ b/build.xml
@@ -137,6 +137,7 @@ TODO:
<property name="build-quick.dir" value="${build.dir}/quick"/>
<property name="build-pack.dir" value="${build.dir}/pack"/>
<property name="build-osgi.dir" value="${build.dir}/osgi"/>
+ <property name="build-junit.dir" value="${build.dir}/junit"/>
<property name="build-strap.dir" value="${build.dir}/strap"/>
<property name="build-docs.dir" value="${build.dir}/scaladoc"/>
<property name="build-sbt.dir" value="${build.dir}/sbt-interface"/>
@@ -144,6 +145,9 @@ TODO:
<property name="test.osgi.src" value="${partest.dir}/osgi/src"/>
<property name="test.osgi.classes" value="${build-osgi.dir}/classes"/>
+ <property name="test.junit.src" value="${partest.dir}/junit"/>
+ <property name="test.junit.classes" value="${build-junit.dir}/classes"/>
+
<property name="dists.dir" value="${basedir}/dists"/>
<property name="copyright.string" value="Copyright 2002-2013, LAMP/EPFL"/>
@@ -208,6 +212,12 @@ TODO:
<dependency groupId="biz.aQute" artifactId="bnd" version="1.50.0"/>
</artifact:dependencies>
+ <!-- JUnit -->
+ <property name="junit.version" value="4.10"/>
+ <artifact:dependencies pathId="junit.classpath" filesetId="junit.fileset">
+ <dependency groupId="junit" artifactId="junit" version="${junit.version}"/>
+ </artifact:dependencies>
+
<!-- Pax runner -->
<property name="pax.exam.version" value="2.5.0"/>
<artifact:dependencies pathId="pax.exam.classpath" filesetId="pax.exam.fileset">
@@ -218,10 +228,11 @@ TODO:
<dependency groupId="org.ops4j.pax.swissbox" artifactId="pax-swissbox-framework" version="1.5.1"/>
<dependency groupId="ch.qos.logback" artifactId="logback-core" version="0.9.20"/>
<dependency groupId="ch.qos.logback" artifactId="logback-classic" version="0.9.20"/>
- <dependency groupId="junit" artifactId="junit" version="4.10"/>
+ <dependency groupId="junit" artifactId="junit" version="${junit.version}"/>
<dependency groupId="org.apache.felix" artifactId="org.apache.felix.framework" version="3.2.2"/>
</artifact:dependencies>
+
<artifact:dependencies pathId="partest.extras.classpath" filesetId="partest.extras.fileset" versionsId="partest.extras.versions">
<dependency groupId="com.googlecode.java-diff-utils" artifactId="diffutils" version="1.3.0"/>
<dependency groupId="org.scala-tools.testing" artifactId="test-interface" version="0.5" />
@@ -673,6 +684,12 @@ TODO:
</path>
-->
+ <path id="test.junit.compiler.build.path">
+ <pathelement location="${test.junit.classes}"/>
+ <path refid="quick.compiler.build.path"/>
+ <path refid="junit.classpath"/>
+ </path>
+
<path id="test.osgi.compiler.build.path">
<pathelement location="${test.osgi.classes}"/>
<pathelement location="${build-osgi.dir}/org.scala-lang.scala-library.jar"/>
@@ -1437,6 +1454,45 @@ TODO:
<stopwatch name="quick.sbt-interface.timer" action="total"/>
</target>
+ <target name="test.junit.init" depends="quick.done">
+ <uptodate property="test.junit.available" targetfile="${build-junit.dir}/test-compile.complete">
+ <srcfiles dir="${test.junit.src}">
+ <include name="**/*.scala"/>
+ </srcfiles>
+ </uptodate>
+ </target>
+
+ <target name="test.junit.comp" depends="test.junit.init, quick.done" unless="test.junit.available">
+ <stopwatch name="test.junit.compiler.timer"/>
+ <mkdir dir="${test.junit.classes}"/>
+ <scalacfork
+ destdir="${test.junit.classes}"
+ compilerpathref="quick.compiler.path"
+ params="${scalac.args.quick}"
+ srcdir="${test.junit.src}"
+ jvmargs="${scalacfork.jvmargs}">
+ <include name="**/*.scala"/>
+ <compilationpath refid="test.junit.compiler.build.path"/>
+ </scalacfork>
+ <touch file="${build-junit.dir}/test-compile.complete" verbose="no"/>
+ <stopwatch name="test.junit.compiler.timer" action="total"/>
+ </target>
+
+ <target name="test.junit" depends="test.junit.comp">
+ <stopwatch name="test.junit.timer"/>
+ <mkdir dir="${test.junit.classes}"/>
+ <junit fork="yes" haltonfailure="yes" showoutput="yes" printsummary="on">
+ <classpath refid="test.junit.compiler.build.path"/>
+ <batchtest fork="yes" todir="${build-junit.dir}">
+ <fileset dir="${test.junit.classes}">
+ <include name="**/*Test.class"/>
+ </fileset>
+ </batchtest>
+ <formatter type="plain"/>
+ </junit>
+ <stopwatch name="test.junit.timer" action="total"/>
+ </target>
+
<!-- See test/build-partest.xml for the macro(s) being used here. -->
<target name="test.suite" depends="pack.done">
@@ -1467,7 +1523,7 @@ TODO:
<!-- for use in PR validation, where stability is rarely broken, so we're going to use starr for locker,
and skip test.stability (which requires locker == quick) -->
- <target name="test.core" depends="test.osgi, test.sbt, test.bc, test.interactive, test.continuations.suite, test.scaladoc, test.suite"/>
+ <target name="test.core" depends="test.osgi, test.sbt, test.bc, test.junit, test.interactive, test.continuations.suite, test.scaladoc, test.suite"/>
<target name="test.done" depends="test.core, test.stability"/>
<!-- ===========================================================================
diff --git a/src/eclipse/README.md b/src/eclipse/README.md
index 73aa270b77..2bb1a4da8f 100644
--- a/src/eclipse/README.md
+++ b/src/eclipse/README.md
@@ -11,6 +11,9 @@ IMPORTANT
Preferences/General/Workspace/Linked Resources. The value should be the absolute
path to your scala checkout. All paths in project files are relative to this one,
so nothing will work before you do so.
+Additionally, we start using Maven dependencies (e.g. junit) so you need to define
+`classpath variable` inside Eclipse. Define `M2_REPO` in Java/Build Path/Classpath Variables
+to point to your local Maven repository (e.g. $HOME/.m2/repository).
2. The Eclipse Java compiler does not allow certain calls to restricted APIs in the
JDK. The Scala library uses such APIs, so you'd see this error:
diff --git a/src/eclipse/test-junit/.classpath b/src/eclipse/test-junit/.classpath
new file mode 100644
index 0000000000..718f7b6ece
--- /dev/null
+++ b/src/eclipse/test-junit/.classpath
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="test-junit"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/reflect"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/scala-library"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="lib/ant/ant.jar"/>
+ <classpathentry kind="lib" path="lib/jline.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/scala-compiler"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.10/junit-4.10.jar"/>
+ <classpathentry kind="output" path="build-test-junit"/>
+</classpath>
diff --git a/src/eclipse/test-junit/.project b/src/eclipse/test-junit/.project
new file mode 100644
index 0000000000..052b6c1b6f
--- /dev/null
+++ b/src/eclipse/test-junit/.project
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>test-junit</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.scala-ide.sdt.core.scalabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.scala-ide.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>build-test-junit</name>
+ <type>2</type>
+ <locationURI>SCALA_BASEDIR/build/junit/classes</locationURI>
+ </link>
+ <link>
+ <name>lib</name>
+ <type>2</type>
+ <locationURI>SCALA_BASEDIR/lib</locationURI>
+ </link>
+ <link>
+ <name>test-junit</name>
+ <type>2</type>
+ <locationURI>SCALA_BASEDIR/test/junit</locationURI>
+ </link>
+ </linkedResources>
+</projectDescription>
diff --git a/test/files/run/WeakHashSetTest.scala b/test/files/run/WeakHashSetTest.scala
deleted file mode 100644
index 3c8f380150..0000000000
--- a/test/files/run/WeakHashSetTest.scala
+++ /dev/null
@@ -1,174 +0,0 @@
-object Test {
- def main(args: Array[String]) {
- val test = scala.reflect.internal.util.WeakHashSetTest
- test.checkEmpty
- test.checkPlusEquals
- test.checkPlusEqualsCollisions
- test.checkRehashing
- test.checkRehashCollisions
- test.checkFindOrUpdate
- test.checkMinusEquals
- test.checkMinusEqualsCollisions
- test.checkClear
- test.checkIterator
- test.checkIteratorCollisions
-
- // This test is commented out because it relies on gc behavior which isn't reliable enough in an automated environment
- // test.checkRemoveUnreferencedObjects
- }
-}
-
-// put the main test object in the same package as WeakHashSet because
-// it uses the package private "diagnostics" method
-package scala.reflect.internal.util {
-
- object WeakHashSetTest {
- // a class guaranteed to provide hash collisions
- case class Collider(x : String) extends Comparable[Collider] with Serializable {
- override def hashCode = 0
- def compareTo(y : Collider) = this.x compareTo y.x
- }
-
- // basic emptiness check
- def checkEmpty {
- val hs = new WeakHashSet[String]()
- assert(hs.size == 0)
- hs.diagnostics.fullyValidate
- }
-
- // make sure += works
- def checkPlusEquals {
- val hs = new WeakHashSet[String]()
- val elements = List("hello", "goodbye")
- elements foreach (hs += _)
- assert(hs.size == 2)
- assert(hs contains "hello")
- assert(hs contains "goodbye")
- hs.diagnostics.fullyValidate
- }
-
- // make sure += works when there are collisions
- def checkPlusEqualsCollisions {
- val hs = new WeakHashSet[Collider]()
- val elements = List("hello", "goodbye") map Collider
- elements foreach (hs += _)
- assert(hs.size == 2)
- assert(hs contains Collider("hello"))
- assert(hs contains Collider("goodbye"))
- hs.diagnostics.fullyValidate
- }
-
- // add a large number of elements to force rehashing and then validate
- def checkRehashing {
- val size = 200
- val hs = new WeakHashSet[String]()
- val elements = (0 until size).toList map ("a" + _)
- elements foreach (hs += _)
- elements foreach {i => assert(hs contains i)}
- hs.diagnostics.fullyValidate
- }
-
- // make sure rehashing works properly when the set is rehashed
- def checkRehashCollisions {
- val size = 200
- val hs = new WeakHashSet[Collider]()
- val elements = (0 until size).toList map {x => Collider("a" + x)}
- elements foreach (hs += _)
- elements foreach {i => assert(hs contains i)}
- hs.diagnostics.fullyValidate
- }
-
- // test that unreferenced objects are removed
- // not run in an automated environment because gc behavior can't be relied on
- def checkRemoveUnreferencedObjects {
- val size = 200
- val hs = new WeakHashSet[Collider]()
- val elements = (0 until size).toList map {x => Collider("a" + x)}
- elements foreach (hs += _)
- // don't throw the following into a retained collection so gc
- // can remove them
- for (i <- 0 until size) {
- hs += Collider("b" + i)
- }
- System.gc()
- Thread.sleep(1000)
- assert(hs.size == 200)
- elements foreach {i => assert(hs contains i)}
- for (i <- 0 until size) {
- assert(!(hs contains Collider("b" + i)))
- }
- hs.diagnostics.fullyValidate
- }
-
- // make sure findOrUpdate returns the originally entered element
- def checkFindOrUpdate {
- val size = 200
- val hs = new WeakHashSet[Collider]()
- val elements = (0 until size).toList map {x => Collider("a" + x)}
- elements foreach {x => assert(hs findEntryOrUpdate x eq x)}
- for (i <- 0 until size) {
- // when we do a lookup the result should be the same reference we
- // original put in
- assert(hs findEntryOrUpdate(Collider("a" + i)) eq elements(i))
- }
- hs.diagnostics.fullyValidate
- }
-
- // check -= functionality
- def checkMinusEquals {
- val hs = new WeakHashSet[String]()
- val elements = List("hello", "goodbye")
- elements foreach (hs += _)
- hs -= "goodbye"
- assert(hs.size == 1)
- assert(hs contains "hello")
- assert(!(hs contains "goodbye"))
- hs.diagnostics.fullyValidate
- }
-
- // check -= when there are collisions
- def checkMinusEqualsCollisions {
- val hs = new WeakHashSet[Collider]
- val elements = List(Collider("hello"), Collider("goodbye"))
- elements foreach (hs += _)
- hs -= Collider("goodbye")
- assert(hs.size == 1)
- assert(hs contains Collider("hello"))
- assert(!(hs contains Collider("goodbye")))
- hs -= Collider("hello")
- assert(hs.size == 0)
- assert(!(hs contains Collider("hello")))
- hs.diagnostics.fullyValidate
- }
-
- // check that the clear method actually cleans everything
- def checkClear {
- val size = 200
- val hs = new WeakHashSet[String]()
- val elements = (0 until size).toList map ("a" + _)
- elements foreach (hs += _)
- hs.clear()
- assert(hs.size == 0)
- elements foreach {i => assert(!(hs contains i))}
- hs.diagnostics.fullyValidate
- }
-
- // check that the iterator covers all the contents
- def checkIterator {
- val hs = new WeakHashSet[String]()
- val elements = (0 until 20).toList map ("a" + _)
- elements foreach (hs += _)
- assert(elements.iterator.toList.sorted == elements.sorted)
- hs.diagnostics.fullyValidate
- }
-
- // check that the iterator covers all the contents even when there is a collision
- def checkIteratorCollisions {
- val hs = new WeakHashSet[Collider]
- val elements = (0 until 20).toList map {x => Collider("a" + x)}
- elements foreach (hs += _)
- assert(elements.iterator.toList.sorted == elements.sorted)
- hs.diagnostics.fullyValidate
- }
- }
-}
diff --git a/test/junit/scala/reflect/internal/util/WeakHashSetTest.scala b/test/junit/scala/reflect/internal/util/WeakHashSetTest.scala
new file mode 100644
index 0000000000..7e3b35c7d6
--- /dev/null
+++ b/test/junit/scala/reflect/internal/util/WeakHashSetTest.scala
@@ -0,0 +1,171 @@
+package scala.reflect.internal.util
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class WeakHashSetTest {
+
+ // a class guaranteed to provide hash collisions
+ case class Collider(x : String) extends Comparable[Collider] with Serializable {
+ override def hashCode = 0
+ def compareTo(y : Collider) = this.x compareTo y.x
+ }
+
+ // basic emptiness check
+ @Test
+ def checkEmpty {
+ val hs = new WeakHashSet[String]()
+ assert(hs.size == 0)
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure += works
+ @Test
+ def checkPlusEquals {
+ val hs = new WeakHashSet[String]()
+ val elements = List("hello", "goodbye")
+ elements foreach (hs += _)
+ assert(hs.size == 2)
+ assert(hs contains "hello")
+ assert(hs contains "goodbye")
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure += works when there are collisions
+ @Test
+ def checkPlusEqualsCollisions {
+ val hs = new WeakHashSet[Collider]()
+ val elements = List("hello", "goodbye") map Collider
+ elements foreach (hs += _)
+ assert(hs.size == 2)
+ assert(hs contains Collider("hello"))
+ assert(hs contains Collider("goodbye"))
+ hs.diagnostics.fullyValidate
+ }
+
+ // add a large number of elements to force rehashing and then validate
+ @Test
+ def checkRehashing {
+ val size = 200
+ val hs = new WeakHashSet[String]()
+ val elements = (0 until size).toList map ("a" + _)
+ elements foreach (hs += _)
+ elements foreach {i => assert(hs contains i)}
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure rehashing works properly when the set is rehashed
+ @Test
+ def checkRehashCollisions {
+ val size = 200
+ val hs = new WeakHashSet[Collider]()
+ val elements = (0 until size).toList map {x => Collider("a" + x)}
+ elements foreach (hs += _)
+ elements foreach {i => assert(hs contains i)}
+ hs.diagnostics.fullyValidate
+ }
+
+ // test that unreferenced objects are removed
+ // not run in an automated environment because gc behavior can't be relied on
+ //@Test
+ def checkRemoveUnreferencedObjects {
+ val size = 200
+ val hs = new WeakHashSet[Collider]()
+ val elements = (0 until size).toList map {x => Collider("a" + x)}
+ elements foreach (hs += _)
+ // don't throw the following into a retained collection so gc
+ // can remove them
+ for (i <- 0 until size) {
+ hs += Collider("b" + i)
+ }
+ System.gc()
+ Thread.sleep(1000)
+ assert(hs.size == 200)
+ elements foreach {i => assert(hs contains i)}
+ for (i <- 0 until size) {
+ assert(!(hs contains Collider("b" + i)))
+ }
+ hs.diagnostics.fullyValidate
+ }
+
+ // make sure findOrUpdate returns the originally entered element
+ @Test
+ def checkFindOrUpdate {
+ val size = 200
+ val hs = new WeakHashSet[Collider]()
+ val elements = (0 until size).toList map {x => Collider("a" + x)}
+ elements foreach {x => assert(hs findEntryOrUpdate x eq x)}
+ for (i <- 0 until size) {
+ // when we do a lookup the result should be the same reference we
+ // original put in
+ assert(hs findEntryOrUpdate(Collider("a" + i)) eq elements(i))
+ }
+ hs.diagnostics.fullyValidate
+ }
+
+ // check -= functionality
+ @Test
+ def checkMinusEquals {
+ val hs = new WeakHashSet[String]()
+ val elements = List("hello", "goodbye")
+ elements foreach (hs += _)
+ hs -= "goodbye"
+ assert(hs.size == 1)
+ assert(hs contains "hello")
+ assert(!(hs contains "goodbye"))
+ hs.diagnostics.fullyValidate
+ }
+
+ // check -= when there are collisions
+ @Test
+ def checkMinusEqualsCollisions {
+ val hs = new WeakHashSet[Collider]
+ val elements = List(Collider("hello"), Collider("goodbye"))
+ elements foreach (hs += _)
+ hs -= Collider("goodbye")
+ assert(hs.size == 1)
+ assert(hs contains Collider("hello"))
+ assert(!(hs contains Collider("goodbye")))
+ hs -= Collider("hello")
+ assert(hs.size == 0)
+ assert(!(hs contains Collider("hello")))
+ hs.diagnostics.fullyValidate
+ }
+
+ // check that the clear method actually cleans everything
+ @Test
+ def checkClear {
+ val size = 200
+ val hs = new WeakHashSet[String]()
+ val elements = (0 until size).toList map ("a" + _)
+ elements foreach (hs += _)
+ hs.clear()
+ assert(hs.size == 0)
+ elements foreach {i => assert(!(hs contains i))}
+ hs.diagnostics.fullyValidate
+ }
+
+ // check that the iterator covers all the contents
+ @Test
+ def checkIterator {
+ val hs = new WeakHashSet[String]()
+ val elements = (0 until 20).toList map ("a" + _)
+ elements foreach (hs += _)
+ assert(elements.iterator.toList.sorted == elements.sorted)
+ hs.diagnostics.fullyValidate
+ }
+
+ // check that the iterator covers all the contents even when there is a collision
+ @Test
+ def checkIteratorCollisions {
+ val hs = new WeakHashSet[Collider]
+ val elements = (0 until 20).toList map {x => Collider("a" + x)}
+ elements foreach (hs += _)
+ assert(elements.iterator.toList.sorted == elements.sorted)
+ hs.diagnostics.fullyValidate
+ }
+
+}
diff --git a/test/junit/scala/tools/nsc/SampleTest.scala b/test/junit/scala/tools/nsc/SampleTest.scala
new file mode 100644
index 0000000000..8e026da1ea
--- /dev/null
+++ b/test/junit/scala/tools/nsc/SampleTest.scala
@@ -0,0 +1,17 @@
+package scala.tools.nsc
+package test
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+/** Sample JUnit test that shows that all pieces
+ of JUnit infrastructure work correctly */
+@RunWith(classOf[JUnit4])
+class SampleTest {
+ @Test
+ def testMath: Unit = {
+ assert(2+2 == 4, "you didn't get the math right fellow")
+ }
+}