mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
test: Change FAIL to throw
[FAIL()] is a macro with `return`, making it unsuitable for helpers.
This uses std::runtime_error, because gtest does not seem to provide an
exception type of its own for this purpose. [AssertionException] is for
a different use case.
[FAIL()]: https://google.github.io/googletest/reference/assertions.html#FAIL
[AssertionException]: 35d0c36560/docs/reference/testing.md (assertionexception-assertionexception)
This commit is contained in:
parent
4eecf3c20a
commit
d004c524b8
2 changed files with 3 additions and 4 deletions
|
@ -40,7 +40,7 @@ void checkGTestWith(Testable && testable, MakeTestParams makeTestParams)
|
|||
} else {
|
||||
std::ostringstream ss;
|
||||
printResultMessage(result, ss);
|
||||
FAIL() << ss.str() << std::endl;
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,14 +26,13 @@ protected:
|
|||
|
||||
inline void assert_ctx_ok()
|
||||
{
|
||||
|
||||
if (nix_err_code(ctx) == NIX_OK) {
|
||||
return;
|
||||
}
|
||||
unsigned int n;
|
||||
const char * p = nix_err_msg(nullptr, ctx, &n);
|
||||
std::string msg(p, n);
|
||||
FAIL() << "nix_err_code(ctx) != NIX_OK, message: " << msg;
|
||||
throw std::runtime_error(std::string("nix_err_code(ctx) != NIX_OK, message: ") + msg);
|
||||
}
|
||||
|
||||
inline void assert_ctx_err()
|
||||
|
@ -41,7 +40,7 @@ protected:
|
|||
if (nix_err_code(ctx) != NIX_OK) {
|
||||
return;
|
||||
}
|
||||
FAIL() << "Got NIX_OK, but expected an error!";
|
||||
throw std::runtime_error("Got NIX_OK, but expected an error!");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue