add some unit tests
This commit is contained in:
parent
0f9cee10b4
commit
bd541e581a
7
Makefile
Normal file
7
Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.PHONY: all
|
||||||
|
all:
|
||||||
|
./rscons
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: all
|
||||||
|
./build/e.1/tests
|
7
Rsconscript
Normal file
7
Rsconscript
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
build do
|
||||||
|
Environment.new do |env|
|
||||||
|
sources = glob("src/**/*.c")
|
||||||
|
env["CPPPATH"] += glob("src/**")
|
||||||
|
env.Program("^/tests", sources + glob("test/**/*.c"))
|
||||||
|
end
|
||||||
|
end
|
42
test/test_jairee.c
Normal file
42
test/test_jairee.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "jairee.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define TEST(x) Test(#x, x, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
static int n_tests_passed;
|
||||||
|
static int n_tests_failed;
|
||||||
|
|
||||||
|
static void Test(const char * message, int result, const char * file, int line)
|
||||||
|
{
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
n_tests_passed++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Test failure at %s:%d: \"%s\"\n", file, line, message);
|
||||||
|
n_tests_failed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_asciiz_string()
|
||||||
|
{
|
||||||
|
jairee_string_t * s = jairee_string_from_asciiz("Test String");
|
||||||
|
size_t offset = 0;
|
||||||
|
TEST(s->len == 11u);
|
||||||
|
TEST(s->decode(s->str, &offset) == 'T');
|
||||||
|
TEST(offset == 1u);
|
||||||
|
offset = 10u;
|
||||||
|
TEST(s->decode(s->str, &offset) == 'g');
|
||||||
|
TEST(offset == 11u);
|
||||||
|
jairee_string_free(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
test_asciiz_string();
|
||||||
|
|
||||||
|
printf("%d/%d tests passed\n", n_tests_passed, n_tests_passed + n_tests_failed);
|
||||||
|
|
||||||
|
return n_tests_failed == 0 ? 0 : 1;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user