Пример #1
0
    Totals runTests( Ptr<Config> const& config ) {

        Ptr<IConfig const> iconfig = config.get();

        Ptr<IStreamingReporter> reporter = makeReporter( config );
        reporter = addListeners( iconfig, reporter );

        RunContext context( iconfig, reporter );

        Totals totals;

        context.testGroupStarting( config->name(), 1, 1 );

        TestSpec testSpec = config->testSpec();
        if( !testSpec.hasFilters() )
            testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests

        std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
        for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
                it != itEnd;
                ++it ) {
            if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
                totals += context.runTest( *it );
            else
                reporter->skipTest( *it );
        }

        context.testGroupEnded( iconfig->name(), totals, 1, 1 );
        return totals;
    }
Пример #2
0
        Totals runTests() {

            RunContext context( m_config.get(), m_reporter );

            Totals totals;

            context.testGroupStarting( "all tests", 1, 1 ); // deprecated?

            TestSpec testSpec = m_config->testSpec();
            if( !testSpec.hasFilters() )
                testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests

            std::vector<TestCase> testCases;
            getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, testCases );

            int testsRunForGroup = 0;
            for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
                    it != itEnd;
                    ++it ) {
                testsRunForGroup++;
                if( m_testsAlreadyRun.find( *it ) == m_testsAlreadyRun.end() ) {

                    if( context.aborting() )
                        break;

                    totals += context.runTest( *it );
                    m_testsAlreadyRun.insert( *it );
                }
            }
            context.testGroupEnded( "all tests", totals, 1, 1 );
            return totals;
        }
Пример #3
0
 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;
 }
Пример #4
0
    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();
    }
Пример #5
0
    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;
    }
 inline TestSpec parseTestSpec( std::string const& arg ) {
     return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
 }
Пример #7
0
 inline TestSpec parseTestSpec( std::string const& arg ) {
     return TestSpecParser().parse( arg ).testSpec();
 }