/
TypeCheckSuite.scala
94 lines (89 loc) · 2.27 KB
/
TypeCheckSuite.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package munit
class TypeCheckSuite extends FunSuite {
def check(
options: TestOptions,
obtained: String,
compat: Map[String, String]
)(implicit loc: Location): Unit = {
test(options) {
val split = BuildInfo.scalaVersion.split("\\.")
val binaryVersion = split.take(2).mkString(".")
val majorVersion = split.head match {
case "0" => "3"
case n => n
}
val expected = compat
.get(BuildInfo.scalaVersion)
.orElse(compat.get(binaryVersion))
.orElse(compat.get(majorVersion))
.getOrElse {
compat(BuildInfo.scalaVersion)
}
assertNoDiff(obtained, expected)(loc)
}
}
val msg = "Hello"
check(
"not a member",
compileErrors("msg.foobar"),
Map(
"2" ->
"""|error: value foobar is not a member of String
|msg.foobar
| ^
|""".stripMargin,
"3" ->
"""|error:
|value foobar is not a member of String, but could be made available as an extension method.
|
|The following import might make progress towards fixing the problem:
|
| import munit.Clue.generate
|
|msg.foobar
| ^
|""".stripMargin
)
)
check(
"parse error",
compileErrors("val x: = 2"),
Map(
"2" -> """|error: identifier expected but '=' found.
|val x: = 2
| ^
|""".stripMargin,
"3" ->
"""|error: an identifier expected, but '=' found
|val x: = 2
| ^
|""".stripMargin
)
)
check(
"type mismatch",
compileErrors("val n: Int = msg"),
Map(
"2" ->
"""|error:
|type mismatch;
| found : String
| required: Int
|val n: Int = msg
| ^
|""".stripMargin,
"3" ->
"""|error:
|Found: (TypeCheckSuite.this.msg : String)
|Required: Int
|
|The following import might make progress towards fixing the problem:
|
| import munit.Clue.generate
|
|val n: Int = msg
| ^
|""".stripMargin
)
)
}