Commit 72715901 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Split tests and mark them as skipped if setup fails

parent de44629a
......@@ -14,13 +14,30 @@ if check.found()
'test_utils.c'
]
tests = executable('tests', test_sources,
document = executable('test_document', ['test_document.c', 'tests.c'],
dependencies: build_dependencies + test_dependencies,
include_directories: include_directories,
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
)
endif
......@@ -3,6 +3,7 @@
#include <check.h>
#include "document.h"
#include "tests.h"
START_TEST(test_open) {
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);
} END_TEST
Suite* suite_document()
static Suite* suite_document(void)
{
TCase* tcase = NULL;
Suite* suite = suite_create("Document");
......@@ -23,3 +24,8 @@ Suite* suite_document()
return suite;
}
int main()
{
return run_suite(suite_document());
}
......@@ -3,6 +3,7 @@
#include <check.h>
#include "zathura.h"
#include "tests.h"
START_TEST(test_create) {
zathura_t* zathura = zathura_create();
......@@ -11,15 +12,21 @@ START_TEST(test_create) {
zathura_free(zathura);
} END_TEST
Suite* suite_session()
static Suite* suite_session(void)
{
TCase* tcase = NULL;
Suite* suite = suite_create("Session");
/* basic */
tcase = tcase_create("basic");
tcase_add_checked_fixture(tcase, setup, NULL);
tcase_add_test(tcase, test_create);
suite_add_tcase(suite, tcase);
return suite;
}
int main()
{
return run_suite(suite_session());
}
......@@ -3,6 +3,7 @@
#include <check.h>
#include "utils.h"
#include "tests.h"
START_TEST(test_file_valid_extension_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);
} END_TEST
Suite* suite_utils()
static Suite* suite_utils(void)
{
TCase* tcase = NULL;
Suite* suite = suite_create("Utils");
......@@ -22,3 +23,8 @@ Suite* suite_utils()
return suite;
}
int main()
{
return run_suite(suite_utils());
}
/* See LICENSE file for license and copyright information */
#include <check.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
#include "tests.h"
extern Suite* suite_session();
extern Suite* suite_utils();
extern Suite* suite_document();
int run_suite(Suite* suite)
{
SRunner* suite_runner = srunner_create(suite);
srunner_run_all(suite_runner, CK_NORMAL);
const int number_failed = srunner_ntests_failed(suite_runner);
int ret = EXIT_SUCCESS;
if (number_failed != 0) {
ret = EXIT_FAILURE;
const int tests_run = srunner_ntests_run(suite_runner);
TestResult** results = srunner_failures(suite_runner);
for (int i = 0; i < tests_run; ++i) {
if (tr_ctx(results[i]) == CK_CTX_SETUP) {
/* mark tests as skipped */
ret = 77;
break;
}
}
}
typedef Suite* (*suite_create_fnt_t)(void);
srunner_free(suite_runner);
const suite_create_fnt_t suites[] = {
suite_utils,
suite_document,
suite_session,
};
return ret;
}
int
main(int argc, char* argv[])
void setup(void)
{
Suite* suite = NULL;
SRunner* suite_runner = NULL;
int number_failed = 0;
/* init gtk */
gtk_init(&argc, &argv);
/* run test suites */
for (unsigned int i = 0; i < LENGTH(suites); i++) {
suite = suites[i]();
suite_runner = srunner_create(suite);
srunner_run_all(suite_runner, CK_NORMAL);
number_failed += srunner_ntests_failed(suite_runner);
srunner_free(suite_runner);
}
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
fail_unless(gtk_init_check(NULL, NULL) == TRUE, "GTK+ initializitation failed", NULL);
}
/* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment