コード例 #1
0
ファイル: catch_session.hpp プロジェクト: prapin/Catch
    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
 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;
 }
コード例 #3
0
ファイル: catch_session.hpp プロジェクト: prapin/Catch
    void applyFilenamesAsTags( IConfig const& config ) {
        std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
        for(std::size_t i = 0; i < tests.size(); ++i ) {
            TestCase& test = const_cast<TestCase&>( tests[i] );
            std::set<std::string> tags = test.tags;

            std::string filename = test.lineInfo.file;
            std::string::size_type lastSlash = filename.find_last_of( "\\/" );
            if( lastSlash != std::string::npos )
                filename = filename.substr( lastSlash+1 );

            std::string::size_type lastDot = filename.find_last_of( "." );
            if( lastDot != std::string::npos )
                filename = filename.substr( 0, lastDot );

            tags.insert( "#" + filename );
            setTags( test, tags );
        }
    }
コード例 #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;
    }