Skip to content

Commit

Permalink
[v1.1.0] Merge branch 'bleeding'
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaipe committed Mar 24, 2015
2 parents 0285d32 + c4a0188 commit 227ee45
Show file tree
Hide file tree
Showing 45 changed files with 1,062 additions and 252 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2015-03-24 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
* src/log/: Refactored logging system
* src/log/: Changed output format to a better-looking one
* src/log/: Added Syntactic coloration

* include/, src/: Added test suite separation
* include/, src/: Added test suite statistics

* src/main.c: Added --list option
* src/main.c: Added --fail-fast option
* src/main.c, src/report.c: Added --pattern option

2015-03-18 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
* src/timer.*: Added test timings
* src/, include/: Changed assert prototypes
Expand Down
27 changes: 23 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ SUBDIRS = dependencies/csptr samples
lib_LTLIBRARIES = libcriterion.la

WARNINGS = -Wall -Wextra \
-Wno-unused-result -Wno-missing-field-initializers
-Wno-unused-result

libcriterion_la_CFLAGS = \
$(WARNINGS) \
-std=gnu99 \
-fplan9-extensions \
-std=gnu11 \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/include/ \
-I$(top_srcdir)/dependencies/csptr/include/ \
$(COVERAGE_CFLAGS)
Expand All @@ -29,7 +29,9 @@ subdirinclude_HEADERS = \
include/criterion/event.h \
include/criterion/hooks.h \
include/criterion/logging.h \
include/criterion/types.h \
include/criterion/options.h \
include/criterion/ordered-set.h \
include/criterion/stats.h

libcriterion_la_SOURCES = \
Expand All @@ -43,8 +45,25 @@ libcriterion_la_SOURCES = \
src/process.h \
src/stats.c \
src/stats.h \
src/logging.c \
src/log/logging.c \
src/log/tap.c \
src/log/normal.c \
src/options.c \
src/timer.c \
src/timer.h \
src/ordered-set.c \
src/main.c

TARGET = $(PACKAGE)-$(VERSION)

package: all
rm -Rf $(TARGET)
mkdir -p $(TARGET)
cp -Rf .libs $(TARGET)/lib/
rm -f $(TARGET)/lib/libcriterion.la
cp -f libcriterion.la $(TARGET)/lib
cp -Rf include $(TARGET)
tar -cvjf $(TARGET).tar.bz2 $(TARGET)

clean-local:
rm -Rf $(TARGET) $(TARGET).tar.bz2
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Criterion follows the KISS principle, while keeping the control
the user would have with other frameworks:

* [x] Tests are automatically registered when declared.
* [x] Implements a xUnit framework structure.
* [x] A default entry point is provided, no need to declare a main
unless you want to do special handling.
* [x] Test are isolated in their own process, crashes and signals can be
Expand All @@ -34,10 +35,10 @@ the user would have with other frameworks:

## Downloads

* [Linux (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.0.0/criterion-1.0.0-linux-x86_64.tar.bz2)
* [OS X (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.0.0/criterion-1.0.0-osx-x86_64.tar.bz2)
* [Windows (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.0.0/criterion-1.0.0-win-x86_64.tar.bz2)
* [FreeBSD (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.0.0/criterion-1.0.0-freebsd-x86_64.tar.bz2)
* [Linux (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.1.0/criterion-1.1.0-linux-x86_64.tar.bz2)
* [OS X (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.1.0/criterion-1.1.0-osx-x86_64.tar.bz2)
* [Windows (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.1.0/criterion-1.1.0-win-x86_64.tar.bz2)
* [FreeBSD (x86_64)](https://github.com/Snaipe/Criterion/releases/download/v1.1.0/criterion-1.1.0-freebsd-x86_64.tar.bz2)

If you have a different platform, you can still [build the library from source](http://criterion.readthedocs.org/en/latest/setup.html#installation)

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ([2.60])

AC_INIT([criterion], [1.0.0], [], [criterion], [franklinmathieu@gmail.com])
AC_INIT([criterion], [1.1.0], [], [criterion], [franklinmathieu@gmail.com])
AC_CONFIG_SRCDIR([src/runner.c])

LT_PREREQ([2.2.4])
Expand Down
2 changes: 1 addition & 1 deletion dependencies/csptr
Submodule csptr updated from 3b6b26 to 15b825
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# built documents.
#
# The short X.Y version.
version = '0.1.0'
version = '1.1.0'
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
65 changes: 57 additions & 8 deletions doc/env.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
Environment and CLI
===================

Tests built with Criterion support environment variables to alter
their runtime behaviour.
Tests built with Criterion expose by default various command line switchs
and environment variables to alter their runtime behaviour.

Command line arguments
----------------------

* ``-h or --help``: Show a help message with the available switches.
* ``-v or --version``: Prints the version of criterion that has been
linked against.
* ``-l or --list``: Print all the tests in a list.
* ``-f or --fail-fast``: Exit after the first test failure.
* ``--ascii``: Don't use fancy unicode symbols or colors in the output.
* ``--pattern [PATTERN]``: Run tests whose string identifier matches
the given shell wildcard pattern (see dedicated section below).
* ``--no-early-exit``: The test workers shall not prematurely exit when done and
will properly return from the main, cleaning up their process space.
This is useful when tracking memory leaks with ``valgrind --tool=memcheck``.
* ``--always-succeed``: The process shall exit with a status of ``0``.
* ``--tap``: Enables the TAP (Test Anything Protocol) output format.
* ``--verbose[=level]``: Makes the output verbose. When provided with an integer,
sets the verbosity level to that integer.

Shell Wildcard Pattern
----------------------

Patterns in criterion are matched against a test's string identifier with
``fnmatch``.

Special characters used in shell-style wildcard patterns are:

=========== ===================================
Pattern Meaning
=========== ===================================
``*`` matches everything
----------- -----------------------------------
``?`` matches any character
----------- -----------------------------------
``[seq]`` matches any character in *seq*
----------- -----------------------------------
``[!seq]`` matches any character not in *seq*
=========== ===================================

A test string identifier is of the form ``suite-name/test-name``, so a pattern
of ``simple/*`` matches every tests in the ``simple`` suite, ``*/passing``
matches all tests named ``passing`` regardless of the suite, and ``*`` matches
every possible test.

Environment Variables
---------------------

* `CRITERION_ALWAYS_SUCCEED`: when set to `1`, the exit status of the test
process will be 0, regardless if the tests failed or not.
* `CRITERION_NO_EARLY_EXIT`: when set to `1`, the test workers shall not
call `_exit` when done and will properly return from the main and
clean up their process space. This is useful when tracking memory leaks with
`valgrind --tool=memcheck`.
Environment variables are alternatives to command line switches when set to 1.

* ``CRITERION_ALWAYS_SUCCEED``: Same as ``--always-succeed``.
* ``CRITERION_NO_EARLY_EXIT``: Same as ``--no-early-exit``.
* ``CRITERION_ENABLE_TAP``: Same as ``--tap``.
* ``CRITERION_FAIL_FAST``: Same as ``--fail-fast``.
* ``CRITERION_USE_ASCII``: Same as ``--ascii``.
* ``CRITERION_VERBOSITY_LEVEL``: Same as ``--verbose``. Sets the verbosity level
to its value.
* ``CRITERION_TEST_PATTERN``: Same as ``--pattern``. Sets the test pattern
to its value.
17 changes: 17 additions & 0 deletions doc/faq.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
F.A.Q
=====

**Q. When running the test suite in Windows' cmd.exe, the test executable
prints weird characters, how do I fix that?**

A. Windows' ``cmd.exe`` is not an unicode ANSI-compatible terminal emulator.
There are plenty of ways to fix that behaviour:

* Pass ``--ascii`` to the test suite when executing.
* Define the ``CRITERION_USE_ASCII`` environment variable to ``1``.
* Get a better terminal emulator, such as the one shipped with Git or Cygwin.

**Q. I'm having an issue with the library, what can I do ?**

A. Open a new issue on the `github issue tracker <https://github.com/Snaipe/Criterion/issues>`_,
and describe the problem you are experiencing.
9 changes: 6 additions & 3 deletions doc/hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ Testing Phases
The flow of the test process goes as follows:

1. ``PRE_ALL``: occurs before running the tests.
#. ``PRE_SUITE``: occurs before a suite is initialized.
#. ``PRE_INIT``: occurs before a test is initialized.
#. ``PRE_TEST``: occurs after the test initialization, but before the test is run.
#. ``ASSERT``: occurs when an assertion is hit
#. ``TEST_CRASH``: occurs when a test crashes unexpectedly.
#. ``POST_TEST``: occurs after a test ends, but before the test finalization.
#. ``POST_FINI``: occurs after a test finalization.
#. ``POST_SUITE``: occurs before a suite is finalized.
#. ``POST_ALL``: occurs after all the tests are done.

Hook Parameters
Expand All @@ -40,9 +42,10 @@ type for that phase.

Valid types for each phases are:

* ``struct criterion_test_set *`` for ``PRE_ALL``.
* ``struct criterion_suite_set *`` for ``PRE_SUITE``.
* ``struct criterion_test *`` for ``PRE_INIT`` and ``PRE_TEST``.
* ``struct criterion_test_stats *`` for ``POST_TEST``, ``POST_FINI``, and ``TEST_CRASH``.
* ``struct criterion_assert_stats *`` for ``ASSERT``.
* ``struct criterion_test_stats *`` for ``POST_TEST``, ``POST_FINI``, and ``TEST_CRASH``.
* ``struct criterion_suite_stats *`` for ``POST_SUITE``.
* ``struct criterion_global_stats *`` for ``POST_ALL``.

``PRE_ALL`` does not take any parameter.
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Criterion
starter
hooks
env
faq
4 changes: 4 additions & 0 deletions doc/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ Features
* Test are isolated in their own process, crashes and signals can be
reported and tested.
* Progress and statistics can be followed in real time with report hooks.
* TAP output format can be enabled with an option.
* Runs on Linux, FreeBSD, Mac OS X, and Windows (compiles only with Cygwin
for the moment).
* xUnit framework structure
Binary file modified doc/screencast.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion doc/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Currently, this library only works under \*nix systems.

To compile the static library and its dependencies, GCC 4.9+ is needed.

To use the static library, GCC or Clang are needed.
To use the static library, any GNU-C compatible compiler will suffice
(GCC, Clang/LLVM, ICC, MinGW-GCC, ...).

Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion include/criterion/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# include <string.h>
# include <stdlib.h>
# include <stdbool.h>
# include "criterion.h"
# include "types.h"
# include "stats.h"
# include "hooks.h"
# include "event.h"
Expand Down
4 changes: 2 additions & 2 deletions include/criterion/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
extern Type SECTION_START_(Name) SECTION_START_SUFFIX(#Name); \
extern Type SECTION_END_(Name) SECTION_END_SUFFIX(#Name)

# define IMPL_SECTION_LIMITS(Type, Name) \
Type *const SECTION_START(Name) = &SECTION_START_(Name); \
# define IMPL_SECTION_LIMITS(Type, Name) \
Type *const SECTION_START(Name) = &SECTION_START_(Name); \
Type *const SECTION_END(Name) = &SECTION_END_(Name)

# define UNUSED __attribute__((unused))
Expand Down
70 changes: 20 additions & 50 deletions include/criterion/criterion.h
Original file line number Diff line number Diff line change
@@ -1,68 +1,25 @@
/*
* The MIT License (MIT)
*
* Copyright © 2015 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CRITERION_H_
# define CRITERION_H_

# include <stdbool.h>
# include <stddef.h>
# include "common.h"
# include "assert.h"

struct criterion_test_extra_data {
int sentinel_;
const char *const file_;
const unsigned line_;
void (*init)(void);
void (*fini)(void);
int signal;
bool disabled;
void *data;
};

struct criterion_test {
const char *name;
const char *category;
void (*test)(void);
struct criterion_test_extra_data *const data;
};

struct criterion_test_set {
struct criterion_test **tests;
size_t nb_tests;
};
# include "types.h"

# define IDENTIFIER_(Category, Name, Suffix) \
Category ## _ ## Name ## _ ## Suffix
# define TEST_PROTOTYPE_(Category, Name) \
void IDENTIFIER_(Category, Name, impl)(void)

# define SUITE_IDENTIFIER_(Name, Suffix) \
suite_ ## Name ## _ ## Suffix

# define Test(...) Test_(__VA_ARGS__, .sentinel_ = 0)
# define Test_(Category, Name, ...) \
TEST_PROTOTYPE_(Category, Name); \
struct criterion_test_extra_data IDENTIFIER_(Category, Name, extra) = { \
.file_ = __FILE__, \
.line_ = __LINE__, \
.identifier_ = #Category "/" #Name, \
.file_ = __FILE__, \
.line_ = __LINE__, \
__VA_ARGS__ \
}; \
SECTION_("criterion_tests") \
Expand All @@ -74,6 +31,19 @@ struct criterion_test_set {
}; \
TEST_PROTOTYPE_(Category, Name)

# define TestSuite(...) TestSuite_(__VA_ARGS__, .sentinel_ = 0)
# define TestSuite_(Name, ...) \
struct criterion_test_extra_data SUITE_IDENTIFIER_(Name, extra) = { \
.file_ = __FILE__, \
.line_ = 0, \
__VA_ARGS__ \
}; \
SECTION_("crit_suites") \
const struct criterion_suite SUITE_IDENTIFIER_(Name, meta) = { \
.name = #Name, \
.data = &SUITE_IDENTIFIER_(Name, extra), \
}

int criterion_run_all_tests(void);

#endif /* !CRITERION_H_ */
2 changes: 2 additions & 0 deletions include/criterion/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@

typedef enum {
PRE_ALL,
PRE_SUITE,
PRE_INIT,
PRE_TEST,
ASSERT,
TEST_CRASH,
POST_TEST,
POST_FINI,
POST_SUITE,
POST_ALL,
} e_report_status;

Expand Down
Loading

0 comments on commit 227ee45

Please sign in to comment.