Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
nix_api_util.hh
Go to the documentation of this file.
1#pragma once
3#include "nix_api_util.h"
4
5#include <gtest/gtest.h>
6
7namespace nixC {
8
9class nix_api_util_context : public ::testing::Test
10{
11protected:
12
13 nix_api_util_context()
14 {
15 ctx = nix_c_context_create();
16 nix_libutil_init(ctx);
17 };
18
19 ~nix_api_util_context() override
20 {
21 nix_c_context_free(ctx);
22 ctx = nullptr;
23 }
24
25 nix_c_context * ctx;
26
27 inline void assert_ctx_ok()
28 {
29 if (nix_err_code(ctx) == NIX_OK) {
30 return;
31 }
32 unsigned int n;
33 const char * p = nix_err_msg(nullptr, ctx, &n);
34 std::string msg(p, n);
35 throw std::runtime_error(std::string("nix_err_code(ctx) != NIX_OK, message: ") + msg);
36 }
37
38 inline void assert_ctx_err()
39 {
40 if (nix_err_code(ctx) != NIX_OK) {
41 return;
42 }
43 throw std::runtime_error("Got NIX_OK, but expected an error!");
44 }
45};
46
47}
std::shared_ptr< T > p
Definition lexer.l:1269