Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
result.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/util/result.hh
"
5
#include "
nix/util/system-error.hh
"
6
7
#include <gtest/gtest.h>
8
9
#include <source_location>
10
11
namespace
nix::testing {
12
20
template
<
typename
T>
21
T
valueOrFail
(
Result<T, NativeError>
&& result, std::source_location loc = std::source_location::current())
22
{
23
return
valueOr
(std::move(result), [&](
NativeError
err) {
24
NativeSysError
e(err,
"unexpected failure"
);
25
/* `ASSERT_*` returns from the function it is used in, so cannot be
26
used here, where there is no value to return. Instead record the
27
failure where we were called from, and throw to stop the test. */
28
ADD_FAILURE_AT(loc.file_name(), loc.line()) << e.what();
29
throw
e;
30
});
31
}
32
33
}
// namespace nix::testing
nix::testing::valueOrFail
T valueOrFail(Result< T, NativeError > &&result, std::source_location loc=std::source_location::current())
Definition
result.hh:21
result.hh
nix::valueOr
T valueOr(Result< T, E > &&result, F &&f)
Definition
result.hh:33
nix::Result
outcome::unchecked< T, E > Result
Definition
result.hh:24
system-error.hh
Errors from the operating system: SystemError, and its subclasses for the native error codes,...
nix::NativeError
NativeSysError::NativeCode NativeError
Definition
system-error.hh:359
nix::NativeSysError
SysError NativeSysError
Definition
system-error.hh:347
libutil-test-support
include
nix
util
tests
result.hh
Generated by
1.18.0