mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-08 18:40:23 +02:00
Better errors for odd-length keyword args
* libguile/vm-i-system.c (bind-kwargs): * libguile/vm.c (vm_error_kwargs_missing_value): * libguile/eval.c (error_missing_value) (prepare_boot_closure_env_for_apply): Adapt to mirror VM behavior. * libguile/keywords.c (scm_c_bind_keyword_arguments): Likewise. * module/ice-9/eval.scm (primitive-eval): Update to error on (foo #:kw) with a "Keyword argument has no value" instead of the horrible "odd argument list length". Also adapts to the expected args format for the keyword-argument-error exception printer in all cases. Matches 1.8 optargs behavior also. * test-suite/standalone/test-scm-c-bind-keyword-arguments.c (test_missing_value): (missing_value_error_handler): Update test. * test-suite/tests/optargs.test: Add tests.
This commit is contained in:
parent
f428e93ee7
commit
89ececea95
8 changed files with 142 additions and 91 deletions
|
@ -94,33 +94,31 @@ invalid_keyword_error_handler (void *data, SCM key, SCM args)
|
|||
}
|
||||
|
||||
static SCM
|
||||
test_odd_length (void *data)
|
||||
test_missing_value (void *data)
|
||||
{
|
||||
SCM k_foo = scm_from_utf8_keyword ("foo");
|
||||
SCM k_bar = scm_from_utf8_keyword ("bar");
|
||||
SCM arg_foo, arg_bar;
|
||||
SCM arg_foo;
|
||||
|
||||
scm_c_bind_keyword_arguments ("test",
|
||||
scm_list_n (k_foo, SCM_EOL,
|
||||
SCM_INUM0,
|
||||
scm_list_n (k_foo,
|
||||
SCM_UNDEFINED),
|
||||
SCM_ALLOW_OTHER_KEYS,
|
||||
k_foo, &arg_foo,
|
||||
k_bar, &arg_bar,
|
||||
SCM_UNDEFINED);
|
||||
assert (0);
|
||||
}
|
||||
|
||||
static SCM
|
||||
odd_length_error_handler (void *data, SCM key, SCM args)
|
||||
missing_value_error_handler (void *data, SCM key, SCM args)
|
||||
{
|
||||
SCM expected_args = scm_list_n
|
||||
(scm_from_utf8_string ("test"),
|
||||
scm_from_utf8_string ("Odd length of keyword argument list"),
|
||||
SCM_EOL, SCM_BOOL_F,
|
||||
scm_from_utf8_string ("Keyword argument has no value"),
|
||||
SCM_EOL, scm_list_1 (scm_from_utf8_keyword ("foo")),
|
||||
SCM_UNDEFINED);
|
||||
|
||||
assert (scm_is_eq (key, scm_from_utf8_symbol ("keyword-argument-error")));
|
||||
scm_write (args, scm_current_output_port ());
|
||||
assert (scm_is_true (scm_equal_p (args, expected_args)));
|
||||
|
||||
return SCM_BOOL_T;
|
||||
|
@ -214,10 +212,10 @@ test_scm_c_bind_keyword_arguments ()
|
|||
test_invalid_keyword, NULL,
|
||||
invalid_keyword_error_handler, NULL);
|
||||
|
||||
/* Test odd length error. */
|
||||
/* Test missing value error. */
|
||||
scm_internal_catch (SCM_BOOL_T,
|
||||
test_odd_length, NULL,
|
||||
odd_length_error_handler, NULL);
|
||||
test_missing_value, NULL,
|
||||
missing_value_error_handler, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue