From 10c745ae976f8e488dcde66587d0741890112c13 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Mon, 3 Nov 2014 17:23:05 +0100 Subject: Fix default value for ScalaVersionSetting The default value was NoScalaVersion before, because tryToSet (where the default was supposed to be set) is not called at all if the option is not specified. The initial value of Xmigration is set to NoScalaVersion (which it was before, the AnyScalaVersion argument was ignored). AnyScalaVersion would be wrong, it would give a warning in `Map(1 -> "eis").values` if the option was not specified. See tests. --- test/files/run/xMigration.check | 49 ++++++++++++++++++++++ test/files/run/xMigration.scala | 19 +++++++++ .../scala/tools/nsc/settings/SettingsTest.scala | 16 +++++++ 3 files changed, 84 insertions(+) create mode 100644 test/files/run/xMigration.check create mode 100644 test/files/run/xMigration.scala (limited to 'test') diff --git a/test/files/run/xMigration.check b/test/files/run/xMigration.check new file mode 100644 index 0000000000..378f7bb6c3 --- /dev/null +++ b/test/files/run/xMigration.check @@ -0,0 +1,49 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> Map(1 -> "eis").values // no warn +res0: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:none + +scala> Map(1 -> "eis").values // no warn +res1: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:any + +scala> Map(1 -> "eis").values // warn +:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res2: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.8 + +scala> Map(1 -> "eis").values // no warn +res3: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.7 + +scala> Map(1 -> "eis").values // warn +:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res4: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration:2.11 + +scala> Map(1 -> "eis").values // no warn +res5: Iterable[String] = MapLike(eis) + +scala> :setting -Xmigration // same as :any + +scala> Map(1 -> "eis").values // warn +:8: warning: method values in trait MapLike has changed semantics in version 2.8.0: +`values` returns `Iterable[B]` rather than `Iterator[B]`. + Map(1 -> "eis").values // warn + ^ +res6: Iterable[String] = MapLike(eis) + +scala> :quit diff --git a/test/files/run/xMigration.scala b/test/files/run/xMigration.scala new file mode 100644 index 0000000000..688e878397 --- /dev/null +++ b/test/files/run/xMigration.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +Map(1 -> "eis").values // no warn +:setting -Xmigration:none +Map(1 -> "eis").values // no warn +:setting -Xmigration:any +Map(1 -> "eis").values // warn +:setting -Xmigration:2.8 +Map(1 -> "eis").values // no warn +:setting -Xmigration:2.7 +Map(1 -> "eis").values // warn +:setting -Xmigration:2.11 +Map(1 -> "eis").values // no warn +:setting -Xmigration // same as :any +Map(1 -> "eis").values // warn + """ +} diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala index eda0c27834..96f83c4c2f 100644 --- a/test/junit/scala/tools/nsc/settings/SettingsTest.scala +++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala @@ -164,4 +164,20 @@ class SettingsTest { 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") } + + @Test def xSourceTest(): Unit = { + def check(expected: String, args: String*): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + val (_, residual) = s.processArguments(args.toList, processAll = true) + assert(residual.isEmpty) + assertTrue(s.source.value == ScalaVersion(expected)) + } + check(expected = "2.11.0") // default + check(expected = "2.11.0", "-Xsource:2.11") + check(expected = "2.10", "-Xsource:2.10.0") + check(expected = "2.12", "-Xsource:2.12") + assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource"), _ == "-Xsource requires an argument, the syntax is -Xsource:") + assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource", "2.11"), _ == "-Xsource requires an argument, the syntax is -Xsource:") + assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource:2.invalid"), _ contains "There was a problem parsing 2.invalid") + } } -- cgit v1.2.3