We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
fail(message
a common pattern in swift tests is failing after checking some condition in a if/guard
guard let case .someCase(associatedValue) = someEnum else { fail("some explanation") return }
it could be convenient to have a require counterpart to the fail function that throws an error.
require
fail
Of coarse, users could always throw their own errors, but for users aren't used to doing so, it involves a lot of considerations.
it is possible to achieve this behavior with the existing require DSL, but it looks a bit wierd:
try require(false).verify(false, FailureMessage(stringValue: description), nil)
or as a utility:
private func failWithError( file: FileString = #filePath, line: UInt = #line, _ description: String ) throws -> Never { try require(file: file, line: line, false).verify(false, FailureMessage(stringValue: description), nil) throw SomeErrorSayingWeCantGetHere }
this would be simplified greatly with the access to the RequireError that does nice things. it could be simple as adding
RequireError
public func throwingFail(_ message: String, location: SourceLocation) throws -> Never { let handler = NimbleEnvironment.activeInstance.assertionHandler handler.assert(false, message: FailureMessage(stringValue: message), location: location) throw RequireError(message: message, location: location) }
and the ,file, line) counterparts to DSL+Require
,file, line)
DSL+Require
sorry in advance if there is already something simpler that could be used as a throwing fail
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion! This is a really good idea!
Sorry, something went wrong.
Just merged #1163, and it'll be released whenever #1157 is fixed.
Thanks! that was fast!
You're welcome! This happened to have been suggested shortly before I found time to actually implement it.
BTW, I just released Nimble 13.6.0, which includes this.
Successfully merging a pull request may close this issue.
a common pattern in swift tests is failing after checking some condition in a if/guard
it could be convenient to have a
require
counterpart to thefail
function that throws an error.Of coarse, users could always throw their own errors, but for users aren't used to doing so, it involves a lot of considerations.
it is possible to achieve this behavior with the existing
require
DSL, but it looks a bit wierd:or as a utility:
this would be simplified greatly with the access to the
RequireError
that does nice things.it could be simple as adding
and the
,file, line)
counterparts toDSL+Require
sorry in advance if there is already something simpler that could be used as a throwing
fail
The text was updated successfully, but these errors were encountered: