mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 18:13:46 +01:00
Split tests and mark them as skipped if setup fails
This commit is contained in:
parent
de44629a6b
commit
72715901ff
@ -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());
|
||||
}
|
||||
|
@ -1,41 +1,38 @@
|
||||
/* 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();
|
||||
|
||||
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[])
|
||||
int run_suite(Suite* suite)
|
||||
{
|
||||
Suite* suite = NULL;
|
||||
SRunner* suite_runner = NULL;
|
||||
int number_failed = 0;
|
||||
SRunner* suite_runner = srunner_create(suite);
|
||||
srunner_run_all(suite_runner, CK_NORMAL);
|
||||
const int number_failed = srunner_ntests_failed(suite_runner);
|
||||
|
||||
/* init gtk */
|
||||
gtk_init(&argc, &argv);
|
||||
int ret = EXIT_SUCCESS;
|
||||
if (number_failed != 0) {
|
||||
ret = EXIT_FAILURE;
|
||||
|
||||
/* 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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
11
tests/tests.h
Normal 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
|
Loading…
Reference in New Issue
Block a user