Added some tests (e-mail recognition)
This commit is contained in:
parent
8893649fd8
commit
c02e69308b
6
Makefile
6
Makefile
|
@ -1,6 +1,6 @@
|
|||
PACKAGE = Mailer
|
||||
VERSION = 0.1.5
|
||||
SUBDIRS = data doc include po src src/plugins
|
||||
SUBDIRS = data doc include po src src/plugins tests
|
||||
RM ?= rm -f
|
||||
LN ?= ln -f
|
||||
TAR ?= tar -czvf
|
||||
|
@ -107,6 +107,10 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/src/plugins/search.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/tests/email.c \
|
||||
$(PACKAGE)-$(VERSION)/tests/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/tests/tests.sh \
|
||||
$(PACKAGE)-$(VERSION)/tests/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/COPYING \
|
||||
$(PACKAGE)-$(VERSION)/config.h \
|
||||
|
|
|
@ -2,5 +2,5 @@ package=Mailer
|
|||
version=0.1.5
|
||||
config=h,sh
|
||||
|
||||
subdirs=data,doc,include,po,src,src/plugins
|
||||
subdirs=data,doc,include,po,src,src/plugins,tests
|
||||
dist=Makefile,COPYING,config.h,config.sh
|
||||
|
|
2
tests/.cvsignore
Normal file
2
tests/.cvsignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
email
|
||||
tests.log
|
43
tests/Makefile
Normal file
43
tests/Makefile
Normal file
|
@ -0,0 +1,43 @@
|
|||
TARGETS = email tests.log
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
CC ?= cc
|
||||
CPPFLAGSF= -I ../include
|
||||
CPPFLAGS?=
|
||||
CFLAGSF = -W
|
||||
CFLAGS = -Wall -g -O2 -ffreestanding
|
||||
LDFLAGSF= -L ../src -Wl,-rpath,../src -lMailer
|
||||
LDFLAGS =
|
||||
RM ?= rm -f
|
||||
LN ?= ln -f
|
||||
MKDIR ?= mkdir -p
|
||||
INSTALL ?= install
|
||||
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
email_OBJS = email.o
|
||||
email_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
email: $(email_OBJS)
|
||||
$(CC) -o email $(email_OBJS) $(email_LDFLAGS)
|
||||
|
||||
tests.log: email
|
||||
./tests.sh -P "$(PREFIX)" -- "tests.log"
|
||||
|
||||
email.o: email.c ../src/libMailer.a
|
||||
$(CC) $(email_CFLAGS) -c email.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(email_OBJS) $(tests.log_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
|
||||
install: $(TARGETS)
|
||||
|
||||
uninstall:
|
||||
|
||||
.PHONY: all clean distclean install uninstall
|
42
tests/email.c
Normal file
42
tests/email.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* $Id$ */
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "Mailer.h"
|
||||
|
||||
|
||||
/* email */
|
||||
static int _email(char const * progname, char const * name, char const * email,
|
||||
char const * str)
|
||||
{
|
||||
int ret = 0;
|
||||
char * n;
|
||||
char * e;
|
||||
|
||||
n = mailer_helper_get_name(str);
|
||||
e = mailer_helper_get_email(str);
|
||||
if(strcmp(name, n) != 0)
|
||||
fprintf(stderr, "%s: %s: %s (\"%s\")\n", progname, str,
|
||||
"The name does not match", n);
|
||||
if(strcmp(email, e) != 0)
|
||||
fprintf(stderr, "%s: %s: %s (\"%s\")\n", progname, str,
|
||||
"The e-mail does not match", e);
|
||||
free(e);
|
||||
free(n);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* main */
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret |= _email(argv[0], "John Doe", "john@doe.com",
|
||||
"john@doe.com (John Doe)");
|
||||
ret |= _email(argv[0], "John Doe", "john@doe.com",
|
||||
"John Doe <john@doe.com>");
|
||||
return ret;
|
||||
}
|
19
tests/project.conf
Normal file
19
tests/project.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
targets=email,tests.log
|
||||
cppflags_force=-I ../include
|
||||
cflags_force=-W
|
||||
cflags=-Wall -g -O2 -ffreestanding
|
||||
ldflags_force=-L ../src -Wl,-rpath,../src -lMailer
|
||||
ldflags=
|
||||
dist=Makefile,tests.sh
|
||||
|
||||
[email]
|
||||
type=binary
|
||||
sources=email.c
|
||||
|
||||
[email.c]
|
||||
depends=../src/libMailer.a
|
||||
|
||||
[tests.log]
|
||||
type=script
|
||||
script=./tests.sh
|
||||
depends=email
|
52
tests/tests.sh
Executable file
52
tests/tests.sh
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env sh
|
||||
#$Id$
|
||||
#Copyright (c) 2012 Pierre Pronchery <khorben@defora.org>
|
||||
#This file is part of DeforaOS System libc
|
||||
#This program is free software: you can redistribute it and/or modify
|
||||
#it under the terms of the GNU General Public License as published by
|
||||
#the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
#This program is distributed in the hope that it will be useful,
|
||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
#GNU General Public License for more details.
|
||||
#
|
||||
#You should have received a copy of the GNU General Public License
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#functions
|
||||
#usage
|
||||
_usage()
|
||||
{
|
||||
echo "Usage: tests.sh" 1>&2
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
#main
|
||||
while getopts "P:" "name"; do
|
||||
case "$name" in
|
||||
P)
|
||||
#XXX ignored
|
||||
;;
|
||||
?)
|
||||
_usage
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
if [ $# -ne 1 ]; then
|
||||
_usage
|
||||
exit $?
|
||||
fi
|
||||
target="$1"
|
||||
|
||||
> "$target"
|
||||
FAILED=
|
||||
./email >> "$target" || FAILED="$FAILED email(error $?)"
|
||||
[ -z "$FAILED" ] && exit 0
|
||||
echo "Failed tests:$FAILED" 1>&2
|
||||
#XXX ignore errors for now
|
||||
#exit 2
|
Loading…
Reference in New Issue
Block a user