Fixed generation local_cpptest
authorKrista Bennett <krista@pep-project.org>
Thu, 03 May 2018 12:39:56 +0200
branchlocal_cpptest
changeset 2645a1932fb654b8
parent 2644 271d7a25c8d3
child 2649 52ca3faa2a2d
Fixed generation
test/Makefile
test/gensuitemaker.py
test/include/DecorateTests.h
test/include/EngineTestSessionSuite.h
test/include/EngineTestSuite.h
test/include/SuiteMaker.h
test/src/EngineTestSuite.cc
test/src/SuiteMaker.cc
     1.1 --- a/test/Makefile	Thu May 03 12:01:06 2018 +0200
     1.2 +++ b/test/Makefile	Thu May 03 12:39:56 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
    1.12 @@ -100,11 +100,9 @@
    1.13  test_home_: 
    1.14  	mkdir -p $(TEST_HOME)
    1.15  
    1.16 -TEST_CMD_=$(TARGET)
    1.17 -
    1.18  .PHONY: test
    1.19  test: all
    1.20 -	./$(TARGET) $(TEST_CMD_)
    1.21 +	./$(TARGET)
    1.22  	
    1.23  .PHONY: clean
    1.24  clean:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/gensuitemaker.py	Thu May 03 12:39:56 2018 +0200
     2.3 @@ -0,0 +1,97 @@
     2.4 +# This file is under GNU General Public License 3.0
     2.5 +# see LICENSE.txt
     2.6 +
     2.7 +from os import listdir, getcwd
     2.8 +from os.path import isfile, join
     2.9 +from re import sub
    2.10 +import datetime
    2.11 +
    2.12 +srcpath = join(getcwd(), "src/engine_tests")
    2.13 +
    2.14 +ls = listdir(srcpath)
    2.15 +
    2.16 +suites = []
    2.17 +
    2.18 +indent = "    "
    2.19 +
    2.20 +for f in ls:
    2.21 +    if isfile(join(srcpath, f)):
    2.22 +        if (f.endswith(".cc")):
    2.23 +            suite = sub('\.cc$', '', f)
    2.24 +            suites.append(suite)
    2.25 +
    2.26 +license = (''
    2.27 +'// This file is under GNU General Public License 3.0\n'
    2.28 +'// see LICENSE.txt\n\n')
    2.29 +
    2.30 +
    2.31 +header = license + "//\n// src/SuiteMaker.cc generated by gensuitemaker.py - changes may be overwritten. You've been warned!\n//\n\n"
    2.32 +
    2.33 +header += (''
    2.34 +'#include <cpptest.h>\n'
    2.35 +'#include <cpptest-suite.h>\n'
    2.36 +'#include <memory>\n'
    2.37 +'#include <vector>\n'
    2.38 +'#include "SuiteMaker.h"\n')
    2.39 +
    2.40 +suiteincludes = ""
    2.41 +
    2.42 +for s in suites:
    2.43 +    suiteincludes += '#include "' + s + '.h"\n'
    2.44 +
    2.45 +output = header + "\n// Begin where we generate stuff\n" + suiteincludes + "\n"
    2.46 +
    2.47 +output += ("\n"
    2.48 +"const char* SuiteMaker::all_suites[] = {\n")
    2.49 +
    2.50 +first = True
    2.51 +
    2.52 +for s in suites:
    2.53 +    output += indent + '"' + s + '",\n'
    2.54 +
    2.55 +output += "};\n\n"
    2.56 +
    2.57 +output += (
    2.58 +'// This file is generated, so magic constants are ok.\n'
    2.59 +'int SuiteMaker::num_suites = ')
    2.60 +
    2.61 +output += str(len(suites)) + ";\n\n"
    2.62 +    
    2.63 +output += "void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {\n"
    2.64 +
    2.65 +first = True
    2.66 +
    2.67 +for s in suites:
    2.68 +    output += indent
    2.69 +    
    2.70 +    if not first:
    2.71 +        output += "else "
    2.72 +    else:
    2.73 +        first = False
    2.74 +    
    2.75 +    output += ('if (strcmp(test_class_name, "' + s + '") == 0)\n' + 
    2.76 +               indent + indent + '*test_suite = new ' + s + '(test_class_name, test_home);\n')
    2.77 +        
    2.78 +output += "}\n\n"
    2.79 +
    2.80 +output += (
    2.81 +'void SuiteMaker::suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites) {\n'
    2.82 +'    for (int i = 0; i < num_to_run; i++) {\n'
    2.83 +'        Test::Suite* suite = NULL;\n'
    2.84 +'        SuiteMaker::suitemaker_build(test_class_names[i], test_home, &suite);\n'
    2.85 +'        if (!suite)\n'
    2.86 +'            throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously\n'
    2.87 +'        test_suites.push_back(suite);\n'
    2.88 +'    }\n'    
    2.89 +'}'
    2.90 +'\n'
    2.91 +'void SuiteMaker::suitemaker_buildall(const char* test_home, std::vector<Test::Suite*>& test_suites) {\n'
    2.92 +'    SuiteMaker::suitemaker_buildlist(SuiteMaker::all_suites, SuiteMaker::num_suites, test_home, test_suites);\n'
    2.93 +'}\n\n')
    2.94 +
    2.95 +suitemaker = open("src/SuiteMaker.cc", 'w') 
    2.96 +suitemaker.write(output)
    2.97 +suitemaker.close()
    2.98 +
    2.99 +generated_at = ("src/SuiteMaker.cc" + " generated at " + datetime.datetime.now().strftime('%c'))
   2.100 +print(generated_at)
     3.1 --- a/test/include/DecorateTests.h	Thu May 03 12:01:06 2018 +0200
     3.2 +++ b/test/include/DecorateTests.h	Thu May 03 12:39:56 2018 +0200
     3.3 @@ -1,7 +1,8 @@
     3.4 +// This file is under GNU General Public License 3.0
     3.5 +// see LICENSE.txt
     3.6 +
     3.7  #ifndef DECORATE_TESTS_H
     3.8  #define DECORATE_TESTS_H
     3.9 -// This file is under GNU General Public License 3.0
    3.10 -// see LICENSE.txt
    3.11  
    3.12  #include <string>
    3.13  #include "EngineTestIndividualSuite.h"
     4.1 --- a/test/include/EngineTestSessionSuite.h	Thu May 03 12:01:06 2018 +0200
     4.2 +++ b/test/include/EngineTestSessionSuite.h	Thu May 03 12:39:56 2018 +0200
     4.3 @@ -12,6 +12,6 @@
     4.4  class EngineTestSessionSuite : public EngineTestSuite {
     4.5      public:
     4.6          EngineTestSessionSuite(string suitename, string test_home_dir);
     4.7 -        ~EngineTestSessionSuite();
     4.8 +        virtual ~EngineTestSessionSuite();
     4.9  };
    4.10  #endif
     5.1 --- a/test/include/EngineTestSuite.h	Thu May 03 12:01:06 2018 +0200
     5.2 +++ b/test/include/EngineTestSuite.h	Thu May 03 12:39:56 2018 +0200
     5.3 @@ -12,6 +12,7 @@
     5.4  class EngineTestSuite : public Test::Suite {
     5.5      public:
     5.6          EngineTestSuite(string suitename, string test_home_dir);
     5.7 +        virtual ~EngineTestSuite();
     5.8          
     5.9      protected:
    5.10          PEP_SESSION session;
     6.1 --- a/test/include/SuiteMaker.h	Thu May 03 12:01:06 2018 +0200
     6.2 +++ b/test/include/SuiteMaker.h	Thu May 03 12:39:56 2018 +0200
     6.3 @@ -1,3 +1,6 @@
     6.4 +// This file is under GNU General Public License 3.0
     6.5 +// see LICENSE.txt
     6.6 +
     6.7  #ifndef SUITEMAKER_H
     6.8  #define SUITEMAKER_H
     6.9  
     7.1 --- a/test/src/EngineTestSuite.cc	Thu May 03 12:01:06 2018 +0200
     7.2 +++ b/test/src/EngineTestSuite.cc	Thu May 03 12:39:56 2018 +0200
     7.3 @@ -24,6 +24,8 @@
     7.4      }
     7.5  }
     7.6  
     7.7 +EngineTestSuite::~EngineTestSuite() {}
     7.8 +
     7.9  void EngineTestSuite::set_full_env() {
    7.10  
    7.11      if (test_home.empty())
     8.1 --- a/test/src/SuiteMaker.cc	Thu May 03 12:01:06 2018 +0200
     8.2 +++ b/test/src/SuiteMaker.cc	Thu May 03 12:39:56 2018 +0200
     8.3 @@ -1,18 +1,24 @@
     8.4 +// This file is under GNU General Public License 3.0
     8.5 +// see LICENSE.txt
     8.6 +
     8.7 +//
     8.8 +// src/SuiteMaker.cc generated by gensuitemaker.py - changes may be overwritten. You've been warned!
     8.9 +//
    8.10 +
    8.11  #include <cpptest.h>
    8.12  #include <cpptest-suite.h>
    8.13  #include <memory>
    8.14  #include <vector>
    8.15 +#include "SuiteMaker.h"
    8.16  
    8.17 -
    8.18 -// Begin where we should generate stuff
    8.19 +// Begin where we generate stuff
    8.20  #include "DecorateTests.h"
    8.21  #include "AppleMailTests.h"
    8.22  
    8.23 -#include "SuiteMaker.h"
    8.24  
    8.25  const char* SuiteMaker::all_suites[] = {
    8.26      "DecorateTests",
    8.27 -    "AppleMailTests"
    8.28 +    "AppleMailTests",
    8.29  };
    8.30  
    8.31  // This file is generated, so magic constants are ok.
    8.32 @@ -22,7 +28,7 @@
    8.33      if (strcmp(test_class_name, "DecorateTests") == 0)
    8.34          *test_suite = new DecorateTests(test_class_name, test_home);
    8.35      else if (strcmp(test_class_name, "AppleMailTests") == 0)
    8.36 -        *test_suite = new AppleMailTests(test_class_name, test_home);    
    8.37 +        *test_suite = new AppleMailTests(test_class_name, test_home);
    8.38  }
    8.39  
    8.40  void SuiteMaker::suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites) {
    8.41 @@ -32,9 +38,9 @@
    8.42          if (!suite)
    8.43              throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously
    8.44          test_suites.push_back(suite);
    8.45 -    }    
    8.46 +    }
    8.47  }
    8.48 -
    8.49  void SuiteMaker::suitemaker_buildall(const char* test_home, std::vector<Test::Suite*>& test_suites) {
    8.50      SuiteMaker::suitemaker_buildlist(SuiteMaker::all_suites, SuiteMaker::num_suites, test_home, test_suites);
    8.51  }
    8.52 +