Cleaner test output, add click on test failures.

Open a file at the location of the test failure if detected
This commit is contained in:
Andy Williams 2015-01-30 00:08:12 +00:00
parent 47f02e2dd6
commit 8c8a890d58
1 changed files with 71 additions and 46 deletions

View File

@ -18,6 +18,7 @@
#include "edi_private.h"
static const char *_current_dir = NULL;
static const char *_current_test_dir = NULL;
static unsigned int _edi_strlen_current_dir;
static int _edi_test_count;
@ -33,7 +34,7 @@ _edi_consolepanel_startswith_location(const char *line)
regex_t regex;
int ret;
regcomp(&regex, "^[^/].*:[0-9]*:[0-9]* ", 0);
regcomp(&regex, "^[^/].*:[0-9]*:[0-9]*[ :]", 0);
ret = !regexec(&regex, line, 0, NULL, 0);
regfree(&regex);
@ -41,19 +42,23 @@ _edi_consolepanel_startswith_location(const char *line)
}
static char *
_edi_consolepanel_extract_location(const char *line)
_edi_consolepanel_extract_location(const char *line, const char *dir, int dirlen)
{
char *path;
const char *pos;
int file_len, length;
pos = strstr(line, " ");
pos = strstr(line, ":F:");
if (!pos)
pos = strstr(line, ":P:");
if (!pos)
pos = strstr(line, " ");
file_len = strlen(line) - strlen(pos);
length = _edi_strlen_current_dir + file_len + 2;
length = dirlen + file_len + 2;
path = malloc(sizeof(char) * length);
snprintf(path, _edi_strlen_current_dir + 2, "%s/", _current_dir);
snprintf(path + _edi_strlen_current_dir + 1, file_len + 1, "%s", line);
snprintf(path, dirlen + 2, "%s/", dir);
snprintf(path + dirlen + 1, file_len + 1, "%s", line);
return path;
}
@ -94,7 +99,11 @@ _edi_consolepanel_clicked_cb(void *data, Eo *obj EINA_UNUSED,
if (_edi_consolepanel_startswith_location(terminated))
{
path = _edi_consolepanel_extract_location(terminated);
if (code == _edi_console_code)
path = _edi_consolepanel_extract_location(terminated, _current_dir, _edi_strlen_current_dir);
else
path = _edi_consolepanel_extract_location(terminated, _current_test_dir, strlen(_current_test_dir));
if (strstr(path, edi_project_get()) == path)
{
options = edi_path_options_create(path);
@ -131,11 +140,9 @@ void edi_consolepanel_append_error_line(const char *line)
void edi_consolepanel_clear()
{
elm_code_file_clear(_edi_console_code->file);
elm_code_file_clear(_edi_test_code->file);
_edi_test_count = 0;
_edi_test_pass = 0;
_edi_test_fail = 0;
_edi_test_count = _edi_test_pass = _edi_test_fail = 0;
}
static Eina_Bool
@ -164,13 +171,34 @@ _exe_error(void *d EINA_UNUSED, int t EINA_UNUSED, void *event_info)
return ECORE_CALLBACK_RENEW;
}
static void _edi_test_append(const char *content, int length, Elm_Code_Status_Type type)
static void
_edi_test_append(const char *content, int length, Elm_Code_Status_Type type)
{
elm_code_file_line_append(_edi_test_code->file, content, length);
elm_code_file_line_status_set(_edi_test_code->file, elm_code_file_lines_get(_edi_test_code->file), type);
}
static Eina_Bool _edi_test_line_contains(const char *start, unsigned int length, const char *needle)
static void
_edi_test_output_suite(int count, int pass, int fail)
{
char *line;
const char *format = "Total pass %d (%d%%), fail %d";
int linemax, percent;
linemax = strlen(format) - 6 + 30;
line = malloc(sizeof(char) * linemax);
percent = 0;
if (count > 0)
percent = (int) ((pass / (double) count) * 100);
snprintf(line, linemax, format, pass, percent, fail);
_edi_test_append(line, strlen(line), (fail > 0) ? ELM_CODE_STATUS_TYPE_FAILED : ELM_CODE_STATUS_TYPE_PASSED);
free(line);
}
static Eina_Bool
_edi_test_line_contains(const char *start, unsigned int length, const char *needle)
{
unsigned int needlelen, c;
char *ptr;
@ -189,51 +217,52 @@ static Eina_Bool _edi_test_line_contains(const char *start, unsigned int length
return EINA_FALSE;
}
static void _edi_test_line_parse_suite(const char *path)
static void
_edi_test_line_parse_suite(const char *path)
{
Eina_File *file;
Eina_File_Line *line;
Eina_Iterator *it;
char logfile[PATH_MAX];
char logfile[PATH_MAX], logpath[PATH_MAX];
int pathlength;
Elm_Code_Status_Type status;
pathlength = strlen(path);
snprintf(logfile, pathlength + 4 + 1, "%s.log", path);
realpath(logfile, logpath);
if (_current_test_dir)
eina_stringshare_del(_current_test_dir);
_current_test_dir = eina_stringshare_add(dirname(logpath));
file = eina_file_open(logfile, EINA_FALSE);
it = eina_file_map_lines(file);
EINA_ITERATOR_FOREACH(it, line)
{
status = ELM_CODE_STATUS_TYPE_DEFAULT;
if (_edi_test_line_contains(line->start, line->length, ":P:"))
status = ELM_CODE_STATUS_TYPE_PASSED;
{
_edi_test_count++;
_edi_test_pass++;
continue;
}
else if (_edi_test_line_contains(line->start, line->length, ":F:"))
status = ELM_CODE_STATUS_TYPE_FAILED;
_edi_test_append(line->start, line->length, status);
{
_edi_test_count++;
_edi_test_fail++;
_edi_test_append(line->start, line->length, ELM_CODE_STATUS_TYPE_FAILED);
}
else if (_edi_test_line_contains(line->start, line->length, "Running"))
{
_edi_test_count = _edi_test_pass = _edi_test_fail = 0;
_edi_test_append(line->start, line->length, ELM_CODE_STATUS_TYPE_DEFAULT);
}
}
eina_iterator_free(it);
eina_file_close(file);
}
static void _edi_test_line_parse_suite_pass_line(const char *line)
{
_edi_test_line_parse_suite(line);
_edi_test_append("Suite passed", 13, ELM_CODE_STATUS_TYPE_DEFAULT);
}
static void _edi_test_line_parse_suite_fail_line(const char *line)
{
_edi_test_line_parse_suite(line);
_edi_test_append("Suite failed", 13, ELM_CODE_STATUS_TYPE_DEFAULT);
}
static void _edi_test_line_parse_summary_line(const char *line)
{
_edi_test_append(line, strlen(line), ELM_CODE_STATUS_TYPE_DEFAULT);
if (_edi_test_count > 0)
{
_edi_test_output_suite(_edi_test_count, _edi_test_pass, _edi_test_fail);
}
}
static void _edi_test_line_callback(const char *content)
@ -243,21 +272,16 @@ static void _edi_test_line_callback(const char *content)
if (content[0] == '#')
{
_edi_test_line_parse_summary_line(content + 2);
return;
}
if (!strncmp(content, "PASS:", 5))
{
_edi_test_count++;
_edi_test_pass++;
_edi_test_line_parse_suite_pass_line(content + 6);
_edi_test_line_parse_suite(content + 6);
}
else if (!strncmp(content, "FAIL:", 5))
{
_edi_test_count++;
_edi_test_fail++;
_edi_test_line_parse_suite_fail_line(content + 6);
_edi_test_line_parse_suite(content + 6);
}
}
@ -298,7 +322,8 @@ void edi_testpanel_add(Evas_Object *parent)
eo_do(widget,
elm_code_widget_code_set(code),
elm_code_widget_font_size_set(_edi_cfg->font.size),
elm_code_widget_gravity_set(0.0, 1.0));
elm_code_widget_gravity_set(0.0, 1.0),
eo_event_callback_add(ELM_CODE_WIDGET_EVENT_LINE_CLICKED, _edi_consolepanel_clicked_cb, code));
evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);