Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acutest updates #2314

Merged
merged 3 commits into from May 4, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 24 additions & 3 deletions test/acutest.h
Expand Up @@ -925,6 +925,26 @@ test_error_(const char* fmt, ...)
}
}

/* This is called just before each test */
static void
test_init_(const char *test_name)
{
#ifdef TEST_INIT
TEST_INIT
; /* Allow for a single unterminated function call */
#endif
}

/* This is called after each test */
static void
test_fini_(const char *test_name)
{
#ifdef TEST_FINI
TEST_FINI
; /* Allow for a single unterminated function call */
#endif
}

/* Call directly the given test unit function. */
static int
test_do_run_(const struct test_* test, int index)
Expand All @@ -936,13 +956,13 @@ test_do_run_(const struct test_* test, int index)
test_current_already_logged_ = 0;
test_cond_failed_ = 0;

test_begin_test_line_(test);

#ifdef __cplusplus
try {
#endif
test_init_(test->name);
test_begin_test_line_(test);

/* This is good to do for case the test unit e.g. crashes. */
/* This is good to do in case the test unit crashes. */
fflush(stdout);
fflush(stderr);

Expand Down Expand Up @@ -988,6 +1008,7 @@ test_do_run_(const struct test_* test, int index)
test_finish_test_line_(0);
}

test_fini_(test->name);
test_case_(NULL);
test_current_unit_ = NULL;
return (test_current_failures_ == 0) ? 0 : -1;
Expand Down
13 changes: 12 additions & 1 deletion test/common.c
Expand Up @@ -23,6 +23,7 @@
#define TEST_NO_MAIN
#include "config.h"
#include "acutest.h"
#include <locale.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Expand All @@ -40,7 +41,7 @@ void test_gen_path(char *buf, size_t buflen, const char *fmt)
snprintf(buf, buflen, NONULL(fmt), NONULL(get_test_dir()));
}

void test_common(void)
void test_init(void)
{
const char *path = get_test_dir();
bool success = false;
Expand Down Expand Up @@ -71,8 +72,18 @@ void test_common(void)
TEST_MSG("Test dir '%s' isn't a directory\n", path);
goto done;
}

if (!TEST_CHECK((setlocale(LC_ALL, "en_US.UTF-8") != NULL) ||
(setlocale(LC_ALL, "C.UTF-8") != NULL)))
flatcap marked this conversation as resolved.
Show resolved Hide resolved
{
TEST_MSG("Can't set locale to (en_US|C).UTF-8");
goto done;
}

success = true;
done:
if (!success)
TEST_MSG("See: https://github.com/neomutt/neomutt-test-files#test-files\n");
}


4 changes: 2 additions & 2 deletions test/main.c
Expand Up @@ -22,14 +22,14 @@
*/

#include "config.h"
#include "test_common.h"
#define TEST_INIT test_init()
#include "acutest.h"

/******************************************************************************
* Add your test cases to this list.
*****************************************************************************/
#define NEOMUTT_TEST_LIST \
NEOMUTT_TEST_ITEM(test_common) \
\
/* account */ \
NEOMUTT_TEST_ITEM(test_account_free) \
NEOMUTT_TEST_ITEM(test_account_mailbox_add) \
Expand Down
6 changes: 0 additions & 6 deletions test/rfc2047/rfc2047_decode.c
Expand Up @@ -32,12 +32,6 @@ void test_rfc2047_decode(void)
{
// void rfc2047_decode(char **pd);

if (!TEST_CHECK((setlocale(LC_ALL, "en_US.UTF-8") != NULL) ||
(setlocale(LC_ALL, "C.UTF-8") != NULL)))
{
TEST_MSG("Cannot set locale to (en_US|C).UTF-8");
return;
}
char *previous_charset = C_Charset;
C_Charset = "utf-8";

Expand Down
6 changes: 0 additions & 6 deletions test/rfc2047/rfc2047_encode.c
Expand Up @@ -32,12 +32,6 @@ void test_rfc2047_encode(void)
{
// void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets);

if (!TEST_CHECK((setlocale(LC_ALL, "en_US.UTF-8") != NULL) ||
(setlocale(LC_ALL, "C.UTF-8") != NULL)))
{
TEST_MSG("Cannot set locale to (en_US|C).UTF-8");
return;
}
char *previous_charset = C_Charset;
C_Charset = "utf-8";

Expand Down
2 changes: 1 addition & 1 deletion test/test_common.h
Expand Up @@ -23,10 +23,10 @@
#ifndef TEST_TEST_COMMON_H
#define TEST_TEST_COMMON_H

#include "acutest.h"
#include <stdio.h>
#include "mutt/lib.h"

void test_gen_path(char *buf, size_t buflen, const char *fmt);
void test_init(void);

#endif /* TEST_TEST_COMMON_H */
4 changes: 0 additions & 4 deletions test/url/url_parse.c
Expand Up @@ -23,7 +23,6 @@
#define TEST_NO_MAIN
#include "config.h"
#include "acutest.h"
#include <locale.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "email/lib.h"
Expand Down Expand Up @@ -228,9 +227,6 @@ void check_query_string(const char *exp, const struct UrlQueryList *act)

void test_url_parse(void)
{
// let's pick a utf-8 locale, since we're also parsing utf-8 text */
setlocale(LC_ALL, "en_US.UTF-8");

// struct Url *url_parse(const char *src);

{
Expand Down