aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Lira <larry@expertisesolutions.com.br>2018-09-11 00:44:17 -0300
committerLarry Lira <larry@expertisesolutions.com.br>2018-09-11 00:44:17 -0300
commit7b9a9cb35fb7ebc7865a5f8ec7e223fbe3839b19 (patch)
tree4787a806014085eb147fe879f7b9cb5d58e207c7
parenttestgen: Fix compilation of generated csharp code (diff)
downloadefl-7b9a9cb35fb7ebc7865a5f8ec7e223fbe3839b19.tar.gz
testgen: added README.md
- How to use testgen - Fixed cmd line --help
-rw-r--r--src/scripts/testgen/README.md127
-rw-r--r--src/scripts/testgen/suitegen.py20
-rwxr-xr-xsrc/scripts/testgen/testgen.py17
3 files changed, 141 insertions, 23 deletions
diff --git a/src/scripts/testgen/README.md b/src/scripts/testgen/README.md
new file mode 100644
index 0000000000..278d273019
--- /dev/null
+++ b/src/scripts/testgen/README.md
@@ -0,0 +1,127 @@
+
+Testgen: Template-based Eolian tests generator
+=====================================================================
+
+Testgen is a Python Script using the Pyolian to generate tests rendering
+templates with custom files, this can be a easy way to expand the
+API test coveraged.
+
+Testgen can generate tests C and to other bingings languages only
+adding new language specialized templates.
+
+Installation
+============
+
+There is nothing to install to use the generator, everything is included in
+the efl source tree and it is intended to work directly inside the tree,
+usually at efl tests compilation time (make check).
+
+The only requirement is that **the source tree must be already built** (not
+installed) because pyolian search the eolian .so/.dll inside the source tree.
+
+If you built the efl tree in a custom location (fe, you build out-of-tree) you
+can tell pyolian where to find the built eolian .so files using the
+`EOLIAN_SO_DIR` environment variable.
+
+
+Command line usage
+==================
+
+The simplest way to use the generator is from the command line, using the
+`src/scripts/testgen/testgen.py` command, the `--help` option state:
+
+```
+usage: testgen.py [-h] testname suitename filename [eofiles [eofiles ...]]
+
+Eolian Test Generator.
+
+positional arguments:
+ testname The Test Name used to find custom and template files. (REQUIRED)
+ suitename The Suite Name used to find custom files. (REQUIRED)
+ filename Generated test file destination. (REQUIRED)
+ eofiles The Eolian Files to use.
+
+optional arguments:
+ -h, --help show this help message and exit
+```
+Use .c extension to generate C tests or .cs to CSharp (.cpp too in the future)
+
+To test this generator in `src/scripts/testgen` you can run:
+```
+./testgen.py automated efl efl_automated_test.c efl_loop.eo
+```
+This will rendere the automated tests using files in `src/tests/automated` with suite
+name `efl_automated` and with Efl.Loop Class as Test Case `efl_automated_efl_loop_test`
+
+or run:
+```
+./testgen.py automated eio eio_automated_test.c eio_sentry.eo eio_model.eo
+```
+This will rendere with suite name `eio_automated` and with Eio.Sentry and Eio.Model
+Class as Test Cases `eio_automated_eio_sentry_test` and `eio_automated_eio_model_test`
+
+
+How customise a Generated Test
+==============================
+
+Testgen use the filesystem to find custom files if you need customise a test,
+add/write follow files in src/tests:
+
+ Suite custom files
+ * `src/test/<testname>/`
+ |-> <suitename>_custom.c #add include files and global functions or structs
+ |-> <suitename>_init.c #add code in SUITE_INIT
+ |-> <suitename>_shutdown.c #add code in SUITE_SHUTDOWN
+
+ Class Test case custom files
+ * `src/test/<testname>/<class_name>/` #use lowercase and `_` separator
+ |-> custom.c #add include files and global functions or structs
+ |-> init.c #add default way to create the object of this class
+ |-> shutdown.c #add default way to free the object
+
+Funtions Tests
+- Tests methodes custom files
+ * `src/test/<testname>/<class_name>/<method_name>`
+ |-> arg_init.c #initialize arguments of the method (arg_<argument_name>)
+ |-> init.c #add how to create the object (replace default)
+ |-> arg_shutdown.c #free arguments
+ |-> shutdown.c #add how to free the object (replace default)
+
+- Tests properties custom files
+ * `src/test/<testname>/<class_name>/<property_name>`
+ | -- Property Get --
+ |-> arg_get_init.c #initialize arguments of property get (arg_<argument_name>)
+ |-> get_init.c #how to create the object (replace default)
+ |-> arg_get_shutdown.c #free arguments
+ |-> get_shutdown.c #how to free the object (replace default)
+ | -- Property Set --
+ |-> arg_set_init.c #initialize arguments of propety set (arg_<argument_name>)
+ |-> set_init.c #how to create the object (replace default)
+ |-> arg_set_shutdown.c #free arguments
+ |-> set_shutdown.c #how to free the object (replace default)
+
+to make some custom files you only need a code using:
+ `parent` -> default name of parent object defined as `Eo *`
+ `obj` -> default name of current object
+ `arg_<name>` -> replace <name> with functions arguments name
+
+you can use custom.c (suite or class) to add specilized code, structs and callbacks
+
+-- Use `*.cs` to Emono/CSharp generated code --
+
+
+Where to find more info
+=======================
+
+ * read the Pyolian README file in EFL scripts
+ * read the eolian.py file (it declare the full eolian API)
+ * read the generator.py file (it's super simple)
+ * read the original [pyratemp docs](https://www.simple-is-better.org/template/pyratemp.html)
+
+
+Note
+====
+
+This markdown file is mirrored in efl src tree (src/scripts/pyolian) and in
+phab wiki (phab.enlightenment.org/w/pyolian). Don't forget to update the other
+if you change one!
diff --git a/src/scripts/testgen/suitegen.py b/src/scripts/testgen/suitegen.py
index 7762e74c4f..654acb9e8e 100644
--- a/src/scripts/testgen/suitegen.py
+++ b/src/scripts/testgen/suitegen.py
@@ -2,7 +2,6 @@ import itertools
import os
from testgen.ekeys import GetKey
-
class BaseItem:
def __init__(self, path, keys, prefix=""):
self.path = path
@@ -11,7 +10,7 @@ class BaseItem:
def __getattr__(self, attr):
if not attr.split("_")[-1] in self.keys.keyloads:
- raise AttributeError
+ raise AttributeError("Error getting {}".format(attr))
filename = os.path.join(self.path, self.prefix + attr) + self.keys.ext
if os.path.isfile(filename):
@@ -19,7 +18,6 @@ class BaseItem:
return f.read()
return None
-
class ComItem(BaseItem):
def __init__(self, comp, path, keys):
super().__init__(path, keys)
@@ -30,10 +28,8 @@ class ComItem(BaseItem):
return getattr(self.comp, attr)
return super().__getattr__(attr)
-
class FuncItem(ComItem):
def __init__(self, comp, path, keys):
- print(comp.name)
super().__init__(comp, os.path.join(path, comp.name), keys)
@property
@@ -43,7 +39,6 @@ class FuncItem(ComItem):
names.insert(0, names.pop())
return "".join([name.capitalize() for name in names])
-
class ClassItem(ComItem):
def __init__(self, comp, path, keys):
self.myname = os.path.splitext(comp.file)[0]
@@ -71,14 +66,13 @@ class ClassItem(ComItem):
def __iter__(self):
return itertools.chain(self.methods, self.properties)
-
class SuiteGen(BaseItem):
def __init__(self, name, testname, filename, path, template=None):
keys = GetKey(os.path.splitext(filename)[1])
super().__init__(path, keys, name + "_")
self.name = name
self.testname = testname
- self.fullname = "{}_{}".format(name, testname)
+ self.fullname = "_".join([name, testname]) if testname else name
self.filename = filename
self.template = template
self.clslist = []
@@ -98,13 +92,15 @@ class SuiteGen(BaseItem):
def print_arg(self, eoarg):
return self.keys.print_arg(eoarg)
- def load(self, eolian_db, eofiles):
+ def loadFiles(self, eolian_db, eofiles):
self.clslist.clear()
for eofile in eofiles:
eocls = eolian_db.class_by_file_get(os.path.basename(eofile))
if not eocls or eocls.type != eocls.type.REGULAR:
continue
+ self.loadObj(eocls)
- cls = ClassItem(eocls, self.path, self.keys)
- cls.myfullname = "{}_{}".format(self.fullname, cls.myname)
- self.clslist.append(cls)
+ def loadObj(self, eocls):
+ cls = ClassItem(eocls, self.path, self.keys)
+ cls.myfullname = "{}_{}".format(self.fullname, cls.myname)
+ self.clslist.append(cls)
diff --git a/src/scripts/testgen/testgen.py b/src/scripts/testgen/testgen.py
index 6a2b769d47..b91d7b7e81 100755
--- a/src/scripts/testgen/testgen.py
+++ b/src/scripts/testgen/testgen.py
@@ -48,11 +48,6 @@ def cleanup_db():
atexit.register(cleanup_db)
-"""
-It will find methods and functions with owned return and without other params
-"""
-
-
class Template(pyratemp.Template):
def __init__(
self,
@@ -101,18 +96,18 @@ class Template(pyratemp.Template):
if __name__ == "__main__":
import argparse
- parser = argparse.ArgumentParser(description="Pyolian search owned functions.")
- parser.add_argument("testname", help="The Test Name to use. (REQUIRED)")
- parser.add_argument("suitename", help="The Suite Name to use. (REQUIRED)")
- parser.add_argument("filename", help="Build file dest. (REQUIRED)")
- parser.add_argument("eofiles", nargs="*", help="The Eolian File to use.")
+ parser = argparse.ArgumentParser(description="Eolian Test Generator.")
+ parser.add_argument("testname", help="The Test Name used to find custom and template files. (REQUIRED)")
+ parser.add_argument("suitename", help="The Suite Name used to find custom files. (REQUIRED)")
+ parser.add_argument("filename", help="Generated test file destination. (REQUIRED)")
+ parser.add_argument("eofiles", nargs="*", help="The Eolian Files to use.")
args = parser.parse_args()
testdir = os.path.join(root_path, "src", "tests", args.testname)
suite = SuiteGen(args.suitename, args.testname, args.filename, testdir)
- suite.load(eolian_db, args.eofiles)
+ suite.loadFiles(eolian_db, args.eofiles)
t = Template(suite.template)
# try: