diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/instrumented/InstrumentationTest.check | 4 | ||||
-rw-r--r-- | test/files/instrumented/InstrumentationTest.scala | 14 | ||||
-rw-r--r-- | test/files/instrumented/README | 15 | ||||
-rw-r--r-- | test/files/neg/reflection-names-neg.check | 10 | ||||
-rw-r--r-- | test/files/neg/reflection-names-neg.scala | 6 | ||||
-rw-r--r-- | test/files/neg/t1286.check | 6 | ||||
-rw-r--r-- | test/files/neg/t5830.check | 5 | ||||
-rw-r--r-- | test/files/neg/t5956.check | 20 | ||||
-rw-r--r-- | test/files/neg/t5956.scala | 2 | ||||
-rw-r--r-- | test/files/neg/t6011.check | 10 | ||||
-rw-r--r-- | test/files/neg/t6011.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t6011.scala | 23 | ||||
-rw-r--r-- | test/files/neg/t6048.check | 10 | ||||
-rw-r--r-- | test/files/neg/t6048.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t6048.scala | 22 | ||||
-rw-r--r-- | test/files/run/reflection-names.check | 4 | ||||
-rw-r--r-- | test/files/run/reflection-names.scala | 15 | ||||
-rw-r--r-- | test/files/run/t6011b.check | 1 | ||||
-rw-r--r-- | test/files/run/t6011b.scala | 11 |
19 files changed, 174 insertions, 6 deletions
diff --git a/test/files/instrumented/InstrumentationTest.check b/test/files/instrumented/InstrumentationTest.check new file mode 100644 index 0000000000..3652df270a --- /dev/null +++ b/test/files/instrumented/InstrumentationTest.check @@ -0,0 +1,4 @@ +true +Method call statistics: + 1 scala/Predef$.println(Ljava/lang/Object;)V + 1 scala/runtime/BoxesRunTime.boxToBoolean(Z)Ljava/lang/Boolean; diff --git a/test/files/instrumented/InstrumentationTest.scala b/test/files/instrumented/InstrumentationTest.scala new file mode 100644 index 0000000000..ec5314c624 --- /dev/null +++ b/test/files/instrumented/InstrumentationTest.scala @@ -0,0 +1,14 @@ +import scala.tools.partest.instrumented.Instrumentation._ + +/** Tests if instrumentation itself works correctly */ +object Test { + def main(args: Array[String]) { + // force predef initialization before profiling + Predef + startProfiling() + // should box the boolean + println(true) + stopProfiling() + printStatistics() + } +} diff --git a/test/files/instrumented/README b/test/files/instrumented/README new file mode 100644 index 0000000000..32d0ef2da5 --- /dev/null +++ b/test/files/instrumented/README @@ -0,0 +1,15 @@ +Tests in `instrumented` directory are executed the same way as in `run` but +they have additional byte-code instrumentation performed for profiling. You +should put your tests in `instrumented` directory if you are interested in +method call counts. Examples include tests for specialization (you want to +count boxing and unboxing method calls) or high-level tests for optimizer +where you are interested if methods are successfuly inlined (so they should +not be called at runtime) or closures are eliminated (so no constructors +of closures are called). + +Check `scala.tools.partest.instrumented.Instrumentation` to learn how to +use the instrumentation infrastructure. + +The instrumentation itself is achieved by attaching a Java agent to the forked +VM process that injects calls to profiler. Check +`scala.tools.partest.instrumented.Instrumentation`. diff --git a/test/files/neg/reflection-names-neg.check b/test/files/neg/reflection-names-neg.check new file mode 100644 index 0000000000..a56a19e7fd --- /dev/null +++ b/test/files/neg/reflection-names-neg.check @@ -0,0 +1,10 @@ +reflection-names-neg.scala:5: error: type mismatch; + found : String("abc") + required: reflect.runtime.universe.Name +Note that implicit conversions are not applicable because they are ambiguous: + both method stringToTermName in trait Names of type (s: String)reflect.runtime.universe.TermName + and method stringToTypeName in trait Names of type (s: String)reflect.runtime.universe.TypeName + are possible conversion functions from String("abc") to reflect.runtime.universe.Name + val x2 = ("abc": Name) drop 1 // error + ^ +one error found diff --git a/test/files/neg/reflection-names-neg.scala b/test/files/neg/reflection-names-neg.scala new file mode 100644 index 0000000000..7283d16db9 --- /dev/null +++ b/test/files/neg/reflection-names-neg.scala @@ -0,0 +1,6 @@ +import scala.reflect.runtime.universe._ + +object Test { + val x1 = "abc" drop 1 // "bc": String + val x2 = ("abc": Name) drop 1 // error +} diff --git a/test/files/neg/t1286.check b/test/files/neg/t1286.check index c937fb9cf1..912709613c 100644 --- a/test/files/neg/t1286.check +++ b/test/files/neg/t1286.check @@ -1,9 +1,5 @@ -a.scala:1: error: Companions 'object Foo' and 'trait Foo' must be defined in same file: - Found in t1286/b.scala and t1286/a.scala -trait Foo { - ^ b.scala:1: error: Companions 'trait Foo' and 'object Foo' must be defined in same file: Found in t1286/a.scala and t1286/b.scala object Foo extends Foo { ^ -two errors found +one error found diff --git a/test/files/neg/t5830.check b/test/files/neg/t5830.check index 85cb84378f..726fac2a1e 100644 --- a/test/files/neg/t5830.check +++ b/test/files/neg/t5830.check @@ -1,4 +1,7 @@ t5830.scala:6: error: unreachable code case 'a' => println("b") // unreachable ^ -one error found +t5830.scala:4: error: could not emit switch for @switch annotated match + def unreachable(ch: Char) = (ch: @switch) match { + ^ +two errors found diff --git a/test/files/neg/t5956.check b/test/files/neg/t5956.check new file mode 100644 index 0000000000..6641dac97f --- /dev/null +++ b/test/files/neg/t5956.check @@ -0,0 +1,20 @@ +t5956.scala:1: warning: case classes without a parameter list have been deprecated; +use either case objects or case classes with `()' as parameter list. +object O { case class C[T]; class C } + ^ +t5956.scala:2: warning: case classes without a parameter list have been deprecated; +use either case objects or case classes with `()' as parameter list. +object T { case class C[T]; case class C } + ^ +t5956.scala:2: warning: case classes without a parameter list have been deprecated; +use either case objects or case classes with `()' as parameter list. +object T { case class C[T]; case class C } + ^ +t5956.scala:1: error: C is already defined as case class C +object O { case class C[T]; class C } + ^ +t5956.scala:2: error: C is already defined as case class C +object T { case class C[T]; case class C } + ^ +three warnings found +two errors found diff --git a/test/files/neg/t5956.scala b/test/files/neg/t5956.scala new file mode 100644 index 0000000000..d985fa97a4 --- /dev/null +++ b/test/files/neg/t5956.scala @@ -0,0 +1,2 @@ +object O { case class C[T]; class C } +object T { case class C[T]; case class C } diff --git a/test/files/neg/t6011.check b/test/files/neg/t6011.check new file mode 100644 index 0000000000..5b5a861e5b --- /dev/null +++ b/test/files/neg/t6011.check @@ -0,0 +1,10 @@ +t6011.scala:4: error: unreachable code + case 'a' | 'c' => 1 // unreachable + ^ +t6011.scala:10: error: unreachable code + case 'b' | 'a' => 1 // unreachable + ^ +t6011.scala:8: error: could not emit switch for @switch annotated match + def f2(ch: Char): Any = (ch: @annotation.switch) match { + ^ +three errors found diff --git a/test/files/neg/t6011.flags b/test/files/neg/t6011.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/t6011.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t6011.scala b/test/files/neg/t6011.scala new file mode 100644 index 0000000000..a36cca7897 --- /dev/null +++ b/test/files/neg/t6011.scala @@ -0,0 +1,23 @@ +object Test { + def f(ch: Char): Any = ch match { + case 'a' => 1 + case 'a' | 'c' => 1 // unreachable + } + + // won't be compiled to a switch since it has an unreachable (duplicate) case + def f2(ch: Char): Any = (ch: @annotation.switch) match { + case 'a' | 'b' => 1 + case 'b' | 'a' => 1 // unreachable + case _ => + } + + // s'all good + def f3(ch: Char): Any = (ch: @annotation.switch) match { + case 'a' | 'b' if (true: Boolean) => 1 + case 'b' | 'a' => 1 // ok + case _ => // need third case to check switch annotation (two-case switches are always okay to compile to if-then-else) + } + + + def main(args: Array[String]): Unit = f('a') +}
\ No newline at end of file diff --git a/test/files/neg/t6048.check b/test/files/neg/t6048.check new file mode 100644 index 0000000000..051f41877e --- /dev/null +++ b/test/files/neg/t6048.check @@ -0,0 +1,10 @@ +t6048.scala:3: error: unreachable code + case _ if false => x // unreachable + ^ +t6048.scala:8: error: unreachable code + case _ if false => x // unreachable + ^ +t6048.scala:14: error: unreachable code + case 5 if true => x // unreachable + ^ +three errors found diff --git a/test/files/neg/t6048.flags b/test/files/neg/t6048.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/t6048.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t6048.scala b/test/files/neg/t6048.scala new file mode 100644 index 0000000000..803e651d19 --- /dev/null +++ b/test/files/neg/t6048.scala @@ -0,0 +1,22 @@ +class A { + def f1(x: Int) = x match { + case _ if false => x // unreachable + case 5 => x + } + + def f2(x: Int) = x match { + case _ if false => x // unreachable + case 5 if true => x + } + + def f3(x: Int) = x match { + case _ => x + case 5 if true => x // unreachable + } + + def test1(x: Int) = x match { + case c if c < 0 => 0 + case 1 => 1 + case _ => 2 + } +} diff --git a/test/files/run/reflection-names.check b/test/files/run/reflection-names.check new file mode 100644 index 0000000000..f8cb78cc67 --- /dev/null +++ b/test/files/run/reflection-names.check @@ -0,0 +1,4 @@ +(java.lang.String,bc) +(scala.reflect.internal.Names$TermName_R,bc) +(scala.reflect.internal.Names$TypeName_R,bc) +(scala.reflect.internal.Names$TypeName_R,bc) diff --git a/test/files/run/reflection-names.scala b/test/files/run/reflection-names.scala new file mode 100644 index 0000000000..2433c84813 --- /dev/null +++ b/test/files/run/reflection-names.scala @@ -0,0 +1,15 @@ +import scala.tools.nsc._ + +object Test { + val global = new Global(new Settings()) + import global._ + + val x1 = "abc" drop 1 // "bc": String + val x2 = ("abc": TermName) drop 1 // "bc": TermName + val x3 = ("abc": TypeName) drop 1 // "bc": TypeName + val x4 = (("abc": TypeName): Name) drop 1 // "bc": Name + + def main(args: Array[String]): Unit = { + List(x1, x2, x3, x4) foreach (x => println(x.getClass.getName, x)) + } +} diff --git a/test/files/run/t6011b.check b/test/files/run/t6011b.check new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/test/files/run/t6011b.check @@ -0,0 +1 @@ +3 diff --git a/test/files/run/t6011b.scala b/test/files/run/t6011b.scala new file mode 100644 index 0000000000..3d405e0705 --- /dev/null +++ b/test/files/run/t6011b.scala @@ -0,0 +1,11 @@ +object Test extends App { + var cond = true + + // should not generate a switch + def f(ch: Char): Int = ch match { + case 'a' if cond => 1 + case 'z' | 'a' => 2 + } + + println(f('a') + f('z')) // 3 +}
\ No newline at end of file |