From 3636b0d1abc17044605a46a32834b6566080869a Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 7 Oct 2017 20:53:38 +0100 Subject: [PATCH] Improvements to unit tests on Windows --- src/bounds.c | 5 +++++ src/lib.c | 5 +++++ src/parse.c | 5 +++++ src/phase.h | 3 +++ src/sem.c | 5 +++++ test/test_util.c | 13 +++++++++++++ 6 files changed, 36 insertions(+) diff --git a/src/bounds.c b/src/bounds.c index f0b3c423..d1f69e80 100644 --- a/src/bounds.c +++ b/src/bounds.c @@ -984,3 +984,8 @@ int bounds_errors(void) { return errors; } + +void reset_bounds_errors(void) +{ + errors = 0; +} diff --git a/src/lib.c b/src/lib.c index e3de5025..27e3a0ce 100644 --- a/src/lib.c +++ b/src/lib.c @@ -365,6 +365,11 @@ lib_t lib_tmp(const char *name) static void push_path(const char *path) { + for (search_path_t *it = search_paths; it != NULL; it = it->next) { + if (strcmp(it->path, path) == 0) + return; + } + search_path_t *s = xmalloc(sizeof(search_path_t)); s->next = search_paths; s->path = path; diff --git a/src/parse.c b/src/parse.c index 55710ac4..3ceddf2d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -5820,3 +5820,8 @@ int parse_errors(void) { return n_errors; } + +void reset_parse_errors(void) +{ + n_errors = 0; +} diff --git a/src/phase.h b/src/phase.h index d3905248..5ac501cf 100644 --- a/src/phase.h +++ b/src/phase.h @@ -36,6 +36,7 @@ bool sem_check(tree_t t); // The number of errors found during the semantic check phase. int sem_errors(void); +void reset_sem_errors(void); // The number of errors found while constant folding int eval_errors(void); @@ -48,6 +49,7 @@ void bounds_check(tree_t top); // Number of errors found during bounds checking int bounds_errors(void); +void reset_bounds_errors(void); // Evaluate a function call at compile time tree_t eval(tree_t fcall, eval_flags_t flags); @@ -81,6 +83,7 @@ tree_t parse(void); // Number of errors found while parsing last unit int parse_errors(void); +void reset_parse_errors(void); // Generate vcode for a design unit vcode_unit_t lower_unit(tree_t unit); diff --git a/src/sem.c b/src/sem.c index 254cd07a..3a8d8516 100644 --- a/src/sem.c +++ b/src/sem.c @@ -7474,3 +7474,8 @@ int sem_errors(void) { return errors; } + +void reset_sem_errors(void) +{ + errors = 0; +} diff --git a/test/test_util.c b/test/test_util.c index ffc63b44..0d51089a 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -48,6 +48,13 @@ static void setup(void) intern_strings(); } +static void setup_per_test(void) +{ + reset_bounds_errors(); + reset_sem_errors(); + reset_parse_errors(); +} + static void teardown(void) { lib_free(lib_work()); @@ -55,8 +62,13 @@ static void teardown(void) void expect_errors(const error_t *lines) { +#ifdef __MINGW32__ + if (orig_error_fn == NULL) + orig_error_fn = set_error_fn(test_error_fn, false); +#else fail_unless(orig_error_fn == NULL); orig_error_fn = set_error_fn(test_error_fn, false); +#endif error_lines = lines; } @@ -69,6 +81,7 @@ TCase *nvc_unit_test(void) TCase *tc_core = tcase_create("Core"); tcase_add_unchecked_fixture(tc_core, setup, teardown); + tcase_add_checked_fixture(tc_core, setup_per_test, NULL); return tc_core; } -- 2.39.2