Skip to content

Commit

Permalink
Merge pull request scala#558 from dotty-staging/run-tests
Browse files Browse the repository at this point in the history
Add run tests to pending.
  • Loading branch information
DarkDimius committed May 15, 2015
2 parents 595f245 + f904062 commit 49e537e
Show file tree
Hide file tree
Showing 3,387 changed files with 93,299 additions and 27 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
10 changes: 7 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ object DottyBuild extends Build {
partestLockFile.createNewFile
partestLockFile.deleteOnExit
},
runPartestRunner <<= Def.taskDyn {
runPartestRunner <<= Def.inputTaskDyn {
// Magic! This is both an input task and a dynamic task. Apparently
// command line arguments get passed to the last task in an aliased
// sequence (see partest alias below), so this works.
val args = Def.spaceDelimited("<arg>").parsed
val jars = Seq((packageBin in Compile).value.getAbsolutePath) ++
getJarPaths(partestDeps.value, ivyPaths.value.ivyHome)
val dottyJars = "-dottyJars " + jars.length + " " + jars.mkString(" ")
// Provide the jars required on the classpath of run tests
runTask(Test, "dotty.partest.DPConsoleRunner", dottyJars)
runTask(Test, "dotty.partest.DPConsoleRunner", dottyJars + " " + args.mkString(" "))
},

// Adjust classpath for running dotty
Expand Down Expand Up @@ -170,7 +174,7 @@ object DottyBuild extends Build {
lazy val partestLockFile = new File("." + File.separator + "tests" + File.separator + "locks" + File.separator + s"partest-$pid.lock")
def pid = java.lang.Long.parseLong(java.lang.management.ManagementFactory.getRuntimeMXBean().getName().split("@")(0))

lazy val runPartestRunner = TaskKey[Unit]("runPartestRunner", "Runs partest")
lazy val runPartestRunner = InputKey[Unit]("runPartestRunner", "Runs partest")

lazy val partestDeps = SettingKey[Seq[ModuleID]]("partestDeps", "Finds jars for partest dependencies")
def getJarPaths(modules: Seq[ModuleID], ivyHome: Option[File]): Seq[String] = ivyHome match {
Expand Down
9 changes: 9 additions & 0 deletions src/dotty/runtime/LegacyApp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dotty.runtime


/**
* replaces the `scala.App` class which relies on `DelayedInit` functionality, not supported by Dotty.
*/
class LegacyApp {
def main(args: Array[String]): Unit = ()
}
4 changes: 2 additions & 2 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class tests extends CompilerTest {
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
@Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)
@Test def neg_selfInheritance = compileFile(negDir, "selfInheritance", xerrors = 5)


@Test def run_hello = runFile(runDir, "hello")
@Test def run_lazyVals = runFile(runDir, "lazyVals")
@Test def run_all = runFiles(runDir)


@Test def dotty = compileDir(dottyDir, "tools", "-deep" :: allowDeepSubtypes ++ twice) // note the -deep argument
Expand Down
13 changes: 8 additions & 5 deletions test/dotty/partest/DPConsoleRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ object DPConsoleRunner {
// extra jars for run tests are passed with -dottyJars <count> <jar1> <jar2> ...
val jarFinder = """-dottyJars (\d*) (.*)""".r
val (jarList, otherArgs) = args.toList.partition(jarFinder.findFirstIn(_).isDefined)
val extraJars = jarList match {
val (extraJars, moreArgs) = jarList match {
case Nil => sys.error("Error: DPConsoleRunner needs \"-dottyJars <jarCount> <jars>*\".")
case jarFinder(nr, jarString) :: Nil =>
val jars = jarString.split(" ").toList
if (jars.length.toString != nr)
sys.error("Error: DPConsoleRunner found wrong number of dottyJars: " + jars + ", expected: " + nr + ". Make sure the path doesn't contain any spaces.")
else jars
val count = nr.toInt
if (jars.length < count)
sys.error("Error: DPConsoleRunner found wrong number of dottyJars: " + jars + ", expected: " + nr)
else (jars.take(count), jars.drop(count))
case list => sys.error("Error: DPConsoleRunner found several -dottyJars options: " + list)
}
new DPConsoleRunner(otherArgs mkString (" "), extraJars).runPartest
new DPConsoleRunner((otherArgs ::: moreArgs) mkString (" "), extraJars).runPartest
}
}

// console runner has a suite runner which creates a test runner for each test
class DPConsoleRunner(args: String, extraJars: List[String]) extends ConsoleRunner(args) {
println("ConsoleRunner options: " + args)

override val suiteRunner = new DPSuiteRunner (
testSourcePath = optSourcePath getOrElse DPConfig.testRoot,
fileManager = new DottyFileManager(extraJars),
Expand Down
32 changes: 19 additions & 13 deletions test/test/CompilerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract class CompilerTest extends DottyTest {
* @param extension the file extension, .scala by default
* @param defaultOptions more arguments to the compiler
*/
def compileFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
def compileFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
extension: String = ".scala", runTest: Boolean = false)
(implicit defaultOptions: List[String]): Unit = {
if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions, xerrors)) {
Expand All @@ -102,7 +102,8 @@ abstract class CompilerTest extends DottyTest {
}
}
}
def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,

def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
extension: String = ".scala")(implicit defaultOptions: List[String]): Unit =
compileFile(prefix, fileName, args, xerrors, extension, true)

Expand Down Expand Up @@ -140,23 +141,28 @@ abstract class CompilerTest extends DottyTest {
}
}
}

def runDir(prefix: String, dirName: String, args: List[String] = Nil, xerrors: Int = 0)
(implicit defaultOptions: List[String]): Unit =
compileDir(prefix, dirName, args, xerrors, true)

def runFiles(path: String, args: List[String] = Nil, verbose: Boolean = true)
(implicit defaultOptions: List[String]): Unit =
compileFiles(path, args, verbose, true)

/** Compiles each source in the directory path separately by calling
* compileFile resp. compileDir. */
def compileFiles(path: String, args: List[String] = Nil, verbose: Boolean = true)
def compileFiles(path: String, args: List[String] = Nil, verbose: Boolean = true, isRunTest: Boolean = false)
(implicit defaultOptions: List[String]): Unit = {
val dir = Directory(path)
val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
for (name <- fileNames) {
if (verbose) println(s"testing $path$name")
compileFile(path, name, args, 0, "")
compileFile(path, name, args, 0, "", isRunTest)
}
for (subdir <- dir.dirs) {
if (verbose) println(s"testing $subdir")
compileDir(path, subdir.jfile.getName, args, 0)
compileDir(path, subdir.jfile.getName, args, 0, isRunTest)
}
}

Expand All @@ -167,7 +173,7 @@ abstract class CompilerTest extends DottyTest {
compileArgs((files ++ args).toArray, xerrors)
} else {
val destDir = Directory(DPConfig.testRoot + JFile.separator + testName)
files.foreach({ file =>
files.foreach({ file =>
val jfile = new JFile(file)
recCopyFiles(jfile, destDir / jfile.getName)
})
Expand All @@ -192,7 +198,7 @@ abstract class CompilerTest extends DottyTest {
if (runTest) "run"
else if (xerrors > 0) "neg"
else if (prefixDir.endsWith("run" + JFile.separator)) {
NestUI.echoWarning("WARNING: test is being run as pos test despite being in a run directory. " +
NestUI.echoWarning("WARNING: test is being run as pos test despite being in a run directory. " +
"Use runFile/runDir instead of compileFile/compileDir to do a run test")
"pos"
} else "pos"
Expand Down Expand Up @@ -226,7 +232,7 @@ abstract class CompilerTest extends DottyTest {
computeDestAndCopyFiles(source, nextDest, kind, flags, nerr, nr + 1, partestOutput)
}
}

/** Copies the test sources. Creates flags, nerr, check and output files. */
private def copyFiles(sourceFile: Path, dest: Path, partestOutput: String, flags: List[String], nerr: String, kind: String) = {
recCopyFiles(sourceFile, dest)
Expand All @@ -237,7 +243,7 @@ abstract class CompilerTest extends DottyTest {
dest.changeExtension("flags").createFile(true).writeAll(flags.mkString(" "))
if (nerr != "0")
dest.changeExtension("nerr").createFile(true).writeAll(nerr)
sourceFile.changeExtension("check").ifFile({ check =>
sourceFile.changeExtension("check").ifFile({ check =>
if (kind == "run")
FileManager.copyFile(check.jfile, dest.changeExtension("check").jfile)
else
Expand All @@ -256,7 +262,7 @@ abstract class CompilerTest extends DottyTest {
} else {
NestUI.echoWarning(s"WARNING: ignoring $sf")
}
}, { sdir =>
}, { sdir =>
dest.jfile.mkdirs
sdir.list.foreach(path => recCopyFiles(path, dest / path.name))
}, Some("DPCompilerTest.recCopyFiles: sourceFile not found: " + sourceFile))
Expand All @@ -278,7 +284,7 @@ abstract class CompilerTest extends DottyTest {
if (!genSrc.isDefined) {
NotExists
} else {
val source = processFileDir(sourceFile, { f => f.safeSlurp }, { d => Some("") },
val source = processFileDir(sourceFile, { f => f.safeSlurp }, { d => Some("") },
Some("DPCompilerTest sourceFile doesn't exist: " + sourceFile)).get
if (source == genSrc) {
nerr match {
Expand All @@ -299,7 +305,7 @@ abstract class CompilerTest extends DottyTest {
val nrString = nr.toString
name match {
case nrFinder(prefix, `nrString`) => prefix + (nr + 1)
case _ =>
case _ =>
assert(nr == 0, "DPCompilerTest couldn't create new version of files, match error")
name + "_v1"
}
Expand All @@ -324,7 +330,7 @@ abstract class CompilerTest extends DottyTest {
Directory(prefix + dirName).deepFiles.foreach(source => recCopyFiles(source, destDir / source.name))
destDir.jfile
}

}

object CompilerTest extends App {
Expand Down
1 change: 1 addition & 0 deletions tests/pending/run/.checkSrcRegen
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source regeneration: Tue May 12 18:21:01 CEST 2015
37 changes: 37 additions & 0 deletions tests/pending/run/Course-2002-01.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Course-2002-01.scala:41: warning: method loop in object M0 does nothing other than call itself recursively
def loop: Int = loop;
^
232
667
11
10
62.8318
62.8318
62.8318
4.0
81.0
256.0
25.0
1
737.0
1.0
0.0
1.0
76.0
1.4142156862745097
1.7321428571428572
2.0000000929222947
1.4142156862745097
1.7321428571428572
2.0000000929222947
1.4142156862745097
1.7321428571428572
2.0000000929222947
sqrt(2) = 1.4142135623746899
sqrt(2) = 1.4142135623746899
cbrt(2) = 1.2599210500177698
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Loading

0 comments on commit 49e537e

Please sign in to comment.