Skip to content

Commit

Permalink
Add docstrings for several assertion methods
Browse files Browse the repository at this point in the history
Originally in #225
Co-authored-by: Ólafur Páll Geirsson <olafurpg@gmail.com>
  • Loading branch information
valencik committed Apr 10, 2022
1 parent 1af9fc7 commit f5a3be9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions munit/shared/src/main/scala/munit/Assertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,18 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
}
}

/**
* Evalutes the given expression and asserts that an exception of type T is thrown.
*/
def intercept[T <: Throwable](
body: => Any
)(implicit T: ClassTag[T], loc: Location): T = {
runIntercept(None, body)
}

/**
* Evalutes the given expression and asserts that an exception of type T with the expected message is thrown.
*/
def interceptMessage[T <: Throwable](expectedExceptionMessage: String)(
body: => Any
)(implicit T: ClassTag[T], loc: Location): T = {
Expand Down Expand Up @@ -270,6 +276,9 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
}
}

/**
* Unconditionally fails this test with the given message and exception marked as the cause.
*/
def fail(message: String, cause: Throwable)(implicit
loc: Location
): Nothing = {
Expand All @@ -281,6 +290,9 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
)
}

/**
* Unconditionally fails this test with the given message and optional clues.
*/
def fail(
message: String,
clues: Clues = new Clues(Nil)
Expand All @@ -291,6 +303,13 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
)
}

/**
* Unconditionally fails this test due to result of comparing two values.
*
* The only reason to use this method instead of `fail()` is if you want to
* allow comparing the two different values in the the IntelliJ GUI diff
* viewer.
*/
def failComparison(
message: String,
obtained: Any,
Expand All @@ -305,6 +324,9 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
)
}

/**
* Unconditionally fail this test case and cancel all the subsequent tests in this suite.
*/
def failSuite(
message: String,
clues: Clues = new Clues(Nil)
Expand Down

0 comments on commit f5a3be9

Please sign in to comment.