Add two tests
This commit is contained in:
parent
d67b34519f
commit
fd17180496
4 changed files with 74 additions and 49 deletions
12
config.mk
12
config.mk
|
@ -0,0 +1,12 @@
|
|||
PREFIX ?= /usr/local
|
||||
bindir = $(DESTDIR)$(PREFIX)/bin
|
||||
includedir = $(DESTDIR)$(PREFIX)/include
|
||||
libdir = $(DESTDIR)$(PREFIX)/lib
|
||||
sharedir = $(DESTDIR)$(PREFIX)/share
|
||||
mandir = $(sharedir)/man
|
||||
docdir = $(sharedir)/doc/libsemver
|
||||
# We need an `echo` program that doesn't screw with terminal escape sequences.
|
||||
# This only matters if /bin/sh is a symlink to dash, as the echo builtin in dash
|
||||
# will screw with them and pass them as printed characters.
|
||||
ECHO = /bin/echo
|
||||
|
|
@ -33,73 +33,36 @@
|
|||
include ../config.mk
|
||||
|
||||
CFLAGS += -I../include
|
||||
LDLIBS += ../libhaggis.a
|
||||
CFLAGS += -I../../libepoch/include
|
||||
LDLIBS += ../libsemver.a
|
||||
LIBS += ../../libepoch/libepoch.a
|
||||
LDLIBS += $(LIBS)
|
||||
|
||||
tests += store_u16
|
||||
tests += load_u16
|
||||
tests += store_u32
|
||||
tests += load_u32
|
||||
tests += store_u64
|
||||
tests += load_u64
|
||||
tests += store_header
|
||||
tests += check_header
|
||||
tests += store_device
|
||||
tests += load_device
|
||||
tests += store_md5
|
||||
tests += load_md5
|
||||
tests += store_sha1
|
||||
tests += load_sha1
|
||||
tests += store_sha256
|
||||
tests += load_sha256
|
||||
tests += init_file_md5
|
||||
tests += init_file_sha1
|
||||
tests += init_file_sha256
|
||||
tests += store_file_md5
|
||||
tests += load_file_md5
|
||||
tests += store_file_sha1
|
||||
tests += load_file_sha1
|
||||
tests += store_file_sha256
|
||||
tests += load_file_sha256
|
||||
tests += fnv1a_hash_inode
|
||||
tests += fnv1a_hash_str
|
||||
tests += linkmap_init
|
||||
tests += linkmap_put
|
||||
tests += create_dir_node
|
||||
tests += create_symlink_node
|
||||
tests += create_fifo_node
|
||||
tests += create_dev_node
|
||||
tests += create_file_node
|
||||
tests += mq_push_pop
|
||||
tests += extract_dev_node
|
||||
tests += extract_dir_node
|
||||
tests += extract_fifo_node
|
||||
tests += extract_file_node
|
||||
tests += extract_symlink_node
|
||||
tests += extract_hardlink_node
|
||||
tests += u128_from_version
|
||||
tests += compare
|
||||
|
||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||
|
||||
.PHONY: test
|
||||
test: $(tests) output
|
||||
@echo -e "\n\t=== \e[0;33mRunning $(total) tests\e[0m ===\n"
|
||||
@$(ECHO) -e "\n\t=== \e[0;33mRunning $(total) tests\e[0m ===\n"
|
||||
@idx=1 ; success=0 ; fail=0; skip=0; for t in $(tests) ; \
|
||||
do printf "[%02i/$(total)] %-25s" $${idx} $${t} ; \
|
||||
idx=$$(expr $${idx} + 1) ; \
|
||||
./$${t} ; \
|
||||
retval=$$? ; \
|
||||
if [ $${retval} -eq 0 ] ; \
|
||||
then echo -e '\e[0;32mSuccess\e[0m' ; \
|
||||
then $(ECHO) -e '\e[0;32mSuccess\e[0m' ; \
|
||||
success=$$(expr $${success} + 1) ; \
|
||||
elif [ $${retval} -eq 255 ] ; \
|
||||
then echo Skipped ; \
|
||||
then $(ECHO) Skipped ; \
|
||||
skip=$$(expr $${skip} + 1) ; \
|
||||
else echo -e '\e[0;31mFailure\e[0m' ; \
|
||||
else $(ECHO) -e '\e[0;31mFailure\e[0m' ; \
|
||||
fail=$$(expr $${fail} + 1) ; \
|
||||
fi ; done || true ; \
|
||||
if [ $${fail} == 0 ] ; \
|
||||
then echo -e '\nResults: \e[0;32mOk\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \
|
||||
else echo -e '\nResults: \e[0;31mFAILED\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \
|
||||
if [ $${fail} -eq 0 ] ; \
|
||||
then $(ECHO) -e '\nResults: \e[0;32mOk\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \
|
||||
else $(ECHO) -e '\nResults: \e[0;31mFAILED\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \
|
||||
fi
|
||||
|
||||
output:
|
||||
|
|
31
test/compare.c
Normal file
31
test/compare.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "semver.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
Version a, b;
|
||||
|
||||
a.vk_tag = SemVer;
|
||||
a.semver.major = 3;
|
||||
a.semver.minor = 14;
|
||||
a.semver.patch = 0;
|
||||
a.pr.tag = PRNone;
|
||||
a.arch = x86_64;
|
||||
b.vk_tag = Rapid;
|
||||
b.rapid.major = 3;
|
||||
b.rapid.minor = 14;
|
||||
b.pr.tag = PRNone;
|
||||
b.arch = x86_64;
|
||||
assert(compareVersion(&a, &b) == CompEqual);
|
||||
b.pr.tag = Alpha;
|
||||
b.pr.alpha = 1;
|
||||
assert(compareVersion(&a, &b) == CompGreater);
|
||||
a.pr.tag = Beta;
|
||||
a.pr.beta = 2;
|
||||
assert(compareVersion(&a, &b) == CompGreater);
|
||||
b.pr.tag = ReleaseCandidate;
|
||||
b.pr.rc = 1;
|
||||
assert(compareVersion(&a, &b) == CompLess);
|
||||
a.arch = arm64;
|
||||
assert(compareVersion(&a, &b) == CompNone);
|
||||
return 0;
|
||||
}
|
19
test/u128_from_version.c
Normal file
19
test/u128_from_version.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "semver.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
Version v;
|
||||
u128 n;
|
||||
uint64_t sn;
|
||||
|
||||
v.vk_tag = SemVer;
|
||||
v.semver.major = 3;
|
||||
v.semver.minor = 14;
|
||||
v.semver.patch = 0;
|
||||
v.pr.tag = PRNone;
|
||||
v.arch = x86_64;
|
||||
n = u128FromVersion(&v);
|
||||
sn = (uint64_t)(n >> 64);
|
||||
assert(sn == 0600340000000100000);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue