mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 22:36:38 +02:00
tests: read WeeChat command line arguments in environment variable "WEECHAT_TESTS_ARGS"
This commit is contained in:
+28
-6
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user