Skip to content

Use virtual file instead of temporary file for tests #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Contexts._, Periods._, Symbols._
import io.PlainFile
import util.{SourceFile, NoSource, Stats, SimpleMap}
import reporting.Reporter
import java.io.FileWriter
import java.io.{BufferedWriter, OutputStreamWriter}
import scala.reflect.io.VirtualFile

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

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

def compile(fileNames: List[String]): Unit = Stats.monitorHeartBeat {
def compile(fileNames: List[String]): Unit = {
val sources = fileNames map getSource
compileSources(sources)
}

def compileSources(sources: List[SourceFile]) = Stats.monitorHeartBeat {
if (sources forall (_.exists)) {
units = sources map (new CompilationUnit(_))
for (phase <- ctx.allPhases)
Expand All @@ -31,12 +36,11 @@ class Run(comp: Compiler)(implicit ctx: Context) {
}

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

/** Print summary; return # of errors encountered */
Expand Down