Working CUnit test but still meh autoconf

This commit is contained in:
Bandie 2018-05-11 04:03:19 +02:00
parent 28ce22b131
commit b7cb4c0b81
Signed by: Bandie
GPG Key ID: C1E133BC65A822DD
4 changed files with 19 additions and 9 deletions

View File

@ -4,7 +4,7 @@ AC_INIT(
[https://github.com/pampanic/pam_panic/issues], [https://github.com/pampanic/pam_panic/issues],
[pam_panic]) [pam_panic])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([-Wall]) AM_INIT_AUTOMAKE([-Wall subdir-objects])
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADER([src/config.h]) AC_CONFIG_HEADER([src/config.h])

View File

@ -8,10 +8,8 @@ LICENSE : GNU-GPLv3
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#ifndef TEST #include <security/pam_modules.h>
#include <security/pam_modules.h> #include <security/pam_ext.h>
#include <security/pam_ext.h>
#endif
#include <syslog.h> #include <syslog.h>
#include "pam_panic_reject.h" #include "pam_panic_reject.h"

View File

@ -1,3 +1,4 @@
CFLAGS += -DTEST
bin_PROGRAMS = test bin_PROGRAMS = test
test_SOURCES = test.h ../src/pam_panic/pam_panic_authdevice.c ../src/pam_panic/pam_panic_reject.c test.c test_SOURCES = test.h ../src/pam_panic/pam_panic_authdevice.c ../src/pam_panic/pam_panic_reject.c test.c
test_LDFLAGS = -lpam -lcunit test_LDFLAGS = -lpam -lcunit
@ -5,4 +6,3 @@ test_LDFLAGS = -lpam -lcunit
all: all:
@printf "Running test...\n" @printf "Running test...\n"
./test ./test
@printf "OK!\n"

View File

@ -4,7 +4,7 @@
#include "../src/pam_panic/pam_panic_authdevice.h" #include "../src/pam_panic/pam_panic_authdevice.h"
#include "../src/pam_panic/pam_panic_reject.h" #include "../src/pam_panic/pam_panic_reject.h"
#include <CUnit/Basic.h> #include <CUnit/Basic.h>
#include <CUnit/TestRun.h>
#define STATE_GOOD 0 #define STATE_GOOD 0
#define STATE_BAD 99 #define STATE_BAD 99
@ -36,6 +36,7 @@ void test_authDeviceGood(void) {
fclose(f); fclose(f);
int ret = authDevice(NULL, gU, bU, NULL, 0, 0, 0); int ret = authDevice(NULL, gU, bU, NULL, 0, 0, 0);
printf("%d\n", ret);
CU_ASSERT_EQUAL(ret, STATE_GOOD); CU_ASSERT_EQUAL(ret, STATE_GOOD);
unlink(gU); unlink(gU);
} }
@ -81,7 +82,7 @@ void test_rejectNA(void) {
int main(void) { int main(void) {
// no stdout buffering // no stdout buffering
setbuf(stdout, NULL); //setbuf(stdout, NULL);
// init CUnit test registry // init CUnit test registry
CU_pSuite pSuiteDevice = NULL; CU_pSuite pSuiteDevice = NULL;
@ -112,6 +113,17 @@ int main(void) {
return CU_get_error(); return CU_get_error();
} }
return 0; /* Run all tests */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
int fail = CU_get_number_of_failures();
CU_cleanup_registry();
if(fail)
return 1;
return CU_get_error();
} }