Skip to content

Commit e2e0846

Browse files
committed
Add IDE tests
1 parent 3365ed3 commit e2e0846

35 files changed

+955
-5
lines changed

.drone.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ pipeline:
3636
- cp -R . /tmp/3/ && cd /tmp/3/
3737
- ./project/scripts/sbt dotty-optimised/test
3838

39-
test_sbt:
39+
test_ide:
4040
group: test
4141
image: lampepfl/dotty:2018-01-17
4242
commands:
4343
- cp -R . /tmp/4/ && cd /tmp/4/
44+
- ./project/scripts/sbt dotty-language-server/test:run
45+
46+
test_sbt:
47+
group: test
48+
image: lampepfl/dotty:2017-11-17
49+
commands:
50+
- cp -R . /tmp/5/ && cd /tmp/5/
4451
- ./project/scripts/sbt sbt-dotty/scripted
4552
when:
4653
# sbt scripted tests are slow and don't run on PRs

compiler/src/dotty/tools/dotc/util/DiffUtil.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ object DiffUtil {
5959
(fnd, exp, totalChange.toDouble / (expected.length + found.length))
6060
}
6161

62+
def mkColoredLineDiff(expected: Seq[String], actual: Seq[String]): String = {
63+
val expectedSize = DiffUtil.EOF.length max expected.map(_.length).max
64+
actual.padTo(expected.length, "").zip(expected.padTo(actual.length, "")).map { case (act, exp) =>
65+
mkColoredLineDiff(exp, act, expectedSize)
66+
}.mkString("\n")
67+
}
68+
6269
def mkColoredLineDiff(expected: String, actual: String, expectedSize: Int): String = {
6370
lazy val diff = {
6471
val tokens = splitTokens(expected, Nil).toArray

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
613613

614614
if (outputLines.length != checkLines.length || !linesMatch) {
615615
// Print diff to files and summary:
616-
val expectedSize = DiffUtil.EOF.length max checkLines.map(_.length).max
617-
val diff = outputLines.padTo(checkLines.length, "").zip(checkLines.padTo(outputLines.length, "")).map { case (act, exp) =>
618-
DiffUtil.mkColoredLineDiff(exp, act, expectedSize)
619-
}.mkString("\n")
616+
val diff = DiffUtil.mkColoredLineDiff(checkLines, outputLines)
620617

621618
val msg =
622619
s"""|Output from '$sourceTitle' did not match check file.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class CompletionTest {
8+
9+
@Test def competion0: Unit = {
10+
code"class Foo { val xyz: Int = 0; def y: Int = xy$m1 }".withSource
11+
.completion(m1, List(("xyz", "Field", "Int")))
12+
}
13+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class DefinitionTest {
8+
9+
@Test def classDefinitionNotFound0: Unit =
10+
code"class Foo { new ${m1}Bar$m2 }".withSource.definition(m1 to m2, None)
11+
12+
@Test def classDefinition0: Unit = {
13+
withSources(
14+
code"class ${m1}Foo$m2 { new Foo }",
15+
code"class Bar { val foo: ${m3}Foo$m4 = new ${m5}Foo$m6 }"
16+
) .definition(m1 to m2, Some(m1 to m2))
17+
.definition(m3 to m4, Some(m1 to m2))
18+
.definition(m5 to m6, Some(m1 to m2))
19+
}
20+
21+
@Test def valDefinition0: Unit = {
22+
withSources(
23+
code"class Foo { val ${m1}x$m2 = 0; ${m3}x$m4 }",
24+
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
25+
) .definition(m1 to m2, Some(m1 to m2))
26+
.definition(m3 to m4, Some(m1 to m2))
27+
.definition(m5 to m6, Some(m1 to m2))
28+
}
29+
30+
@Test def defDefinition0: Unit = {
31+
withSources(
32+
code"class Foo { def ${m1}x$m2 = 0; ${m3}x$m4 }",
33+
code"class Bar { val foo = new Foo; foo.${m5}x$m6 }"
34+
) .definition(m1 to m2, Some(m1 to m2))
35+
.definition(m3 to m4, Some(m1 to m2))
36+
.definition(m5 to m6, Some(m1 to m2))
37+
}
38+
39+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class DocumentSymbolTest {
8+
9+
@Test def documentSymbol0: Unit =
10+
code"class ${m1}Foo$m2".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", "Class"))
11+
12+
@Test def documentSymbol1: Unit =
13+
code"class ${m1}Foo$m2; class ${m3}Bar$m4".withSource
14+
.documentSymbol(m1, (m1 to m2).symInfo("Foo", "Class"), (m3 to m4).symInfo("Bar", "Class"))
15+
16+
@Test def documentSymbol3: Unit = {
17+
withSources(
18+
code"class ${m1}Foo$m2",
19+
code"class ${m3}Bar$m4"
20+
) .documentSymbol(m1, (m1 to m2).symInfo("Foo", "Class"))
21+
.documentSymbol(m3, (m3 to m4).symInfo("Bar", "Class"))
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class HighlightTest {
8+
9+
@Test def valHighlight0: Unit = {
10+
val xDef = (m1 to m2).withCode("x")
11+
code"class X { val $xDef = 9 }".withSource
12+
.highlight(xDef.range, (xDef.range, "Read"))
13+
}
14+
15+
@Test def valHighlight1: Unit = {
16+
val xDef = (m1 to m2).withCode("x")
17+
val xRef = (m3 to m4).withCode("x")
18+
code"class X { val $xDef = 9; $xRef}".withSource
19+
.highlight(xRef.range, (xDef.range, "Read"), (xRef.range, "Read"))
20+
}
21+
22+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class HoverTest {
8+
9+
@Test def hoverOnWhiteSpace0: Unit =
10+
code"$m1 $m2".withSource.hover(m1 to m2, "")
11+
12+
@Test def hoverOnClass0: Unit = {
13+
code"""$m1 ${m2}class Foo $m3 $m4""".withSource
14+
.hover(m1 to m2, "")
15+
.hover(m2 to m3, "Foo")
16+
.hover(m3 to m4, "")
17+
}
18+
19+
@Test def hoverOnClass1: Unit = {
20+
code"""$m1 ${m2}class Foo { } $m3 $m4""".withSource
21+
.hover(m1 to m2, "")
22+
.hover(m2 to m3, "Foo")
23+
.hover(m3 to m4, "")
24+
}
25+
26+
@Test def hoverOnValDef0: Unit = {
27+
code"""class Foo {
28+
| ${m1}val x = ${m2}8$m3; ${m4}x$m5
29+
|}""".withSource
30+
.hover(m1 to m2, "Int")
31+
.hover(m2 to m3, "Int(8)")
32+
.hover(m4 to m5, "Int")
33+
}
34+
35+
@Test def hoverOnValDef1: Unit = {
36+
code"""class Foo {
37+
| ${m1}final val x = 8$m2; ${m3}x$m4
38+
|}""".withSource
39+
.hover(m1 to m2, "Int(8)")
40+
.hover(m3 to m4, "Int(8)")
41+
}
42+
43+
@Test def hoverOnDefDef0: Unit = {
44+
code"""class Foo {
45+
| ${m1}def x = ${m2}8$m3; ${m4}x$m5
46+
|}""".withSource
47+
.hover(m1 to m2, "Int")
48+
.hover(m2 to m3, "Int(8)")
49+
.hover(m4 to m5, "Int")
50+
}
51+
52+
@Test def hoverMissingRef0: Unit = {
53+
code"""class Foo {
54+
| ${m1}x$m2
55+
|}""".withSource
56+
.hover(m1 to m2, "<error not found: x>")
57+
}
58+
59+
@Test def hoverFun0: Unit = {
60+
code"""class Foo {
61+
| def x: String = $m1"abc"$m2
62+
| ${m3}x$m4
63+
|
64+
| def y(): Int = 9
65+
| ${m5}y($m6)$m7
66+
|}
67+
""".withSource
68+
.hover(m1 to m2, "String(\"abc\")")
69+
.hover(m3 to m4, "String")
70+
.hover(m5 to m6, "(): Int")
71+
.hover(m6 to m7, "Int")
72+
}
73+
74+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import java.lang.reflect.InvocationTargetException
6+
7+
// TODO remove this and use JUnit to run the tests
8+
object Main {
9+
def main(args: Array[String]): Unit = {
10+
var testsFailed = 0
11+
for (clazz <- testsClasses) {
12+
val t0 = System.currentTimeMillis()
13+
var passed = 0
14+
var failed = 0
15+
println(s"Starting tests in ${clazz.getSimpleName}")
16+
for (method <- clazz.getMethods.sortBy(_.getName)) {
17+
if (method.getAnnotation(classOf[Test]) ne null) {
18+
print(s"Testing $clazz.${method.getName} ")
19+
try {
20+
method.invoke(clazz.getConstructor().newInstance())
21+
println(Console.GREEN + "passed" + Console.RESET)
22+
passed += 1
23+
} catch {
24+
case ex: InvocationTargetException =>
25+
ex.getCause match {
26+
case ex1: AssertionError =>
27+
println(Console.RED + "failed" + Console.RESET)
28+
System.err.println(s"${method.getName} failed with")
29+
ex1.printStackTrace()
30+
failed += 1
31+
case _ => throw ex.getCause
32+
}
33+
}
34+
}
35+
}
36+
37+
val time = (System.currentTimeMillis() - t0).toDouble / 1000
38+
39+
if (failed == 0) {
40+
println(s"${Console.GREEN}Passed all $passed tests${Console.RESET} in ${time}s")
41+
} else {
42+
testsFailed += 1
43+
System.err.println(s"Passed $passed, ${Console.RED}failed $failed${Console.RESET}, total ${passed + failed} in ${time}s")
44+
}
45+
println()
46+
}
47+
if (testsFailed != 0) {
48+
System.err.println(s"Failed $testsFailed tests")
49+
System.exit(1)
50+
}
51+
}
52+
53+
private def testsClasses = List(
54+
classOf[HighlightTest],
55+
classOf[CompletionTest],
56+
classOf[DefinitionTest],
57+
classOf[HoverTest],
58+
classOf[ReferencesTest],
59+
classOf[RenameTest],
60+
classOf[DocumentSymbolTest],
61+
classOf[SymbolTest],
62+
)
63+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class ReferencesTest {
8+
9+
@Test def valNoReferences0: Unit =
10+
code"class X { val ${m1}x$m2 = 9 }".withSource.references(m1 to m2, Nil)
11+
12+
@Test def valReferences0: Unit = {
13+
code"class X { val ${m1}x$m2 = 9; ${m3}x$m4; ${m5}x$m6 }".withSource
14+
.references(m1 to m2, List(m3 to m4, m5 to m6))
15+
}
16+
17+
@Test def valReferences1: Unit = {
18+
code"class X { val ${m1}x$m2 = 9; ${m3}x$m4; ${m5}x$m6 }".withSource
19+
.references(m1 to m2, List(m1 to m2, m3 to m4, m5 to m6), withDecl = true)
20+
}
21+
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
import dotty.tools.languageserver.util.embedded.CodeMarker
7+
8+
class RenameTest {
9+
10+
@Test def rename0: Unit = {
11+
def testRenameFrom(m: CodeMarker) =
12+
code"class ${m1}Foo$m2 { new ${m3}Foo$m4 }".withSource.rename(m, "Bar", List(m1 to m2, m3 to m4))
13+
testRenameFrom(m1)
14+
testRenameFrom(m3)
15+
}
16+
17+
18+
@Test def rename1: Unit = {
19+
def testRenameFrom(m: CodeMarker) =
20+
withSources(
21+
code"class ${m1}Foo$m2 { new ${m3}Foo$m4 }",
22+
code"class Bar { new ${m5}Foo$m6 }"
23+
).rename(m, "Bar", List(m1 to m2, m3 to m4, m5 to m6))
24+
25+
testRenameFrom(m1)
26+
testRenameFrom(m3)
27+
testRenameFrom(m5)
28+
}
29+
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dotty.tools.languageserver
2+
3+
import org.junit.Test
4+
5+
import dotty.tools.languageserver.util.Code._
6+
7+
class SymbolTest {
8+
9+
// @Test def symbol0: Unit =
10+
// code"class ${m1}Foo$m2".withSource.symbol("Foo", ("Foo", "Class", m1 to m2))
11+
12+
@Test def symbol1: Unit = {
13+
val Foo = (m1 to m2).withCode("Foo")
14+
val Bar = (m3 to m4).withCode("Bar")
15+
val fooFoo = (m5 to m6).withCode("Foo")
16+
withSources(
17+
code"class $Foo",
18+
code"class $Bar",
19+
code"""package foo
20+
|class $fooFoo {
21+
| class Bar
22+
|}
23+
"""
24+
) .symbol("Foo", Foo.range.symInfo("Foo", "Class"), fooFoo.range.symInfo("Foo", "Class", "foo"))
25+
.symbol("Bar", Bar.range.symInfo("Bar", "Class"))
26+
}
27+
}

0 commit comments

Comments
 (0)