5 #include <tut/tut_console_reporter.hpp>
6 #include <tut/tut_cppunit_reporter.hpp>
13 /** Helper function to make test binaries simpler.
15 * Example of basic usage follows.
18 * namespace tut { test_runner_singleton runner; }
20 * int main(int argc, char **argv)
22 * if( tut_main(argc, argv) )
29 * It is also possible to do some generic initialization before
30 * running any tests and cleanup before exiting application.
31 * Note that tut_main can throw tut::no_such_group or tut::no_such_test.
34 * namespace tut { test_runner_singleton runner; }
36 * int main(int argc, char **argv)
38 * tut::xml_reporter reporter;
39 * tut::runner.get().insert_callback(&reporter);
44 * tut_main(argc, argv);
46 * catch(const tut::tut_error &ex)
48 * std::cerr << "TUT error: " << ex.what() << std::endl;
54 inline bool tut_main(int argc, const char * const * const argv, std::ostream &os = std::cerr)
56 std::stringstream usage;
57 usage << "Usage: " << argv[0] << " [group] [testcase]" << std::endl;
58 groupnames gr = runner.get().list_groups();
59 usage << "Available test groups:" << std::endl;
60 for(groupnames::const_iterator i = gr.begin(); i != gr.end(); ++i)
62 usage << " " << *i << std::endl;
67 if(std::string(argv[1]) == "-h" ||
68 std::string(argv[1]) == "--help" ||
69 std::string(argv[1]) == "/?" ||
77 // Check command line options.
81 runner.get().run_tests();
85 runner.get().run_tests(argv[1]);
91 int t = strtol(argv[2], &end, 10);
92 if(end != argv[2] + strlen(argv[2]))
94 throw no_such_test("`" + std::string(argv[2]) + "` should be a number");
98 if(!runner.get().run_test(argv[1], t, tr) || tr.result == test_result::dummy)
100 throw no_such_test("No testcase `" + std::string(argv[2]) + "` in group `" + argv[1] + "`");