diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/varargs/VaClass.scala | 4 | ||||
-rw-r--r-- | test/files/neg/compile-time-only-a.check | 5 | ||||
-rw-r--r-- | test/files/pos/t8410.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t8410.scala | 15 | ||||
-rw-r--r-- | test/files/pos/t8498.scala | 6 | ||||
-rw-r--r-- | test/files/run/t8803.check | 16 | ||||
-rw-r--r-- | test/files/run/t8803.scala | 57 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/ScriptRunnerTest.scala | 23 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/settings/SettingsTest.scala | 109 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala | 4 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala | 4 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/StdNamesTest.scala | 8 | ||||
-rw-r--r-- | test/junit/scala/tools/testing/AssertUtil.scala | 2 | ||||
-rw-r--r-- | test/scaladoc/resources/code-indent.scala | 6 | ||||
-rw-r--r-- | test/scaladoc/run/t8113.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/t8113.scala | 36 | ||||
-rw-r--r-- | test/scaladoc/scalacheck/HtmlFactoryTest.scala | 7 |
17 files changed, 289 insertions, 15 deletions
diff --git a/test/files/jvm/varargs/VaClass.scala b/test/files/jvm/varargs/VaClass.scala index e94e8a625a..d83e63ace1 100644 --- a/test/files/jvm/varargs/VaClass.scala +++ b/test/files/jvm/varargs/VaClass.scala @@ -9,5 +9,7 @@ class VaClass { @varargs def vs(a: Int, b: String*) = println(a + b.length) @varargs def vi(a: Int, b: Int*) = println(a + b.sum) @varargs def vt[T](a: Int, b: T*) = println(a + b.length) - @varargs def vt1[T](a: Int, b: T*): T = b.head + + // TODO remove type bound after fixing SI-8786, see also https://github.com/scala/scala/pull/3961 + @varargs def vt1[T <: String](a: Int, b: T*): T = b.head } diff --git a/test/files/neg/compile-time-only-a.check b/test/files/neg/compile-time-only-a.check index 9bc96f6b9b..b1ed1d24c2 100644 --- a/test/files/neg/compile-time-only-a.check +++ b/test/files/neg/compile-time-only-a.check @@ -4,9 +4,6 @@ compile-time-only-a.scala:10: error: C3 compile-time-only-a.scala:12: error: C4 @compileTimeOnly("C4") case class C4(x: Int) ^ -compile-time-only-a.scala:17: error: C5 - implicit class C5(val x: Int) { - ^ compile-time-only-a.scala:32: error: C1 new C1() ^ @@ -76,4 +73,4 @@ compile-time-only-a.scala:75: error: placebo compile-time-only-a.scala:75: error: placebo @placebo def x = (2: @placebo) ^ -26 errors found +25 errors found diff --git a/test/files/pos/t8410.flags b/test/files/pos/t8410.flags new file mode 100644 index 0000000000..dcd5943c2f --- /dev/null +++ b/test/files/pos/t8410.flags @@ -0,0 +1 @@ +-optimise -Xfatal-warnings -deprecation:false -Yinline-warnings:false diff --git a/test/files/pos/t8410.scala b/test/files/pos/t8410.scala new file mode 100644 index 0000000000..4d862311fa --- /dev/null +++ b/test/files/pos/t8410.scala @@ -0,0 +1,15 @@ + +object Test extends App { + @deprecated("","") def f = 42 + @deprecated("","") def z = f + def g = { @deprecated("","") def _f = f ; _f } // warns in 2.11.0-M8 + def x = { @deprecated("","") class X { def x = f } ; new X().x } // warns in 2.11.0-M8 + Console println g + Console println f // warns + + @deprecated("","") trait T + object T extends T { def t = f } + Console println T.t + + def k = List(0).dropWhile(_ < 1) // inlining warns doubly +} diff --git a/test/files/pos/t8498.scala b/test/files/pos/t8498.scala new file mode 100644 index 0000000000..6808c89051 --- /dev/null +++ b/test/files/pos/t8498.scala @@ -0,0 +1,6 @@ +import scala.annotation.compileTimeOnly + +class C(val s: String) extends AnyVal { + @compileTimeOnly("error") + def error = ??? +} diff --git a/test/files/run/t8803.check b/test/files/run/t8803.check new file mode 100644 index 0000000000..bd26a0fb14 --- /dev/null +++ b/test/files/run/t8803.check @@ -0,0 +1,16 @@ +a +b +b +c +a +b +b +c +a +b +b +c +a +b +b +c diff --git a/test/files/run/t8803.scala b/test/files/run/t8803.scala new file mode 100644 index 0000000000..2e56180502 --- /dev/null +++ b/test/files/run/t8803.scala @@ -0,0 +1,57 @@ +class A { + def m = "a" + protected def n = "a" +} + +trait B { + def m = "b" + protected def n = "b" +} + +class C extends A with B { + override def m = "c" + override protected def n = "c" + + val f1 = () => super[A].m + val f2 = () => super[B].m + val f3 = () => super.m + val f4 = () => this.m + + val g1 = new runtime.AbstractFunction0[String] { def apply() = C.super[A].m } + val g2 = new runtime.AbstractFunction0[String] { def apply() = C.super[B].m } + val g3 = new runtime.AbstractFunction0[String] { def apply() = C.super.m } + val g4 = new runtime.AbstractFunction0[String] { def apply() = C.this.m } + + val h1 = () => super[A].n + val h2 = () => super[B].n + val h3 = () => super.n + val h4 = () => this.n + + val i1 = new runtime.AbstractFunction0[String] { def apply() = C.super[A].n } + val i2 = new runtime.AbstractFunction0[String] { def apply() = C.super[B].n } + val i3 = new runtime.AbstractFunction0[String] { def apply() = C.super.n } + val i4 = new runtime.AbstractFunction0[String] { def apply() = C.this.n } +} + +object Test extends App { + val c = new C + println(c.f1()) + println(c.f2()) + println(c.f3()) + println(c.f4()) + + println(c.g1()) + println(c.g2()) + println(c.g3()) + println(c.g4()) + + println(c.h1()) + println(c.h2()) + println(c.h3()) + println(c.h4()) + + println(c.i1()) + println(c.i2()) + println(c.i3()) + println(c.i4()) +} diff --git a/test/junit/scala/tools/nsc/ScriptRunnerTest.scala b/test/junit/scala/tools/nsc/ScriptRunnerTest.scala new file mode 100644 index 0000000000..9bae7a0487 --- /dev/null +++ b/test/junit/scala/tools/nsc/ScriptRunnerTest.scala @@ -0,0 +1,23 @@ +package scala.tools.nsc + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class ScriptRunnerTest { + @Test + def testEmptyScriptSucceeds: Unit = { + val s = new GenericRunnerSettings(s => ()) + s.nc.value = true + s.usejavacp.value = true + + // scala -nc -e '' + assertTrue(ScriptRunner.runCommand(s, "", Nil)) + + // scala -nc -save -e '' + s.save.value = true + assertTrue(ScriptRunner.runCommand(s, "", Nil)) + } +} diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala index 960d7f8ac1..eda0c27834 100644 --- a/test/junit/scala/tools/nsc/settings/SettingsTest.scala +++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala @@ -39,7 +39,7 @@ class SettingsTest { } // for the given args, select the desired setting - private def check(args: String*)(b: MutableSettings => MutableSettings#BooleanSetting): MutableSettings#BooleanSetting = { + private def check(args: String*)(b: MutableSettings => Boolean): Boolean = { val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) val (ok, residual) = s.processArguments(args.toList, processAll = true) assert(residual.isEmpty) @@ -54,7 +54,114 @@ class SettingsTest { @Test def anonymousLintersCanBeNamed() { assertTrue(check("-Xlint")(_.warnMissingInterpolator)) // among Xlint assertFalse(check("-Xlint:-missing-interpolator")(_.warnMissingInterpolator)) + + // positive overrides negative, but not the other way around + assertTrue(check("-Xlint:-missing-interpolator,missing-interpolator")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint:-missing-interpolator", "-Xlint:missing-interpolator")(_.warnMissingInterpolator)) + + assertTrue(check("-Xlint:missing-interpolator,-missing-interpolator")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint:missing-interpolator", "-Xlint:-missing-interpolator")(_.warnMissingInterpolator)) + + // -Xlint:_ adds all possible choices, but explicit negative settings will override + assertFalse(check("-Xlint:-missing-interpolator,_")(_.warnMissingInterpolator)) + assertFalse(check("-Xlint:-missing-interpolator", "-Xlint:_")(_.warnMissingInterpolator)) + assertFalse(check("-Xlint:_", "-Xlint:-missing-interpolator")(_.warnMissingInterpolator)) + assertFalse(check("-Xlint:_,-missing-interpolator")(_.warnMissingInterpolator)) + + // -Xlint is the same as -Xlint:_ assertFalse(check("-Xlint:-missing-interpolator", "-Xlint")(_.warnMissingInterpolator)) assertFalse(check("-Xlint", "-Xlint:-missing-interpolator")(_.warnMissingInterpolator)) + + // combination of positive, negative and _ + assertTrue(check("-Xlint:_,-missing-interpolator,missing-interpolator")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint:-missing-interpolator,_,missing-interpolator")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint:-missing-interpolator,missing-interpolator,_")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint:missing-interpolator,-missing-interpolator,_")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint:missing-interpolator,_,-missing-interpolator")(_.warnMissingInterpolator)) + } + + @Test def xLintInvalidChoices(): Unit = { + assertThrows[IllegalArgumentException](check("-Xlint:-_")(_.warnAdaptedArgs)) + assertThrows[IllegalArgumentException](check("-Xlint:-warn-adapted-args")(_.warnAdaptedArgs)) // "warn-" should not be there + } + + @Test def xLintNonColonated(): Unit = { + assertTrue(check("-Xlint", "adapted-args", "-deprecation")(_.warnAdaptedArgs)) + assertFalse(check("-Xlint", "adapted-args", "-deprecation")(_.warnMissingInterpolator)) + assertTrue(check("-Xlint", "adapted-args", "missing-interpolator", "-deprecation")(s => s.warnMissingInterpolator && s.warnAdaptedArgs)) + assertThrows[IllegalArgumentException](check("-Xlint", "adapted-args", "-missing-interpolator")(_.warnAdaptedArgs)) // non-colonated: cannot provide negative args + } + + @Test def xLintContainsValues(): Unit = { + // make sure that lint.contains and lint.value.contains are consistent + def t(s: MutableSettings, v: String) = { + val r = s.lint.contains(v) + assertSame(r, s.lint.value.contains((s.LintWarnings withName v).asInstanceOf[s.lint.domain.Value])) + r + } + + assertTrue(check("-Xlint")(t(_, "adapted-args"))) + assertTrue(check("-Xlint:_")(t(_, "adapted-args"))) + assertFalse(check("-Xlint:_,-adapted-args")(t(_, "adapted-args"))) + assertFalse(check("-Xlint:-adapted-args,_")(t(_, "adapted-args"))) + assertTrue(check("-Xlint:-adapted-args,_,adapted-args")(t(_, "adapted-args"))) + } + + @Test def xLintDeprecatedAlias(): Unit = { + assertTrue(check("-Ywarn-adapted-args")(_.warnAdaptedArgs)) + assertTrue(check("-Xlint:_,-adapted-args", "-Ywarn-adapted-args")(_.warnAdaptedArgs)) + assertTrue(check("-Xlint:-adapted-args", "-Ywarn-adapted-args")(_.warnAdaptedArgs)) + assertTrue(check("-Ywarn-adapted-args", "-Xlint:-adapted-args,_")(_.warnAdaptedArgs)) + + assertFalse(check("-Ywarn-adapted-args:false")(_.warnAdaptedArgs)) + assertFalse(check("-Ywarn-adapted-args:false", "-Xlint:_")(_.warnAdaptedArgs)) + assertFalse(check("-Ywarn-adapted-args:false", "-Xlint:_,-adapted-args")(_.warnAdaptedArgs)) + assertTrue(check("-Ywarn-adapted-args:false", "-Xlint:_,adapted-args")(_.warnAdaptedArgs)) + } + + @Test def expandingMultichoice(): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + object mChoices extends s.MultiChoiceEnumeration { + val a = Choice("a") + val b = Choice("b") + val c = Choice("c") + val d = Choice("d") + + val ab = Choice("ab", expandsTo = List(a, b)) + val ac = Choice("ac", expandsTo = List(a, c)) + val uber = Choice("uber", expandsTo = List(ab, d)) + } + val m = s.MultiChoiceSetting("-m", "args", "magic sauce", mChoices, Some(List("ac"))) + + def check(args: String*)(t: s.MultiChoiceSetting[mChoices.type] => Boolean): Boolean = { + m.clear() + val (ok, rest) = s.processArguments(args.toList, processAll = true) + assert(rest.isEmpty) + t(m) + } + + import mChoices._ + + assertTrue(check("-m")(_.value == Set(a,c))) + assertTrue(check("-m:a,-b,c")(_.value == Set(a,c))) + + // expanding options don't end up in the value set, only the terminal ones + assertTrue(check("-m:ab,ac")(_.value == Set(a,b,c))) + assertTrue(check("-m:_")(_.value == Set(a,b,c,d))) + assertTrue(check("-m:uber,ac")(_.value == Set(a,b,c,d))) // recursive expansion of uber + + // explicit nays + assertTrue(check("-m:_,-b")(_.value == Set(a,c,d))) + assertTrue(check("-m:b,_,-b")(_.value == Set(a,b,c,d))) + assertTrue(check("-m:ac,-c")(_.value == Set(a))) + assertTrue(check("-m:ac,-a,-c")(_.value == Set())) + assertTrue(check("-m:-d,ac")(_.value == Set(a,c))) + assertTrue(check("-m:-b,ac,uber")(_.value == Set(a,c,d))) + + assertFalse(check("-m:uber")(_.contains("i-m-not-an-option"))) + + assertThrows[IllegalArgumentException](check("-m:-_")(_ => true), _ contains "'-_' is not a valid choice") + assertThrows[IllegalArgumentException](check("-m:a,b,-ab")(_ => true), _ contains "'ab' cannot be negated") + assertThrows[IllegalArgumentException](check("-m:a,ac,-uber,uber")(_ => true), _ contains "'uber' cannot be negated") } } diff --git a/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala b/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala index 355771bf04..d424f12710 100644 --- a/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala +++ b/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala @@ -47,7 +47,7 @@ class CannotHaveAttrsTest { assertEquals(t.tpe, NoType) } - @Test + @Test @org.junit.Ignore // SI-8816 def nonDefaultPosAssignmentFails = { val pos = new OffsetPosition(null, 0) attrlessTrees.foreach { t => @@ -56,7 +56,7 @@ class CannotHaveAttrsTest { } } - @Test + @Test @org.junit.Ignore // SI-8816 def nonDefaultTpeAssignmentFails = { val tpe = typeOf[Int] attrlessTrees.foreach { t => diff --git a/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala b/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala index cf09abdfff..effbfb2f7c 100644 --- a/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala +++ b/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala @@ -36,7 +36,7 @@ class FreshNameExtractorTest { } } - @Test + @Test @org.junit.Ignore // SI-8818 def extractionsFailsIfNameDoesntEndWithNumber = { val Creator = new FreshNameCreator(prefixes.head) val Extractor = new FreshNameExtractor(prefixes.head) @@ -44,4 +44,4 @@ class FreshNameExtractorTest { val Extractor(_) = TermName(Creator.newName("foo") + "bar") } } -}
\ No newline at end of file +} diff --git a/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala index 4a39cf9d48..524d2e45e0 100644 --- a/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala +++ b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala @@ -15,12 +15,16 @@ class StdNamesTest { @Test def testNewTermNameInvalid(): Unit = { - assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, 0, -1)) - assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, 0, 0)) assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, -1, 1)) } @Test + def testNewTermNameNegativeLenght(): Unit = { + assertEquals(nme.EMPTY, newTermName("foo".toCharArray, 0, -1)) + assertEquals(nme.EMPTY, newTermName("foo".toCharArray, 0, 0)) + } + + @Test def testUnspecializedName(): Unit = { def test(expected: Name, nme: Name) { assertEquals(expected, unspecializedName(nme)) diff --git a/test/junit/scala/tools/testing/AssertUtil.scala b/test/junit/scala/tools/testing/AssertUtil.scala index 9a97c5114f..9b4833d46b 100644 --- a/test/junit/scala/tools/testing/AssertUtil.scala +++ b/test/junit/scala/tools/testing/AssertUtil.scala @@ -19,6 +19,8 @@ object AssertUtil { val clazz = manifest.runtimeClass if (!clazz.isAssignableFrom(e.getClass)) throw e + else return } + throw new AssertionError("Expression did not throw!") } } diff --git a/test/scaladoc/resources/code-indent.scala b/test/scaladoc/resources/code-indent.scala index 88946ffc7f..2eee3352b4 100644 --- a/test/scaladoc/resources/code-indent.scala +++ b/test/scaladoc/resources/code-indent.scala @@ -20,6 +20,12 @@ * an alternative * the e l s e branch * }}} + * {{{ + * Trait example { + * Val x = a + * Val y = b + * } + * }}} * NB: Trailing spaces are necessary for this test! * {{{ * l1 diff --git a/test/scaladoc/run/t8113.check b/test/scaladoc/run/t8113.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/t8113.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/t8113.scala b/test/scaladoc/run/t8113.scala new file mode 100644 index 0000000000..f006213ef2 --- /dev/null +++ b/test/scaladoc/run/t8113.scala @@ -0,0 +1,36 @@ +import scala.tools.nsc.doc.base._ +import scala.tools.nsc.doc.base.comment._ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + + override def code = """ + /** + * Check out [[http://www.scala-lang.org + * this great website]]! + */ + class Test + """ + + def scaladocSettings = "" + + def testModel(rootPackage: Package) = { + import access._ + + val test = rootPackage._class("Test") + + // find Link + def find(body: Any): Option[Link] = body match { + case l: Link => Some(l) + case s: Seq[_] => s.toList.map(find(_)).flatten.headOption + case p: Product => p.productIterator.toList.map(find(_)).flatten.headOption + case _ => None + } + + val link = find(test.comment.get.body).collect { case Link(ta, Text(ti)) => (ta, ti) } + assert(link.isDefined) + val expected = ("http://www.scala-lang.org", "this great website") + link.foreach {l => assert(l == expected, s"$l != $expected")} + } +} diff --git a/test/scaladoc/scalacheck/HtmlFactoryTest.scala b/test/scaladoc/scalacheck/HtmlFactoryTest.scala index fdc4f9527f..fc190b188c 100644 --- a/test/scaladoc/scalacheck/HtmlFactoryTest.scala +++ b/test/scaladoc/scalacheck/HtmlFactoryTest.scala @@ -659,6 +659,7 @@ object Test extends Properties("HtmlFactory") { s.contains("<pre>two lines, one useful</pre>") && s.contains("<pre>line1\nline2\nline3\nline4</pre>") && s.contains("<pre>a ragged example\na (condition)\n the t h e n branch\nan alternative\n the e l s e branch</pre>") && + s.contains("<pre>Trait example {\n Val x = a\n Val y = b\n}</pre>") && s.contains("<pre>l1\n\nl2\n\nl3\n\nl4\n\nl5</pre>") } case _ => false @@ -683,7 +684,7 @@ object Test extends Properties("HtmlFactory") { oneAuthor match { case node: scala.xml.Node => { val s = node.toString - s.contains("<h6>Author:</h6>") + s.contains("<h6>Author:</h6>") && s.contains("<p>The Only Author\n</p>") } case _ => false @@ -696,8 +697,8 @@ object Test extends Properties("HtmlFactory") { twoAuthors match { case node: scala.xml.Node => { val s = node.toString - s.contains("<h6>Authors:</h6>") - s.contains("<p>The First Author\n</p>") + s.contains("<h6>Authors:</h6>") && + s.contains("<p>The First Author</p>") && s.contains("<p>The Second Author\n</p>") } case _ => false |