Skip to content

Commit 5e6a9a2

Browse files
committed
Merge pull request #691 from vsalvis/vsalvis-partest-output
Partest output redirection over context.reporter
2 parents 6dbb991 + 4b42a19 commit 5e6a9a2

File tree

12 files changed

+61
-55
lines changed

12 files changed

+61
-55
lines changed

src/dotty/tools/dotc/Bench.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ object Bench extends Driver {
2929
private def ntimes(n: Int)(op: => Reporter): Reporter =
3030
(emptyReporter /: (0 until n)) ((_, _) => op)
3131

32-
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
32+
override def doCompile(compiler: Compiler, fileNames: List[String], reporter: Option[Reporter] = None)
33+
(implicit ctx: Context): Reporter =
3334
if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx))
3435
resident(compiler)
3536
else
3637
ntimes(numRuns) {
3738
val start = System.nanoTime()
38-
val r = super.doCompile(compiler, fileNames)
39-
println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms")
39+
val r = super.doCompile(compiler, fileNames, reporter)
40+
ctx.println(s"time elapsed: ${(System.nanoTime - start) / 1000000}ms")
4041
r
4142
}
4243

@@ -46,11 +47,11 @@ object Bench extends Driver {
4647
else (args(pos + 1).toInt, (args take pos) ++ (args drop (pos + 2)))
4748
}
4849

49-
override def process(args: Array[String], rootCtx: Context): Reporter = {
50+
override def process(args: Array[String], rootCtx: Context, reporter: Option[Reporter] = None): Reporter = {
5051
val (numCompilers, args1) = extractNumArg(args, "#compilers")
5152
val (numRuns, args2) = extractNumArg(args1, "#runs")
5253
this.numRuns = numRuns
53-
ntimes(numCompilers)(super.process(args2, rootCtx))
54+
ntimes(numCompilers)(super.process(args2, rootCtx, reporter))
5455
}
5556
}
5657

src/dotty/tools/dotc/Compiler.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Periods._
77
import Symbols._
88
import Scopes._
99
import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks}
10-
import reporting.ConsoleReporter
10+
import reporting.{ConsoleReporter, Reporter}
1111
import Phases.Phase
1212
import dotty.tools.dotc.transform._
1313
import dotty.tools.dotc.transform.TreeTransforms.{TreeTransform, TreeTransformer}
@@ -94,7 +94,7 @@ class Compiler {
9494
* for type checking.
9595
* imports For each element of RootImports, an import context
9696
*/
97-
def rootContext(implicit ctx: Context): Context = {
97+
def rootContext(implicit ctx: Context, r: Option[Reporter] = None): Context = {
9898
ctx.definitions.init(ctx)
9999
ctx.setPhasePlan(phases)
100100
val rootScope = new MutableScope
@@ -106,7 +106,7 @@ class Compiler {
106106
.setOwner(defn.RootClass)
107107
.setTyper(new Typer)
108108
.setMode(Mode.ImplicitsEnabled)
109-
.setTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true))
109+
.setTyperState(new MutableTyperState(ctx.typerState, r.getOrElse(new ConsoleReporter()(ctx)), isCommittable = true))
110110
ctx.definitions.init(start) // set context of definitions to start
111111
def addImport(ctx: Context, symf: () => Symbol) =
112112
ctx.fresh.setImportInfo(ImportInfo.rootImport(symf)(ctx))
@@ -118,8 +118,8 @@ class Compiler {
118118
ctx.runInfo.clear()
119119
}
120120

121-
def newRun(implicit ctx: Context): Run = {
121+
def newRun(implicit ctx: Context, r: Option[Reporter] = None): Run = {
122122
reset()
123-
new Run(this)(rootContext)
123+
new Run(this)(rootContext(ctx, r))
124124
}
125125
}

src/dotty/tools/dotc/Driver.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ abstract class Driver extends DotClass {
1414

1515
protected def emptyReporter: Reporter = new StoreReporter
1616

17-
protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
17+
protected def doCompile(compiler: Compiler, fileNames: List[String], reporter: Option[Reporter] = None)
18+
(implicit ctx: Context): Reporter =
1819
if (fileNames.nonEmpty) {
19-
val run = compiler.newRun
20+
val run = compiler.newRun(ctx, reporter)
2021
run.compile(fileNames)
2122
run.printSummary()
2223
} else emptyReporter
2324

2425
protected def initCtx = (new ContextBase).initialCtx
2526

26-
def process(args: Array[String], rootCtx: Context): Reporter = {
27+
def process(args: Array[String], rootCtx: Context, reporter: Option[Reporter] = None): Reporter = {
2728
val summary = CompilerCommand.distill(args)(rootCtx)
2829
implicit val ctx: Context = initCtx.fresh.setSettings(summary.sstate)
2930
val fileNames = CompilerCommand.checkUsage(summary)
3031
try {
31-
doCompile(newCompiler(), fileNames)
32+
doCompile(newCompiler(), fileNames, reporter)
3233
} catch {
3334
case ex: FatalError =>
3435
ctx.error(ex.getMessage) // signals that we should fail compilation.

src/dotty/tools/dotc/FromTasty.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SymDenotations._
1212
import typer.FrontEnd
1313
import Phases.Phase
1414
import util._
15+
import reporting.Reporter
1516
import Decorators._
1617
import dotty.tools.dotc.transform.Pickler
1718
import tasty.DottyUnpickler
@@ -41,7 +42,7 @@ object FromTasty extends Driver {
4142
List(new ReadTastyTreesFromClasses) :: backendPhases
4243
}
4344

44-
override def newRun(implicit ctx: Context): Run = {
45+
override def newRun(implicit ctx: Context, reporter: Option[Reporter] = None): Run = {
4546
reset()
4647
new TASTYRun(this)(rootContext)
4748
}

src/dotty/tools/dotc/Main.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ object Main extends Driver {
1919

2020
override def newCompiler(): Compiler = new Compiler
2121

22-
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = {
22+
override def doCompile(compiler: Compiler, fileNames: List[String], reporter: Option[Reporter] = None)(implicit ctx: Context): Reporter = {
2323
if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx))
2424
resident(compiler)
2525
else
26-
super.doCompile(compiler, fileNames)
26+
super.doCompile(compiler, fileNames, reporter)
2727
}
2828
}

src/dotty/tools/dotc/Run.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
3333
compileSources(sources)
3434
} catch {
3535
case NonFatal(ex) =>
36-
println(i"exception occurred while compiling $units%, %")
36+
ctx.println(i"exception occurred while compiling $units%, %")
3737
throw ex
3838
}
3939

@@ -55,7 +55,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
5555
ctx.usePhases(phases)
5656
for (phase <- ctx.allPhases)
5757
if (!ctx.reporter.hasErrors) {
58-
if (ctx.settings.verbose.value) println(s"[$phase]")
58+
if (ctx.settings.verbose.value) ctx.println(s"[$phase]")
5959
units = phase.runOn(units)
6060
def foreachUnit(op: Context => Unit)(implicit ctx: Context): Unit =
6161
for (unit <- units) op(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
@@ -69,8 +69,8 @@ class Run(comp: Compiler)(implicit ctx: Context) {
6969
val prevPhase = ctx.phase.prev // can be a mini-phase
7070
val squashedPhase = ctx.squashed(prevPhase)
7171

72-
println(s"result of $unit after ${squashedPhase}:")
73-
println(unit.tpdTree.show(ctx))
72+
ctx.println(s"result of $unit after ${squashedPhase}:")
73+
ctx.println(unit.tpdTree.show(ctx))
7474
}
7575

7676
def compile(sourceCode: String): Unit = {

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class TreeChecker extends Phase with SymTransformer {
4242
private val seenClasses = collection.mutable.HashMap[String, Symbol]()
4343
private val seenModuleVals = collection.mutable.HashMap[String, Symbol]()
4444

45-
def printError(str: String) = {
46-
println(Console.RED + "[error] " + Console.WHITE + str)
45+
def printError(str: String)(implicit ctx: Context) = {
46+
ctx.println(Console.RED + "[error] " + Console.WHITE + str)
4747
}
4848

4949
val NoSuperClass = Trait | Package
@@ -109,15 +109,15 @@ class TreeChecker extends Phase with SymTransformer {
109109
def check(phasesToRun: Seq[Phase], ctx: Context) = {
110110
val prevPhase = ctx.phase.prev // can be a mini-phase
111111
val squahsedPhase = ctx.squashed(prevPhase)
112-
println(s"checking ${ctx.compilationUnit} after phase ${squahsedPhase}")
112+
ctx.println(s"checking ${ctx.compilationUnit} after phase ${squahsedPhase}")
113113
val checkingCtx = ctx.fresh
114114
.setTyperState(ctx.typerState.withReporter(new ThrowingReporter(ctx.typerState.reporter)))
115115
val checker = new Checker(previousPhases(phasesToRun.toList)(ctx))
116116
try checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
117117
catch {
118118
case NonFatal(ex) =>
119119
implicit val ctx: Context = checkingCtx
120-
println(i"*** error while checking after phase ${checkingCtx.phase.prev} ***")
120+
ctx.println(i"*** error while checking after phase ${checkingCtx.phase.prev} ***")
121121
throw ex
122122
}
123123
}
@@ -151,10 +151,10 @@ class TreeChecker extends Phase with SymTransformer {
151151
}
152152

153153
nowDefinedSyms += tree.symbol
154-
//println(i"defined: ${tree.symbol}")
154+
//ctx.println(i"defined: ${tree.symbol}")
155155
val res = op
156156
nowDefinedSyms -= tree.symbol
157-
//println(i"undefined: ${tree.symbol}")
157+
//ctx.println(i"undefined: ${tree.symbol}")
158158
res
159159
case _ => op
160160
}

src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FrontEnd extends Phase {
1919
try body
2020
catch {
2121
case NonFatal(ex) =>
22-
println(s"exception occurred while $doing ${ctx.compilationUnit}")
22+
ctx.println(s"exception occurred while $doing ${ctx.compilationUnit}")
2323
throw ex
2424
}
2525

test/dotty/partest/DPConfig.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package dotty.partest
22

3-
import java.io.File
43
import scala.collection.JavaConversions._
4+
import scala.reflect.io.Path
5+
import java.io.File
56

67

78
/** Dotty Partest runs all tests in the provided testDirs located under
@@ -14,7 +15,9 @@ import scala.collection.JavaConversions._
1415
* otherwise pos/__defaultFlags.flags are used if the file exists).
1516
*/
1617
object DPConfig {
17-
val testRoot = "./tests/partest-generated"
18+
val testRoot = (Path(".") / Path("tests") / Path("partest-generated")).toString
19+
val genLog = Path(testRoot) / Path("gen.log")
20+
1821
lazy val testDirs = {
1922
val root = new File(testRoot)
2023
val dirs = if (!root.exists) Array.empty[String] else root.listFiles.filter(_.isDirectory).map(_.getName)

test/dotty/partest/DPConsoleRunner.scala

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scala.tools.partest._
99
import scala.tools.partest.nest._
1010
import scala.util.matching.Regex
1111
import tools.nsc.io.{ File => NSCFile }
12-
import java.io.{ File, PrintStream, FileOutputStream }
12+
import java.io.{ File, PrintStream, FileOutputStream, PrintWriter, FileWriter }
1313
import java.net.URLClassLoader
1414

1515
/** Runs dotty partest from the Console, discovering test sources in
@@ -91,23 +91,11 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
9191

9292
val state =
9393
try {
94-
// IO redirection is messy, there are no concurrency guarantees.
95-
// Parts of test output might end up in the wrong file or get lost.
96-
Console.out.flush
97-
Console.err.flush
98-
val clog = runner.cLogFile
99-
val stream = new PrintStream(new FileOutputStream(clog.jfile), true)
100-
val result = Console.withOut(stream)({ Console.withErr(stream)({
101-
val res = runner.run()
102-
Console.err.flush
103-
Console.out.flush
104-
res
105-
})})
106-
result match {
94+
runner.run match {
10795
// Append compiler output to transcript if compilation failed,
10896
// printed with --verbose option
10997
case TestState.Fail(f, r@"compilation failed", transcript) =>
110-
TestState.Fail(f, r, transcript ++ clog.fileLines.dropWhile(_ == ""))
98+
TestState.Fail(f, r, transcript ++ runner.cLogFile.fileLines.dropWhile(_ == ""))
11199
case res => res
112100
}
113101
} catch {
@@ -261,11 +249,16 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
261249
override def groupedFiles(sources: List[File]): List[List[File]] = {
262250
val grouped = sources groupBy (_.group)
263251
val flatGroup = List(grouped.keys.toList.sorted.map({ k => grouped(k) sortBy (_.getName) }).flatten)
264-
try { // try/catch because of bug in partest
252+
try { // try/catch because of bug in partest that throws exception
265253
if (flatGroup != super.groupedFiles(sources))
266-
NestUI.echoWarning("Warning: Overriding compilation groups for tests: " + sources)
254+
throw new java.lang.UnsupportedOperationException()
267255
} catch {
268-
case e: java.lang.UnsupportedOperationException => NestUI.echoWarning("Warning: Overriding compilation groups for tests: " + sources)
256+
case e: java.lang.UnsupportedOperationException =>
257+
val genlogFWriter = new FileWriter(DPConfig.genLog.jfile, true)
258+
val genlogWriter = new PrintWriter(genlogFWriter, true)
259+
genlogWriter.println("Warning: Overriding compilation groups for tests: " + sources)
260+
genlogWriter.close
261+
genlogFWriter.close
269262
}
270263
flatGroup
271264
}

0 commit comments

Comments
 (0)