Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
result.hh
Go to the documentation of this file.
1#pragma once
3
4#include "nix/util/result.hh"
6
7#include <gtest/gtest.h>
8
9#include <source_location>
10
11namespace nix::testing {
12
20template<typename T>
21T 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
T valueOrFail(Result< T, NativeError > &&result, std::source_location loc=std::source_location::current())
Definition result.hh:21
T valueOr(Result< T, E > &&result, F &&f)
Definition result.hh:33
outcome::unchecked< T, E > Result
Definition result.hh:24
Errors from the operating system: SystemError, and its subclasses for the native error codes,...
NativeSysError::NativeCode NativeError
Definition system-error.hh:359
SysError NativeSysError
Definition system-error.hh:347