nissy-classic

Stable branch of nissy
git clone https://git.tronto.net/nissy-classic
Download | Log | Files | Refs | README | LICENSE

commit 0571557ad1a943739806046a24fdaf1e62b32886
parent 49eab61d8be0d0a83f6a6c00c0a8fee73cf70992
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Wed,  1 Feb 2023 18:15:51 +0100

Enabled make test and test.sh

Diffstat:
MMakefile | 7++++---
Msrc/shell.c | 14--------------
Mtest.sh | 1+
Mtests/fst_tests.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/fst_tests.h | 54+++++++-----------------------------------------------
Mtests/test.c | 6++++--
Mtests/test.h | 16++--------------
Atests/test_common.h | 19+++++++++++++++++++
8 files changed, 85 insertions(+), 80 deletions(-)

diff --git a/Makefile b/Makefile @@ -13,7 +13,6 @@ DBGFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \ CC = cc - all: nissy nissy: clean @@ -25,6 +24,9 @@ nissy.exe: debug: ${CC} ${DBGFLAGS} -o nissy src/*.c +test: + ${CC} ${CFLAGS} -DTEST -o tests/nissy_test src/*.c tests/*.c + clean: rm -rf nissy nissy*.exe nissy*.tar.gz doc/nissy.html doc/nissy.pdf @@ -63,5 +65,4 @@ uninstall: rm -rf ${DESTDIR}${PREFIX}/bin/nissy ${DESTDIR}${MANPREFIX}/man1/nissy.1 for s in ${SCRIPTS}; do rm -rf ${DESTDIR}${PREFIX}/bin/$$s; done -.PHONY: all debug clean dist install test uninstall upload - +.PHONY: all debug test clean dist install uninstall upload diff --git a/src/shell.c b/src/shell.c @@ -151,20 +151,6 @@ main(int argc, char *argv[]) init_env(); init_trans(); -/* - Cube c; - make_solved(&c); - c.co[0] = 1; - c.co[6] = 2; - print_cube(&c); - apply_trans(uf_mirror, &c); - print_cube(&c); -*/ - -/* - test_coord(&coord_coud_cpudsep); -*/ - if (!checkfiles()) { fprintf(stderr, "--- Warning ---\n" diff --git a/test.sh b/test.sh @@ -11,6 +11,7 @@ test_module() { done } +make test if [ -n "$@" ]; then test_module $@ else diff --git a/tests/fst_tests.c b/tests/fst_tests.c @@ -1,5 +1,10 @@ #include "fst_tests.h" +static bool testmethod_fst_is_consistent(void *); +static bool testmethod_cube_to_fst_to_cube(void *); +static bool testmethod_fst_move(void *); +static bool testmethod_fst_inverse(void *); + static bool check_equal_and_log(Cube *, Cube *); static void void_to_cube(void *, Cube *); @@ -18,6 +23,49 @@ char *algs[] = { NULL, }; +Test test_fst_is_consistent = { + .name = "Consitency of FST (converted from cube)", + .t = testmethod_fst_is_consistent, + .cases = (void **)algs, +}; +Test test_cube_to_fst_to_cube = { + .name = "Cube to FST to cube", + .t = testmethod_cube_to_fst_to_cube, + .cases = (void **)algs, +}; +Test test_fst_move = { + .name = "FST move", + .t = testmethod_fst_move, + .cases = (void **)algs, +}; +Test test_fst_inverse = { + .name = "FST inverse", + .t = testmethod_fst_inverse, + .cases = (void **)algs, +}; + +Test *pre_init[] = { + &test_fst_is_consistent, + &test_cube_to_fst_to_cube, + NULL +}; +TestSuite fst_pre_init_suite = { + .setup = NULL, + .tests = pre_init, + .teardown = NULL, +}; + +Test *post_init[] = { + &test_fst_move, + &test_fst_inverse, + NULL +}; +TestSuite fst_post_init_suite = { + .setup = init_fst, + .tests = post_init, + .teardown = NULL, +}; + static bool check_equal_and_log(Cube *c, Cube *d) { diff --git a/tests/fst_tests.h b/tests/fst_tests.h @@ -2,56 +2,16 @@ #define FST_TESTS_H #include "../src/fst.h" -#include "test.h" - -bool testmethod_fst_is_consistent(void *); -bool testmethod_cube_to_fst_to_cube(void *); -bool testmethod_fst_move(void *); -bool testmethod_fst_inverse(void *); +#include "test_common.h" extern char *algs[]; -Test test_fst_is_consistent = { - .name = "Consitency of FST (converted from cube)", - .t = testmethod_fst_is_consistent, - .cases = (void **)algs, -}; -Test test_cube_to_fst_to_cube = { - .name = "Cube to FST to cube", - .t = testmethod_cube_to_fst_to_cube, - .cases = (void **)algs, -}; -Test test_fst_move = { - .name = "FST move", - .t = testmethod_fst_move, - .cases = (void **)algs, -}; -Test test_fst_inverse = { - .name = "FST inverse", - .t = testmethod_fst_inverse, - .cases = (void **)algs, -}; - -Test *pre_init[] = { - &test_fst_is_consistent, - &test_cube_to_fst_to_cube, - NULL -}; -TestSuite fst_pre_init_suite = { - .setup = NULL, - .tests = pre_init, - .teardown = NULL, -}; +extern Test test_fst_is_consistent; +extern Test test_cube_to_fst_to_cube; +extern Test test_fst_move; +extern Test test_fst_inverse; -Test *post_init[] = { - &test_fst_move, - &test_fst_inverse, - NULL -}; -TestSuite fst_post_init_suite = { - .setup = init_fst, - .tests = post_init, - .teardown = NULL, -}; +extern TestSuite fst_pre_init_suite; +extern TestSuite fst_post_init_suite; #endif diff --git a/tests/test.c b/tests/test.c @@ -1,5 +1,4 @@ -#include <stdio.h> -#include "fst_tests.h" +#include "test.h" static bool run_test(Test *); static bool run_suite(TestSuite *); @@ -38,6 +37,9 @@ run_suite(TestSuite *suite) } int main() { + init_env(); + init_trans(); + if (!run_suite(&fst_pre_init_suite)) return 1; if (!run_suite(&fst_post_init_suite)) diff --git a/tests/test.h b/tests/test.h @@ -1,19 +1,7 @@ #ifndef TEST_H #define TEST_H -typedef void (*VoidMethod)(void); -typedef bool (*TestMethod)(void *); - -typedef struct { - char * name; - TestMethod t; - void ** cases; -} Test; - -typedef struct { - VoidMethod setup; - Test ** tests; - VoidMethod teardown; -} TestSuite; +#include <stdio.h> +#include "fst_tests.h" #endif diff --git a/tests/test_common.h b/tests/test_common.h @@ -0,0 +1,19 @@ +#ifndef TEST_COMMON_H +#define TEST_COMMON_H + +typedef void (*VoidMethod)(void); +typedef bool (*TestMethod)(void *); + +typedef struct { + char * name; + TestMethod t; + void ** cases; +} Test; + +typedef struct { + VoidMethod setup; + Test ** tests; + VoidMethod teardown; +} TestSuite; + +#endif