diff --git a/README b/README index 65084d62bb6f34408b269c60267f0f36a918a51b..c48f350336143719aeff7e2f44048887d7c37f04 100644 --- a/README +++ b/README @@ -182,6 +182,15 @@ Currently undocumented (will be merged with sieve-test). Various example scripts are bundled in the directory 'examples'. +Known issues +------------ + +Most open issues are outlined in the TODO file. The more generic ones are (re-) +listed here: + +- Compile errors are sometimes a bit obscure and long. This needs work. + Suggestions for improvement are welcome. + Authors ------- diff --git a/src/lib-sieve/sieve-validator.c b/src/lib-sieve/sieve-validator.c index c8093812a206eee9a58c620c2c13390753ab14a5..08c8f72cd3b7d291e1e99aa601d472523d8836f0 100644 --- a/src/lib-sieve/sieve-validator.c +++ b/src/lib-sieve/sieve-validator.c @@ -857,24 +857,44 @@ static bool sieve_validate_arguments_context */ static bool sieve_validate_command_subtests -(struct sieve_validator *validator, struct sieve_command_context *cmd, +(struct sieve_validator *valdtr, struct sieve_command_context *cmd, const unsigned int count) { switch ( count ) { case 0: if ( sieve_ast_test_count(cmd->ast_node) > 0 ) { - sieve_command_validate_error(validator, cmd, - "the %s %s accepts no sub-tests, but tests are specified anyway " - "(forgot semicolon?)", - cmd->command->identifier, sieve_command_type_name(cmd->command)); - + /* Unexpected command specified */ + enum sieve_command_type ctype = SCT_NONE; + struct sieve_command_registration *cmd_reg; + struct sieve_ast_node *test = sieve_ast_test_first(cmd->ast_node); + + cmd_reg = sieve_validator_find_command_registration + (valdtr, test->identifier); + + /* First check what we are dealing with */ + if ( cmd_reg != NULL && cmd_reg->command != NULL ) + ctype = cmd_reg->command->type; + + switch ( ctype ) { + case SCT_TEST: + sieve_command_validate_error(valdtr, cmd, + "the %s %s accepts no sub-tests, but one is specified anyway", + cmd->command->identifier, sieve_command_type_name(cmd->command)); + break; + case SCT_NONE: + case SCT_COMMAND: + sieve_command_validate_error(valdtr, cmd, + "missing semicolon ';' after %s %s", + cmd->command->identifier, sieve_command_type_name(cmd->command)); + break; + } return FALSE; } break; case 1: if ( sieve_ast_test_count(cmd->ast_node) == 0 ) { - sieve_command_validate_error(validator, cmd, + sieve_command_validate_error(valdtr, cmd, "the %s %s requires one sub-test, but none is specified", cmd->command->identifier, sieve_command_type_name(cmd->command)); @@ -883,7 +903,7 @@ static bool sieve_validate_command_subtests } else if ( sieve_ast_test_count(cmd->ast_node) > 1 || cmd->ast_node->test_list ) { - sieve_command_validate_error(validator, cmd, + sieve_command_validate_error(valdtr, cmd, "the %s %s requires one sub-test, but a list of tests is specified", cmd->command->identifier, sieve_command_type_name(cmd->command)); @@ -893,7 +913,7 @@ static bool sieve_validate_command_subtests default: if ( sieve_ast_test_count(cmd->ast_node) == 0 ) { - sieve_command_validate_error(validator, cmd, + sieve_command_validate_error(valdtr, cmd, "the %s %s requires a list of sub-tests, but none is specified", cmd->command->identifier, sieve_command_type_name(cmd->command)); @@ -902,7 +922,7 @@ static bool sieve_validate_command_subtests } else if ( sieve_ast_test_count(cmd->ast_node) == 1 && !cmd->ast_node->test_list ) { - sieve_command_validate_error(validator, cmd, + sieve_command_validate_error(valdtr, cmd, "the %s %s requires a list of sub-tests, " "but a single test is specified", cmd->command->identifier, sieve_command_type_name(cmd->command) ); diff --git a/tests/compile/errors.svtest b/tests/compile/errors.svtest index 98430a163dc36f49d9cff28561f77d1e6a9c093f..81a389bf01e14c1da6854f8b78518d9980252eb7 100644 --- a/tests/compile/errors.svtest +++ b/tests/compile/errors.svtest @@ -80,7 +80,7 @@ test "Header errors" { } if not test_error :index 7 :matches - "*header test accepts no sub-tests* are specified*" { + "*header test accepts no sub-tests* is specified*" { test_fail "error 7 is invalid"; } @@ -313,6 +313,36 @@ test "Tagged argument errors (FIXME: count only)" { } } +/* + * Typos + */ + +test "Typos" { + if test_compile "errors/typos.sieve" { + test_fail "compile should have failed."; + } + + if not test_error :count "eq" :comparator "i;ascii-numeric" "4" { + test_fail "wrong number of errors reported"; + } + + if not test_error :index 1 :matches + "missing semicolon * fileinto *" { + test_fail "error 1 is invalid"; + } + + if not test_error :index 2 :matches + "*fileinto command * no *tests* one is specified*" { + test_fail "error 2 is invalid"; + } + + if not test_error :index 3 :matches + "missing semicolon * fileinto *" { + test_fail "error 3 is invalid"; + } +} + + /* * Unsupported language features */ @@ -326,4 +356,3 @@ test "Unsupported language features (FIXME: count only)" { test_fail "wrong number of errors reported"; } } -