1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-27 20:51:00 +01:00

Merge remote-tracking branch 'origin/2.29-maintenance' into detsys-main

This commit is contained in:
Eelco Dolstra 2025-05-16 12:48:44 +02:00
commit c20642ac7b
354 changed files with 6768 additions and 3808 deletions

View file

@ -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__)
};
}