From 7eb03b68d01216d290f397dbd85404d5e85a3203 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Tue, 10 Feb 2015 01:37:45 +0100 Subject: [PATCH] Added a bunch of docs, removed additional links in index. --- doc/hooks.rst | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ doc/index.rst | 10 +++------- doc/intro.rst | 28 ++++++++++++++++++++++++++++ doc/setup.rst | 29 +++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 doc/hooks.rst create mode 100644 doc/intro.rst create mode 100644 doc/setup.rst diff --git a/doc/hooks.rst b/doc/hooks.rst new file mode 100644 index 0000000..1450305 --- /dev/null +++ b/doc/hooks.rst @@ -0,0 +1,48 @@ +Report Hooks +============ + +Report hooks are functions that are called at key moments during the testing +process. These are useful to report statistics gathered during the execution. + +A report hook can be declared using the ``ReportHook`` macro: + +.. code-block:: c + + #include + #include + + ReportHook(Phase)() { + } + +The macro takes a Phase parameter that indicates the phase at which the function +shall be run. Valid phases are described below. + +Testing Phases +-------------- + +The flow of the test process goes as follows: + +1. ``PRE_EVERYTHING``: occurs before running the tests. +#. ``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_EVERYTHING``: occurs after all the tests are done. + +Hook Parameters +--------------- + +A report hook may take zero or one parameter. If a parameter is given, it +is undefined behaviour if it is not a pointer type and not of the proper pointed +type for that phase. + +Valid types for each phases are: + +* ``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_global_stats *`` for ``POST_EVERYTHING``. + +``PRE_EVERYTHING`` does not take any parameter. diff --git a/doc/index.rst b/doc/index.rst index 7a59a3a..7aba9ad 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -4,11 +4,7 @@ Criterion .. toctree:: :maxdepth: 2 + intro + setup starter - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`search` -* :ref:`glossary` + hooks diff --git a/doc/intro.rst b/doc/intro.rst new file mode 100644 index 0000000..e26f031 --- /dev/null +++ b/doc/intro.rst @@ -0,0 +1,28 @@ +Introduction +============ + +Criterion is a dead-simple, non-intrusive testing framework for the C +programming language. + +Philosophy +---------- + +Most test frameworks for C require a lot of boilerplate code to +set up tests and test suites -- you need to create a main, +then register new test suites, then register the tests within +these suits, and finally call the right functions. + +This gives the user great control, at the unfortunate cost of simplicity. + +Criterion follows the KISS principle, while keeping the control +the user would have with other frameworks. + +Features +-------- + +* Tests are automatically registered when declared. +* A default entry point is provided, no need to declare a main + unless you want to do special handling. +* 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. diff --git a/doc/setup.rst b/doc/setup.rst new file mode 100644 index 0000000..aa26708 --- /dev/null +++ b/doc/setup.rst @@ -0,0 +1,29 @@ +Setup +===== + +Prerequisites +------------- + +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. + +Installation +------------ + +.. code-block:: bash + + $ git clone https://github.com/Snaipe/Criterion.git + $ cd Criterion + $ ./autogen.sh && ./configure && make && sudo make install + +Usage +----- + +Given a test file named test.c, compile it with `-lcriterion`: + +.. code-block:: bash + + $ gcc -o test test.c -lcriterion