summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-07-01 11:29:34 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-07-01 11:29:34 -0700
commit7e833bcc75b382cecc4b6e8f33b8def68037af82 (patch)
treeea00f9602770f40e3efc7d53dd129e94249c993c /test
parente2fbbb28fa0200d4799ed81a4c93dcb224f6564b (diff)
parent609070953cfce003fbfcf232ffbfb7fb284cda54 (diff)
downloadscala-7e833bcc75b382cecc4b6e8f33b8def68037af82.tar.gz
scala-7e833bcc75b382cecc4b6e8f33b8def68037af82.tar.bz2
scala-7e833bcc75b382cecc4b6e8f33b8def68037af82.zip
Merge pull request #2692 from soc/SI-7591
SI-7591 Migrate command-line parsing to s.t.cmd
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/t7591/Demo.scala83
-rw-r--r--test/files/run/t6331.scala7
-rw-r--r--test/files/run/t6331b.scala9
-rw-r--r--test/files/run/t7271.scala1
4 files changed, 85 insertions, 15 deletions
diff --git a/test/files/pos/t7591/Demo.scala b/test/files/pos/t7591/Demo.scala
new file mode 100644
index 0000000000..696d53585b
--- /dev/null
+++ b/test/files/pos/t7591/Demo.scala
@@ -0,0 +1,83 @@
+/* NEST (New Scala Test)
+ * Copyright 2007-2013 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+import scala.tools.cmd._
+
+/** A sample command specification for illustrative purposes.
+ * First take advantage of the meta-options:
+ *
+ * // this command creates an executable runner script "demo"
+ * % scala scala.tools.cmd.Demo --self-update demo
+ *
+ * // this one creates and sources a completion file - note backticks
+ * % `./demo --bash`
+ *
+ * // and now you have a runner with working completion
+ * % ./demo --<tab>
+ * --action --defint --int
+ * --bash --defstr --str
+ * --defenv --self-update --unary
+ *
+ * The normal option configuration is plausibly self-explanatory.
+ */
+trait DemoSpec extends Spec with Meta.StdOpts with Interpolation {
+ lazy val referenceSpec = DemoSpec
+ lazy val programInfo = Spec.Info("demo", "Usage: demo [<options>]", "scala.tools.cmd.Demo")
+
+ help("""Usage: demo [<options>]""")
+ heading("Unary options:")
+
+ val optIsUnary = "unary" / "a unary option" --? ;
+ ("action" / "a body which may be run") --> println("Hello, I am the --action body.")
+
+ heading("Binary options:")
+ val optopt = "str" / "an optional String" --|
+ val optoptInt = ("int" / "an optional Int") . --^[Int]
+ val optEnv = "defenv" / "an optional String" defaultToEnv "PATH"
+ val optDefault = "defstr" / "an optional String" defaultTo "default"
+ val optDefaultInt = "defint" / "an optional Int" defaultTo -1
+ val optExpand = "alias" / "an option which expands" expandTo ("--int", "15")
+}
+
+object DemoSpec extends DemoSpec with Property {
+ lazy val propMapper = new PropertyMapper(DemoSpec)
+
+ type ThisCommandLine = SpecCommandLine
+ def creator(args: List[String]) =
+ new SpecCommandLine(args) {
+ override def errorFn(msg: String) = { println("Error: " + msg) ; sys.exit(0) }
+ }
+}
+
+class Demo(args: List[String]) extends {
+ val parsed = DemoSpec(args: _*)
+} with DemoSpec with Instance {
+ import java.lang.reflect._
+
+ def helpMsg = DemoSpec.helpMsg
+ def demoSpecMethods = this.getClass.getMethods.toList
+ private def isDemo(m: Method) = (m.getName startsWith "opt") && !(m.getName contains "$") && (m.getParameterTypes.isEmpty)
+
+ def demoString(ms: List[Method]) = {
+ val longest = ms map (_.getName.length) max
+ val formatStr = " %-" + longest + "s: %s"
+ val xs = ms map (m => formatStr.format(m.getName, m.invoke(this)))
+
+ xs mkString ("Demo(\n ", "\n ", "\n)\n")
+ }
+
+ override def toString = demoString(demoSpecMethods filter isDemo)
+}
+
+object Demo {
+ def main(args: Array[String]): Unit = {
+ val runner = new Demo(args.toList)
+
+ if (args.isEmpty)
+ println(runner.helpMsg)
+
+ println(runner)
+ }
+}
diff --git a/test/files/run/t6331.scala b/test/files/run/t6331.scala
index 5ac627a8ea..d9d46f10ea 100644
--- a/test/files/run/t6331.scala
+++ b/test/files/run/t6331.scala
@@ -1,9 +1,4 @@
-import scala.tools.partest._
-import java.io._
-import scala.tools.nsc._
-import scala.tools.cmd.CommandLineParser
-import scala.tools.nsc.{Global, Settings, CompilerCommand}
-import scala.tools.nsc.reporters.ConsoleReporter
+import scala.tools.partest.DirectTest
// Test of Constant#equals, which must must account for floating point intricacies.
object Test extends DirectTest {
diff --git a/test/files/run/t6331b.scala b/test/files/run/t6331b.scala
index c567455c5c..3e09965ee8 100644
--- a/test/files/run/t6331b.scala
+++ b/test/files/run/t6331b.scala
@@ -1,12 +1,5 @@
-import scala.tools.partest._
-import java.io._
-import scala.tools.nsc._
-import scala.tools.cmd.CommandLineParser
-import scala.tools.nsc.{Global, Settings, CompilerCommand}
-import scala.tools.nsc.reporters.ConsoleReporter
-
import scala.tools.partest.trace
-import scala.util.control.Exception._
+import scala.util.control.Exception.allCatch
object Test extends App {
diff --git a/test/files/run/t7271.scala b/test/files/run/t7271.scala
index 55c388b7f5..69d5ea377e 100644
--- a/test/files/run/t7271.scala
+++ b/test/files/run/t7271.scala
@@ -1,5 +1,4 @@
import scala.tools.partest._
-import java.io._
import scala.tools.nsc._
import scala.tools.cmd.CommandLineParser
import scala.tools.nsc.{Global, Settings, CompilerCommand}