add --list option to list test names
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Fri, 14 Sep 2012 21:56:03 +0000 (14:56 -0700)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Fri, 14 Sep 2012 21:56:03 +0000 (14:56 -0700)
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/common/test.cpp
src/common/test.h
src/testmain.cpp

index a5a8594..46feec6 100644 (file)
@@ -32,3 +32,18 @@ bool GlobalTestSuite::registerTest(TFun fn, const std::string& name)
        tcase_set_timeout(tc, 30);
        cases_.insert(std::make_pair(name, tc));
 }
+
+std::vector<std::string> GlobalTestSuite::testNames(const std::string& testPattern) const
+{
+       boost::regex exp(testPattern, boost::regex::egrep | boost::regex::icase);
+       boost::cmatch what;
+       std::vector<std::string> result;
+       foreach (const Cases::value_type& tcase, cases_)
+       {
+               if (boost::regex_match(tcase.first.c_str(), what, exp))
+               {
+                       result.push_back(tcase.first);
+               }
+       }
+       return result;
+}
\ No newline at end of file
index 427e780..9a7333b 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <boost/foreach.hpp>
 #include <map>
+#include <vector>
 #include <check.h> // Check unit testing framework... see http://check.sourceforge.net
 
 #include "singleton.h"
@@ -24,6 +25,8 @@ public:
 
        const std::string name;
 
+       std::vector<std::string> testNames(const std::string& = ".*") const;
+
 private:
        friend class Singleton<GlobalTestSuite>;
        GlobalTestSuite(); // non-default constructible
index 76856cb..7eb2069 100644 (file)
@@ -2,6 +2,7 @@
 #include <fstream>
 #include <deque>
 #include <map>
+#include <vector>
 #include <boost/algorithm/string.hpp>
 #include <boost/program_options.hpp>
 #include <boost/shared_ptr.hpp>
@@ -16,6 +17,7 @@ po::variables_map parseArgs(int argc, char** argv)
        po::options_description options("optional arguments");
        options.add_options()
                ("help", "display this help message")
+               ("list", "list test names")
                ("xml", po::value<std::string>(), "send results to XML file")
                ("filter", po::value<std::string>()->default_value(".*"), "egrep style regular expression to match tests to run")
        ;
@@ -38,7 +40,7 @@ po::variables_map parseArgs(int argc, char** argv)
                std::cout << options << std::endl;
                exit(EXIT_SUCCESS);
        }
-       
+
        return args;
 }
 
@@ -247,6 +249,13 @@ int main(int argc, char** argv)
 {
        po::variables_map args(parseArgs(argc, argv));
 
+       if (args.count("list"))
+       {
+               std::vector<std::string> names = TheGlobalTestSuite::instance().testNames(args["filter"].as<std::string>());
+               std::copy(names.begin(), names.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
+               exit(EXIT_SUCCESS);
+       }
+
        TheGlobalTestSuite::instance().argc = argc;
        TheGlobalTestSuite::instance().argv = argv;