Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/libexpr-tests/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier/faster to do this as a language test in tests/functional/lang. Those can also check for error messages, see eval-fail-*.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do those test the C API ?

The original issue was specifically with the C-api vs. the C++ API.

{
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
Loading