Skip to content

Commit b7118b7

Browse files
committed
Add test to validate fix for fromTOML assertion not hit
Add a unit test specifically for the issue #11972 which said that an assertion in the fromTOML builtin was hit when called from the C API. fixes #11972
1 parent 64c5596 commit b7118b7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libexpr-tests/nix_api_expr.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,22 @@ TEST_F(nix_api_expr_test, nix_expr_attrset_update)
513513
assert_ctx_ok();
514514
}
515515

516+
/**
517+
* @brief Validates the fix for https://github.com/NixOS/nix/issues/11972
518+
*/
519+
TEST_F(nix_api_expr_test, fromTOML_invalid_syntax_should_error_gracefully)
520+
{
521+
const char * expr = "builtins.fromTOML ''0000000000000000000000000000000000000'0''";
522+
523+
int status = nix_expr_eval_from_string(ctx, state, expr, ".", value);
524+
525+
ASSERT_NE(0, status) << "Evaluation should have failed but returned a success code.";
526+
527+
ASSERT_EQ(nix_err_code(ctx), NIX_ERR_NIX_ERROR)
528+
<< "Expected a generic Nix error, but a different error code was set.";
529+
530+
ASSERT_THAT(nix_err_msg(nullptr, ctx, nullptr), ::testing::HasSubstr("invalid key value separator"))
531+
<< "The error message should indicate a TOML parsing issue.";
532+
}
533+
516534
} // namespace nixC

0 commit comments

Comments
 (0)