8000 Some tests on jdk10 by som-snytt · Pull Request #6889 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Some tests on jdk10 #6889

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

8000
Merged
merged 3 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Unit test fixes
  • Loading branch information
som-snytt committed Jul 14, 2018
commit 8599598443fcc9c1692725aa75877072454f664c
9 changes: 7 additions & 2 deletions test/junit/scala/SerializationStabilityTest.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scala

import javax.xml.bind.DatatypeConverter._
import scala.reflect.io.File
import java.util.Base64
import org.junit.Test

// This test is self-modifying when run as follows:
Expand All @@ -12,6 +12,11 @@ import org.junit.Test

// based on run/t8549.scala partest
object SerializationStability {

def parseBase64Binary(s: String): Array[Byte] = Base64.getDecoder.decode(s)

def printBase64Binary(data: Array[Byte]): String = Base64.getEncoder.encode(data).map(_.toChar).mkString

val overwrite: Option[File] = sys.props.get("overwrite.source").map(s => new File(new java.io.File(s)))

def serialize(o: AnyRef): String = {
Expand Down Expand Up @@ -219,4 +224,4 @@ object SerializationStability {
class SerializationStabilityTest {
@Test
def testAll: Unit = SerializationStability.main(new Array[String](0))
}
}
2 changes: 1 addition & 1 deletion test/junit/scala/lang/annotations/RunTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RunTest extends RunTesting {
@Test
def annotationInfoNotErased(): Unit = {
val code =
"""import javax.annotation.Resource
"""import scala.tools.testing.Resource
|import scala.annotation.meta.getter
|class C {
| type Rg = Resource @getter
Expand Down
2 changes: 1 addition & 1 deletion test/junit/scala/reflect/ClassOfTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ClassOfTest extends RunTesting {
@Test
def t9702(): Unit = {
val code =
"""import javax.annotation.Resource
"""import scala.tools.testing.Resource
|import scala.reflect.ClassOfTest.VC
|class C {
| type aList[K] = List[K]
Expand Down
6 changes: 3 additions & 3 deletions test/junit/scala/tools/nsc/backend/jvm/opt/BoxUnboxTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class BoxUnboxTest extends BytecodeTesting {
| }
|
| def t6: Long = {
| val y = new java.lang.Boolean(true)
| val i: Integer = if (y) new Integer(10) else 13
| val y = java.lang.Boolean.valueOf(true)
| val i: Integer = if (y) Integer.valueOf(10) else 13
| val j: java.lang.Long = 3l
| j + i
| }
Expand Down Expand Up @@ -273,7 +273,7 @@ class BoxUnboxTest extends BytecodeTesting {
|
| def t3 = {
| // boxed before tuple creation, a non-specialized tuple is created
| val t = (new Integer(3), Integer.valueOf(4))
| val t = (Integer.valueOf(3), Integer.valueOf(4))
| t._1 + t._2 // invokes the generic `_1` / `_2` getters, both values unboxed by Integer2int
| }
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scala.collection.immutable.IntMap
import scala.tools.asm.tree._
import scala.tools.nsc.backend.jvm.BackendReporting._
import scala.tools.nsc.reporters.StoreReporter
import scala.tools.testing.AssertUtil._
import scala.tools.testing.BytecodeTesting
import scala.tools.testing.BytecodeTesting._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class MethodLevelOptsTest extends BytecodeTesting {
| }
|}
""".stripMargin
val c = compileClass(code)
val c = compileClass(code, allowMessage = ignoreDeprecations)
assertSameCode(getMethod(c, "t"), List(
IntOp(BIPUSH, 23), IntOp(NEWARRAY, 5), Op(POP), VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))
}
Expand All @@ -173,7 +173,7 @@ class MethodLevelOptsTest extends BytecodeTesting {
| }
|}
""".stripMargin
val c = compileClass(code)
val c = compileClass(code, allowMessage = ignoreDeprecations)
assertSameCode(getMethod(c, "t"), List(
TypeOp(NEW, "java/lang/Integer"), Ldc(LDC, "nono"), Invoke(INVOKESPECIAL, "java/lang/Integer", "<init>", "(Ljava/lang/String;)V", false),
VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))
Expand Down
9 changes: 9 additions & 0 deletions test/junit/scala/tools/testing/AssertUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import scala.runtime.ScalaRunTime.stringOf
import scala.collection.GenIterable
import scala.collection.JavaConverters._
import scala.collection.mutable
import scala.tools.nsc.settings.ScalaVersion
import scala.util.Properties.javaSpecVersion
import java.lang.ref._
import java.lang.reflect._
import java.util.IdentityHashMap
Expand Down Expand Up @@ -88,4 +90,11 @@ object AssertUtil {
assertFalse(s"Root $r held reference", refs(r) contains wkref.get)
}
}

private[this] val version8 = ScalaVersion("8")

/** Assert on Java 8, but on later versions, just print if assert would fail. */
def assert8(b: => Boolean, msg: => Any) =
if (ScalaVersion(javaSpecVersion) == version8) assert(b, msg)
else if (!b) println(s"assert not $msg")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this still useful or does it hide migration errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not used, actually.

}
2 changes: 2 additions & 0 deletions test/junit/scala/tools/testing/BytecodeTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,6 @@ object BytecodeTesting {
implicit class listStringLines[T](val l: List[T]) extends AnyVal {
def stringLines = l.mkString("\n")
}

val ignoreDeprecations = (info: StoreReporter#Info) => info.msg.contains("deprecation")
}
13 changes: 13 additions & 0 deletions test/junit/scala/tools/testing/Resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

package scala.tools.testing;

import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* An annotation for test scenarios, akin to common Resource.
*/
@Retention(RUNTIME)
public @interface Resource {
Class<?> type();
}
0