initialise tests using check
This commit is contained in:
parent
2981a65e25
commit
94388aea07
6 changed files with 98 additions and 7 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
/iast
|
/iast
|
||||||
|
/tests/test
|
||||||
/doc/*.gz
|
/doc/*.gz
|
||||||
/*.o
|
|
||||||
/*.d
|
|
||||||
|
|
19
Makefile
19
Makefile
|
@ -2,9 +2,12 @@ PREFIX=/usr
|
||||||
|
|
||||||
.PHONY: main test install uninstall clean
|
.PHONY: main test install uninstall clean
|
||||||
|
|
||||||
CFLAGS := -Wall
|
OBJECTS = iast.o transliteration.o utf8.o encoder.o
|
||||||
SRCFILES := $(shell find . -type f -name "*.c")
|
TEST_OBJECTS = tests/main.o tests/translit.o
|
||||||
OBJFILES := $(patsubst %.c, %.o, $(SRCFILES))
|
CFLAGS = -Wall
|
||||||
|
LIBS =
|
||||||
|
TEST_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags check)
|
||||||
|
TEST_LIBS = $(LIBS) $(shell pkg-config --libs check)
|
||||||
|
|
||||||
|
|
||||||
all: iast doc/iast.1.gz
|
all: iast doc/iast.1.gz
|
||||||
|
@ -12,12 +15,18 @@ all: iast doc/iast.1.gz
|
||||||
iast: main.o $(OBJFILES)
|
iast: main.o $(OBJFILES)
|
||||||
$(CC) $^ -o $@ $(CFLAGS)
|
$(CC) $^ -o $@ $(CFLAGS)
|
||||||
|
|
||||||
test: iast
|
test: tests/test
|
||||||
sh tests/test.sh
|
tests/test
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) -MMD -MP -c $< -o $@ $(CFLAGS)
|
$(CC) -MMD -MP -c $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
|
tests/%.o: tests/%.c
|
||||||
|
$(CC) -MMD -MP -c $< -o $@ $(TEST_CFLAGS) $(TEST_LIBS)
|
||||||
|
|
||||||
|
tests/test: $(OBJECTS) $(TEST_OBJECTS)
|
||||||
|
$(CC) $^ -o $@ $(TEST_CFLAGS) $(TEST_LIBS)
|
||||||
|
|
||||||
doc/%.gz: doc/%.adoc
|
doc/%.gz: doc/%.adoc
|
||||||
asciidoctor -d manpage -b manpage $< -o $(<:.adoc=) && gzip -f $(<:.adoc=)
|
asciidoctor -d manpage -b manpage $< -o $(<:.adoc=) && gzip -f $(<:.adoc=)
|
||||||
|
|
||||||
|
|
32
tests/main.c
Normal file
32
tests/main.c
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include "test.h"
|
||||||
|
#include "translit.h"
|
||||||
|
|
||||||
|
static Suite *create_test_suite()
|
||||||
|
{
|
||||||
|
Suite *suite;
|
||||||
|
TCase *test_case;
|
||||||
|
|
||||||
|
suite = suite_create(NULL);
|
||||||
|
test_case = tcase_create(NULL);
|
||||||
|
|
||||||
|
register_translit_tests(test_case);
|
||||||
|
suite_add_tcase(suite, test_case);
|
||||||
|
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
Suite *suite;
|
||||||
|
SRunner *runner;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
suite = create_test_suite();
|
||||||
|
runner = srunner_create(suite);
|
||||||
|
|
||||||
|
srunner_run_all(runner, CK_NORMAL);
|
||||||
|
retval = srunner_ntests_failed(runner);
|
||||||
|
srunner_free(runner);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
7
tests/test.h
Normal file
7
tests/test.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef __TEST_TEST_H
|
||||||
|
#define __TEST_TEST_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
|
#endif /* __TEST_TEST_H */
|
34
tests/translit.c
Normal file
34
tests/translit.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "translit.h"
|
||||||
|
#include "../transliteration.h"
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_translit_devanagari_to_latin)
|
||||||
|
{
|
||||||
|
char *latin;
|
||||||
|
|
||||||
|
/* https://en.wikipedia.org/wiki/Sanskrit */
|
||||||
|
latin = transliterate_devanagari_to_latin("संस्कृतम्");
|
||||||
|
ck_assert_str_eq("saṃskṛtam", latin);
|
||||||
|
free(latin);
|
||||||
|
|
||||||
|
/* https://en.wikipedia.org/wiki/Bhagavad_Gita */
|
||||||
|
latin = transliterate_devanagari_to_latin("भगवद्गीता");
|
||||||
|
ck_assert_str_eq("bhagavadgītā", latin);
|
||||||
|
free(latin);
|
||||||
|
|
||||||
|
/* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */
|
||||||
|
latin = transliterate_devanagari_to_latin("आर्यावर्त");
|
||||||
|
ck_assert_str_eq("āryāvarta", latin);
|
||||||
|
free(latin);
|
||||||
|
|
||||||
|
/* https://en.wikipedia.org/wiki/Mahabharata */
|
||||||
|
latin = transliterate_devanagari_to_latin("महाभारतम्");
|
||||||
|
ck_assert_str_eq("mahābhāratam", latin);
|
||||||
|
free(latin);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
void register_translit_tests(TCase *test_case)
|
||||||
|
{
|
||||||
|
tcase_add_test(test_case, test_translit_devanagari_to_latin);
|
||||||
|
}
|
8
tests/translit.h
Normal file
8
tests/translit.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef __TEST_TRANSLIT_H
|
||||||
|
#define __TEST_TRANSLIT_H
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
|
void register_translit_tests(TCase *test_case);
|
||||||
|
|
||||||
|
#endif /* __TEST_TRANSLIT_H */
|
Loading…
Reference in a new issue