annotate README.markdown @ 4:9d536614c4c0 tip

Added tag fructose1.1.0 for changeset d8aeeb7f6785
author Brian Neal <bgneal@gmail.com>
date Sat, 21 May 2011 21:11:44 -0500
parents 62a54c46da31
children
rev   line source
bgneal@0 1 fructose_gen.py
bgneal@0 2 ===============
bgneal@0 3
bgneal@0 4 Quick Start
bgneal@0 5 -----------
bgneal@0 6
bgneal@0 7 `fructose_gen.py` is a Python script for auto-generatng the `main()` function
bgneal@0 8 for the C++ testing framework [Fructose][1].
bgneal@0 9
bgneal@0 10 Sample usage:
bgneal@0 11
bgneal@0 12 $ python fructose_gen.py [options] test1.h test2.h ... testN.h > main.cpp
bgneal@0 13
bgneal@0 14 In this example, `fructose_gen.py` will read the Fructose test files `test1.h`
bgneal@0 15 through `testN.h` and produce on standard output C++ code with a generated
bgneal@0 16 `main()` function. This auto-generated code will instantiate all the test
bgneal@0 17 instances, register the appropriate tests with each instance, and then execute
bgneal@0 18 each test in turn.
bgneal@0 19
bgneal@0 20 To see usage information and a list of options:
bgneal@0 21
bgneal@0 22 $ python fructose_gen.py --help
bgneal@0 23
bgneal@0 24
bgneal@0 25 Code Generation Styles
bgneal@0 26 ----------------------
bgneal@0 27
bgneal@0 28 `fructose_gen.py` supports two styles of code generation, described below.
bgneal@0 29
bgneal@0 30 ### xUnit Style ###
bgneal@0 31
bgneal@0 32 The default style is xUnit style. In this form, `fructose_gen.py` will scan
bgneal@0 33 C++ code looking for classes or structs that inherit from `fructose::test_base<>`.
bgneal@0 34 Inside those classes or structs, member functions that match the following
bgneal@0 35 pattern are assumed to be test functions:
bgneal@0 36
bgneal@0 37 void testXXXX(const std::string&)
bgneal@0 38
bgneal@0 39 Upon finding such a function, `fructose_gen.py` will register that member
bgneal@0 40 function as a test with the name "testXXXX".
bgneal@0 41
bgneal@0 42
bgneal@0 43 ### Generator Style ###
bgneal@0 44
bgneal@0 45 To remain backward compatible with the `generator` program that ships with
bgneal@0 46 Fructose, invoke `fructose_gen.py` with a `-g` or `--generator` option flag.
bgneal@0 47
bgneal@0 48 In this style, `fructose_gen.py` will scan files for the `FRUCTOSE_CLASS`,
bgneal@0 49 `FRUCTOSE_STRUCT` and `FRUCTOSE_TEST` macros. See the Fructose documentation
bgneal@0 50 for more information.
bgneal@0 51
bgneal@0 52
bgneal@0 53 Caveats
bgneal@0 54 -------
bgneal@0 55
bgneal@0 56 `fructose_gen.py` is not a true C++ code parser, and in fact is quite simple
bgneal@0 57 in how it operates. This is sufficient for most cases, but please be aware of
bgneal@0 58 the following limitations.
bgneal@0 59
bgneal@1 60 1. Ensure your class (or struct) definition is all on one line:
bgneal@0 61
bgneal@0 62 class my_unit_test : public fructose::test_base<my_unit_test>
bgneal@0 63
bgneal@1 64 If you split the above across multiple lines `fructose_gen.py` will not
bgneal@1 65 recognize your class and will not generate a test instance for it.
bgneal@0 66
bgneal@1 67 2. `fructose_gen.py` does not understand C-style comments or the preprocessor.
bgneal@1 68 To comment out a test, you can either use C++ comments, or change the function
bgneal@1 69 name slightly to ensure it won't be recognized. Examples:
bgneal@0 70
bgneal@0 71 /*
bgneal@0 72 ** void test_is_sorted(const std::string& name) // this won't work
bgneal@0 73 */
bgneal@0 74
bgneal@0 75 #if 0
bgneal@0 76 void test_is_sorted(const std::string& name) // this won't work
bgneal@0 77 #endif
bgneal@0 78
bgneal@0 79 void not_a_test_is_sorted(const std::string& name) // this works
bgneal@0 80 // void test_is_sorted(const std::string& name) // this works
bgneal@0 81 // FRUCTOSE_TEST(is_sorted) // this works
bgneal@0 82
bgneal@1 83 The above also applies to commenting out test classes.
bgneal@0 84
bgneal@0 85
bgneal@0 86 Support
bgneal@0 87 -------
bgneal@0 88 See the [fructose_gen support site][2] hosted at [bitbucket.org][3].
bgneal@0 89
bgneal@0 90
bgneal@0 91 [1]: http://fructose.sourceforge.net/
bgneal@0 92 [2]: https://bitbucket.org/bgneal/fructose_gen
bgneal@0 93 [3]: https://bitbucket.org