Skip to content

Commit 092456b

Browse files
committed
Merge pull request #41 from DarkDimius/virtualFile
Use virtual file instead of temporary file for tests
2 parents 340ec61 + fd5b429 commit 092456b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/dotty/tools/dotc/Run.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import Contexts._, Periods._, Symbols._
66
import io.PlainFile
77
import util.{SourceFile, NoSource, Stats, SimpleMap}
88
import reporting.Reporter
9-
import java.io.FileWriter
9+
import java.io.{BufferedWriter, OutputStreamWriter}
10+
import scala.reflect.io.VirtualFile
1011

1112
class Run(comp: Compiler)(implicit ctx: Context) {
1213

@@ -21,8 +22,12 @@ class Run(comp: Compiler)(implicit ctx: Context) {
2122
}
2223
}
2324

24-
def compile(fileNames: List[String]): Unit = Stats.monitorHeartBeat {
25+
def compile(fileNames: List[String]): Unit = {
2526
val sources = fileNames map getSource
27+
compileSources(sources)
28+
}
29+
30+
def compileSources(sources: List[SourceFile]) = Stats.monitorHeartBeat {
2631
if (sources forall (_.exists)) {
2732
units = sources map (new CompilationUnit(_))
2833
for (phase <- ctx.allPhases)
@@ -31,12 +36,11 @@ class Run(comp: Compiler)(implicit ctx: Context) {
3136
}
3237

3338
def compile(sourceCode: String): Unit = {
34-
val tmpFile = java.io.File.createTempFile("dotty-source-tmp", ".scala")
35-
tmpFile.createNewFile()
36-
val writer = new FileWriter(tmpFile)
39+
val virtualFile = new VirtualFile(sourceCode) // use source code as name as it's used for equals
40+
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
3741
writer.write(sourceCode)
3842
writer.close()
39-
compile(List(tmpFile.getAbsolutePath))
43+
compileSources(List(new SourceFile(virtualFile)))
4044
}
4145

4246
/** Print summary; return # of errors encountered */

0 commit comments

Comments
 (0)