|
1 | 1 | import scala.tools.nsc.Settings |
2 | 2 | import scala.tools.nsc.interpreter._, shell._ |
| 3 | +import scala.util.Properties.lineSeparator |
3 | 4 |
|
4 | | -import java.io.{PrintWriter, OutputStream} |
| 5 | +import java.io.{PrintWriter, StringWriter} |
5 | 6 |
|
6 | 7 | object Test { |
7 | 8 |
|
8 | 9 | def main(args: Array[String]): Unit = { |
9 | | - //val filename: String = ".../data/generated_01mb.base64" |
10 | | - val filename: String = sys.props("partest.test-path") |
11 | 10 | val code: String = |
12 | | - "import scala.io.Source\n " + |
13 | | - "Source.fromFile(\"" + filename + "\").getLines().mkString(\"\\n\")" |
| 11 | + s"""|import scala.io.Source |
| 12 | + |import scala.util.Properties.lineSeparator |
| 13 | + |import scala.util.chaining._ |
| 14 | + |Source.fromFile(sys.props("partest.test-path")).pipe(s => s.getLines().mkString(lineSeparator).tap(_ => s.close())) |
| 15 | + |""".stripMargin.linesIterator.mkString(lineSeparator) |
14 | 16 |
|
15 | 17 | val s = new Settings() |
16 | 18 |
|
17 | 19 | s.processArguments( |
18 | 20 | List( |
19 | | - //"-Xprint:typer", |
20 | 21 | "-deprecation", |
21 | 22 | "-Yrepl-class-based", |
22 | | - "-Yrepl-outdir", "./target" |
| 23 | + "-Yrepl-outdir", "target" |
23 | 24 | ), processAll = true) |
24 | 25 |
|
25 | | - val drain = new OutputStream { override def write(byte: Int) = () } |
| 26 | + val drain = new StringWriter //new OutputStream { override def write(byte: Int) = () } |
26 | 27 | val sinkWriter = new PrintWriter(drain) |
27 | 28 | val reporter = new ReplReporterImpl(ShellConfig(s), s, sinkWriter) |
28 | 29 | val repl = new IMain(s, reporter) |
29 | 30 | repl.settings.usejavacp.value = true |
30 | | - for(i <- 1 to 65) { |
| 31 | + for (i <- 1 to 65) { |
31 | 32 | repl.interpret(code) match { |
32 | 33 | case Results.Success => |
33 | 34 | assert(repl.valueOfTerm(repl.mostRecentVar).get != null) // 2.12: null after 60 |
34 | 35 | case other => |
| 36 | + println(drain.toString) |
35 | 37 | throw new MatchError(other) |
36 | 38 | } |
37 | 39 | } |
|
0 commit comments