コード例 #1
0
ファイル: framework.cpp プロジェクト: mikejs/mongo
        int Suite::run( vector<string> suites ){
            for ( unsigned int i = 0; i < suites.size(); i++ ) {
                if ( _suites->find( suites[i] ) == _suites->end() ) {
                    cout << "invalid test [" << suites[i] << "], use --list to see valid names" << endl;
                    return -1;
                }
            }

            list<string> torun(suites.begin(), suites.end());

            if ( torun.size() == 0 )
                for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
                    torun.push_back( i->first );

            list<Result*> results;

            for ( list<string>::iterator i=torun.begin(); i!=torun.end(); i++ ){
                string name = *i;
                Suite * s = (*_suites)[name];
                assert( s );

                log() << "going to run suite: " << name << endl;
                results.push_back( s->run() );
            }

            Logstream::get().flush();

            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;

            int rc = 0;

            int tests = 0;
            int fails = 0;
            int asserts = 0;

            for ( list<Result*>::iterator i=results.begin(); i!=results.end(); i++ ){
                Result * r = *i;
                cout << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();
                
                tests += r->_tests;
                fails += r->_fails;
                asserts += r->_asserts;
            }

            Result totals ("TOTALS");
            totals._tests = tests;
            totals._fails = fails;
            totals._asserts = asserts;
            
            cout << totals.toString(); // includes endl

            return rc;
        }
コード例 #2
0
ファイル: test_pellets.cpp プロジェクト: LieLowMan/zpublic
void UniTest()
{
    Suite ts;
    AddTest(ts);
    std::auto_ptr<Output> output(new XmlOutput);
    ts.run(*output, true);
    Test::XmlOutput* const xml_output = dynamic_cast<XmlOutput*>(output.get());
    if (xml_output)
    {
        std::ofstream fout("./test_pellets.xml");
        xml_output->generate(fout, true, "zpublic");
    }
}
コード例 #3
0
ファイル: unittest.cpp プロジェクト: ANTco/mongo
        int Suite::run( const std::vector<std::string>& suites , const std::string& filter , int runsPerTest ) {

            if (_allSuites().empty()) {
                log() << "error: no suites registered.";
                return EXIT_FAILURE;
            }

            for ( unsigned int i = 0; i < suites.size(); i++ ) {
                if ( _allSuites().count( suites[i] ) == 0 ) {
                    log() << "invalid test suite [" << suites[i] << "], use --list to see valid names" << std::endl;
                    return EXIT_FAILURE;
                }
            }

            std::vector<std::string> torun(suites);

            if ( torun.empty() ) {
                for ( SuiteMap::const_iterator i = _allSuites().begin();
                      i !=_allSuites().end(); ++i ) {

                    torun.push_back( i->first );
                }
            }

            std::vector<Result*> results;

            for ( std::vector<std::string>::iterator i=torun.begin(); i!=torun.end(); i++ ) {
                std::string name = *i;
                Suite* s = _allSuites()[name];
                fassert( 16145,  s );

                log() << "going to run suite: " << name << std::endl;
                results.push_back( s->run( filter, runsPerTest ) );
            }

            log() << "**************************************************" << std::endl;

            int rc = 0;

            int tests = 0;
            int asserts = 0;
            int millis = 0;

            Result totals ("TOTALS");
            std::vector<std::string> failedSuites;

            for ( std::vector<Result*>::iterator i=results.begin(); i!=results.end(); i++ ) {
                Result* r = *i;
                log() << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();

                tests += r->_tests;
                if ( !r->_fails.empty() ) {
                    failedSuites.push_back(r->toString());
                    for ( std::vector<std::string>::const_iterator j=r->_fails.begin();
                          j!=r->_fails.end(); j++ ) {
                        const std::string& s = (*j);
                        totals._fails.push_back(r->_name + "/" + s);
                    }
                }
                asserts += r->_asserts;
                millis += r->_millis;
            }

            totals._tests = tests;
            totals._asserts = asserts;
            totals._millis = millis;

            log() << totals.toString(); // includes endl

            // summary
            if ( !totals._fails.empty() ) {
                log() << "Failing tests:" << std::endl;
                for ( std::vector<std::string>::const_iterator i=totals._fails.begin();
                      i!=totals._fails.end(); i++ ) {
                    const std::string& s = (*i);
                    log() << "\t " << s << " Failed";
                }
                log() << "FAILURE - " << totals._fails.size() << " tests in "
                      << failedSuites.size() << " suites failed";
            }
            else {
                log() << "SUCCESS - All tests in all suites passed";
            }

            return rc;
        }
コード例 #4
0
ファイル: framework.cpp プロジェクト: zhuk/mongo
        int Suite::run( int argc , char ** argv ){
            list<string> torun;

            for ( int i=1; i<argc; i++ ){
            
                string s = argv[i];
                
                if ( s == "-list" ){
                    for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
                        cout << i->first << endl;
                    return 0;
                }

                if ( s == "-debug" ){
                    logLevel = 1;
                    continue;
                }
                
                torun.push_back( s );
                if ( _suites->find( s ) == _suites->end() ){
                    cout << "invalid test [" << s << "]  use -list to see valid names" << endl;
                    return -1;
                }
            }
            
            if ( torun.size() == 0 )
                for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
                    torun.push_back( i->first );
            
            list<Result*> results;
            
            for ( list<string>::iterator i=torun.begin(); i!=torun.end(); i++ ){
                string name = *i;
                Suite * s = (*_suites)[name];
                assert( s );
                
                log() << "going to run suite: " << name << endl;
                results.push_back( s->run() );
            }
            
            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;
            
            int rc = 0;
            
            int tests = 0;
            int fails = 0;
            int asserts = 0;

            for ( list<Result*>::iterator i=results.begin(); i!=results.end(); i++ ){
                Result * r = *i;
                cout << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();

                tests += r->_tests;
                fails += r->_fails;
                asserts += r->_asserts;
            }
            
            cout << "TOTALS  tests:" << tests << " fails: " << fails << " asserts calls: " << asserts << endl;

            return rc;
        }
コード例 #5
0
ファイル: unittest.cpp プロジェクト: 89snake89/mongo
        int Suite::run( const std::vector<std::string>& suites , const std::string& filter , int runsPerTest ) {

            if (_allSuites().empty()) {
                log() << "error: no suites registered.";
                return EXIT_FAILURE;
            }

            for ( unsigned int i = 0; i < suites.size(); i++ ) {
                if ( _allSuites().count( suites[i] ) == 0 ) {
                    log() << "invalid test suite [" << suites[i] << "], use --list to see valid names" << std::endl;
                    return EXIT_FAILURE;
                }
            }

            std::vector<std::string> torun(suites);

            if ( torun.empty() ) {
                for ( SuiteMap::const_iterator i = _allSuites().begin();
                      i !=_allSuites().end(); ++i ) {

                    torun.push_back( i->first );
                }
            }

            std::vector<Result*> results;

            for ( std::vector<std::string>::iterator i=torun.begin(); i!=torun.end(); i++ ) {
                std::string name = *i;
                Suite* s = _allSuites()[name];
                fassert( 16145,  s );

                log() << "going to run suite: " << name << std::endl;
                results.push_back( s->run( filter, runsPerTest ) );
            }

            log() << "**************************************************" << std::endl;

            int rc = 0;

            int tests = 0;
            int fails = 0;
            int asserts = 0;

            for ( std::vector<Result*>::iterator i=results.begin(); i!=results.end(); i++ ) {
                Result* r = *i;
                log() << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();

                tests += r->_tests;
                fails += r->_fails;
                asserts += r->_asserts;
            }

            Result totals ("TOTALS");
            totals._tests = tests;
            totals._fails = fails;
            totals._asserts = asserts;

            log() << totals.toString(); // includes endl

            return rc;
        }