Skip to content

Commit 187480b

Browse files
committed
Merge pull request scala#482 from vsalvis/vsalvis-partest2
Partest for Dotty with pos tests and neg tests with error count
2 parents c3844e5 + 9608854 commit 187480b

File tree

9 files changed

+620
-82
lines changed

9 files changed

+620
-82
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.DS_Store
12
*.class
23
*.log
34
*~
@@ -24,3 +25,6 @@ classes/
2425
.idea
2526
.idea_modules
2627
/.worksheet/
28+
29+
# Partest
30+
tests/partest-generated/

project/Build.scala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sbt.Keys._
22
import sbt._
3+
import java.io.{ RandomAccessFile, File }
4+
import java.nio.channels.FileLock
35

46
object DottyBuild extends Build {
57

@@ -10,6 +12,7 @@ object DottyBuild extends Build {
1012
// "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so"
1113
)
1214

15+
var partestLock: FileLock = null
1316

1417
val defaults = Defaults.defaultSettings ++ Seq(
1518
// set sources to src/, tests to test/ and resources to resources/
@@ -32,10 +35,11 @@ object DottyBuild extends Build {
3235
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value,
3336
"org.scala-lang.modules" %% "scala-xml" % "1.0.1",
3437
"me.d-d" % "scala-compiler" % "2.11.5-20150416-144435-09c4a520e1",
38+
"org.scala-lang.modules" %% "scala-partest" % "1.0.5" % "test",
3539
"jline" % "jline" % "2.12"),
3640

3741
// get junit onboard
38-
libraryDependencies += "com.novocode" % "junit-interface" % "0.11-RC1" % "test",
42+
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
3943

4044
// scalac options
4145
scalacOptions in Global ++= Seq("-feature", "-deprecation", "-language:_"),
@@ -46,7 +50,16 @@ object DottyBuild extends Build {
4650
incOptions := incOptions.value.withNameHashing(true),
4751

4852
// enable verbose exception messages for JUnit
49-
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "--run-listener=test.ContextEscapeDetector"),
53+
testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "--run-listener=test.ContextEscapeDetector"),
54+
testOptions in Test += Tests.Cleanup({ () => if (partestLock != null) partestLock.release }),
55+
// when this file is locked, running test generates the files for partest
56+
// otherwise it just executes the tests directly
57+
lockPartestFile := {
58+
val partestLockFile = "." + File.separator + "tests" + File.separator + "partest.lock"
59+
partestLock = new RandomAccessFile(partestLockFile, "rw").getChannel.tryLock
60+
},
61+
runPartestRunner <<= runTask(Test, "dotty.partest.DPConsoleRunner", "") dependsOn (test in Test),
62+
5063
// Adjust classpath for running dotty
5164
mainClass in (Compile, run) := Some("dotty.tools.dotc.Main"),
5265
fork in run := true,
@@ -79,7 +92,7 @@ object DottyBuild extends Build {
7992

8093
tuning ::: agentOptions ::: travis_build ::: fullpath
8194
}
82-
)
95+
) ++ addCommandAlias("partest", ";lockPartestFile;runPartestRunner")
8396

8497
lazy val dotty = Project(id = "dotty", base = file("."), settings = defaults)
8598

@@ -92,7 +105,7 @@ object DottyBuild extends Build {
92105

93106

94107
libraryDependencies ++= Seq("com.storm-enroute" %% "scalameter" % "0.6" % Test,
95-
"com.novocode" % "junit-interface" % "0.11-RC1"),
108+
"com.novocode" % "junit-interface" % "0.11"),
96109
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
97110

98111
// scalac options
@@ -129,4 +142,8 @@ object DottyBuild extends Build {
129142

130143
lazy val benchmarks = Project(id = "dotty-bench", settings = benchmarkSettings,
131144
base = file("bench")) dependsOn(dotty % "compile->test")
145+
146+
lazy val lockPartestFile = TaskKey[Unit]("lockPartestFile", "Creates the file lock on ./tests/partest.lock")
147+
lazy val runPartestRunner = TaskKey[Unit]("runPartestRunner", "Runs partests")
148+
132149
}

test/dotc/comptest.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import test._
44

55
object comptest extends CompilerTest {
66

7+
override val generatePartestFiles = false
8+
val defaultOutputDir: String = ""
9+
710
val posDir = "./tests/pos/"
811
val negDir = "./tests/neg/"
912
val dotcDir = "./src/dotty/"
1013

1114
def main(args: Array[String]) =
12-
compileArgs(Array(
15+
compileList("comptest", List(
1316
dotcDir + "tools/dotc/CompilationUnit.scala",
1417
dotcDir + "tools/dotc/core/Types.scala",
15-
dotcDir + "tools/dotc/ast/Trees.scala",
18+
dotcDir + "tools/dotc/ast/Trees.scala"), List(
1619
"#runs", "2",
1720
"-Ylog:frontend",
1821
"-Xprompt"))(Nil)
1922

20-
// compileDir(dotcDir + "tools/dotc/printing", List("-Xprompt", "-Ylog:frontend", "#runs", "2", "-uniqid"))
23+
// compileDir(dotcDir + "tools/dotc/", "printing", List("-Xprompt", "-Ylog:frontend", "#runs", "2", "-uniqid"))
2124
}

test/dotc/tests.scala

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package dotc
22

3-
import org.junit.Test
43
import test._
4+
import dotty.partest._
5+
import org.junit.Test
6+
import org.junit.experimental.categories._
7+
58

69
class tests extends CompilerTest {
710

@@ -13,12 +16,13 @@ class tests extends CompilerTest {
1316
// "-Yshow-suppressed-errors",
1417
"-pagewidth", "160")
1518

19+
val defaultOutputDir = "./out/"
20+
1621
implicit val defaultOptions = noCheckOptions ++ List(
1722
"-Yno-deep-subtypes", "-Yno-double-bindings",
1823
"-Ycheck:tailrec,resolveSuper,mixin,restoreScopes",
19-
"-d", "./out/"
24+
"-d", defaultOutputDir
2025
)
21-
2226
val doEmitBytecode = List("-Ystop-before:terminal")
2327
val failedbyName = List("-Ystop-before:collectEntryPoints") // #288
2428
val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler")
@@ -30,19 +34,23 @@ class tests extends CompilerTest {
3034
val allowDeepSubtypes = defaultOptions diff List("-Yno-deep-subtypes")
3135
val allowDoubleBindings = defaultOptions diff List("-Yno-double-bindings")
3236

33-
val posDir = "./tests/pos/"
34-
val posSpecialDir = "./tests/pos-special/"
35-
val negDir = "./tests/neg/"
36-
val newDir = "./tests/new/"
37-
val dotcDir = "./src/dotty/"
38-
val picklingDir = "./tests/pickling"
37+
val testsDir = "./tests/"
38+
val posDir = testsDir + "pos/"
39+
val posSpecialDir = testsDir + "pos-special/"
40+
val negDir = testsDir + "neg/"
41+
val newDir = testsDir + "new/"
3942

40-
@Test def pickle_pickleOK = compileDir(picklingDir, testPickling)
41-
@Test def pickle_pickling = compileDir(dotcDir + "tools/dotc/core/pickling/", testPickling)
42-
@Test def pickle_ast = compileDir(dotcDir + "tools/dotc/ast/", testPickling)
43+
val dottyDir = "./src/dotty/"
44+
val toolsDir = dottyDir + "tools/"
45+
val dotcDir = toolsDir + "dotc/"
46+
val coreDir = dotcDir + "core/"
4347

44-
//@Test def pickle_core = compileDir(dotcDir + "tools/dotc/core", testPickling, xerrors = 2) // two spurious comparison errors in Types and TypeOps
48+
@Test def pickle_pickleOK = compileDir(testsDir, "pickling", testPickling)
49+
@Test def pickle_pickling = compileDir(coreDir, "pickling", testPickling)
50+
@Test def pickle_ast = compileDir(dotcDir, "ast", testPickling)
4551

52+
//@Test def pickle_core = compileDir(dotcDir, "core", testPickling, xerrors = 2) // two spurious comparison errors in Types and TypeOps
53+
4654
@Test def pos_t2168_pat = compileFile(posDir, "t2168", twice)
4755
@Test def pos_erasure = compileFile(posDir, "erasure", twice)
4856
@Test def pos_Coder() = compileFile(posDir, "Coder", twice)
@@ -66,12 +74,12 @@ class tests extends CompilerTest {
6674
@Test def pos_packageobject() = compileFile(posDir, "packageobject", twice)
6775
@Test def pos_overloaded() = compileFile(posDir, "overloaded", twice)
6876
@Test def pos_overrides() = compileFile(posDir, "overrides", twice)
69-
@Test def pos_javaOverride() = compileDir(posDir + "java-override", twice)
77+
@Test def pos_javaOverride() = compileDir(posDir, "java-override", twice)
7078
@Test def pos_templateParents() = compileFile(posDir, "templateParents", twice)
7179
@Test def pos_overloadedAccess = compileFile(posDir, "overloadedAccess", twice)
7280
@Test def pos_approximateUnion = compileFile(posDir, "approximateUnion", twice)
73-
@Test def pos_tailcall = compileDir(posDir + "tailcall/", twice)
74-
@Test def pos_nullarify = compileFile(posDir, "nullarify", "-Ycheck:nullarify" :: Nil)
81+
@Test def pos_tailcall = compileDir(posDir, "tailcall", twice)
82+
@Test def pos_nullarify = compileFile(posDir, "nullarify", args = "-Ycheck:nullarify" :: Nil)
7583
@Test def pos_subtyping = compileFile(posDir, "subtyping", twice)
7684
@Test def pos_t2613 = compileFile(posSpecialDir, "t2613")(allowDeepSubtypes)
7785
@Test def pos_packageObj = compileFile(posDir, "i0239", twice)
@@ -92,7 +100,7 @@ class tests extends CompilerTest {
92100
@Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2)
93101
@Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2)
94102
@Test def neg_templateParents() = compileFile(negDir, "templateParents", xerrors = 3)
95-
@Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", "-language:noAutoTupling" :: Nil, xerrors = 4)
103+
@Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil, xerrors = 4)
96104
@Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 4)
97105
@Test def neg_companions = compileFile(negDir, "companions", xerrors = 1)
98106
@Test def neg_over = compileFile(negDir, "over", xerrors = 3)
@@ -102,14 +110,18 @@ class tests extends CompilerTest {
102110
@Test def neg_i50_volatile = compileFile(negDir, "i50-volatile", xerrors = 6)
103111
@Test def neg_t0273_doubledefs = compileFile(negDir, "t0273", xerrors = 1)
104112
@Test def neg_zoo = compileFile(negDir, "zoo", xerrors = 12)
105-
@Test def neg_t1192_legalPrefix = compileFile(negDir, "t1192", xerrors = 1)
106-
@Test def neg_tailcall_t1672b = compileFile(negDir, "tailcall/t1672b", xerrors = 6)
107-
@Test def neg_tailcall_t3275 = compileFile(negDir, "tailcall/t3275", xerrors = 1)
108-
@Test def neg_tailcall_t6574 = compileFile(negDir, "tailcall/t6574", xerrors = 2)
109-
@Test def neg_tailcall = compileFile(negDir, "tailcall/tailrec", xerrors = 7)
110-
@Test def neg_tailcall2 = compileFile(negDir, "tailcall/tailrec-2", xerrors = 2)
111-
@Test def neg_tailcall3 = compileFile(negDir, "tailcall/tailrec-3", xerrors = 2)
112-
@Test def nef_t1279a = compileFile(negDir, "t1279a", xerrors = 1)
113+
// TODO: this test file doesn't exist (anymore?), remove?
114+
// @Test def neg_t1192_legalPrefix = compileFile(negDir, "t1192", xerrors = 1)
115+
116+
val negTailcallDir = negDir + "tailcall/"
117+
@Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b", xerrors = 6)
118+
@Test def neg_tailcall_t3275 = compileFile(negTailcallDir, "t3275", xerrors = 1)
119+
@Test def neg_tailcall_t6574 = compileFile(negTailcallDir, "t6574", xerrors = 2)
120+
@Test def neg_tailcall = compileFile(negTailcallDir, "tailrec", xerrors = 7)
121+
@Test def neg_tailcall2 = compileFile(negTailcallDir, "tailrec-2", xerrors = 2)
122+
@Test def neg_tailcall3 = compileFile(negTailcallDir, "tailrec-3", xerrors = 2)
123+
124+
@Test def neg_t1279a = compileFile(negDir, "t1279a", xerrors = 1)
113125
@Test def neg_t1843_variances = compileFile(negDir, "t1843-variances", xerrors = 1)
114126
@Test def neg_t2660_ambi = compileFile(negDir, "t2660", xerrors = 2)
115127
@Test def neg_t2994 = compileFile(negDir, "t2994", xerrors = 2)
@@ -127,62 +139,60 @@ class tests extends CompilerTest {
127139
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
128140
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
129141

130-
@Test def dotc = compileDir(dotcDir + "tools/dotc", failedOther)(allowDeepSubtypes ++ twice) // see dotc_core
131-
@Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", failedOther ++ twice)
142+
@Test def dotc = compileDir(toolsDir, "dotc", failedOther)(allowDeepSubtypes ++ twice) // see dotc_core
143+
@Test def dotc_ast = compileDir(dotcDir, "ast", failedOther ++ twice)
132144
//similar to dotc_core_pickling but for another anon class. Still during firstTransform
133-
@Test def dotc_config = compileDir(dotcDir + "tools/dotc/config")
134-
@Test def dotc_core = compileDir(dotcDir + "tools/dotc/core", failedOther)("-Yno-double-bindings" :: allowDeepSubtypes)// twice omitted to make tests run faster
145+
@Test def dotc_config = compileDir(dotcDir, "config")
146+
@Test def dotc_core = compileDir(dotcDir, "core", failedOther)("-Yno-double-bindings" :: allowDeepSubtypes)// twice omitted to make tests run faster
135147
// error: error while loading ConstraintHandling$$anon$1$,
136148
// class file 'target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar(dotty/tools/dotc/core/ConstraintHandling$$anon$1.class)'
137149
// has location not matching its contents: contains class $anon
138150

139-
@Test def dotc_core_pickling = compileDir(dotcDir + "tools/dotc/core/pickling", failedOther)(allowDeepSubtypes)// twice omitted to make tests run faster
151+
@Test def dotc_core_pickling = compileDir(coreDir, "pickling", failedOther)(allowDeepSubtypes)// twice omitted to make tests run faster
140152
// exception caught when loading class ClassfileParser$$anon$1: dotty.tools.dotc.core.Denotations$NotDefinedHere:
141153
// demanding denotation of module class ClassfileParser$$anon$1$ at phase frontend(1) outside defined interval:
142154
// defined periods are Period(31..36, run = 2) Period(3..24, run = 2) Period(25..26, run = 2)
143155
// Period(27..28, run = 2) Period(29..29, run = 2) Period(30..30, run = 2)
144156
// inside FirstTransform at dotty.tools.dotc.transform.FirstTransform.transform(FirstTransform.scala:33)
145157
// weird.
146158

147-
@Test def dotc_transform = compileDir(dotcDir + "tools/dotc/transform")// twice omitted to make tests run faster
159+
@Test def dotc_transform = compileDir(dotcDir, "transform")// twice omitted to make tests run faster
148160

149-
@Test def dotc_parsing = compileDir(dotcDir + "tools/dotc/parsing")// twice omitted to make tests run faster
161+
@Test def dotc_parsing = compileDir(dotcDir, "parsing") // twice omitted to make tests run faster
150162

151-
@Test def dotc_printing = compileDir(dotcDir + "tools/dotc/printing") // twice omitted to make tests run faster
163+
@Test def dotc_printing = compileDir(dotcDir, "printing") // twice omitted to make tests run faster
152164

153-
@Test def dotc_reporting = compileDir(dotcDir + "tools/dotc/reporting") // twice omitted to make tests run faster
165+
@Test def dotc_reporting = compileDir(dotcDir, "reporting") // twice omitted to make tests run faster
154166

155-
@Test def dotc_typer = compileDir(dotcDir + "tools/dotc/typer", failedOther) // twice omitted to make tests run faster
167+
@Test def dotc_typer = compileDir(dotcDir, "typer", failedOther)// twice omitted to make tests run faster
156168
// error: error while loading Checking$$anon$2$,
157169
// class file 'target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar(dotty/tools/dotc/typer/Checking$$anon$2.class)'
158170
// has location not matching its contents: contains class $anon
159171

160-
@Test def dotc_util = compileDir(dotcDir + "tools/dotc/util", failedOther ++ twice)
172+
@Test def dotc_util = compileDir(dotcDir, "util", failedOther ++ twice)
161173
// java.lang.ClassCastException: dotty.tools.dotc.core.Types$NoType$ cannot be cast to dotty.tools.dotc.core.Types$ClassInfo
162174
// at dotty.tools.dotc.core.SymDenotations$ClassDenotation.classInfo(SymDenotations.scala:1026)
163175
// at dotty.tools.dotc.transform.ExtensionMethods.transform(ExtensionMethods.scala:38)
164176

165-
@Test def tools_io = compileDir(dotcDir + "tools/io", failedOther ++ twice) // inner class has symbol <none>
177+
@Test def tools_io = compileDir(toolsDir, "io", failedOther ++ twice) // inner class has symbol <none>
166178

167179
@Test def helloWorld = compileFile(posDir, "HelloWorld", twice)
168180
@Test def labels = compileFile(posDir, "Labels", twice)
169-
//@Test def tools = compileDir(dotcDir + "tools", "-deep" :: Nil)(allowDeepSubtypes)
181+
//@Test def tools = compileDir(dottyDir, "tools", "-deep" :: Nil)(allowDeepSubtypes)
170182

171-
@Test def testNonCyclic = compileArgs(Array(
172-
dotcDir + "tools/dotc/CompilationUnit.scala",
173-
dotcDir + "tools/dotc/core/Types.scala",
174-
dotcDir + "tools/dotc/ast/Trees.scala",
175-
"-Xprompt"
176-
) ++ staleSymbolError ++ twice)
183+
@Test def testNonCyclic = compileList("testNonCyclic", List(
184+
dotcDir + "CompilationUnit.scala",
185+
coreDir + "Types.scala",
186+
dotcDir + "ast/Trees.scala"
187+
), List("-Xprompt") ++ staleSymbolError ++ twice)
177188

178-
@Test def testIssue_34 = compileArgs(Array(
179-
dotcDir + "tools/dotc/config/Properties.scala",
180-
dotcDir + "tools/dotc/config/PathResolver.scala",
181-
//"-Ylog:frontend",
182-
"-Xprompt") ++ staleSymbolError ++ twice)
189+
@Test def testIssue_34 = compileList("testIssue_34", List(
190+
dotcDir + "config/Properties.scala",
191+
dotcDir + "config/PathResolver.scala"
192+
), List(/* "-Ylog:frontend", */ "-Xprompt") ++ staleSymbolError ++ twice)
183193

184194
val javaDir = "./tests/pos/java-interop/"
185195
@Test def java_all = compileFiles(javaDir, twice)
186196

187-
//@Test def dotc_compilercommand = compileFile(dotcDir + "tools/dotc/config/", "CompilerCommand")
197+
//@Test def dotc_compilercommand = compileFile(dotcDir + "config/", "CompilerCommand")
188198
}

test/dotty/partest/DPConfig.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dotty.partest
2+
3+
import java.io.File
4+
import scala.collection.JavaConversions._
5+
6+
7+
/** Dotty Partest runs all tests in the provided testDirs located under
8+
* testRoot. There can be several directories with pos resp. neg tests, as
9+
* long as the prefix is pos/neg.
10+
*
11+
* Each testDir can also have a __defaultFlags.flags file, which provides
12+
* compiler flags and is used unless there's a specific flags file (e.g. for
13+
* test pos/A.scala, if there's a pos/A.flags file those flags are used,
14+
* otherwise pos/__defaultFlags.flags are used if the file exists).
15+
*/
16+
object DPConfig {
17+
val testRoot = "./tests/partest-generated"
18+
lazy val testDirs = {
19+
val root = new File(testRoot)
20+
val dirs = if (!root.exists) Array.empty[String] else root.listFiles.filter(_.isDirectory).map(_.getName)
21+
if (dirs.length > 0)
22+
println(s"Partest found generated source directories in $testRoot: " + dirs.mkString(", "))
23+
else
24+
throw new Exception("Partest did not detect any generated sources")
25+
dirs
26+
}
27+
28+
// Tests finish faster when running in parallel, but console output is
29+
// out of order and sometimes the compiler crashes
30+
val runTestsInParallel = false
31+
}

0 commit comments

Comments
 (0)