summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2014-08-14 19:15:25 +0200
committerSébastien Helleu <flashcode@flashtux.org>2014-08-14 19:15:25 +0200
commitdcf46a2ca0c84603e9166fe9b390395c0b430b50 (patch)
tree57f05ca977195216d174b4399c803e106e7ffe97
parent99b7aa9d27ce7aea0a095bf74a51c75b170a20b3 (diff)
downloadweechat-dcf46a2ca0c84603e9166fe9b390395c0b430b50.zip
tests: read WeeChat command line arguments in environment variable "WEECHAT_TESTS_ARGS"
-rw-r--r--tests/tests.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/tests.cpp b/tests/tests.cpp
index 50f6051d7..6b2e37431 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -34,6 +35,7 @@ extern "C"
#include "../src/core/weechat.h"
#include "../src/core/wee-hook.h"
#include "../src/core/wee-input.h"
+#include "../src/core/wee-string.h"
#include "../src/plugins/plugin.h"
#include "../src/gui/gui-main.h"
#include "../src/gui/gui-buffer.h"
@@ -117,19 +119,36 @@ test_gui_init ()
int
main (int argc, char *argv[])
{
- int rc;
- const char *weechat_argv[] = { NULL, "--dir", NULL, NULL };
+ int rc, length, weechat_argc;
+ char *weechat_tests_args, *args, **weechat_argv;
/* setup environment: default language, no specific timezone */
setenv ("LANG", "C", 1);
setenv ("TZ", "", 1);
- /* command line arguments: "<this_binary> --dir ./tmp_weechat_test" */
- weechat_argv[0] = argv[0];
- weechat_argv[2] = "./tmp_weechat_test";
+ /* build arguments for WeeChat */
+ weechat_tests_args = getenv ("WEECHAT_TESTS_ARGS");
+ length = strlen (argv[0]) +
+ 64 + /* --dir ... */
+ ((weechat_tests_args) ? 1 + strlen (weechat_tests_args) : 0) +
+ 1;
+ args = (char *)malloc (length);
+ if (!args)
+ {
+ fprintf (stderr, "Memory error\n");
+ return 1;
+ }
+ snprintf (args, length,
+ "%s --dir ./tmp_weechat_test%s%s",
+ argv[0],
+ (weechat_tests_args) ? " " : "",
+ (weechat_tests_args) ? weechat_tests_args : "");
+ weechat_argv = string_split_shell (args, &weechat_argc);
+ printf ("WeeChat arguments: \"%s\"\n", args);
/* init WeeChat */
- weechat_init (3, (char **)weechat_argv, &test_gui_init);
+ printf ("------------------------------------------------------------\n");
+ weechat_init (weechat_argc, weechat_argv, &test_gui_init);
/* display WeeChat version */
input_data (gui_buffer_search_main (), "/command core version");
@@ -143,6 +162,7 @@ main (int argc, char *argv[])
/* end WeeChat */
weechat_end (&gui_main_end);
+ printf ("------------------------------------------------------------\n");
/* display status */
printf ("\n");
@@ -150,5 +170,7 @@ main (int argc, char *argv[])
(rc == 0) ? 32 : 31, /* 32 = green (OK), 31 = red (error) */
(rc == 0) ? "OK" : "ERROR");
+ string_free_split (weechat_argv);
+
return rc;
}