Skip to content

Commit 3fb943d

Browse files
committed
C API: Make store realise tests multi-platform
... and improve assertions.
1 parent aace1fb commit 3fb943d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/libstore-tests/nix_api_store.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ class NixApiStoreTestWithRealisedPath : public nix_api_store_test_base
240240
std::stringstream buffer;
241241
buffer << t.rdbuf();
242242

243-
drv = nix_derivation_from_json(ctx, store, buffer.str().c_str());
243+
// Replace the hardcoded system with the current system
244+
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());
245+
246+
drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
244247
assert_ctx_ok();
245248
ASSERT_NE(drv, nullptr);
246249

@@ -249,6 +252,7 @@ class NixApiStoreTestWithRealisedPath : public nix_api_store_test_base
249252
ASSERT_NE(drvPath, nullptr);
250253

251254
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath_) {
255+
ASSERT_NE(outname, nullptr) << "Output name should not be NULL";
252256
auto is_valid_path = nix_store_is_valid_path(ctx, store, outPath_);
253257
ASSERT_EQ(is_valid_path, true);
254258
ASSERT_STREQ(outname, "out") << "Expected single 'out' output";
@@ -292,23 +296,32 @@ TEST_F(nix_api_store_test_base, build_from_json)
292296
std::stringstream buffer;
293297
buffer << t.rdbuf();
294298

295-
auto * drv = nix_derivation_from_json(ctx, store, buffer.str().c_str());
299+
// Replace the hardcoded system with the current system
300+
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());
301+
302+
auto * drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
296303
assert_ctx_ok();
297304
ASSERT_NE(drv, nullptr);
298305

299306
auto * drvPath = nix_add_derivation(ctx, store, drv);
300307
assert_ctx_ok();
301308
ASSERT_NE(drv, nullptr);
302309

310+
int callbackCount = 0;
303311
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath) {
312+
ASSERT_NE(outname, nullptr);
313+
ASSERT_STREQ(outname, "out");
314+
ASSERT_NE(outPath, nullptr);
304315
auto is_valid_path = nix_store_is_valid_path(ctx, store, outPath);
305316
ASSERT_EQ(is_valid_path, true);
317+
callbackCount++;
306318
}};
307319

308320
auto ret = nix_store_realise(
309321
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
310322
assert_ctx_ok();
311323
ASSERT_EQ(ret, NIX_OK);
324+
ASSERT_EQ(callbackCount, 1) << "Callback should have been invoked exactly once";
312325

313326
// Clean up
314327
nix_store_path_free(drvPath);

0 commit comments

Comments
 (0)