bassosimone/libight — pull request #19 by bassosimone (2014-08-21 10:43:02+00:00)
Title: Add buffer along with its Catch-based unit test

This pull request adds `src/net/buffer.hpp`. It is a file that contains a reworked version of the buffering code that I removed from `IghtConnection` in pull request #17. The pull request also contains a unit test for `src/net/buffer.hpp`.

*Note:* I've decided to use the `.hpp` extension (as opposed to `.h`) because ligight is full C++ (as opposed to libneubot which was mixed C/C++), so we need to communicate that properly. We'll migrate other headers next.

This pull request is also notable because it adds [philsquared/Catch](https://github.com/philsquared/Catch/) as a unit testing framework, as discussed in #9. The way in which the unit test is organized is explained next.

Catch is added in `src/ext` as a submodule. The specific tests for `src/net/buffer.hpp` are added as `test/net/buffer_tests.hpp`. There is the `test/tests.cpp` file that currently pulls the `buffer_tests.hpp` file and that in the future will pull other headers containing more test cases (e.g., `test/common/delayed_call.cpp` can easily be converted to catch and renamed `test/common/delayed_call_tests.hpp`). Such `.cpp` file is then compiled into the Catch executable (the `main()` being supplied automatically by catch). By default, this executable runs all the test cases that were pulled from header files. I expand below on why I chose a single executable.

I opted for a single testing executable for two reasons. Firstly, because I anticipate that in the common case we need to run all the unit tests in a simple way (typically before submitting a pull request, to make sure there are no breakages). Secondly, because the executable compiled by catch allows one to specify from the command line which test to run (by specifying the test name, a pattern, or a test tag). So, there is always the possibility to limit the number of tests run, to nail down a specific test-related problem.