mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 13:36:02 +01:00
Merge pull request #12877 from roberth/c-api-libflake-override-input
C API: Flake loading, input overriding
This commit is contained in:
commit
e76bbe413e
26 changed files with 956 additions and 11 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "nix_api_util.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace nixC {
|
||||
|
||||
|
|
@ -24,7 +25,12 @@ protected:
|
|||
|
||||
nix_c_context * ctx;
|
||||
|
||||
inline void assert_ctx_ok()
|
||||
inline std::string loc(const char * file, int line)
|
||||
{
|
||||
return std::string(file) + ":" + std::to_string(line);
|
||||
}
|
||||
|
||||
inline void assert_ctx_ok(const char * file, int line)
|
||||
{
|
||||
if (nix_err_code(ctx) == NIX_OK) {
|
||||
return;
|
||||
|
|
@ -32,16 +38,18 @@ protected:
|
|||
unsigned int n;
|
||||
const char * p = nix_err_msg(nullptr, ctx, &n);
|
||||
std::string msg(p, n);
|
||||
throw std::runtime_error(std::string("nix_err_code(ctx) != NIX_OK, message: ") + msg);
|
||||
throw std::runtime_error(loc(file, line) + ": nix_err_code(ctx) != NIX_OK, message: " + msg);
|
||||
}
|
||||
#define assert_ctx_ok() assert_ctx_ok(__FILE__, __LINE__)
|
||||
|
||||
inline void assert_ctx_err()
|
||||
inline void assert_ctx_err(const char * file, int line)
|
||||
{
|
||||
if (nix_err_code(ctx) != NIX_OK) {
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("Got NIX_OK, but expected an error!");
|
||||
throw std::runtime_error(loc(file, line) + ": Got NIX_OK, but expected an error!");
|
||||
}
|
||||
#define assert_ctx_err() assert_ctx_err(__FILE__, __LINE__)
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue