Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings for several assertion methods #519

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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