diff options
author | Lukas Rytz <lukas.rytz@typesafe.com> | 2014-09-08 23:04:45 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2014-09-08 23:04:45 +0200 |
commit | 068237ab750b92d3b1e81876afaca0246416e1ea (patch) | |
tree | dff8d866081cce2f91dde16eea51215b762ce5de /test | |
parent | 87ca181e7b6874cce734a4a40f90fe4af2391d97 (diff) | |
parent | 1ea684341ba9eeff7c6bc6f943fb2d048a9ff5a3 (diff) | |
download | scala-068237ab750b92d3b1e81876afaca0246416e1ea.tar.gz scala-068237ab750b92d3b1e81876afaca0246416e1ea.tar.bz2 scala-068237ab750b92d3b1e81876afaca0246416e1ea.zip |
Merge pull request #3939 from lrytz/ystats
-Ystatistics accepts a list of phases for which to print stats
Diffstat (limited to 'test')
5 files changed, 120 insertions, 7 deletions
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!") } } |