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