Redesign the interface between the interpreter and 'gb.test' component.
[INTERPRETER] * NEW: Now '-T' option with no argument calls Test._List() method. * NEW: If '-T' gets an argument, the Test._Run() method is used. * NEW: If '-T' argument is '*', then the Test._RunAll() method is called.
This commit is contained in:
parent
f55faedede
commit
d8f4c5a7cf
4 changed files with 144 additions and 10 deletions
|
@ -76,7 +76,8 @@ gbx3_SOURCES = \
|
|||
gbx_c_enum.h gbx_c_enum.c \
|
||||
gbx_c_timer.h gbx_c_timer.c \
|
||||
gbx_struct.h gbx_struct.c \
|
||||
gbx_signal.h gbx_signal.c
|
||||
gbx_signal.h gbx_signal.c \
|
||||
gbx_test.h gbx_test.c
|
||||
|
||||
gb_la_SOURCES = \
|
||||
gbx_info.h \
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "gbx_api.h"
|
||||
#include "gbx_signal.h"
|
||||
#include "gbx_jit.h"
|
||||
#include "gbx_test.h"
|
||||
|
||||
#if USE_PROFILE
|
||||
#include "gbx_profile.h"
|
||||
|
@ -420,9 +421,12 @@ int main(int argc, char *argv[])
|
|||
/* Startup class */
|
||||
|
||||
CLASS_load(PROJECT_class);
|
||||
startup = (CLASS_DESC_METHOD *)CLASS_get_symbol_desc_kind(PROJECT_class, "main", CD_STATIC_METHOD, 0, T_ANY);
|
||||
if (startup == NULL)
|
||||
THROW(E_MAIN);
|
||||
if (!PROJECT_run_tests)
|
||||
{
|
||||
startup = (CLASS_DESC_METHOD *)CLASS_get_symbol_desc_kind(PROJECT_class, "main", CD_STATIC_METHOD, 0, T_ANY);
|
||||
if (startup == NULL)
|
||||
THROW(E_MAIN);
|
||||
}
|
||||
|
||||
//CAPP_init(); /* needs startup class */
|
||||
CFILE_init_watch();
|
||||
|
@ -454,16 +458,18 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
if (PROJECT_run_tests)
|
||||
{
|
||||
GB_Push(1, T_STRING, _tests, -1);
|
||||
EXEC_public_desc(PROJECT_class, NULL, startup, 1);
|
||||
TEST_run(_tests);
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
EXEC_public_desc(PROJECT_class, NULL, startup, 0);
|
||||
|
||||
if (TYPE_is_boolean(startup->type))
|
||||
ret = RP->_boolean.value ? 1 : 0;
|
||||
else if (TYPE_is_integer(startup->type))
|
||||
ret = RP->_integer.value & 0xFF;
|
||||
if (TYPE_is_boolean(startup->type))
|
||||
ret = RP->_boolean.value ? 1 : 0;
|
||||
else if (TYPE_is_integer(startup->type))
|
||||
ret = RP->_integer.value & 0xFF;
|
||||
}
|
||||
|
||||
EXEC_release_return_value();
|
||||
|
||||
|
|
95
main/gbx/gbx_test.c
Normal file
95
main/gbx/gbx_test.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
/***************************************************************************
|
||||
|
||||
gbx_test.c
|
||||
|
||||
(c) Benoît Minisini <g4mba5@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#define __GBX_TEST_C
|
||||
|
||||
#include "gb_common.h"
|
||||
#include "gbx_class.h"
|
||||
#include "gbx_api.h"
|
||||
#include "gbx_project.h"
|
||||
#include "gbx_exec.h"
|
||||
#include "gbx_test.h"
|
||||
|
||||
static void error_test_run(CARRAY *tests)
|
||||
{
|
||||
OBJECT_UNREF(tests);
|
||||
}
|
||||
|
||||
void TEST_run(const char *test_list)
|
||||
{
|
||||
CLASS_DESC_METHOD *startup;
|
||||
CARRAY *tests;
|
||||
int i;
|
||||
char *test;
|
||||
char *p;
|
||||
char *name;
|
||||
CLASS *class;
|
||||
|
||||
|
||||
if (!test_list || !*test_list)
|
||||
{
|
||||
startup = (CLASS_DESC_METHOD *)CLASS_get_symbol_desc_kind(PROJECT_class, "_list", CD_STATIC_METHOD, 0, T_ANY);
|
||||
if (!startup)
|
||||
ERROR_panic("Test._List() method unavailable");
|
||||
EXEC_public_desc(PROJECT_class, NULL, startup, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (test_list[0] == '*' && !test_list[1])
|
||||
{
|
||||
startup = (CLASS_DESC_METHOD *)CLASS_get_symbol_desc_kind(PROJECT_class, "_runall", CD_STATIC_METHOD, 0, T_ANY);
|
||||
if (!startup)
|
||||
ERROR_panic("Test._RunAll() method unavailable");
|
||||
EXEC_public_desc(PROJECT_class, NULL, startup, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
startup = (CLASS_DESC_METHOD *)CLASS_get_symbol_desc_kind(PROJECT_class, "_run", CD_STATIC_METHOD, 0, T_ANY);
|
||||
if (!startup)
|
||||
ERROR_panic("Test._Run() method unavailable");
|
||||
|
||||
tests = STRING_split(test_list, strlen(test_list), ",", 1, NULL, 0, TRUE, FALSE);
|
||||
|
||||
ON_ERROR_1(error_test_run, tests)
|
||||
{
|
||||
for (i = 0; i < tests->count; i++)
|
||||
{
|
||||
test = *(char **)CARRAY_get_data_unsafe(tests, i);
|
||||
p = index(test, '.');
|
||||
if (p)
|
||||
name = STRING_new_temp(test, p - test);
|
||||
else
|
||||
name = test;
|
||||
|
||||
class = CLASS_find(name);
|
||||
CLASS_load(class);
|
||||
|
||||
GB_Push(2, T_OBJECT, class, T_STRING, test, STRING_length(test));
|
||||
EXEC_public_desc(PROJECT_class, NULL, startup, 2);
|
||||
}
|
||||
}
|
||||
END_ERROR
|
||||
|
||||
OBJECT_UNREF(tests);
|
||||
}
|
||||
|
32
main/gbx/gbx_test.h
Normal file
32
main/gbx/gbx_test.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/***************************************************************************
|
||||
|
||||
gbx_test.h
|
||||
|
||||
(c) Benoît Minisini <g4mba5@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __GBX_TEST_H
|
||||
#define __GBX_TEST_H
|
||||
|
||||
#include "gbx_c_array.h"
|
||||
#include "gbx_split.h"
|
||||
|
||||
void TEST_run(const char *test_list);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue