fructose_gen /

Filename Size Date modified Message
25 B
55 B
35.1 KB
7.7 KB
3.0 KB
6.9 KB

Quick Start is a Python script for auto-generatng the main() function for the C++ testing framework Fructose.

Sample usage:

$ python [options] test1.h test2.h ... testN.h > main.cpp

In this example, will read the Fructose test files test1.h through testN.h and produce on standard output C++ code with a generated main() function. This auto-generated code will instantiate all the test instances, register the appropriate tests with each instance, and then execute each test in turn.

To see usage information and a list of options:

$ python --help

Code Generation Styles supports two styles of code generation, described below.

xUnit Style

The default style is xUnit style. In this form, will scan C++ code looking for classes or structs that inherit from fructose::test_base<>. Inside those classes or structs, member functions that match the following pattern are assumed to be test functions:

  void testXXXX(const std::string&)

Upon finding such a function, will register that member function as a test with the name "testXXXX".

Generator Style

To remain backward compatible with the generator program that ships with Fructose, invoke with a -g or --generator option flag.

In this style, will scan files for the FRUCTOSE_CLASS, FRUCTOSE_STRUCT and FRUCTOSE_TEST macros. See the Fructose documentation for more information.

Caveats is not a true C++ code parser, and in fact is quite simple in how it operates. This is sufficient for most cases, but please be aware of the following limitations.

  1. Ensure your class (or struct) definition is all on one line:

     class my_unit_test : public fructose::test_base<my_unit_test>

    If you split the above across multiple lines will not recognize your class and will not generate a test instance for it.

  2. does not understand C-style comments or the preprocessor. To comment out a test, you can either use C++ comments, or change the function name slightly to ensure it won't be recognized. Examples:

      ** void test_is_sorted(const std::string& name)  // this won't work
      #if 0
      void test_is_sorted(const std::string& name)   // this won't work
      void not_a_test_is_sorted(const std::string& name) // this works
      // void test_is_sorted(const std::string& name)    // this works
      // FRUCTOSE_TEST(is_sorted)                        // this works

    The above also applies to commenting out test classes.


See the fructose_gen support site hosted at