dovecot-2.0-pigeonhole: Testsuite: made command syntax more unif...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Aug 28 14:13:38 EEST 2010


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/1701bfb17ce0
changeset: 1393:1701bfb17ce0
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Aug 28 13:13:16 2010 +0200
description:
Testsuite: made command syntax more uniform.

diffstat:

 TODO                                               |    1 -
 src/testsuite/Makefile.am                          |    5 +-
 src/testsuite/cmd-test-binary.c                    |  148 ++-------
 src/testsuite/cmd-test-config.c                    |  377 +++++++++++++++-----------
 src/testsuite/cmd-test-mailbox.c                   |  156 +++-------
 src/testsuite/cmd-test-result-print.c              |   81 -----
 src/testsuite/cmd-test-result-reset.c              |   83 -----
 src/testsuite/cmd-test-result.c                    |  132 +++++++++
 src/testsuite/ext-testsuite.c                      |   16 +-
 src/testsuite/testsuite-common.h                   |   15 +-
 src/testsuite/tst-test-result-action.c             |  269 +++++++++++++++++++
 src/testsuite/tst-test-result.c                    |  274 -------------------
 tests/deprecated/notify/execute.svtest             |    2 +-
 tests/execute/actions.svtest                       |   22 +-
 tests/execute/errors.svtest                        |    2 +-
 tests/execute/examples.svtest                      |   40 +-
 tests/extensions/enotify/execute.svtest            |    2 +-
 tests/extensions/imap4flags/execute.svtest         |    4 +-
 tests/extensions/include/execute.svtest            |   10 +-
 tests/extensions/mailbox/execute.svtest            |    6 +-
 tests/extensions/reject/execute.svtest             |    4 +-
 tests/extensions/spamvirustest/spamtest.svtest     |   72 ++--
 tests/extensions/spamvirustest/spamtestplus.svtest |   36 +-
 tests/extensions/spamvirustest/virustest.svtest    |   50 +-
 tests/extensions/subaddress/config.svtest          |   16 +-
 tests/extensions/vacation/execute.svtest           |    6 +-
 tests/multiscript/basic.svtest                     |   12 +-
 tests/multiscript/conflicts.svtest                 |    8 +-
 28 files changed, 863 insertions(+), 986 deletions(-)

diffs (truncated from 2735 to 300 lines):

diff -r 5f800639ee17 -r 1701bfb17ce0 TODO
--- a/TODO	Fri Aug 27 22:33:52 2010 +0200
+++ b/TODO	Sat Aug 28 13:13:16 2010 +0200
@@ -5,7 +5,6 @@
 	- Review logging and error handling; add more warning/info/debug messages
 	  where useful.
 * Cleanup the test suite
-	- Make uniform command implementations
 	- Cleanup test scripts
 
 Next (in order of descending priority/precedence):
diff -r 5f800639ee17 -r 1701bfb17ce0 src/testsuite/Makefile.am
--- a/src/testsuite/Makefile.am	Fri Aug 27 22:33:52 2010 +0200
+++ b/src/testsuite/Makefile.am	Sat Aug 28 13:13:16 2010 +0200
@@ -20,8 +20,7 @@
 	cmd-test-fail.c \
 	cmd-test-config.c \
 	cmd-test-set.c \
-	cmd-test-result-reset.c \
-	cmd-test-result-print.c \
+	cmd-test-result.c \
 	cmd-test-message.c \
 	cmd-test-mailbox.c \
 	cmd-test-binary.c
@@ -31,7 +30,7 @@
 	tst-test-script-run.c \
 	tst-test-multiscript.c \
 	tst-test-error.c \
-	tst-test-result.c \
+	tst-test-result-action.c \
 	tst-test-result-execute.c
 
 testsuite_SOURCES = \
diff -r 5f800639ee17 -r 1701bfb17ce0 src/testsuite/cmd-test-binary.c
--- a/src/testsuite/cmd-test-binary.c	Fri Aug 27 22:33:52 2010 +0200
+++ b/src/testsuite/cmd-test-binary.c	Sat Aug 28 13:13:16 2010 +0200
@@ -15,25 +15,42 @@
 #include "testsuite-script.h"
 
 /*
- * Test_binary command
- *
- * Syntax:   
- *   test_binary ( :load / :save ) <mailbox: string>
+ * Commands
  */
 
-static bool cmd_test_binary_registered
-	(struct sieve_validator *valdtr, const struct sieve_extension *ext,
-		struct sieve_command_registration *cmd_reg);
 static bool cmd_test_binary_validate
 	(struct sieve_validator *valdtr, struct sieve_command *cmd);
 static bool cmd_test_binary_generate
 	(const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
 
-const struct sieve_command_def cmd_test_binary = { 
-	"test_binary", 
+/* Test_binary_load command
+ *
+ * Syntax:   
+ *   test_binary_load <binary-name: string>
+ */
+
+const struct sieve_command_def cmd_test_binary_load = { 
+	"test_binary_load", 
 	SCT_COMMAND, 
 	1, 0, FALSE, FALSE,
-	cmd_test_binary_registered, 
+	NULL, 
+	NULL,
+	cmd_test_binary_validate, 
+	cmd_test_binary_generate, 
+	NULL 
+};
+
+/* Test_binary_save command
+ *
+ * Syntax:   
+ *   test_binary_save <binary-name: string>
+ */
+
+const struct sieve_command_def cmd_test_binary_save = { 
+	"test_binary_save", 
+	SCT_COMMAND, 
+	1, 0, FALSE, FALSE,
+	NULL, 
 	NULL,
 	cmd_test_binary_validate, 
 	cmd_test_binary_generate, 
@@ -69,88 +86,6 @@
 	cmd_test_binary_operation_execute 
 };
 
-/*
- * Compiler context data
- */
- 
-enum test_binary_operation {
-	BINARY_OP_LOAD, 
-	BINARY_OP_SAVE,
-	BINARY_OP_LAST
-};
-
-const struct sieve_operation_def *test_binary_operations[] = {
-	&test_binary_load_operation,
-	&test_binary_save_operation
-};
-
-struct cmd_test_binary_context_data {
-	enum test_binary_operation binary_op;
-	const char *folder;
-};
-
-/* 
- * Command tags 
- */
- 
-static bool cmd_test_binary_validate_tag
-	(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
-		struct sieve_command *cmd);
-
-static const struct sieve_argument_def test_binary_load_tag = { 
-	"load", 
-	NULL, 
-	cmd_test_binary_validate_tag,
-	NULL, NULL, NULL,
-};
-
-static const struct sieve_argument_def test_binary_save_tag = { 
-	"save", 
-	NULL,
-	cmd_test_binary_validate_tag,
-	NULL, NULL, NULL, 
-};
-
-static bool cmd_test_binary_registered
-(struct sieve_validator *valdtr, const struct sieve_extension *ext, 
-	struct sieve_command_registration *cmd_reg) 
-{
-	/* Register our tags */
-	sieve_validator_register_tag(valdtr, cmd_reg, ext, &test_binary_load_tag, 0); 	
-	sieve_validator_register_tag(valdtr, cmd_reg, ext, &test_binary_save_tag, 0); 	
-
-	return TRUE;
-}
-
-static bool cmd_test_binary_validate_tag
-(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, 
-	struct sieve_command *cmd)
-{
-	struct cmd_test_binary_context_data *ctx_data = 
-		(struct cmd_test_binary_context_data *) cmd->data;	
-	
-	if ( ctx_data != NULL ) {
-		sieve_argument_validate_error
-			(valdtr, *arg, "exactly one of the ':load' or ':save' tags must be "
-				"specified for the test_binary command, but more were found");
-		return NULL;		
-	}
-	
-	ctx_data = p_new
-		(sieve_command_pool(cmd), struct cmd_test_binary_context_data, 1);
-	cmd->data = ctx_data;
-	
-	if ( sieve_argument_is(*arg, test_binary_load_tag) ) 
-		ctx_data->binary_op = BINARY_OP_LOAD;
-	else
-		ctx_data->binary_op = BINARY_OP_SAVE;
-
-	/* Delete this tag */
-	*arg = sieve_ast_arguments_detach(*arg, 1);
-
-	return TRUE;
-}
-
 /* 
  * Validation 
  */
@@ -159,14 +94,7 @@
 (struct sieve_validator *valdtr, struct sieve_command *cmd) 
 {	
 	struct sieve_ast_argument *arg = cmd->first_positional;
-	
-	if ( cmd->data == NULL ) {
-		sieve_command_validate_error(valdtr, cmd, 
-			"the test_binary command requires either the :load or the :save tag "
-			"to be specified");
-		return FALSE;		
-	}
-		
+			
 	if ( !sieve_validate_positional_argument
 		(valdtr, cmd, arg, "binary-name", 1, SAAT_STRING) ) {
 		return FALSE;
@@ -182,15 +110,14 @@
 static bool cmd_test_binary_generate
 (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
 {
-	struct cmd_test_binary_context_data *ctx_data =
-		(struct cmd_test_binary_context_data *) cmd->data; 
-
-	i_assert( ctx_data->binary_op < BINARY_OP_LAST );
-	
 	/* Emit operation */
-	sieve_operation_emit(cgenv->sblock, cmd->ext, 
-		test_binary_operations[ctx_data->binary_op]);
-	  	
+	if ( sieve_command_is(cmd, cmd_test_binary_load) )
+		sieve_operation_emit(cgenv->sblock, cmd->ext, &test_binary_load_operation);
+	else if ( sieve_command_is(cmd, cmd_test_binary_save) )
+		sieve_operation_emit(cgenv->sblock, cmd->ext, &test_binary_save_operation);
+	else
+		i_unreached();
+		  	
  	/* Generate arguments */
 	if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
 		return FALSE;
@@ -212,7 +139,6 @@
 	return sieve_opr_string_dump(denv, address, "binary-name");
 }
 
-
 /*
  * Intepretation
  */
@@ -242,7 +168,7 @@
 		struct sieve_binary *sbin = testsuite_binary_load(str_c(binary_name));
 
 		if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
-			sieve_runtime_trace(renv, 0, "testsuite: test_binary command");
+			sieve_runtime_trace(renv, 0, "testsuite: test_binary_load command");
 			sieve_runtime_trace_descend(renv);
 			sieve_runtime_trace(renv, 0, "load binary `%s'", str_c(binary_name));
 		}
@@ -260,7 +186,7 @@
 		struct sieve_binary *sbin = testsuite_script_get_binary();
 
 		if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
-			sieve_runtime_trace(renv, 0, "testsuite: test_binary command");
+			sieve_runtime_trace(renv, 0, "testsuite: test_binary_save command");
 			sieve_runtime_trace_descend(renv);
 			sieve_runtime_trace(renv, 0, "save binary `%s'", str_c(binary_name));
 		}
diff -r 5f800639ee17 -r 1701bfb17ce0 src/testsuite/cmd-test-config.c
--- a/src/testsuite/cmd-test-config.c	Fri Aug 27 22:33:52 2010 +0200
+++ b/src/testsuite/cmd-test-config.c	Sat Aug 28 13:13:16 2010 +0200
@@ -15,36 +15,101 @@
 #include "testsuite-settings.h"
 
 /*
- * Test_config command
- *
- * Syntax:   
- *   test_config (
- *     :set <setting: string> <value: string> /
- *     :unset <setting: string> /  
- *     :reload [<extension: string>] )
+ * Commands
  */
 
-static bool cmd_test_config_registered
-	(struct sieve_validator *valdtr, const struct sieve_extension *ext,
-		struct sieve_command_registration *cmd_reg);
 static bool cmd_test_config_generate
 	(const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
 
-const struct sieve_command_def cmd_test_config = { 
-	"test_config", 
+/* Test_config_set command
+ *
+ * Syntax:   
+ *   test_config_set <setting: string> <value: string>
+ */
+
+static bool cmd_test_config_set_validate
+	(struct sieve_validator *valdtr, struct sieve_command *cmd);
+
+const struct sieve_command_def cmd_test_config_set = { 
+	"test_config_set", 
+	SCT_COMMAND, 
+	2, 0, FALSE, FALSE,
+	NULL, NULL,
+	cmd_test_config_set_validate, 
+	cmd_test_config_generate, 
+	NULL 
+};
+
+/* Test_config_unset command
+ *
+ * Syntax:   
+ *   test_config_unset <setting: string> 
+ */
+
+static bool cmd_test_config_unset_validate
+	(struct sieve_validator *valdtr, struct sieve_command *cmd);
+
+const struct sieve_command_def cmd_test_config_unset = { 
+	"test_config_unset", 
+	SCT_COMMAND, 
+	1, 0, FALSE, FALSE,


More information about the dovecot-cvs mailing list