Split tests and mark them as skipped if setup fails

This commit is contained in:
Sebastian Ramacher 2018-05-21 11:38:55 +02:00
parent de44629a6b
commit 72715901ff
6 changed files with 79 additions and 35 deletions

View file

@ -14,13 +14,30 @@ if check.found()
'test_utils.c' 'test_utils.c'
] ]
tests = executable('tests', test_sources, document = executable('test_document', ['test_document.c', 'tests.c'],
dependencies: build_dependencies + test_dependencies, dependencies: build_dependencies + test_dependencies,
include_directories: include_directories, include_directories: include_directories,
c_args: defines + flags c_args: defines + flags
) )
test('document', document,
timeout: 60*60
)
test('tests', tests, session = executable('test_session', ['test_session.c', 'tests.c'],
dependencies: build_dependencies + test_dependencies,
include_directories: include_directories,
c_args: defines + flags
)
test('session', session,
timeout: 60*60
)
utils = executable('test_utils', ['test_utils.c', 'tests.c'],
dependencies: build_dependencies + test_dependencies,
include_directories: include_directories,
c_args: defines + flags
)
test('utils', utils,
timeout: 60*60 timeout: 60*60
) )
endif endif

View file

@ -3,6 +3,7 @@
#include <check.h> #include <check.h>
#include "document.h" #include "document.h"
#include "tests.h"
START_TEST(test_open) { START_TEST(test_open) {
fail_unless(zathura_document_open(NULL, NULL, NULL, NULL, NULL) == NULL, "Could create document", NULL); fail_unless(zathura_document_open(NULL, NULL, NULL, NULL, NULL) == NULL, "Could create document", NULL);
@ -11,7 +12,7 @@ START_TEST(test_open) {
fail_unless(zathura_document_open(NULL, "fl", NULL, "pw", NULL) == NULL, "Could create document", NULL); fail_unless(zathura_document_open(NULL, "fl", NULL, "pw", NULL) == NULL, "Could create document", NULL);
} END_TEST } END_TEST
Suite* suite_document() static Suite* suite_document(void)
{ {
TCase* tcase = NULL; TCase* tcase = NULL;
Suite* suite = suite_create("Document"); Suite* suite = suite_create("Document");
@ -23,3 +24,8 @@ Suite* suite_document()
return suite; return suite;
} }
int main()
{
return run_suite(suite_document());
}

View file

@ -3,6 +3,7 @@
#include <check.h> #include <check.h>
#include "zathura.h" #include "zathura.h"
#include "tests.h"
START_TEST(test_create) { START_TEST(test_create) {
zathura_t* zathura = zathura_create(); zathura_t* zathura = zathura_create();
@ -11,15 +12,21 @@ START_TEST(test_create) {
zathura_free(zathura); zathura_free(zathura);
} END_TEST } END_TEST
Suite* suite_session() static Suite* suite_session(void)
{ {
TCase* tcase = NULL; TCase* tcase = NULL;
Suite* suite = suite_create("Session"); Suite* suite = suite_create("Session");
/* basic */ /* basic */
tcase = tcase_create("basic"); tcase = tcase_create("basic");
tcase_add_checked_fixture(tcase, setup, NULL);
tcase_add_test(tcase, test_create); tcase_add_test(tcase, test_create);
suite_add_tcase(suite, tcase); suite_add_tcase(suite, tcase);
return suite; return suite;
} }
int main()
{
return run_suite(suite_session());
}

View file

@ -3,6 +3,7 @@
#include <check.h> #include <check.h>
#include "utils.h" #include "utils.h"
#include "tests.h"
START_TEST(test_file_valid_extension_null) { START_TEST(test_file_valid_extension_null) {
fail_unless(file_valid_extension(NULL, NULL) == false, NULL); fail_unless(file_valid_extension(NULL, NULL) == false, NULL);
@ -10,7 +11,7 @@ START_TEST(test_file_valid_extension_null) {
fail_unless(file_valid_extension(NULL, "pdf") == false, NULL); fail_unless(file_valid_extension(NULL, "pdf") == false, NULL);
} END_TEST } END_TEST
Suite* suite_utils() static Suite* suite_utils(void)
{ {
TCase* tcase = NULL; TCase* tcase = NULL;
Suite* suite = suite_create("Utils"); Suite* suite = suite_create("Utils");
@ -22,3 +23,8 @@ Suite* suite_utils()
return suite; return suite;
} }
int main()
{
return run_suite(suite_utils());
}

View file

@ -1,41 +1,38 @@
/* See LICENSE file for license and copyright information */ /* See LICENSE file for license and copyright information */
#include <check.h>
#include <stdlib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <stdlib.h>
#define LENGTH(x) (sizeof(x)/sizeof((x)[0])) #include "tests.h"
extern Suite* suite_session(); int run_suite(Suite* suite)
extern Suite* suite_utils();
extern Suite* suite_document();
typedef Suite* (*suite_create_fnt_t)(void);
const suite_create_fnt_t suites[] = {
suite_utils,
suite_document,
suite_session,
};
int
main(int argc, char* argv[])
{ {
Suite* suite = NULL; SRunner* suite_runner = srunner_create(suite);
SRunner* suite_runner = NULL; srunner_run_all(suite_runner, CK_NORMAL);
int number_failed = 0; const int number_failed = srunner_ntests_failed(suite_runner);
/* init gtk */ int ret = EXIT_SUCCESS;
gtk_init(&argc, &argv); if (number_failed != 0) {
ret = EXIT_FAILURE;
/* run test suites */ const int tests_run = srunner_ntests_run(suite_runner);
for (unsigned int i = 0; i < LENGTH(suites); i++) { TestResult** results = srunner_failures(suite_runner);
suite = suites[i]();
suite_runner = srunner_create(suite); for (int i = 0; i < tests_run; ++i) {
srunner_run_all(suite_runner, CK_NORMAL); if (tr_ctx(results[i]) == CK_CTX_SETUP) {
number_failed += srunner_ntests_failed(suite_runner); /* mark tests as skipped */
srunner_free(suite_runner); ret = 77;
break;
}
}
} }
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; srunner_free(suite_runner);
return ret;
}
void setup(void)
{
fail_unless(gtk_init_check(NULL, NULL) == TRUE, "GTK+ initializitation failed", NULL);
} }

11
tests/tests.h Normal file
View file

@ -0,0 +1,11 @@
/* See LICENSE file for license and copyright information */
#ifndef ZATHURA_TESTS_H
#define ZATHURA_TESTS_H
#include <check.h>
int run_suite(Suite* suite);
void setup(void);
#endif