From b7118b7c39b5a8f5dedf89e63c209ceacbc8177b Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Fri, 17 Oct 2025 16:06:37 -0400 Subject: [PATCH] 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 --- src/libexpr-tests/nix_api_expr.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libexpr-tests/nix_api_expr.cc b/src/libexpr-tests/nix_api_expr.cc index de508b4e4..8a307aded 100644 --- a/src/libexpr-tests/nix_api_expr.cc +++ b/src/libexpr-tests/nix_api_expr.cc @@ -513,4 +513,22 @@ TEST_F(nix_api_expr_test, nix_expr_attrset_update) assert_ctx_ok(); } +/** + * @brief Validates the fix for https://github.com/NixOS/nix/issues/11972 + */ +TEST_F(nix_api_expr_test, fromTOML_invalid_syntax_should_error_gracefully) +{ + const char * expr = "builtins.fromTOML ''0000000000000000000000000000000000000'0''"; + + int status = nix_expr_eval_from_string(ctx, state, expr, ".", value); + + ASSERT_NE(0, status) << "Evaluation should have failed but returned a success code."; + + ASSERT_EQ(nix_err_code(ctx), NIX_ERR_NIX_ERROR) + << "Expected a generic Nix error, but a different error code was set."; + + ASSERT_THAT(nix_err_msg(nullptr, ctx, nullptr), ::testing::HasSubstr("invalid key value separator")) + << "The error message should indicate a TOML parsing issue."; +} + } // namespace nixC