Skip to content

Commit 3599c24

Browse files
authored
Merge pull request #1739 from dotty-staging/topic/environmentally-friendly-tests
Environmentally friendly tests
2 parents e043954 + 2f1a794 commit 3599c24

12 files changed

+101
-64
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ object Symbols {
428428
final def entered(implicit ctx: Context): this.type = {
429429
assert(this.owner.isClass, s"symbol ($this) entered the scope of non-class owner ${this.owner}") // !!! DEBUG
430430
this.owner.asClass.enter(this)
431-
if (this.is(Module, butNot = Package)) this.owner.asClass.enter(this.moduleClass)
431+
if (this is Module) this.owner.asClass.enter(this.moduleClass)
432432
this
433433
}
434434

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
555555
val tp = readType()
556556
val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
557557
annots += Annotation.deferredSymAndTree(tp.typeSymbol, _ => lazyAnnotTree.complete)
558-
case _ =>
559-
assert(false, s"illegal modifier tag at $currentAddr")
558+
case tag =>
559+
assert(false, s"illegal modifier tag $tag at $currentAddr, end = $end")
560560
}
561561
}
562562
(flags, annots.toList, privateWithin)

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,20 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
120120
}
121121
else false
122122

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

133138
/** Find the denotation of enclosing `name` in given context `ctx`.
134139
* @param previous A denotation that was found in a more deeply nested scope,

compiler/test/dotc/tests.scala

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dotc
22

3+
import dotty.Jars
34
import dotty.tools.dotc.CompilerTest
45
import org.junit.{Before, Test}
56

@@ -32,18 +33,28 @@ class tests extends CompilerTest {
3233
)
3334

3435
val classPath = {
35-
val paths = List(
36-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar",
37-
"./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar",
38-
"../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
39-
).map { p =>
36+
val paths = Jars.dottyTestDeps map { p =>
4037
val file = new JFile(p)
4138
assert(
4239
file.exists,
43-
s"""File "$p" couldn't be found. Run `packageAll` from build tool before testing"""
40+
s"""|File "$p" couldn't be found. Run `packageAll` from build tool before
41+
|testing.
42+
|
43+
|If running without sbt, test paths need to be setup environment variables:
44+
|
45+
| - DOTTY_LIBRARY
46+
| - DOTTY_COMPILER
47+
| - DOTTY_INTERFACES
48+
| - DOTTY_EXTRAS
49+
|
50+
|Where these all contain locations, except extras which is a colon
51+
|separated list of jars.
52+
|
53+
|When compiling with eclipse, you need the sbt-interfaces jar, put
54+
|it in extras."""
4455
)
4556
file.getAbsolutePath
46-
}.mkString(":")
57+
} mkString (":")
4758

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

356+
compileDir(libDir, "dotty", "-deep" :: opt)
357+
compileDir(libDir, "scala", "-deep" :: opt)
345358
compileDir(dottyDir, "tools", opt)
346359
compileDir(toolsDir, "dotc", opt)
347360
compileDir(dotcDir, "ast", opt)

compiler/test/dotty/Jars.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dotty
2+
3+
/** Jars used when compiling test, defaults to sbt locations */
4+
object Jars {
5+
val dottyLib: String = sys.env.get("DOTTY_LIB") getOrElse {
6+
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
7+
}
8+
9+
val dottyCompiler: String = sys.env.get("DOTTY_COMPILER") getOrElse {
10+
"./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar"
11+
}
12+
13+
val dottyInterfaces: String = sys.env.get("DOTTY_INTERFACE") getOrElse {
14+
"../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
15+
}
16+
17+
val dottyExtras: List[String] = sys.env.get("DOTTY_EXTRAS")
18+
.map(_.split(":").toList).getOrElse(Nil)
19+
20+
val dottyReplDeps: List[String] = dottyLib :: dottyExtras
21+
22+
val dottyTestDeps: List[String] =
23+
dottyLib :: dottyCompiler :: dottyInterfaces :: dottyExtras
24+
}

compiler/test/dotty/partest/DPConsoleRunner.scala

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,43 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
8888
""".stripMargin
8989
}
9090

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

98107
override def runTestsForFiles(kindFiles: Array[File], kind: String): Array[TestState] = {
99-
val (sequentialTests, parallelTests) =
108+
val (limitResourceTests, parallelTests) =
100109
kindFiles partition { kindFile =>
101110
val flags = kindFile.changeExtension("flags").fileContents
102-
sequentialFlags.exists(seqFlag => flags.contains(seqFlag))
111+
limitResourceFlags.exists(seqFlag => flags.contains(seqFlag))
103112
}
104113

105114
val seqResults =
106-
if (!sequentialTests.isEmpty) {
115+
if (!limitResourceTests.isEmpty) {
107116
val savedThreads = sys.props("partest.threads")
108-
sys.props("partest.threads") = "2"
117+
sys.props("partest.threads") = {
118+
assert(
119+
savedThreads == null || limitedThreads.toInt <= savedThreads.toInt,
120+
"""|Should not use more threads than the default, when the point
121+
|is to limit the amount of resources""".stripMargin
122+
)
123+
limitedThreads
124+
}
109125

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

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

385401
// override to keep class files if failed and delete clog if ok
386-
override def cleanup = if (lastState.isOk) try {
402+
override def cleanup = if (lastState.isOk) {
387403
logFile.delete
388404
cLogFile.delete
389405
Directory(outDir).deleteRecursively
390-
} catch {
391-
case t: Throwable =>
392-
println("whhhhhhhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat")
393-
throw t
394406
}
395407
}

compiler/test/dotty/tools/DottyTest.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ class DottyTest extends ContextEscapeDetection{
2323
import base.settings._
2424
val ctx = base.initialCtx.fresh
2525
ctx.setSetting(ctx.settings.encoding, "UTF8")
26-
ctx.setSetting(
27-
ctx.settings.classpath,
28-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
29-
)
26+
ctx.setSetting(ctx.settings.classpath, Jars.dottyLib)
3027
// when classpath is changed in ctx, we need to re-initialize to get the
3128
// correct classpath from PathResolver
3229
base.initialize()(ctx)

compiler/test/dotty/tools/ShowClassTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools
1+
package dotty
2+
package tools
23

34
import dotc.core._
45
import dotc.core.Contexts._
@@ -18,8 +19,7 @@ class ShowClassTests extends DottyTest {
1819
ctx.setSetting(ctx.settings.encoding, "UTF8")
1920
ctx.setSetting(
2021
ctx.settings.classpath,
21-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar" +
22-
":../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar"
22+
Jars.dottyLib + ":" + Jars.dottyInterfaces
2323
)
2424
base.initialize()(ctx)
2525
ctx

compiler/test/dotty/tools/dotc/CompilerTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ abstract class CompilerTest {
264264
private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile])
265265
(implicit defaultOptions: List[String]): Unit = {
266266
val allArgs = args ++ defaultOptions
267+
val verbose = allArgs.contains("-verbose")
267268
//println(s"""all args: ${allArgs.mkString("\n")}""")
268269
val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
269270
val storeReporter = new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
270271
private val consoleReporter = new ConsoleReporter()
271272
private val innerStoreReporter = new StoreReporter(consoleReporter)
272273
def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
273-
if (m.level == ERROR) {
274+
if (m.level == ERROR || verbose) {
274275
innerStoreReporter.flush()
275276
consoleReporter.doReport(m)
276277
}

compiler/test/dotty/tools/dotc/EntryPointsTest.scala

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools
1+
package dotty
2+
package tools
23
package dotc
34

45
import org.junit.Test
@@ -19,14 +20,7 @@ import scala.collection.mutable.ListBuffer
1920
class EntryPointsTest {
2021
private val sources =
2122
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
22-
private val dottyInterfaces =
23-
new java.io.File("../interfaces/dotty-interfaces-0.1-SNAPSHOT.jar").getPath
24-
private val dottyLibrary =
25-
new java.io.File("../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar").getPath
26-
private val args =
27-
sources ++
28-
List("-d", "../out/") ++
29-
List("-classpath", dottyInterfaces + ":" + dottyLibrary)
23+
private val args = sources ++ List("-d", "../out/", "-usejavacp")
3024

3125
@Test def runCompiler = {
3226
val reporter = new CustomReporter

compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty
2+
package tools.dotc
23

34
import org.junit.Test
45
import org.junit.Assert._
@@ -20,15 +21,7 @@ class InterfaceEntryPointTest {
2021
@Test def runCompilerFromInterface = {
2122
val sources =
2223
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
23-
val dottyInterfaces =
24-
new java.io.File("../interfaces/dotty-interfaces-0.1-SNAPSHOT.jar").getPath
25-
val dottyLibrary =
26-
new java.io.File("../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar").getPath
27-
28-
val args =
29-
sources ++
30-
List("-d", "../out/") ++
31-
List("-classpath", dottyInterfaces + ":" + dottyLibrary)
24+
val args = sources ++ List("-d", "../out/", "-usejavacp")
3225

3326
val mainClass = Class.forName("dotty.tools.dotc.Main")
3427
val process = mainClass.getMethod("process",

compiler/test/dotty/tools/dotc/repl/TestREPL.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty
2+
package tools.dotc
23
package repl
34

45
import core.Contexts.Context
@@ -23,10 +24,7 @@ class TestREPL(script: String) extends REPL {
2324
override def context(ctx: Context) = {
2425
val fresh = ctx.fresh
2526
fresh.setSetting(ctx.settings.color, "never")
26-
fresh.setSetting(
27-
ctx.settings.classpath,
28-
"../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
29-
)
27+
fresh.setSetting(ctx.settings.classpath, Jars.dottyReplDeps.mkString(":"))
3028
fresh.initialize()(fresh)
3129
fresh
3230
}

0 commit comments

Comments
 (0)