aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/debug
diff options
context:
space:
mode:
authorliu fengyun <liu@fengy.me>2017-02-10 19:43:28 +0100
committerliu fengyun <liu@fengy.me>2017-02-10 19:43:28 +0100
commit093081f0faf7d3c6efdc12f2b33d89cbd52a9070 (patch)
tree5b933c60c3d20ecbaa7dfbe530a8b0465ab5ee0a /compiler/test/debug
parent7ca25fbca7bbfa8755ce74ca24b138705a7f904d (diff)
downloaddotty-093081f0faf7d3c6efdc12f2b33d89cbd52a9070.tar.gz
dotty-093081f0faf7d3c6efdc12f2b33d89cbd52a9070.tar.bz2
dotty-093081f0faf7d3c6efdc12f2b33d89cbd52a9070.zip
remove dependency on scala script
Diffstat (limited to 'compiler/test/debug')
-rwxr-xr-xcompiler/test/debug/Gen178
-rwxr-xr-xcompiler/test/debug/Gen.scala171
-rwxr-xr-xcompiler/test/debug/test5
3 files changed, 182 insertions, 172 deletions
diff --git a/compiler/test/debug/Gen b/compiler/test/debug/Gen
index 84e0db76e..c5c4d6ec6 100755
--- a/compiler/test/debug/Gen
+++ b/compiler/test/debug/Gen
@@ -1,175 +1,13 @@
-#!/bin/sh
-exec scala -savecompiled "$0" "$@"
-!#
+#! /usr/bin/env bash
-import scala.io.Source
-import scala.collection.mutable.Buffer
-import scala.collection.mutable.ListBuffer
-import scala.collection.mutable.StringBuilder
+DIR="$( cd "$( dirname "$0" )" && pwd )"
-/** Automate testing debuggability of generated code using JDB and expect
- *
- * The debugging information is annotated as comments to the code in brackets:
- *
- * val x = f(3) // [break] [next: line=5]
- * val y = 5
- *
- * 1. A jdb command must be wrapped in brackets, like `[step]`. All jdb commands can be used.
- * 2. To check output of jdb for a command, use `[cmd: expect]`.
- * 3. If `expect` is wrapped in double quotes, regex is supported.
- * 4. Break commands are collected and set globally.
- * 5. Other commands will be send to jdb in the order they appear in the source file
- *
- * Note: jdb uses line number starts from 1
- */
+SOURCE=$DIR/Gen.scala
+CLASS=./Gen.class
-object Gen {
- val MainObject = "Test"
- val CommandWait = 0.5
+if [ ! -e $CLASS ] || [ $SOURCE -nt $CLASS ]; then
+ ./bin/dotc $DIR/Gen.scala
+fi
- sealed trait Tree
+./bin/dotr Gen $@
- case class Break(line: Int) extends Tree
-
- case class Command(val name: String, val expect: Expect = EmptyExpect) extends Tree
-
- sealed trait Expect
-
- case object EmptyExpect extends Expect
-
- case class LitExpect(lit: String) extends Expect
-
- case class PatExpect(pat: String) extends Expect
-
- case class Program(breaks: Seq[Break], commands: Seq[Command])
-
- def error(msg: String): Nothing = {
- throw new Exception(msg)
- }
-
- def parseCommand(command: String, lineNo: Int): Tree = {
- val index = command.indexOf(':')
- if (index == -1) {
- // simple command
- if (command == "break") Break(lineNo)
- else Command(command)
- } else {
- val Seq(cmd, rhs) = command.split(":", 2).toSeq.map(_.trim)
- if (rhs.startsWith("\"")) {
- // regex match
- val content = "\"(.+)\"".r
- rhs match {
- case content(expect) => Command(cmd, PatExpect(expect))
- case _ => error(s"""incorrect specification: `$rhs` for `$cmd` at line $lineNo. Ending " expected.""")
- }
- } else {
- // literal match
- Command(cmd, LitExpect(rhs))
- }
- }
- }
-
- def parse(file: String): Program = {
- val lines = Source.fromFile(file).getLines.toBuffer
-
- val breaks = new ListBuffer[Break]()
- val cmds = new ListBuffer[Command]()
- lines.zipWithIndex.map { case (code, line) =>
- val comment = if (code.indexOf("//") != -1) code.split("//").last else ""
- val regex = """(?<=\[).*?(?=\])""".r
- for (p <- regex findAllIn comment) parseCommand(p.trim, line + 1) match { // jdb index from 0
- case b: Break => breaks += b
- case c: Command => cmds += c
- }
- }
-
- Program(breaks, cmds)
- }
-
- def generate(program: Program, source: String = "tests/debug/"): String = {
- val Program(breaks, cmds) = program
- val breakpoints = (breaks.map {
- case Break(point) =>
- s"""|send "stop at $MainObject$$:$point\\r"
- |sleep $CommandWait
- |expect "breakpoint $MainObject$$:$point"
- |expect -re $$
- """.stripMargin
- }).mkString("\n\n")
-
- val commands = (cmds.map {
- case Command(cmd, EmptyExpect) =>
- s"""|# send_user "send command `$cmd`\\n"
- |send "$cmd\\r"
- |sleep $CommandWait
- |expect -re $$
- """.stripMargin
- case Command(cmd, LitExpect(lit)) =>
- s"""|# send_user "send command `$cmd`\\n"
- |send "$cmd\\r"
- |sleep $CommandWait
- |expect {
- | "*$lit*" { send_user "success - $cmd : $lit \\n" }
- | timeout {
- | send_user "timeout while waiting for response: $cmd : $lit\\n"
- | exit 1
- | }
- |}
- |expect -re $$
- |""".stripMargin
- case Command(cmd, PatExpect(pat)) =>
- s"""|# send_user "send command `$cmd`\\n"
- |send "$cmd\\r"
- |sleep $CommandWait
- |expect {
- | -re {$pat} { send_user "success - $cmd : $pat \\n" }
- | timeout {
- | send_user "timeout while waiting for response: $cmd : $pat\\n"
- | exit 1
- | }
- |}
- |expect -re $$
- |""".stripMargin
- }).mkString("\n\n")
-
-s"""|#!/usr/bin/expect
- |
- |# log_user 1
- |# exp_internal 1
- |# set timeout 5
- |
- |send_user "spawning job...\\n"
- |
- |spawn jdb -attach 5005 -sourcepath $source
- |
- |send_user "interacting...\\n"
- |
- |expect {
- | "*VM Started*" { send_user "success - connected to server \\n" }
- | timeout {
- | send_user "timeout while waiting for: *VM Started*\\n"
- | exit 1
- | }
- |}
- |
- |send_user "setting breakpoints...\\n"
- |
- |# breakpoints
- |$breakpoints
- |
- |# run
- |send_user "run program...\\n"
- |send "run\\r"
- |expect "Breakpoint hit"
- |
- |# interactions
- |$commands""".stripMargin
- }
-}
-
-val prog = Gen.parse(args(0))
-// println("--------------------------------")
-// println("prog:" + prog)
-// println("\n\n\n scrip:")
-// println("--------------------------------")
-println(Gen.generate(prog))
diff --git a/compiler/test/debug/Gen.scala b/compiler/test/debug/Gen.scala
new file mode 100755
index 000000000..f7a5cc432
--- /dev/null
+++ b/compiler/test/debug/Gen.scala
@@ -0,0 +1,171 @@
+import scala.io.Source
+import scala.collection.mutable.ListBuffer
+
+/** Automate testing debuggability of generated code using JDB and expect
+ *
+ * The debugging information is annotated as comments to the code in brackets:
+ *
+ * val x = f(3) // [break] [next: line=5]
+ * val y = 5
+ *
+ * 1. A jdb command must be wrapped in brackets, like `[step]`. All jdb commands can be used.
+ * 2. To check output of jdb for a command, use `[cmd: expect]`.
+ * 3. If `expect` is wrapped in double quotes, regex is supported.
+ * 4. Break commands are collected and set globally.
+ * 5. Other commands will be send to jdb in the order they appear in the source file
+ *
+ * Note: jdb uses line number starts from 1
+ */
+
+object Gen {
+ val MainObject = "Test"
+ val CommandWait = 0.5
+
+ sealed trait Tree
+
+ case class Break(line: Int) extends Tree
+
+ case class Command(val name: String, val expect: Expect = EmptyExpect) extends Tree
+
+ sealed trait Expect
+
+ case object EmptyExpect extends Expect
+
+ case class LitExpect(lit: String) extends Expect
+
+ case class PatExpect(pat: String) extends Expect
+
+ case class Program(breaks: Seq[Break], commands: Seq[Command])
+
+ def error(msg: String): Nothing = {
+ throw new Exception(msg)
+ }
+
+ def parseCommand(command: String, lineNo: Int): Tree = {
+ val index = command.indexOf(':')
+ if (index == -1) {
+ // simple command
+ if (command == "break") Break(lineNo)
+ else Command(command)
+ } else {
+ val Seq(cmd, rhs) = command.split(":", 2).toSeq.map(_.trim)
+ if (rhs.startsWith("\"")) {
+ // regex match
+ val content = "\"(.+)\"".r
+ rhs match {
+ case content(expect) => Command(cmd, PatExpect(expect))
+ case _ => error(s"""incorrect specification: `$rhs` for `$cmd` at line $lineNo. Ending " expected.""")
+ }
+ } else {
+ // literal match
+ Command(cmd, LitExpect(rhs))
+ }
+ }
+ }
+
+ def parse(file: String): Program = {
+ val lines = Source.fromFile(file).getLines.toBuffer
+
+ val breaks = new ListBuffer[Break]()
+ val cmds = new ListBuffer[Command]()
+ lines.zipWithIndex.map { case (code, line) =>
+ val comment = if (code.indexOf("//") != -1) code.split("//").last else ""
+ val regex = """(?<=\[).*?(?=\])""".r
+ for (p <- regex findAllIn comment) parseCommand(p.trim, line + 1) match { // jdb index from 0
+ case b: Break => breaks += b
+ case c: Command => cmds += c
+ }
+ }
+
+ Program(breaks, cmds)
+ }
+
+ def generate(program: Program, source: String = "tests/debug/"): String = {
+ val Program(breaks, cmds) = program
+ val breakpoints = (breaks.map {
+ case Break(point) =>
+ s"""|send "stop at $MainObject$$:$point\\r"
+ |sleep $CommandWait
+ |expect "breakpoint $MainObject$$:$point"
+ |expect -re $$
+ """.stripMargin
+ }).mkString("\n\n")
+
+ val commands = (cmds.map {
+ case Command(cmd, EmptyExpect) =>
+ s"""|# send_user "send command `$cmd`\\n"
+ |send "$cmd\\r"
+ |sleep $CommandWait
+ |expect -re $$
+ """.stripMargin
+ case Command(cmd, LitExpect(lit)) =>
+ s"""|# send_user "send command `$cmd`\\n"
+ |send "$cmd\\r"
+ |sleep $CommandWait
+ |expect {
+ | "*$lit*" { send_user "success - $cmd : $lit \\n" }
+ | timeout {
+ | send_user "timeout while waiting for response: $cmd : $lit\\n"
+ | exit 1
+ | }
+ |}
+ |expect -re $$
+ |""".stripMargin
+ case Command(cmd, PatExpect(pat)) =>
+ s"""|# send_user "send command `$cmd`\\n"
+ |send "$cmd\\r"
+ |sleep $CommandWait
+ |expect {
+ | -re {$pat} { send_user "success - $cmd : $pat \\n" }
+ | timeout {
+ | send_user "timeout while waiting for response: $cmd : $pat\\n"
+ | exit 1
+ | }
+ |}
+ |expect -re $$
+ |""".stripMargin
+ }).mkString("\n\n")
+
+s"""|#!/usr/bin/expect
+ |
+ |# log_user 1
+ |# exp_internal 1
+ |# set timeout 5
+ |
+ |send_user "spawning job...\\n"
+ |
+ |spawn jdb -attach 5005 -sourcepath $source
+ |
+ |send_user "interacting...\\n"
+ |
+ |expect {
+ | "*VM Started*" { send_user "success - connected to server \\n" }
+ | timeout {
+ | send_user "timeout while waiting for: *VM Started*\\n"
+ | exit 1
+ | }
+ |}
+ |
+ |send_user "setting breakpoints...\\n"
+ |
+ |# breakpoints
+ |$breakpoints
+ |
+ |# run
+ |send_user "run program...\\n"
+ |send "run\\r"
+ |expect "Breakpoint hit"
+ |
+ |# interactions
+ |$commands""".stripMargin
+ }
+
+ def main(args: Array[String]): Unit = {
+ val prog = Gen.parse(args(0))
+ // println("--------------------------------")
+ // println("prog:" + prog)
+ // println("\n\n\n scrip:")
+ // println("--------------------------------")
+ println(Gen.generate(prog))
+ }
+}
diff --git a/compiler/test/debug/test b/compiler/test/debug/test
index c24801cb1..78bec3be0 100755
--- a/compiler/test/debug/test
+++ b/compiler/test/debug/test
@@ -2,12 +2,12 @@
set -x
-sbt compile package || exit 1
+DIR="$( cd "$( dirname "$0" )" && pwd )"
for file in tests/debug/*.scala; do
./bin/dotc $file || exit 1
./bin/dotr -d Test&
- ./compiler/test/debug/Gen $file > robot
+ $DIR/Gen $file > robot
expect robot
if [[ $? != 0 ]]; then
@@ -15,3 +15,4 @@ for file in tests/debug/*.scala; do
exit 1
fi
done
+