-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from olafurpg/compile-time
Add assertions for compile-time errors
- Loading branch information
Showing
6 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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 fix 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" -> | ||
// NOTE(olafur): I'm not sure what's going on with the second errors but | ||
// that's what Dotty reports. | ||
"""|error: an identifier expected, but eof found | ||
|val x: = 2 | ||
| ^ | ||
|error: Declaration of value x not allowed here: only classes can have declared but undefined members | ||
|package munit | ||
| ^ | ||
|""".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 | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters