Skip to content

Commit 5cb7705

Browse files
committed
renamed library to libtdd; added better print handling
1 parent 7c5f203 commit 5cb7705

14 files changed

Lines changed: 251 additions & 161 deletions

File tree

Doxyfile

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
# Project related configuration options
1818
#---------------------------------------------------------------------------
1919

20-
#------------------
21-
things you need to change for each project
22-
#------------------
2320
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
2421
# double-quotes, unless you are using Doxywizard) that should identify the
2522
# project for which the documentation is generated. This name is used in the
2623
# title of most generated pages and in a few other places.
2724
# The default value is: My Project.
2825

29-
PROJECT_NAME = "ctest"
26+
PROJECT_NAME = "libtdd"
3027

3128

3229
# The INPUT tag is used to specify the files and/or directories that contain
@@ -37,20 +34,13 @@ PROJECT_NAME = "ctest"
3734

3835
INPUT = include
3936

40-
4137
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
4238
# into which the generated documentation will be written. If a relative path is
4339
# entered, it will be relative to the location where doxygen was started. If
4440
# left blank the current directory will be used.
4541

4642
OUTPUT_DIRECTORY = docs
4743

48-
49-
50-
#------------------
51-
things that can remain the same for each project unless you want to play
52-
#------------------
53-
5444
# This tag specifies the encoding used for all characters in the config file
5545
# that follow. The default is UTF-8 which is also the encoding used for all text
5646
# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv
@@ -60,8 +50,6 @@ things that can remain the same for each project unless you want to play
6050

6151
DOXYFILE_ENCODING = UTF-8
6252

63-
64-
6553
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
6654
# could be handy for archiving the generated documentation or if some version
6755
# control system is used.
@@ -81,7 +69,6 @@ PROJECT_BRIEF =
8169

8270
PROJECT_LOGO =
8371

84-
8572
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
8673
# directories (in 2 levels) under the output directory of each output format and
8774
# will distribute the generated files over these directories. Enabling this

Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# libctest Makefile
1+
# libtdd Makefile
22
# Keefer Rourke <mail@krourke.org>
33
#
44
# This Makefile creates dynamic and static library binaries for `libctest`.
@@ -13,6 +13,11 @@ SHELL = /bin/bash
1313
# determine platform
1414
UNAME = $(shell uname -s)
1515

16+
# let make determine the compiler and archiver;
17+
# if it complains, try uncommenting the following lines
18+
# CC = gcc
19+
# AR = ar
20+
1621
# set suffix list, to prevent confusion between different make programs
1722
# line 15 clears an implied suffix list, and line 16 sets a new one
1823
.SUFFIXES:
@@ -25,9 +30,7 @@ UNAME = $(shell uname -s)
2530
STD = -std=c99 -D_POSIX_C_SOURCE=199506L
2631

2732
# library project structure
28-
CC = gcc
29-
AR = ar
30-
WD = $(PWD)
33+
WD := $(PWD)
3134
INCLDIR = $(WD)/include
3235
SRCDIR = $(WD)/src
3336
OBJDIR = $(WD)/obj
@@ -39,8 +42,8 @@ DOCDIR = docs
3942
TEXDIR = latex
4043

4144
# library output
42-
_LIB = libctest
43-
LIB = $(addprefix $(OUTDIR)/, $(_LIB))
45+
OUTNAME = libtdd
46+
LIB = $(addprefix $(OUTDIR)/, $(OUTNAME))
4447

4548
# files; here all object files will be stored in OBJDIR, with the same names
4649
# as corresponding c files from SRCDIR
@@ -49,7 +52,8 @@ _OBJS = $(patsubst $(SRCDIR)/%.c, %.o, $(SRC))
4952
OBJS = $(addprefix $(OBJDIR)/, $(_OBJS))
5053

5154
# compilation flags
52-
CFLAGS = -Wall -pedantic -g $(STD) $(DEFINE)
55+
# add extra flags on the command line by DEFINE=...
56+
CFLAGS = -Wall -Wextra -pedantic -g $(STD) $(DEFINE)
5357
OFLAGS = -pthread
5458
INCLUDE = -I$(INCLDIR)
5559

@@ -60,15 +64,15 @@ all: lib dylib doc
6064

6165
lib: $(OBJS) $(OUTDIR)
6266
@$(AR) crs $(LIB).a $(OBJS)
63-
@echo "Compiled libctest.a to $(OUTDIR)"
67+
@echo "Compiled $(OUTNAME).a to $(OUTDIR)"
6468

6569
dylib: $(OBJS) $(OUTDIR)
6670
ifeq ($(UNAME),Darwin)
6771
@$(CC) -shared -o $(LIB).dylib $(OBJS)
68-
@echo "Compiled libctest.dylib to $(OUTDIR)"
72+
@echo "Compiled $(OUTNAME).dylib to $(OUTDIR)"
6973
else
7074
@$(CC) -shared -o $(LIB).so $(OBJS)
71-
@echo "Compiled libctest.so to $(OUTDIR)"
75+
@echo "Compiled $(OUTNAME).so to $(OUTDIR)"
7276
endif
7377

7478
# automatically compile all objects

README

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
ctest
2-
=======
1+
libtdd
2+
======
3+
4+
`libtdd` is a minimalist testing framework inspired by the Golang
5+
testing pkg. It is designed to provide a framework which may be used to
6+
build scaffolding during Test Driven Development (TDD).
7+
8+
This small C library attempts to provide a consistent API for creating,
9+
running, and checking the results of tests. There is very little
10+
boilerplate required in the main function.
311

4-
`ctest` is a minimalist testing framework inspired by the Golang
5-
testing pkg. This small C library attempts to provide a consistent API
6-
for creating, running, and checking the results of tests. There is very
7-
little boilerplate required in the main function.
812

913
Features
1014
--------
@@ -22,15 +26,15 @@ Build and usage
2226
The Makefile included with this project creates static and dynamic
2327
libraries in the `lib/` directory. To build this, simply run:
2428

25-
make lib # libctest.a
26-
make dylib # libctest.so (or libctest.dylib on Darwin)
29+
make lib # libtdd.a
30+
make dylib # libtdd.so (or libtdd.dylib on macOS/Darwin)
2731

2832
Colour output support can be enabled at compile time by including the
2933
`DEFINE=-DUSE_COLOUR` directive on the `make` line. ex.
3034

3135
make dylib DEFINE=-DUSE_COLOUR # enables pretty colour printing
3236

33-
You can then include the outputted `libctest.so` or `libctest.a` in your
37+
You can then include the outputted `libtdd.so` or `libtdd.a` in your
3438
project as is required.
3539

3640
API documentation can be compiled with Doxygen and LaTeX via:
@@ -39,7 +43,7 @@ API documentation can be compiled with Doxygen and LaTeX via:
3943

4044
See the Makefile for other relevant build targets.
4145

42-
**NOTE** Darwin/macOS support is untested at this time.
46+
**NOTE** macOS/Darwin support is untested at this time.
4347
This library was built and tested on Fedora 27 Workstation with glibc
4448
v2.26.
4549

@@ -52,9 +56,9 @@ library can be found in the `examples/` directory of this project.
5256
It can be compiled and run as follows:
5357

5458
make lib
55-
gcc -o ctest_example -std=c99 -Iinclude examples/main.c -pthread \
56-
-Llib -lctest
57-
./ctest_example
59+
cc -o tdd_example -std=c99 -Iinclude examples/main.c -pthread \
60+
-Llib -ltdd
61+
./tdd_example
5862

5963

6064
Conventions

examples/main.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* main.c
22
*
3-
* Example program demonstrating libctest usage.
3+
* Example program demonstrating libtdd usage and features.
44
* This program uses all the public features of the library.
55
*/
66
#include <signal.h>
77
#include <stdio.h>
88
#include <stdlib.h>
99
#include <string.h>
1010

11-
#include "ctest.h"
11+
#include "tdd.h"
1212

1313
static void* test_errfunc(void* t);
1414
static void* test_failfunc(void* t);
@@ -21,30 +21,35 @@ int main(int argc, char* argv[]) {
2121

2222
// suite_add is a variadic function that can be used to add an arbitrary
2323
// number of tests at once
24+
// new tests are added with a function pointer, a name, and an optional
25+
// description; if the description is to be omitted, you may pass NULL
2426
suite_add(s, 2,
2527
newtest(&test_timer, "test_timer",
2628
"Manual benchmark. Requires timespan to be printed "
2729
"manually."),
2830
newtest(&bench_func, "bench_func",
2931
"Builtin benchmark. Execution timespan is printed "
3032
"automatically below."));
33+
3134
// suite_addtest is a function that simply appends a test to the list of
3235
// tests in the suite; could be used to programmatically add tests
33-
suite_addtest(
34-
s, newtest(&test_errfunc, "test_errfunc", "Produces an error."));
36+
suite_addtest(s, newtest(&test_errfunc, "test_errfunc", "Raises error."));
37+
3538
// suite_add can be called multiple times to add groups of tests to the
3639
// test suite
3740
suite_add(s, 2,
3841
newtest(&test_failfunc, "test_failfunc", "Fails immediately."),
39-
newtest(&test_segvfunc, "test_segvfunc", "Raised SIGSEGV."));
42+
newtest(&test_segvfunc, "test_segvfunc", "Raises SIGSEGV."));
4043

4144
printf("Running tests ignoring failures.\n");
45+
4246
suite_run(s, false);
4347
if (s->finished) {
4448
printf("Suite ran all tests.\n");
4549
} else {
4650
printf("Suite only ran %d tests.\n", s->test_index + 1);
4751
}
52+
printf("Suite encountered: %d segmentation faults.\n", s->n_segv);
4853
printf("\n");
4954

5055
// reset the test suite to demonstrate that it can be rerun with fatal
@@ -56,7 +61,7 @@ int main(int argc, char* argv[]) {
5661
if (s->finished) {
5762
printf("Suite ran all tests.\n");
5863
} else {
59-
printf("Suite may not have run all tests!\n");
64+
printf("Suite only ran %d tests.\n", s->test_index + 1);
6065
}
6166

6267
// print summary statistics
@@ -74,13 +79,13 @@ int main(int argc, char* argv[]) {
7479

7580
void* test_errfunc(void* t) {
7681
test_error(t, "a non-critical error ocurred.");
77-
return t;
82+
return NULL;
7883
}
7984

8085
void* test_failfunc(void* t) {
8186
test_fail(t, "a critical error occurred!");
8287
printf("this code should not run unless fatal failures are disabled!\n");
83-
return t;
88+
return NULL;
8489
}
8590

8691
void* test_timer(void* t) {
@@ -89,17 +94,17 @@ void* test_timer(void* t) {
8994
strcpy(s, "This function is being timed!");
9095
free(s);
9196
test_done(t);
92-
return t;
97+
return NULL;
9398
}
9499

95100
void* bench_func(void* t) {
96101
char* s = calloc(128, sizeof(char));
97102
strcpy(s, "This function is being timed!");
98103
free(s);
99-
return t;
104+
return NULL;
100105
}
101106

102107
void* test_segvfunc(void* t) {
103108
raise(SIGSEGV);
104-
return t;
109+
return NULL;
105110
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
2-
* @file ctest_signals.c
2+
* @file signals.c
33
* @author Keefer Rourke <mail@krourke.org>
44
* @date Wed Apr 11
5-
* @brief This file defines signal handlers for libctest.
5+
* @brief This file defines signal handlers for libtdd.
6+
* @private
67
**/
7-
#ifndef __CTEST_SIGNAL_HANDLERS_H__
8-
#define __CTEST_SIGNAL_HANDLERS_H__
8+
#ifndef __TDD_SIGNAL_HANDLERS_H__
9+
#define __TDD_SIGNAL_HANDLERS_H__
910

1011
#include <signal.h>
1112
#include <stdlib.h>
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
/**
2-
* @file ctest_strutil.h
2+
* @file strutil.h
33
* @author Keefer Rourke <mail@krourke.org
44
* @date 08 Apr 2018
5-
* @brief String format and manipulation functions and macros for libctest.
5+
* @brief String format and manipulation functions and macros for libtdd.
66
* @private
77
*/
8-
#ifndef __CTEST_UTIL_H__
9-
#define __CTEST_UTIL_H__
8+
#ifndef __TDD_STRING_UTIL_H__
9+
#define __TDD_STRING_UTIL_H__
1010

11+
#include <stdio.h>
1112
#include <stdlib.h>
1213

14+
/**
15+
* INDENT is a macro that prints 6 space characters to the FILE* x
16+
**/
17+
#define INDENT(x) fprintf(x, " ")
18+
1319
int __hasprefix(char* str, char* pre);
1420
void __print_error(FILE* f, char* str);
1521
void __print_warning(FILE* f, char* str);

0 commit comments

Comments
 (0)