7 retval = re.sub('([A-Z])', r'_\1', name).lower()
8 return re.sub('^_', r'', retval)
10 parser = argparse.ArgumentParser()
11 parser.add_argument("suite_name", help="(convention is <NameInUpperCamelCase>, e.g. StringpairList - suite created will then be StringpairListTests)")
12 parser.add_argument("--clobber", "-c", help="Overwrite extant files (must be explicitly indicated)", action='store_true')
14 gengroup = parser.add_mutually_exclusive_group()
15 gengroup.add_argument("--no_src", help="Generate header only, no source", action='store_true')
16 gengroup.add_argument("--no_hdr", help="Generate source only, no header", action='store_true')
18 typegroup = parser.add_mutually_exclusive_group()
19 typegroup.add_argument("--test", "-t", help="Just generate a generic test suite (no engine initialisation or db/gpg setup/teardown - default)", action='store_true')
20 typegroup.add_argument("--indiv", "-i", help="Generate a test suite with engine initialisation/release and gpg/db teardown between each test function", action='store_true')
21 typegroup.add_argument("--session", "-s", help="Generate a test suite with engine initialisation/release and gpg/db teardown only at the beginning and end of the test suite", action='store_true')
23 args = parser.parse_args()
25 suitename = args.suite_name
26 test_suite = suitename + "Tests"
28 superclass = "EngineTestSuite"
31 superclass = "EngineTestIndividualSuite"
33 superclass = "EngineTestSessionSuite"
35 print("\nCreating " + test_suite + " as an " + superclass + "\n")
37 uncamel = decamel(suitename)
41 nspace = "using namespace std;\n\n"
43 license = ("// This file is under GNU General Public License 3.0\n"
44 "// see LICENSE.txt\n\n")
46 default_single_testname = "check_" + re.sub('_tests$', r'', uncamel)
50 header_def = uncamel.upper() + "_H"
52 deftxt = "#ifndef " + header_def + "\n#define " + header_def + "\n\n"
54 header_inc = ("#include <string>\n"
55 "#include \"" + superclass + ".h\"\n\n")
57 header = license + deftxt + header_inc + nspace
60 classdef = "class " + test_suite + " : public " + superclass + " {\n" + \
62 " " + test_suite + "(string test_suite, string test_home_dir);\n" + \
64 " void " + default_single_testname + "();\n" + \
67 header_file = header + classdef + "\n#endif\n"
72 hfile_name = test_suite + ".h"
73 hfile_path = os.path.join(os.path.join(os.getcwd(), "include"), hfile_name)
76 if (os.path.isfile(hfile_path)):
77 print(hfile_path + " exists. Not writing header file. Use --clobber to overwrite.")
81 header_out = open(hfile_path, 'w')
82 header_out.write(header_file)
86 src_inc = ('#include <stdlib.h>\n'
87 '#include <string>\n\n'
88 '#include "pEpEngine.h"\n\n'
89 '#include "' + superclass +'.h"\n'
90 '#include "' + test_suite + '.h"\n\n')
92 test_suite_prefix = test_suite + "::"
93 fname = test_suite_prefix + default_single_testname
95 constructor = test_suite_prefix + test_suite + "(string suitename, string test_home_dir) :\n" + \
96 " " + superclass + "::" + superclass + "(suitename, test_home_dir) {\n" + \
97 " add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string(\"" + fname + "\"),\n" + \
98 " static_cast<Func>(&" + fname + ")));\n" + \
101 def_funct = "void " + test_suite_prefix + default_single_testname + "() {\n" + \
102 " TEST_ASSERT(true);\n" + \
105 src_file = license + src_inc + nspace + constructor + def_funct
108 sfile_name = test_suite + ".cc"
109 sfile_path = os.path.join(os.path.join(os.getcwd(), "src/engine_tests"), sfile_name)
112 if (os.path.isfile(sfile_path)):
113 print(sfile_path + " exists. Not writing source file. Use --clobber to overwrite.")
117 src_out = open(sfile_path, 'w')
118 src_out.write(src_file)