summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-09-19 15:42:38 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-09-19 15:42:38 +0100
commit57d19346b6ff61c360ce5d1653d1e25118277c88 (patch)
tree8cc845db0d615031b3dbe1831fc28419287aa236 /test
parent50d51fca34585b51c1e6ecd168bda6e9e48b0bb2 (diff)
downloadrspamd-57d19346b6ff61c360ce5d1653d1e25118277c88.tar.gz
rspamd-57d19346b6ff61c360ce5d1653d1e25118277c88.zip
[Test] Added key to run specifig lua-test
example: $ ./test/rspamd-test -p /rspamd/lua -t selectors.lua no way to run two test suites atm
Diffstat (limited to 'test')
-rw-r--r--test/rspamd_lua_test.c22
-rw-r--r--test/rspamd_test_suite.c21
2 files changed, 42 insertions, 1 deletions
diff --git a/test/rspamd_lua_test.c b/test/rspamd_lua_test.c
index 0c785e9e6..b87df0f58 100644
--- a/test/rspamd_lua_test.c
+++ b/test/rspamd_lua_test.c
@@ -24,6 +24,8 @@
#endif
static const char *lua_src = BUILDROOT "/test/lua/tests.lua";
+extern gchar *lua_test;
+extern struct rspamd_main *rspamd_main;
static int
traceback (lua_State *L)
@@ -61,6 +63,8 @@ rspamd_lua_test_func (void)
glob_t globbuf;
gint i, len;
+ rspamd_lua_set_globals (rspamd_main->cfg, L, NULL);
+
rspamd_printf ("Starting lua tests\n");
if ((rp = realpath (lua_src, rp_buf)) == NULL) {
@@ -90,11 +94,27 @@ rspamd_lua_test_func (void)
pattern = g_malloc (len);
rspamd_snprintf (pattern, len, "%s/unit/%s", dir, "*.lua");
+ gint lua_test_len = 0;
+ gint inserted_file = 1;
+ gint path_start;
+ if (lua_test) {
+ lua_test_len = strlen (lua_test);
+ }
if (glob (pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) {
for (i = 0; i < (gint)globbuf.gl_pathc; i++) {
- lua_pushinteger (L, i + 1);
+ if (lua_test) {
+ path_start = strlen (globbuf.gl_pathv[i]) - lua_test_len;
+ if (path_start < 0 ||
+ strncmp (globbuf.gl_pathv[i] + path_start, lua_test, lua_test_len) != 0) {
+ continue;
+ }
+ }
+
+ lua_pushinteger (L, inserted_file);
lua_pushstring (L, globbuf.gl_pathv[i]);
lua_settable (L, -3);
+
+ inserted_file ++;
}
globfree (&globbuf);
g_free (pattern);
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index 07b728ecf..0be3091d9 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -7,10 +7,22 @@ struct rspamd_main *rspamd_main = NULL;
struct event_base *base = NULL;
worker_t *workers[] = { NULL };
+gchar *lua_test = NULL;
+gboolean verbose = FALSE;
+
+static GOptionEntry entries[] =
+{
+ { "test", 't', 0, G_OPTION_ARG_STRING, &lua_test,
+ "Lua test to run (i.e. selectors.lua)", NULL },
+ { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
+};
+
int
main (int argc, char **argv)
{
struct rspamd_config *cfg;
+ GOptionContext *context;
+ GError *error = NULL;
rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
memset (rspamd_main, 0, sizeof (struct rspamd_main));
@@ -27,6 +39,15 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
+ context = g_option_context_new ("- run rspamd test");
+ g_option_context_add_main_entries (context, entries, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ fprintf (stderr, "option parsing failed: %s\n", error->message);
+ g_option_context_free (context);
+ exit (1);
+ }
+
cfg->libs_ctx = rspamd_init_libs ();
base = event_init ();