1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 04:46:37 +02:00

tests: add scripting API tests (issue #104)

Automatic tests of scripting API are made with Python scripts:

- unparse.py: convert Python code to other languages
- testapigen.py: generate scripts in all languages to test the API
- testapi.py scripting API tests
This commit is contained in:
Sébastien Helleu
2017-10-07 16:51:25 +02:00
parent f6fe6be7a4
commit e8af853624
11 changed files with 2122 additions and 18 deletions
+40 -9
View File
@@ -36,6 +36,7 @@ extern "C"
#include "src/core/wee-hook.h"
#include "src/core/wee-input.h"
#include "src/core/wee-string.h"
#include "src/core/wee-util.h"
#include "src/plugins/plugin.h"
#include "src/gui/gui-main.h"
#include "src/gui/gui-buffer.h"
@@ -49,6 +50,8 @@ extern "C"
#define LOCALE_TESTS "en_US.UTF-8"
#define WEECHAT_TESTS_HOME "./tmp_weechat_test"
/* import tests from libs */
IMPORT_TEST_GROUP(Plugins);
IMPORT_TEST_GROUP(Arraylist);
@@ -61,7 +64,23 @@ IMPORT_TEST_GROUP(String);
IMPORT_TEST_GROUP(Url);
IMPORT_TEST_GROUP(Utf8);
IMPORT_TEST_GROUP(Util);
IMPORT_TEST_GROUP(Scripts);
struct t_gui_buffer *ptr_core_buffer = NULL;
/*
* Callback for exec_on_files (to remove all files in WeeChat home directory).
*/
void
exec_on_files_cb (void *data, const char *filename)
{
/* make C++ compiler happy */
(void) data;
unlink (filename);
}
/*
* Callback for any message displayed by WeeChat or a plugin.
@@ -69,10 +88,8 @@ IMPORT_TEST_GROUP(Util);
int
test_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
time_t date, int tags_count,
const char **tags, int displayed,
int highlight, const char *prefix,
const char *message)
time_t date, int tags_count, const char **tags, int displayed,
int highlight, const char *prefix, const char *message)
{
/* make C++ compiler happy */
(void) pointer;
@@ -119,6 +136,17 @@ test_gui_init ()
gui_main_init ();
}
/*
* Displays and runs a command on a buffer.
*/
void
run_cmd (const char *command)
{
printf (">>> Running command: %s\n", command);
input_data (ptr_core_buffer, command);
}
/*
* Runs tests in WeeChat environment.
*/
@@ -128,7 +156,6 @@ main (int argc, char *argv[])
{
int rc, length, weechat_argc;
char *weechat_tests_args, *args, **weechat_argv;
struct t_gui_buffer *ptr_core_buffer;
/* setup environment: English language, no specific timezone */
setenv ("LC_ALL", LOCALE_TESTS, 1);
@@ -144,6 +171,9 @@ main (int argc, char *argv[])
return 1;
}
/* clean WeeChat home */
util_exec_on_files (WEECHAT_TESTS_HOME, 1, 1, &exec_on_files_cb, NULL);
/* build arguments for WeeChat */
weechat_tests_args = getenv ("WEECHAT_TESTS_ARGS");
length = strlen (argv[0]) +
@@ -157,8 +187,9 @@ main (int argc, char *argv[])
return 1;
}
snprintf (args, length,
"%s --dir ./tmp_weechat_test%s%s",
"%s --dir %s%s%s",
argv[0],
WEECHAT_TESTS_HOME,
(weechat_tests_args) ? " " : "",
(weechat_tests_args) ? weechat_tests_args : "");
weechat_argv = string_split_shell (args, &weechat_argc);
@@ -184,9 +215,9 @@ main (int argc, char *argv[])
}
/* display WeeChat version and directories */
input_data (ptr_core_buffer, "/command core version");
input_data (ptr_core_buffer, "/debug dirs");
input_data (ptr_core_buffer, "/debug libs");
run_cmd ("/command core version");
run_cmd ("/debug dirs");
run_cmd ("/debug libs");
/* run all tests */
printf ("\n");