-Primary maintainer
-arien_malec@yahoo.com
+Original author:
+Arien Malec <arien_malec@yahoo.com>
-Check 0.8.0
+Current maintainer:
+Sven Neumann <sven@convergence.de>
Patches:
Bernhard Reiter (configure issues)
+Neil Spring (const fixes)
Design suggestions:
Fred Drake (checked fixture functions)
-Wed Oct 24, 2001:
-Released Check 0.8.0
+Sat Mar 2, 2001: Released Check 0.8.1
+
+Changed license to LGPL.
+Fixed bug in running checked setup in nofork mode.
+
+
+Wed Oct 24, 2001: Released Check 0.8.0
Support running in a nofork mode. Defined a checked fixture as well as
an unchecked fixture, support failing in checked and uncheck fixture
on Solaris systems (and hopefully others), and cleaned up a minor
problem in Debian packaging.
-Fri Aug 17, 2001:
-Released Check 0.7.2
+
+Fri Aug 17, 2001: Released Check 0.7.2
Automated RPM packaging, and included debian packaging. The makefiles
now has an rpm target (the RPMFLAGS variable can be set to add
sure).
-Wed Jul 30, 2001:
-Released Check 0.7.1
+Wed Jul 30, 2001: Released Check 0.7.1
Reorganized printing and logging functions to allow for a less
primitive logging function. Logging is now documented in the tutorial
documentation.
-Wed Jul 11, 2001:
-Released Check 0.7.0
+
+Wed Jul 11, 2001: Released Check 0.7.0
Included a primitive logging function (at the moment, it only prints a
copy of the CRVERBOSE output to the log file), added the ability for
comes up...
-Wed Jun 27, 2001:
-
-Released Check 0.6.1
+Wed Jun 27, 2001: Released Check 0.6.1
Bug fix for srunner_failures (bad version actually returned all
results), added srunner_results to do what srunner_failures used to
new function srunner_ntests_run. This unfortunately may break some
unit tests slightly -- that's why the major release number is 0 :-)
-Thu Jun 21, 2001:
-Released Check 0.6.0
+
+Thu Jun 21, 2001: Released Check 0.6.0
Features improved unit test reporting options, more complete unit
tests, and end-to-end test, and a full API into TestResults
+
Check 0.5.2
Minor edits
Check 0.5.1
AC_PROG_LN_S
AC_PROG_RANLIB
if test -n "$GCC"; then
- CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -Wmissing-prototypes"
+ CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
fi
CK_LYX_LINUXDOC([have_lyx="yes"],[have_lyx="no"])
AC_CHECK_PROG(have_sgmltools,sgml2html,yes)
int ischecked);
static void tr_init (TestResult *tr);
-Suite *suite_create (char *name)
+Suite *suite_create (const char *name)
{
Suite *s;
s = emalloc (sizeof(Suite)); /* freed in suite_free */
free(s);
}
-TCase *tcase_create (char *name)
+TCase *tcase_create (const char *name)
{
TCase *tc = emalloc (sizeof(TCase)); /*freed in tcase_free */
if (name == NULL)
list_add_end (s->tclst, tc);
}
-void _tcase_add_test (TCase *tc, TFun fn, char *name)
+void _tcase_add_test (TCase *tc, TFun fn, const char *name)
{
TF * tf;
if (tc == NULL || fn == NULL || name == NULL)
}
}
-void tcase_fn_start (char *fname, char *file, int line)
+void tcase_fn_start (const char *fname, const char *file, int line)
{
send_ctx_info (get_send_key(),CK_CTX_TEST);
send_loc_info (get_send_key(),file, line);
}
-void _mark_point (char *file, int line)
+void _mark_point (const char *file, int line)
{
send_loc_info (get_send_key(), file, line);
}
-void _fail_unless (int result, char *file, int line, char * msg)
+void _fail_unless (int result, const char *file, int line, const char * msg)
{
if (msg == NULL)
eprintf ("_fail_unless() called with NULL msg",__FILE__,__LINE__);
tr->ctx = -1;
tr->line = -1;
tr->rtype = -1;
- tr->msg = tr->file = tr->tcname = NULL;
+ tr->msg = NULL;
+ tr->file = NULL;
+ tr->tcname = NULL;
}
-char *tr_msg (TestResult *tr)
+const char *tr_msg (TestResult *tr)
{
return tr->msg;
}
return tr->line;
}
-char *tr_lfile (TestResult *tr)
+const char *tr_lfile (TestResult *tr)
{
return tr->file;
}
return tr->ctx;
}
-char *tr_tcname (TestResult *tr)
+const char *tr_tcname (TestResult *tr)
{
return tr->tcname;
}
+/*-*- mode:C; -*- */
/*
* Check: a unit test framework for C
* Copyright (C) 2001, 2002, Arien Malec
/* Creates a test suite with the given name
*/
-Suite *suite_create (char *name);
+Suite *suite_create (const char *name);
/* Free a test suite (For the moment, this also frees all contained
test cases) */
void suite_add_tcase (Suite *s, TCase *tc);
/* Create a test case */
-TCase *tcase_create (char *name);
+TCase *tcase_create (const char *name);
/* Free a test case
/* Add a test function to a test case
(function version -- use this when the macro won't work */
-void _tcase_add_test (TCase *tc, TFun tf, char *fname);
+void _tcase_add_test (TCase *tc, TFun tf, const char *fname);
/* Add unchecked fixture setup/teardown functions to a test case
/* Internal function to mark the start of a test function */
-void tcase_fn_start (char *fname, char *file, int line);
+void tcase_fn_start (const char *fname, const char *file, int line);
/* Start a unit test with START_TEST(unit_name), end with END_TEST
One must use braces within a START_/END_ pair to declare new variables */
_fail_unless(expr,__FILE__,__LINE__, msg ? msg : "Assertion '"#expr"' failed")
/* Non macro version of #fail_unless, with more complicated interface */
-void _fail_unless (int result, char *file, int line, char *msg);
+void _fail_unless (int result, const char *file, int line, const char *msg);
/* Always fail */
#define fail(msg) _fail_unless(0,__FILE__,__LINE__,msg)
#define mark_point() _mark_point(__FILE__,__LINE__)
/* Non macro version of #mark_point */
-void _mark_point (char *file, int line);
+void _mark_point (const char *file, int line);
/* Result of a test */
enum test_result {
/* Context in which the result occurred */
enum ck_result_ctx tr_ctx (TestResult *tr);
/* Failure message */
-char *tr_msg (TestResult *tr);
+const char *tr_msg (TestResult *tr);
/* Line number at which failure occured */
int tr_lno (TestResult *tr);
/* File name at which failure occured */
-char *tr_lfile (TestResult *tr);
+const char *tr_lfile (TestResult *tr);
/* Test case in which unit test was run */
-char *tr_tcname (TestResult *tr);
+const char *tr_tcname (TestResult *tr);
/* Creates an SRunner for the given suite */
SRunner *srunner_create (Suite *s);
done immediatly after SRunner creation, and the log file can't be
changed after being set.
*/
-void srunner_set_log (SRunner *sr, char *fname);
+void srunner_set_log (SRunner *sr, const char *fname);
/* Does the SRunner have a log file?
*/
/* Return the name of the log file, or NULL if none
*/
-char *srunner_log_fname (SRunner *sr);
+const char *srunner_log_fname (SRunner *sr);
/* Control forking */
enum fork_status {
#include "check_error.h"
-void eprintf (char *fmt, char *file, int line, ...)
+void eprintf (const char *fmt, const char *file, int line, ...)
{
va_list args;
fflush(stderr);
/* Print error message and die
If fmt ends in colon, include system error information */
-void eprintf (char *fmt, char *file, int line,...);
+void eprintf (const char *fmt, const char *file, int line,...);
/* malloc or die */
void *emalloc(size_t n);
void *erealloc(void *, size_t n);
typedef struct TF {
TFun fn;
- char *name;
+ const char *name;
} TF;
struct Suite {
- char *name;
+ const char *name;
List *tclst; /* List of test cases */
};
} Fixture;
struct TCase {
- char *name;
+ const char *name;
List *tflst; /* list of test functions */
List *unch_sflst;
List *unch_tflst;
enum ck_result_ctx ctx; /* When the result occurred */
char *file; /* File where the test occured */
int line; /* Line number where the test occurred */
- char *tcname; /* Test case that generated the result */
+ const char *tcname; /* Test case that generated the result */
char *msg; /* Failure message */
};
List *slst; /* List of Suite objects */
TestStats *stats; /* Run statistics */
List *resultlst; /* List of unit test results */
- char *log_fname; /* name of log file */
+ const char *log_fname; /* name of log file */
List *loglst; /* list of Log objects */
enum fork_status fstat; /* controls if suites are forked or not
NOTE: Don't use this value directly,
static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt);
-void srunner_set_log (SRunner *sr, char *fname)
+void srunner_set_log (SRunner *sr, const char *fname)
{
if (sr->log_fname)
return;
return sr->log_fname != NULL;
}
-char *srunner_log_fname (SRunner *sr)
+const char *srunner_log_fname (SRunner *sr)
{
return sr->log_fname;
}
static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx,
RcvMsg *rmsg);
-void send_failure_info (MsgKey *key, char *msg)
+void send_failure_info (MsgKey *key, const char *msg)
{
FailMsg fmsg;
Pipe *p;
- fmsg.msg = msg;
+ fmsg.msg = (char *) msg;
p = get_pipe_by_key(key);
if (p == NULL)
eprintf("Couldn't find pipe with key %d",__FILE__, __LINE__, key);
ppack(p->sendfd, CK_MSG_FAIL, &fmsg);
}
-void send_loc_info (MsgKey *key, char * file, int line)
+void send_loc_info (MsgKey *key, const char * file, int line)
{
LocMsg lmsg;
Pipe *p;
- lmsg.file = file;
+ lmsg.file = (char *) file;
lmsg.line = line;
p = get_pipe_by_key(key);
if (p == NULL)
/* Functions implementing messaging during test runs */
-void send_failure_info (MsgKey *key, char *msg);
-void send_loc_info (MsgKey *key, char *file, int line);
-void send_ctx_info (MsgKey *key,enum ck_result_ctx ctx);
+void send_failure_info (MsgKey *key, const char *msg);
+void send_loc_info (MsgKey *key, const char *file, int line);
+void send_ctx_info (MsgKey *key, enum ck_result_ctx ctx);
TestResult *receive_test_result (MsgKey *key, int waserror);
static void pack_int (char **buf, int val);
static int upack_int (char **buf);
-static void pack_str (char **buf, char *str);
+static void pack_str (char **buf, const char *str);
static char *upack_str (char **buf);
static void pack_ctx (char **buf, void *msg);
static void upack_loc (char **buf, void *msg);
static void upack_fail (char **buf, void *msg);
-static void check_type (int type, char *file, int line);
+static void check_type (int type, const char *file, int line);
static enum ck_msg_type upack_type (char **buf);
static void pack_type (char **buf, enum ck_msg_type type);
static int read_buf (int fdes, char **buf);
static int get_result (char *buf, RcvMsg *rmsg);
static void rcvmsg_update_ctx(RcvMsg *rmsg, enum ck_result_ctx ctx);
-static void rcvmsg_update_loc(RcvMsg *rmsg, char *file, int line);
+static void rcvmsg_update_loc(RcvMsg *rmsg, const char *file, int line);
static RcvMsg *rcvmsg_create(void);
typedef void (*pfun) (char **, void *);
return val;
}
-static void pack_str (char **buf, char *val)
+static void pack_str (char **buf, const char *val)
{
int strsz;
int n;
fmsg->msg = upack_str(buf);
}
-static void check_type (int type, char *file, int line)
+static void check_type (int type, const char *file, int line)
{
if (type >= CK_MSG_LAST)
eprintf ("%s:%d:Bad message type arg", file, line);
rmsg->lastctx = ctx;
}
-static void rcvmsg_update_loc (RcvMsg *rmsg, char *file, int line)
+static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line)
{
int flen = strlen(file);
static void srunner_add_failure (SRunner *sr, TestResult *tf);
static TestResult *tcase_run_tfun_fork (TCase *tc, TF *tf);
static TestResult *tcase_run_tfun_nofork (TCase *tc, TF *tf);
-static TestResult *receive_result_info_fork (char *tcname, int status);
-static TestResult *receive_result_info_nofork (char *tcname);
+static TestResult *receive_result_info_fork (const char *tcname, int status);
+static TestResult *receive_result_info_nofork (const char *tcname);
static void set_fork_info (TestResult *tr, int status);
static void set_nofork_info (TestResult *tr);
static char *signal_msg (int sig);
}
}
-static TestResult *receive_result_info_fork (char *tcname, int status)
+static TestResult *receive_result_info_fork (const char *tcname, int status)
{
TestResult *tr;
return tr;
}
-static TestResult *receive_result_info_nofork (char *tcname)
+static TestResult *receive_result_info_nofork (const char *tcname)
{
TestResult *tr;
#include "check_impl.h"
#include "check_str.h"
-static char *tr_type_str (TestResult *tr);
+static const char *tr_type_str (TestResult *tr);
static int percent_passed (TestStats *t);
char *tr_str (TestResult *tr)
{
- char *exact_msg;
+ const char *exact_msg;
char *rstr;
exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) ": "";
}
-static char *tr_type_str (TestResult *tr)
+static const char *tr_type_str (TestResult *tr)
{
- char *str = NULL;
+ const char *str = NULL;
if (tr->ctx == CK_CTX_TEST) {
if (tr->rtype == CK_PASS)
str = "P";
int max_elts;
int current; /* pointer to the current node */
int last; /* pointer to the node before END */
- void **data;
+ const void **data;
};
static void maybe_grow (List *lp)
return lp;
}
-void list_add_end (List *lp, void *val)
+void list_add_end (List *lp, const void *val)
{
if (lp == NULL)
return;
if (lp->current == -1 || lp->current > lp->last)
return NULL;
- return lp->data[lp->current];
+ return (void*) lp->data[lp->current];
}
void list_advance (List *lp)
/* Add a value to the end of the list,
positioning newly added value as current value */
-void list_add_end (List *lp, void *val);
+void list_add_end (List *lp, const void *val);
/* Give the value of the current node */
void *list_val (List * lp);
START_TEST(test_print_counts)
{
char *srstat = sr_stat_str(fixture_sr);
- char *exp = "0%: Checks: 0, Failures: 1, Errors: 0";
+ const char *exp = "0%: Checks: 0, Failures: 1, Errors: 0";
fail_unless(strcmp(srstat, exp) == 0,
"SRunner stat string incorrect with setup failure");
{
TestResult **tra;
char *trm;
- char *trmexp = "check_check_fixture.c:12:S:Core: Test failure in fixture";
+ const char *trmexp = "check_check_fixture.c:12:S:Core: Test failure in fixture";
tra = srunner_failures(fixture_sr);
trm = tr_str(tra[0]);
START_TEST(test_env)
{
- putenv("CK_FORK=no");
+ putenv((char *) "CK_FORK=no");
fail_unless(srunner_fork_status(fork_dummy_sr) == CK_NOFORK,
"Fork status does not obey environment variable");
}
START_TEST(test_env_and_set)
{
- putenv("CK_FORK=no");
+ putenv((char *) "CK_FORK=no");
srunner_set_fork_status(fork_dummy_sr, CK_FORK);
fail_unless(srunner_fork_status(fork_dummy_sr) == CK_FORK,
"Explicit setting of fork status should override env");
START_TEST(test_check_failure_msgs)
{
int i;
- char *msgar[] = {
+ const char *msgar[] = {
"Failure expected",
"Early exit with return value 1",
/* "Test passed", */
"We failed"};
for (i = 0; i < sub_nfailed; i++) {
- char *msg;
+ const char *msg;
msg = tr_msg(tr_fail_array[i]);
if (strcmp (msg, msgar[i]) != 0) {
char *emsg = malloc (MAXSTR);
START_TEST(test_check_failure_tcnames)
{
int i;
- char *tcnamearr[] = {
+ const char *tcnamearr[] = {
"Simple Tests",
"Simple Tests",
"Simple Tests",
"Core"};
for (i = 0; i < sub_nfailed; i++) {
- char *tcname;
+ const char *tcname;
tcname = tr_tcname(tr_all_array[i]);
if (strcmp (tcname, tcnamearr[i]) != 0) {
char *emsg = malloc (MAXSTR);
START_TEST(test_check_all_msgs)
{
int i;
- char *msgar[] = {
+ const char *msgar[] = {
"Failure expected",
"Early exit with return value 1",
"Passed",
"We failed"};
for (i = 0; i < sub_ntests; i++) {
- char *msg;
+ const char *msg;
msg = tr_msg(tr_all_array[i]);
if (strcmp (msg, msgar[i]) != 0) {
char *emsg = malloc (MAXSTR);
fmsg = emalloc (sizeof(FailMsg));
buf = emalloc (CK_MAXMSGBUF);
- fmsg->msg = "Hello, world!";
+ fmsg->msg = (char *) "Hello, world!";
pack (CK_MSG_FAIL, buf, fmsg);
- fmsg->msg = "";
+
+ fmsg->msg = (char *) "";
upack (buf, fmsg, &type);
fail_unless (type == CK_MSG_FAIL,
lmsg = emalloc (sizeof(LocMsg));
buf = emalloc (CK_MAXMSGBUF);
- lmsg->file = "abc123.c";
+ lmsg->file = (char *) "abc123.c";
lmsg->line = 125;
pack (CK_MSG_LOC, buf, lmsg);
- lmsg->file = "";
+ lmsg->file = NULL;
lmsg->line = 0;
upack (buf, lmsg, &type);
enum ck_msg_type type;
buf = emalloc (CK_MAXMSGBUF);
- fmsg.msg = "";
+ fmsg.msg = (char *) "";
pack(CK_MSG_FAIL,buf,&fmsg);
- fmsg.msg = "abc";
+ fmsg.msg = (char *) "abc";
upack(buf,&fmsg,&type);
fail_unless (strcmp(fmsg.msg, "") == 0, "Empty string not handled properly");
free(fmsg.msg);
enum ck_msg_type type;
buf = emalloc (CK_MAXMSGBUF);
- lmsg.file = "";
+ lmsg.file = (char *) "";
lmsg.line = 0;
pack(CK_MSG_LOC,buf,&lmsg);
- lmsg.file = "abc";
+ lmsg.file = (char *) "abc";
upack(buf,&lmsg,&type);
fail_unless (strcmp(lmsg.file, "") == 0,
"Empty string not handled properly");
RcvMsg *rmsg;
cmsg.ctx = CK_CTX_TEST;
- lmsg.file = "abc123.c";
+ lmsg.file = (char *) "abc123.c";
lmsg.line = 10;
- fmsg.msg = "oops";
+ fmsg.msg = (char *) "oops";
pipe(filedes);
ppack(filedes[1],CK_MSG_CTX, &cmsg);
ppack(filedes[1],CK_MSG_LOC, &lmsg);
FailMsg fmsg;
RcvMsg *rmsg;
- lmsg.file = "abc123.c";
+ lmsg.file = (char *) "abc123.c";
lmsg.line = 10;
- fmsg.msg = "oops";
+ fmsg.msg = (char *) "oops";
pipe(filedes);
ppack(filedes[1],CK_MSG_LOC, &lmsg);
ppack(filedes[1],CK_MSG_FAIL, &fmsg);
cmsg.ctx = CK_CTX_SETUP;
lmsg.line = 5;
- lmsg.file = "abc123.c";
+ lmsg.file = (char *) "abc123.c";
pipe(filedes);
ppack(filedes[1],CK_MSG_CTX, &cmsg);
ppack(filedes[1],CK_MSG_LOC, &lmsg);
LocMsg lmsg;
RcvMsg *rmsg;
- lmsg.file = "abc123.c";
+ lmsg.file = (char *) "abc123.c";
lmsg.line = 10;
cmsg.ctx = CK_CTX_SETUP;
pipe(filedes);
START_TEST(test_add_end)
{
List * lp = list_create();
- char * tval = "abc";
+ const char * tval = "abc";
list_add_end (lp, tval);
START_TEST(test_add_end_and_next)
{
List *lp = list_create();
- char *tval1 = "abc";
- char *tval2 = "123";
+ const char *tval1 = "abc";
+ const char *tval2 = "123";
list_add_end (lp, tval1);
list_add_end (lp, tval2);