Skip to content

Environmentally friendly tests #1739

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
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ object Symbols {
final def entered(implicit ctx: Context): this.type = {
assert(this.owner.isClass, s"symbol ($this) entered the scope of non-class owner ${this.owner}") // !!! DEBUG
this.owner.asClass.enter(this)
if (this.is(Module, butNot = Package)) this.owner.asClass.enter(this.moduleClass)
if (this is Module) this.owner.asClass.enter(this.moduleClass)
this
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
val tp = readType()
val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
annots += Annotation.deferredSymAndTree(tp.typeSymbol, _ => lazyAnnotTree.complete)
case _ =>
assert(false, s"illegal modifier tag at $currentAddr")
case tag =>
assert(false, s"illegal modifier tag $tag at $currentAddr, end = $end")
}
}
(flags, annots.toList, privateWithin)
Expand Down
15 changes: 10 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,20 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
else false

/** A symbol qualifies if it really exists. In addition,
* if we are in a constructor of a pattern, we ignore all definitions
/** A symbol qualifies if it really exists and is not a package class.
* In addition, if we are in a constructor of a pattern, we ignore all definitions
* which are methods and not accessors (note: if we don't do that
* case x :: xs in class List would return the :: method).
*
* Package classes are part of their parent's scope, because otherwise
* we could not reload them via `_.member`. On the other hand, accessing a
* package as a type from source is always an error.
*/
def qualifies(denot: Denotation): Boolean =
reallyExists(denot) && !(
pt.isInstanceOf[UnapplySelectionProto] &&
(denot.symbol is (Method, butNot = Accessor)))
reallyExists(denot) &&
!(pt.isInstanceOf[UnapplySelectionProto] &&
(denot.symbol is (Method, butNot = Accessor))) &&
!(denot.symbol is PackageClass)

/** Find the denotation of enclosing `name` in given context `ctx`.
* @param previous A denotation that was found in a more deeply nested scope,
Expand Down
27 changes: 20 additions & 7 deletions compiler/test/dotc/tests.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dotc

import dotty.Jars
import dotty.tools.dotc.CompilerTest
import org.junit.{Before, Test}

Expand Down Expand Up @@ -32,18 +33,28 @@ class tests extends CompilerTest {
)

val classPath = {
val paths = List(
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar",
"./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar",
"../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
).map { p =>
val paths = Jars.dottyTestDeps map { p =>
val file = new JFile(p)
assert(
file.exists,
s"""File "$p" couldn't be found. Run `packageAll` from build tool before testing"""
s"""|File "$p" couldn't be found. Run `packageAll` from build tool before
|testing.
|
|If running without sbt, test paths need to be setup environment variables:
|
| - DOTTY_LIBRARY
| - DOTTY_COMPILER
| - DOTTY_INTERFACES
| - DOTTY_EXTRAS
|
|Where these all contain locations, except extras which is a colon
|separated list of jars.
|
|When compiling with eclipse, you need the sbt-interfaces jar, put
|it in extras."""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*put

)
file.getAbsolutePath
}.mkString(":")
} mkString (":")

List("-classpath", paths)
}
Expand Down Expand Up @@ -342,6 +353,8 @@ class tests extends CompilerTest {
// first compile dotty
compileDir(dottyDir, ".", List("-deep", "-Ycheck-reentrant", "-strict"))(allowDeepSubtypes)

compileDir(libDir, "dotty", "-deep" :: opt)
compileDir(libDir, "scala", "-deep" :: opt)
compileDir(dottyDir, "tools", opt)
compileDir(toolsDir, "dotc", opt)
compileDir(dotcDir, "ast", opt)
Expand Down
24 changes: 24 additions & 0 deletions compiler/test/dotty/Jars.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dotty

/** Jars used when compiling test, defaults to sbt locations */
object Jars {
val dottyLib: String = sys.env.get("DOTTY_LIB") getOrElse {
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
}

val dottyCompiler: String = sys.env.get("DOTTY_COMPILER") getOrElse {
"./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar"
}

val dottyInterfaces: String = sys.env.get("DOTTY_INTERFACE") getOrElse {
"../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
}

val dottyExtras: List[String] = sys.env.get("DOTTY_EXTRAS")
.map(_.split(":").toList).getOrElse(Nil)

val dottyReplDeps: List[String] = dottyLib :: dottyExtras

val dottyTestDeps: List[String] =
dottyLib :: dottyCompiler :: dottyInterfaces :: dottyExtras
}
46 changes: 29 additions & 17 deletions compiler/test/dotty/partest/DPConsoleRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,43 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
""".stripMargin
}

/** Tests which are compiled with one or more of the flags in this list will be run
* one by one, without any other test running at the same time.
* This is necessary because some test flags require a lot of memory when running
* the compiler and may exhaust the available memory when run in parallel with other tests.
*/
def sequentialFlags = List("-Ytest-pickler")
/** Some tests require a limitation of resources, tests which are compiled
* with one or more of the flags in this list will be run with
* `limitedThreads`. This is necessary because some test flags require a lot
* of memory when running the compiler and may exhaust the available memory
* when run in parallel with too many other tests.
*
* This number could be increased on the CI, but might fail locally if
* scaled too extreme - override with:
*
* ```
* -Ddotty.tests.limitedThreads=X
* ```
*/
def limitResourceFlags = List("-Ytest-pickler")
private val limitedThreads = sys.props.get("dotty.tests.limitedThreads").getOrElse("2")

override def runTestsForFiles(kindFiles: Array[File], kind: String): Array[TestState] = {
val (sequentialTests, parallelTests) =
val (limitResourceTests, parallelTests) =
kindFiles partition { kindFile =>
val flags = kindFile.changeExtension("flags").fileContents
sequentialFlags.exists(seqFlag => flags.contains(seqFlag))
limitResourceFlags.exists(seqFlag => flags.contains(seqFlag))
}

val seqResults =
if (!sequentialTests.isEmpty) {
if (!limitResourceTests.isEmpty) {
val savedThreads = sys.props("partest.threads")
sys.props("partest.threads") = "2"
sys.props("partest.threads") = {
assert(
savedThreads == null || limitedThreads.toInt <= savedThreads.toInt,
"""|Should not use more threads than the default, when the point
|is to limit the amount of resources""".stripMargin
)
limitedThreads
}

NestUI.echo(s"## we will run ${sequentialTests.length} tests using ${PartestDefaults.numThreads} thread(s)")
val res = super.runTestsForFiles(sequentialTests, kind)
NestUI.echo(s"## we will run ${limitResourceTests.length} tests using ${PartestDefaults.numThreads} thread(s) in parallel")
val res = super.runTestsForFiles(limitResourceTests, kind)

if (savedThreads != null)
sys.props("partest.threads") = savedThreads
Expand Down Expand Up @@ -383,13 +399,9 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
suiteRunner.fileManager.asInstanceOf[DottyFileManager].extraJarList ::: super.extraClasspath

// override to keep class files if failed and delete clog if ok
override def cleanup = if (lastState.isOk) try {
override def cleanup = if (lastState.isOk) {
logFile.delete
cLogFile.delete
Directory(outDir).deleteRecursively
} catch {
case t: Throwable =>
println("whhhhhhhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat")
throw t
}
}
5 changes: 1 addition & 4 deletions compiler/test/dotty/tools/DottyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class DottyTest extends ContextEscapeDetection{
import base.settings._
val ctx = base.initialCtx.fresh
ctx.setSetting(ctx.settings.encoding, "UTF8")
ctx.setSetting(
ctx.settings.classpath,
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
)
ctx.setSetting(ctx.settings.classpath, Jars.dottyLib)
// when classpath is changed in ctx, we need to re-initialize to get the
// correct classpath from PathResolver
base.initialize()(ctx)
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/dotty/tools/ShowClassTests.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools
package dotty
package tools

import dotc.core._
import dotc.core.Contexts._
Expand All @@ -18,8 +19,7 @@ class ShowClassTests extends DottyTest {
ctx.setSetting(ctx.settings.encoding, "UTF8")
ctx.setSetting(
ctx.settings.classpath,
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar" +
":../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
Jars.dottyLib + ":" + Jars.dottyInterfaces
)
base.initialize()(ctx)
ctx
Expand Down
3 changes: 2 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,14 @@ abstract class CompilerTest {
private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile])
(implicit defaultOptions: List[String]): Unit = {
val allArgs = args ++ defaultOptions
val verbose = allArgs.contains("-verbose")
//println(s"""all args: ${allArgs.mkString("\n")}""")
val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
val storeReporter = new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
private val consoleReporter = new ConsoleReporter()
private val innerStoreReporter = new StoreReporter(consoleReporter)
def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
if (m.level == ERROR) {
if (m.level == ERROR || verbose) {
innerStoreReporter.flush()
consoleReporter.doReport(m)
}
Expand Down
12 changes: 3 additions & 9 deletions compiler/test/dotty/tools/dotc/EntryPointsTest.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools
package dotty
package tools
package dotc

import org.junit.Test
Expand All @@ -19,14 +20,7 @@ import scala.collection.mutable.ListBuffer
class EntryPointsTest {
private val sources =
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
private val dottyInterfaces =
new java.io.File("../interfaces/dotty-interfaces-0.1-SNAPSHOT.jar").getPath
private val dottyLibrary =
new java.io.File("../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar").getPath
private val args =
sources ++
List("-d", "../out/") ++
List("-classpath", dottyInterfaces + ":" + dottyLibrary)
private val args = sources ++ List("-d", "../out/", "-usejavacp")

@Test def runCompiler = {
val reporter = new CustomReporter
Expand Down
13 changes: 3 additions & 10 deletions compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools.dotc
package dotty
package tools.dotc

import org.junit.Test
import org.junit.Assert._
Expand All @@ -20,15 +21,7 @@ class InterfaceEntryPointTest {
@Test def runCompilerFromInterface = {
val sources =
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
val dottyInterfaces =
new java.io.File("../interfaces/dotty-interfaces-0.1-SNAPSHOT.jar").getPath
val dottyLibrary =
new java.io.File("../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar").getPath

val args =
sources ++
List("-d", "../out/") ++
List("-classpath", dottyInterfaces + ":" + dottyLibrary)
val args = sources ++ List("-d", "../out/", "-usejavacp")

val mainClass = Class.forName("dotty.tools.dotc.Main")
val process = mainClass.getMethod("process",
Expand Down
8 changes: 3 additions & 5 deletions compiler/test/dotty/tools/dotc/repl/TestREPL.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools.dotc
package dotty
package tools.dotc
package repl

import core.Contexts.Context
Expand All @@ -23,10 +24,7 @@ class TestREPL(script: String) extends REPL {
override def context(ctx: Context) = {
val fresh = ctx.fresh
fresh.setSetting(ctx.settings.color, "never")
fresh.setSetting(
ctx.settings.classpath,
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
)
fresh.setSetting(ctx.settings.classpath, Jars.dottyReplDeps.mkString(":"))
fresh.initialize()(fresh)
fresh
}
Expand Down