inline std::size_t listTestsNamesOnly(Config const &config) {
     TestSpec testSpec = config.testSpec();
     if (!config.testSpec().hasFilters())
         testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("*").testSpec();
     std::size_t matchedTests = 0;
     std::vector<TestCase> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
     for (std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
          it != itEnd;
          ++it) {
         matchedTests++;
         TestCaseInfo const &testCaseInfo = it->getTestCaseInfo();
         Catch::cout() << testCaseInfo.name << std::endl;
     }
     return matchedTests;
 }
    inline std::size_t listTags(Config const &config) {
        TestSpec testSpec = config.testSpec();
        if (config.testSpec().hasFilters())
            Catch::cout() << "Tags for matching test cases:\n";
        else {
            Catch::cout() << "All available tags:\n";
            testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("*").testSpec();
        }

        std::map<std::string, TagInfo> tagCounts;

        std::vector<TestCase> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
        for (std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
             it != itEnd;
             ++it) {
            for (std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
                         tagItEnd = it->getTestCaseInfo().tags.end();
                 tagIt != tagItEnd;
                 ++tagIt) {
                std::string tagName = *tagIt;
                std::string lcaseTagName = toLower(tagName);
                std::map<std::string, TagInfo>::iterator countIt = tagCounts.find(lcaseTagName);
                if (countIt == tagCounts.end())
                    countIt = tagCounts.insert(std::make_pair(lcaseTagName, TagInfo())).first;
                countIt->second.add(tagName);
            }
        }

        for (std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
                     countItEnd = tagCounts.end();
             countIt != countItEnd;
             ++countIt) {
            std::ostringstream oss;
            oss << "  " << std::setw(2) << countIt->second.count << "  ";
            Text wrapper(countIt->second.all(), TextAttributes()
                    .setInitialIndent(0)
                    .setIndent(oss.str().size())
                    .setWidth(CATCH_CONFIG_CONSOLE_WIDTH - 10));
            Catch::cout() << oss.str() << wrapper << "\n";
        }
        Catch::cout() << pluralise(tagCounts.size(), "tag") << "\n" << std::endl;
        return tagCounts.size();
    }
    inline std::size_t listTests(Config const &config) {

        TestSpec testSpec = config.testSpec();
        if (config.testSpec().hasFilters())
            Catch::cout() << "Matching test cases:\n";
        else {
            Catch::cout() << "All available test cases:\n";
            testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("*").testSpec();
        }

        std::size_t matchedTests = 0;
        TextAttributes nameAttr, tagsAttr;
        nameAttr.setInitialIndent(2).setIndent(4);
        tagsAttr.setIndent(6);

        std::vector<TestCase> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
        for (std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
             it != itEnd;
             ++it) {
            matchedTests++;
            TestCaseInfo const &testCaseInfo = it->getTestCaseInfo();
            Colour::Code colour = testCaseInfo.isHidden()
                                  ? Colour::SecondaryText
                                  : Colour::None;
            Colour colourGuard(colour);

            Catch::cout() << Text(testCaseInfo.name, nameAttr) << std::endl;
            if (!testCaseInfo.tags.empty())
                Catch::cout() << Text(testCaseInfo.tagsAsString, tagsAttr) << std::endl;
        }

        if (!config.testSpec().hasFilters())
            Catch::cout() << pluralise(matchedTests, "test case") << "\n" << std::endl;
        else
            Catch::cout() << pluralise(matchedTests, "matching test case") << "\n" << std::endl;
        return matchedTests;
    }
Exemple #4
0
int main(int argc, char** argv)  {
  filterTests();
  testing::InitGoogleTest(&argc, argv);
  RUN_ALL_TESTS();
  std::getchar(); // keep console window open until Return keystroke
}