diff options
Diffstat (limited to 'test/junit/scala/tools/nsc/settings/SettingsTest.scala')
-rw-r--r-- | test/junit/scala/tools/nsc/settings/SettingsTest.scala | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala index 0f2d206273..24bfb3dcde 100644 --- a/test/junit/scala/tools/nsc/settings/SettingsTest.scala +++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala @@ -180,4 +180,71 @@ class SettingsTest { assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource", "2.11"), _ == "-Xsource requires an argument, the syntax is -Xsource:<version>") assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource:2.invalid"), _ contains "Bad version (2.invalid)") } + + // equal with stripped margins and normalized line endings + private def marginallyEquals(s1: String, s2: String): Boolean = { + def normally(s: String): String = s.stripMargin.lines.mkString("\n") + normally(s1) == normally(s2) + } + + @Test def helpHasDefault(): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + object mChoices extends s.MultiChoiceEnumeration { + val a = Choice("a", "help a") + val b = Choice("b", "help b") + val c = Choice("c", "help c") + } + val m = s.MultiChoiceSetting("-m", "args", "magic sauce", mChoices, Some(List("b"))) + + 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(b))) + assertTrue(check("-m") { _ => + val expected = + """|magic sauce + | a help a + | b help b + | c help c + |Default: b + |""" + marginallyEquals(expected, m.help) + }) + } + @Test def helpHasDefaultAll(): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + object mChoices extends s.MultiChoiceEnumeration { + val a = Choice("a", "help a") + val b = Choice("b", "help b") + val c = Choice("c", "help c") + } + val m = s.MultiChoiceSetting("-m", "args", "magic sauce", mChoices, Some(List("_"))) + + 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, b, c))) + assertTrue(check("-m") { _ => + val expected = + """|magic sauce + | a help a + | b help b + | c help c + |Default: All choices are enabled by default. + |""" + marginallyEquals(expected, m.help) + }) + } } |