Will need to fix generation, but now set up to run suites in various ways. local_cpptest
authorKrista Bennett <krista@pep-project.org>
Thu, 03 May 2018 12:01:06 +0200
branchlocal_cpptest
changeset 2644271d7a25c8d3
parent 2642 7dbfc6c3f3c8
child 2645 a1932fb654b8
Will need to fix generation, but now set up to run suites in various ways.
test/Makefile
test/include/DecorateTests.h
test/include/SuiteMaker.h
test/src/SuiteMaker.cc
test/src/TestDriver.cc
     1.1 --- a/test/Makefile	Wed May 02 16:59:14 2018 +0200
     1.2 +++ b/test/Makefile	Thu May 03 12:01:06 2018 +0200
     1.3 @@ -6,7 +6,7 @@
     1.4  
     1.5  include ../default.conf
     1.6  
     1.7 -PY_ENV := $(shell command -v python3 2> /dev/null)
     1.8 +#PY_ENV := $(shell command -v python3 2> /dev/null)
     1.9  
    1.10  HERE:=$(CURDIR)
    1.11  TEST_HOME=$(HERE)/pEp_test_home
     2.1 --- a/test/include/DecorateTests.h	Wed May 02 16:59:14 2018 +0200
     2.2 +++ b/test/include/DecorateTests.h	Thu May 03 12:01:06 2018 +0200
     2.3 @@ -3,18 +3,8 @@
     2.4  // This file is under GNU General Public License 3.0
     2.5  // see LICENSE.txt
     2.6  
     2.7 -#include <stdlib.h>
     2.8 -#include <string.h>
     2.9 -#include "platform.h"
    2.10 -#include <iostream>
    2.11 -#include <fstream>
    2.12 -#include <sstream>
    2.13 -#include <cpptest.h>
    2.14 -#include <cpptest-suite.h>
    2.15 -#include <cpptest-textoutput.h>
    2.16 -#include "mime.h"
    2.17 -#include "message_api.h"
    2.18 -#include "test_util.h"
    2.19 +#include <string>
    2.20 +#include "EngineTestIndividualSuite.h"
    2.21  
    2.22  using namespace std;
    2.23  
     3.1 --- a/test/include/SuiteMaker.h	Wed May 02 16:59:14 2018 +0200
     3.2 +++ b/test/include/SuiteMaker.h	Thu May 03 12:01:06 2018 +0200
     3.3 @@ -3,17 +3,20 @@
     3.4  
     3.5  #include <cpptest.h>
     3.6  #include <cpptest-suite.h>
     3.7 -#include <cpptest-textoutput.h>
     3.8 -#include <string>
     3.9 -#include <sys/stat.h>
    3.10 -#include <errno.h>
    3.11 +#include <memory>
    3.12 +#include <vector>
    3.13 +
    3.14  #include "EngineTestSuite.h"
    3.15 -#include "EngineTestIndividualSuite.h"
    3.16 -#include "EngineTestSessionSuite.h"
    3.17  
    3.18 -// Begin where we should generate stuff
    3.19 -#include "DecorateTests.h"
    3.20 +class SuiteMaker {
    3.21 +    public:
    3.22 +        static void suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite);
    3.23 +        static void suitemaker_buildall(const char* test_home, std::vector<Test::Suite*>& test_suites);
    3.24 +        static void suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites);
    3.25  
    3.26 -void suitemaker_build(const char* test_class_name, const char* test_home, std::auto_ptr<Test::Suite>& test_suite);
    3.27 +    private:
    3.28 +        static int num_suites;
    3.29 +        static const char* all_suites[];
    3.30 +};
    3.31  
    3.32  #endif
     4.1 --- a/test/src/SuiteMaker.cc	Wed May 02 16:59:14 2018 +0200
     4.2 +++ b/test/src/SuiteMaker.cc	Thu May 03 12:01:06 2018 +0200
     4.3 @@ -1,31 +1,40 @@
     4.4 -// This file is under GNU General Public License 3.0
     4.5 -// see LICENSE.txt
     4.6  #include <cpptest.h>
     4.7  #include <cpptest-suite.h>
     4.8 -#include <cpptest-textoutput.h>
     4.9 -#include <string>
    4.10 -#include <sys/stat.h>
    4.11 -#include <errno.h>
    4.12 -#include "EngineTestSuite.h"
    4.13 -#include "EngineTestIndividualSuite.h"
    4.14 -#include "EngineTestSessionSuite.h"
    4.15 -#include "SuiteMaker.h"
    4.16 +#include <memory>
    4.17 +#include <vector>
    4.18  
    4.19 -// Begin where we generate stuff
    4.20 +
    4.21 +// Begin where we should generate stuff
    4.22  #include "DecorateTests.h"
    4.23  #include "AppleMailTests.h"
    4.24  
    4.25 -
    4.26 -using namespace std;
    4.27 +#include "SuiteMaker.h"
    4.28  
    4.29 -static const char* const all_suites[] = {
    4.30 +const char* SuiteMaker::all_suites[] = {
    4.31      "DecorateTests",
    4.32 -    "AppleMailTests",
    4.33 +    "AppleMailTests"
    4.34  };
    4.35  
    4.36 -void suitemaker_build(const char* test_class_name, const char* test_home, std::auto_ptr<Test::Suite>& test_suite) {
    4.37 +// This file is generated, so magic constants are ok.
    4.38 +int SuiteMaker::num_suites = 2;
    4.39 +
    4.40 +void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    4.41      if (strcmp(test_class_name, "DecorateTests") == 0)
    4.42 -        test_suite = auto_ptr<Test::Suite> (new DecorateTests(test_class_name, test_home));
    4.43 +        *test_suite = new DecorateTests(test_class_name, test_home);
    4.44      else if (strcmp(test_class_name, "AppleMailTests") == 0)
    4.45 -        test_suite = auto_ptr<Test::Suite> (new AppleMailTests(test_class_name, test_home));
    4.46 +        *test_suite = new AppleMailTests(test_class_name, test_home);    
    4.47  }
    4.48 +
    4.49 +void SuiteMaker::suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites) {
    4.50 +    for (int i = 0; i < num_to_run; i++) {
    4.51 +        Test::Suite* suite = NULL;
    4.52 +        SuiteMaker::suitemaker_build(test_class_names[i], test_home, &suite);
    4.53 +        if (!suite)
    4.54 +            throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously
    4.55 +        test_suites.push_back(suite);
    4.56 +    }    
    4.57 +}
    4.58 +
    4.59 +void SuiteMaker::suitemaker_buildall(const char* test_home, std::vector<Test::Suite*>& test_suites) {
    4.60 +    SuiteMaker::suitemaker_buildlist(SuiteMaker::all_suites, SuiteMaker::num_suites, test_home, test_suites);
    4.61 +}
     5.1 --- a/test/src/TestDriver.cc	Wed May 02 16:59:14 2018 +0200
     5.2 +++ b/test/src/TestDriver.cc	Thu May 03 12:01:06 2018 +0200
     5.3 @@ -3,6 +3,7 @@
     5.4  #include <cpptest-suite.h>
     5.5  #include <cpptest-textoutput.h>
     5.6  #include <string>
     5.7 +#include <vector>
     5.8  #include <sys/stat.h>
     5.9  #include <errno.h>
    5.10  #include "EngineTestSuite.h"
    5.11 @@ -18,12 +19,10 @@
    5.12      throw std::runtime_error("Bad usage. Fix me, you loser developer.");
    5.13  }
    5.14  
    5.15 -int main(int argc, char** argv) {
    5.16 +int main(int argc, const char** argv) {
    5.17      const int MIN_ARGC = 1;
    5.18      if (argc < MIN_ARGC)
    5.19          usage();
    5.20 -
    5.21 -    int start_index = 1;
    5.22      
    5.23      struct stat dirchk;
    5.24      if (stat(common_test_home.c_str(), &dirchk) == 0) {
    5.25 @@ -38,14 +37,17 @@
    5.26      }
    5.27                      
    5.28      EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", common_test_home);
    5.29 +
    5.30 +    std::vector<Test::Suite*> suites_to_run;
    5.31 +    
    5.32 +    if (argc == MIN_ARGC)
    5.33 +        SuiteMaker::suitemaker_buildall(common_test_home.c_str(), suites_to_run);
    5.34 +    else
    5.35 +        SuiteMaker::suitemaker_buildlist(&argv[1], argc - MIN_ARGC, common_test_home.c_str(), suites_to_run);
    5.36          
    5.37 -    for (int i = start_index; i < argc; i++) {
    5.38 -        char* curr_arg = argv[i];
    5.39 -        auto_ptr<Test::Suite> test_suite;
    5.40 -        suitemaker_build(argv[i], common_test_home.c_str(), test_suite);
    5.41 -        if (test_suite.get() == NULL)
    5.42 -            throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously
    5.43 -        test_runner->add(test_suite);
    5.44 +    for (std::vector<Test::Suite*>::iterator it = suites_to_run.begin(); it != suites_to_run.end(); ++it) {
    5.45 +        auto_ptr<Test::Suite> suite(*it);
    5.46 +        test_runner->add(suite); 
    5.47      }
    5.48  
    5.49      Test::TextOutput output(Test::TextOutput::Terse);