Skip to content

Commit 08814e2

Browse files
committed
Merge pull request #15 from adriaanm/neg-to-junit
Replace partest neg tests with JUnit tests.
2 parents 06f38a3 + 9c055a1 commit 08814e2

11 files changed

+203
-425
lines changed

build.sbt

+5-61
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ resolvers += Resolver.sonatypeRepo("snapshots")
1818
// don't use for doc scope, scaladoc warnings are not to be reckoned with
1919
scalacOptions in compile ++= Seq("-optimize", "-Xfatal-warnings", "-feature", "-deprecation", "-unchecked", "-Xlint")
2020

21+
libraryDependencies ++= Seq(
22+
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "test", // used in CompilerErrors test
23+
"junit" % "junit" % "4.11" % "test",
24+
"com.novocode" % "junit-interface" % "0.10" % "test")
25+
2126
// Generate $name.properties to store our version as well as the scala version used to build
2227
resourceGenerators in Compile <+= Def.task {
2328
val props = new java.util.Properties
@@ -81,67 +86,6 @@ pomExtra := (
8186
</developers>
8287
)
8388

84-
// default value must be set here
85-
TestKeys.includeTestDependencies := true
86-
87-
libraryDependencies ++= Seq("junit" % "junit" % "4.11" % "test", "com.novocode" % "junit-interface" % "0.10" % "test")
88-
89-
// default
90-
TestKeys.partestVersion := "1.0.0-RC7"
91-
92-
// the actual partest the interface calls into -- must be binary version close enough to ours
93-
// so that it can link to the compiler/lib we're using (testing)
94-
// NOTE: not sure why, but the order matters (maybe due to the binary version conflicts for xml/parser combinators pulled in for scaladoc?)
95-
libraryDependencies ++= (
96-
if (TestKeys.includeTestDependencies.value) {
97-
/**
98-
* Exclude all transitive dependencies of partest that include scala-.xml.
99-
* This way we avoid having two (or more) versions of scala-xml on a classpath.
100-
* This fixes problem described here:
101-
* https://github.com/scala/scala-xml/pull/6#issuecomment-26614894
102-
*
103-
* Note that we are using ModuleID.exclude instead of more flexible ModuleID.excludeAll
104-
* (describe here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management#exclude-transitive-dependencies)
105-
* because only plain excludes are incorporated in generated pom.xml. There are two ways
106-
* to address this problem:
107-
*
108-
* 1. Figure out how to depend on partest in non-transitive way: not include that dependency
109-
* in generated pom.xml for scala-xml.
110-
* 2. Declare dependencies in partest as provided so they are not includeded transitively.
111-
*
112-
*/
113-
def excludeScalaXml(dep: ModuleID): ModuleID =
114-
dep.exclude("org.scala-lang.modules", "scala-xml_2.11.0-M4").
115-
exclude("org.scala-lang.modules", "scala-xml_2.11.0-M5").
116-
exclude("org.scala-lang.modules", "scala-xml_2.11.0-M6").
117-
exclude("org.scalacheck", "scalacheck_2.11.0-M5")
118-
Seq("org.scala-lang.modules" % s"scala-partest-interface_${scalaBinaryVersion.value}" % "0.2" % "test" intransitive,
119-
"org.scala-lang.modules" % s"scala-partest_${scalaBinaryVersion.value}" % TestKeys.partestVersion.value % "test" intransitive,
120-
// diffutils is needed by partest
121-
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % "test",
122-
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "test").
123-
map(excludeScalaXml)
124-
}
125-
else Seq.empty
126-
)
127-
128-
fork in Test := true
129-
130-
javaOptions in Test += "-Xmx1G"
131-
132-
testFrameworks += new TestFramework("scala.tools.partest.Framework")
133-
134-
definedTests in Test += (
135-
new sbt.TestDefinition(
136-
"partest",
137-
// marker fingerprint since there are no test classes
138-
// to be discovered by sbt:
139-
new sbt.testing.AnnotatedFingerprint {
140-
def isModule = true
141-
def annotationName = "partest"
142-
}, true, Array())
143-
)
144-
14589
osgiSettings
14690

14791
val osgiVersion = version(_.replace('-', '.'))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package scala.xml
2+
3+
import org.junit.Test
4+
5+
class CompilerErrors extends CompilerTesting {
6+
@Test
7+
def t7185() =
8+
expectXmlError("""|overloaded method value apply with alternatives:
9+
| (f: scala.xml.Node => Boolean)scala.xml.NodeSeq <and>
10+
| (i: Int)scala.xml.Node
11+
| cannot be applied to ()""".stripMargin,
12+
"""|object Test {
13+
| <e></e>()
14+
|}""")
15+
16+
@Test
17+
def t1878_typer() =
18+
expectXmlError("_* may only come last",
19+
"""|object Test extends App {
20+
| // illegal - bug #1764
21+
| null match {
22+
| case <p> { _* } </p> =>
23+
| }
24+
|}""")
25+
26+
27+
@Test
28+
def t1017() =
29+
expectXmlErrors(1, "not found: value foo",
30+
"""|object Test {
31+
| <x><x><x><x><x><x><x><x><x><x><x><x><x><x><x><x><x><x>{ foo }</x></x></x></x></x></x></x></x></x></x></x></x></x></x></x></x></x></x>
32+
|}""")
33+
34+
@Test
35+
def t1011() =
36+
expectXmlErrors(69, "not found: value entity",
37+
"""|import scala.xml._;
38+
|
39+
|abstract class Test {
40+
| //val entity : String;
41+
| def primitiveHeader : NodeSeq =
42+
| Group({
43+
| <dl><code>{Text(entity)}</code>
44+
| <code>{Text(entity)}</code>
45+
| <code>{Text(entity)}</code>
46+
| <code>{Text(entity)}</code>
47+
| <code>{Text(entity)}</code>
48+
| <code>{Text(entity)}</code>
49+
| <code>{Text(entity)}</code>
50+
| <code>{Text(entity)}</code>
51+
| <code>{Text(entity)}</code>
52+
| <code>{Text(entity)}</code>
53+
| <code>{Text(entity)}</code>
54+
| <code>{Text(entity)}</code>
55+
| <code>{Text(entity)}</code>
56+
| <code>{Text(entity)}</code>
57+
| <code>{Text(entity)}</code>
58+
| <code>{Text(entity)}</code>
59+
| <code>{Text(entity)}</code>
60+
| <code>{Text(entity)}</code>
61+
| <code>{Text(entity)}</code>
62+
| <code>{Text(entity)}</code>
63+
| <code>{Text(entity)}</code>
64+
| <code>{Text(entity)}</code>
65+
| <code>{Text(entity)}</code>
66+
| <code>{Text(entity)}</code>
67+
| <code>{Text(entity)}</code>
68+
| <code>{Text(entity)}</code>
69+
| <code>{Text(entity)}</code>
70+
| <code>{Text(entity)}</code>
71+
| <code>{Text(entity)}</code>
72+
| <code>{Text(entity)}</code>
73+
| <code>{Text(entity)}</code>
74+
| <code>{Text(entity)}</code>
75+
| <code>{Text(entity)}</code>
76+
| <code>{Text(entity)}</code>
77+
| <code>{Text(entity)}</code>
78+
| <code>{Text(entity)}</code>
79+
| <code>{Text(entity)}</code>
80+
| <code>{Text(entity)}</code>
81+
| <code>{Text(entity)}</code>
82+
| <code>{Text(entity)}</code>
83+
| <code>{Text(entity)}</code>
84+
| <code>{Text(entity)}</code>
85+
| <code>{Text(entity)}</code>
86+
| <code>{Text(entity)}</code>
87+
| <code>{Text(entity)}</code>
88+
| <code>{Text(entity)}</code>
89+
| <code>{Text(entity)}</code>
90+
| <code>{Text(entity)}</code>
91+
| <code>{Text(entity)}</code>
92+
| <code>{Text(entity)}</code>
93+
| <code>{Text(entity)}</code>
94+
| <code>{Text(entity)}</code>
95+
| <code>{Text(entity)}</code>
96+
| <code>{Text(entity)}</code>
97+
| <code>{Text(entity)}</code>
98+
| <code>{Text(entity)}</code>
99+
| <code>{Text(entity)}</code>
100+
| <code>{Text(entity)}</code>
101+
| <code>{Text(entity)}</code>
102+
| <code>{Text(entity)}</code>
103+
| <code>{Text(entity)}</code>
104+
| <code>{Text(entity)}</code>
105+
| <code>{Text(entity)}</code>
106+
| <code>{Text(entity)}</code>
107+
| <code>{Text(entity)}</code>
108+
| <code>{Text(entity)}</code>
109+
| <code>{Text(entity)}</code>
110+
| <code>{Text(entity)}</code>
111+
| <code>{Text(entity)}</code></dl>
112+
| } ++ // 3 seconds
113+
| {}++ // 5 seconds
114+
| {}++ // 10 seconds
115+
| {}++ // 20 seconds
116+
| {}++ // 40 seconds
117+
| {}++ // 40 seconds
118+
| {}++ // 40 seconds
119+
| {}++ // 40 seconds
120+
| {}++ // 40 seconds
121+
| {}++ // 40 seconds
122+
| {}++ // 40 seconds
123+
| {}++ // 40 seconds
124+
| {}++ // 40 seconds
125+
| {}++ // 40 seconds
126+
| {}++ // 40 seconds
127+
| {}++ // 40 seconds
128+
| {}++ // 40 seconds
129+
| {}++ // 5 seconds
130+
| {}++ // 10 seconds
131+
| {}++ // 20 seconds
132+
| {}++ // 40 seconds
133+
| {}++ // 40 seconds
134+
| {}++ // 40 seconds
135+
| {}++ // 40 seconds
136+
| {}++ // 40 seconds
137+
| {}++ // 40 seconds
138+
| {}++ // 40 seconds
139+
| {}++ // 40 seconds
140+
| {}++ // 40 seconds
141+
| {}++ // 40 seconds
142+
| {}++ // 40 seconds
143+
| {}++ // 40 seconds
144+
| {}++ // 40 seconds
145+
| {}++ // 5 seconds
146+
| {}++ // 10 seconds
147+
| {}++ // 20 seconds
148+
| {}++ // 40 seconds
149+
| {}++ // 40 seconds
150+
| {}++ // 40 seconds
151+
| {}++ // 40 seconds
152+
| {}++ // 40 seconds
153+
| {}++ // 40 seconds
154+
| {}++ // 40 seconds
155+
| {}++ // 40 seconds
156+
| {}++ // 40 seconds
157+
| {}++ // 40 seconds
158+
| {}++ // 40 seconds
159+
| {}++ // 40 seconds
160+
| {}++ // 40 seconds
161+
| <hr/>);
162+
|}""")
163+
}
164+
165+
// TODO: factor out somewhere?
166+
class CompilerTesting {
167+
def errorMessages(errorSnippet: String, compileOptions: String = "")(code: String): List[String] = {
168+
import scala.tools.reflect._
169+
val m = scala.reflect.runtime.currentMirror
170+
val tb = m.mkToolBox(options = compileOptions) //: ToolBox[m.universe.type]
171+
val fe = tb.frontEnd
172+
173+
try {
174+
tb.eval(tb.parse(code))
175+
Nil
176+
} catch { case _: ToolBoxError =>
177+
import fe._
178+
infos.toList collect { case Info(_, msg, ERROR) => msg }
179+
}
180+
}
181+
182+
// note: `code` should have a | margin
183+
// the import's needed because toolbox compiler does not accumulate imports like the real one (TODO: verify hypothesis)
184+
def xmlErrorMessages(msg: String, code: String) =
185+
errorMessages(msg)("import scala.xml.{TopScope => $scope}\n"+ code.stripMargin)
186+
187+
def expectXmlError(msg: String, code: String) = {
188+
val errors = xmlErrorMessages(msg, code)
189+
assert(errors exists (_ contains msg), errors mkString "\n")
190+
}
191+
192+
def expectXmlErrors(msgCount: Int, msg: String, code: String) = {
193+
val errors = xmlErrorMessages(msg, code)
194+
val errorCount = errors.filter(_ contains msg).length
195+
assert(errorCount == msgCount, s"$errorCount occurrences of \'$msg\' found -- expected $msgCount in:\n${errors mkString "\n"}")
196+
}
197+
}

src/test/scala/scala/xml/ShouldCompile.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class B {
6363
}
6464

6565
// SI-5858
66-
object Test {
66+
object SI_5858 {
6767
new Elem(null, null, Null, TopScope, Nil: _*) // was ambiguous
6868
}
6969

0 commit comments

Comments
 (0)