Subversion Repositories PlanixRsrch.SVN

Compare Revisions

Ignore whitespace Rev 266 → Rev 321

/tags/libmutests/1.2.0/LICENSE
0,0 → 1,26
/*
* Copyright 2019, The PLANIX Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/tags/libmutests/1.2.0/Makefile
0,0 → 1,35
 
OBJS=mutests_run.o
 
LIBNAME=libmutests.a
 
PREFIX=~
MAN_PREFIX=/usr/local/man
.c.o:
$(CC) -c $(CFLAGS) $<
 
$(LIBNAME): $(OBJS)
$(AR) rcs $(LIBNAME) $(OBJS)
 
example1: $(LIBNAME) example1.o
$(CC) -o example1 example1.o $(LIBNAME)
 
 
clean:
rm -f $(OBJS)
rm -f $(LIBNAME)
rm -f example1.o example1
rm -f example2.o example2
rm -f *.core
 
install: $(LIBNAME)
mkdir -p $(PREFIX)/lib
mkdir -p $(PREFIX)/include/
$(INSTALL) -p $(LIBNAME) $(PREFIX)/lib/$(LIBNAME)
$(INSTALL) -p mutests.h $(PREFIX)/include/mutests.h
 
install-man:
install -p man/mutests.3 $(MAN_PREFIX)/man3/mutests.3
install -p man/mutests.3 $(MAN_PREFIX)/man3/mu_assert.3
install -p man/mutests.3 $(MAN_PREFIX)/man3/mutests_run.3
 
/tags/libmutests/1.2.0/example1.c
0,0 → 1,31
/* file minunit_example.c */
#include <stdio.h>
#include "mutests.h"
int foo = 7;
int bar = 15;
static int test_foo() {
mu_assert(foo == 7, "error, foo != 7");
return 1;
}
static int test_bar() {
mu_assert(bar == 5, "error, bar != 5" );
return 1;
}
 
 
int main() {
mutests tests = {
test_foo,
test_bar,
NULL
};
return mutests_run(tests);
}
 
 
 
/tags/libmutests/1.2.0/man/mutests.3
0,0 → 1,58
.TH MUTESTS 3
.SH NAME
.\" .SH LIBRARY
.\" For sections 2, 3, and 9 only.
.\" Not used in OpenBSD.
\fBmutests_run\fR, \fBmu_assert\fR \- unit test functions
.SH LIBRARY
.BR "Unit Tests Library" " (libmutests, \-lmutests)"
.SH SYNOPSIS
#include <mutests.h>
 
\fIvoid\fR
.BR mutests_run "( \fIint(*tflist[])()\fR )"
 
typedef int(*mutests[])();
 
\fIvoid\fI
.BR mu_assert "(\fIint test\fR, \fIconst char * msg\fR, \fI...\fR)";
.SH DESCRIPTION
\fBmutests_run\fR runs the unit test funtions given by the list of
functions in \fItflist\fR. The List must be terminated with NULL.
 
A unit test functions can call \fBmu_assert\fR to check the result
of a given test and output an error message. \fBmu_assert\fR will
output the message \fImsg\fR if the condition in \fItest\fR is 0.
The calling function wil be terminated by longjmp.
 
.SH EXAMPLES
The following example tests the multiplaction capabillities
of the C compiler.
 
const char * test_mul()
.br
{
.br
mu_assert (3*3 == 9, "3 *3 != 9" );
.br
return 1;
.br
}
 
int main(void) {
.br
mutests tests = {
.br
test_mul,
.br
NULL
.br
};
.br
mutests_run( tests );
.br
}.
.SH BUGS
There are no known bugs.
.SH SEE ALSO
longjmp(3)
/tags/libmutests/1.2.0/mutests.h
0,0 → 1,40
/*
* Copyright 2019 2020, The PLANIX Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/* mutests.h
* based loosely on
* http://www.jera.com/techinfo/jtns/jtn002.html#Source_Code
*/
#ifndef _MUTESTS_H
#define _MUTESTS_H
 
int mutests_run( int (*tflist[])() );
typedef int(*mutests[])();
 
void mu_assert(int test, const char *, ...);
 
#endif
/tags/libmutests/1.2.0/mutests_run.c
0,0 → 1,70
/*
* Copyright 2019, The PLANIX Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <stdio.h>
#include <setjmp.h>
#include <stdarg.h>
 
#include "mutests.h"
 
static jmp_buf mubuf;
 
void mu_assert(int test, const char * msg, ...)
{
va_list vl;
 
if (test)
return;
 
va_start(vl,msg);
(void)fprintf(stderr,"FAIL: ");
(void)vfprintf(stderr,msg,vl);
(void)fprintf(stderr,"\n");
va_end(vl);
longjmp(mubuf,1);
}
 
int mutests_run( int (*tflist[])() )
{
int i,failed;
 
failed = 0;
for (i=0; tflist[i]!=NULL; i++){
if (setjmp(mubuf) ){
failed ++;
}
else{
if (!tflist[i]()){
failed ++;
};
}
}
if (!failed)
(void)printf("ALL %d TESTS PASSED\n",i);
return failed;
}
 
/tags/libmutests/1.2.0
Property changes:
Added: svn:mergeinfo
## -0,0 +0,2 ##
Merged /branches/dq/libmutests:r41-288
Merged /branches/bnf/libmutests:r79-129