summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Rosen <jeremy.rosen@smile.fr>2023-10-10 15:49:29 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-10-15 09:11:40 +0100
commit00d64ac38ae4af6193fae3b02375a16b1821f29e (patch)
tree6295967779b8e77a8740f5944498e6b2773d0761
parent282ae38543e22cbdcbf69c64eace551997927ce3 (diff)
downloadopenembedded-core-00d64ac38ae4af6193fae3b02375a16b1821f29e.tar.gz
insane: Detect python and perl based tests
match_line_in_files will look for a regex in all files matching a glob. we use iglob to avoid a complete, recursive scan of all source. iglob is based on python iterators and will scan as we walk through the directories pytest are detected by looking for "import pytest" or "from pytest" in any python file. perl Test:: is detetected by looking for any t/*.t in the toplevel source directory. Signed-off-by: Jérémy Rosen <jeremy.rosen@smile.fr> Reviewed-by: Yoann Congal <yoann.congal@smile.fr> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
-rw-r--r--meta/classes-global/insane.bbclass22
1 files changed, 22 insertions, 0 deletions
diff --git a/meta/classes-global/insane.bbclass b/meta/classes-global/insane.bbclass
index c40bae7e3d..99b8faccf5 100644
--- a/meta/classes-global/insane.bbclass
+++ b/meta/classes-global/insane.bbclass
@@ -1351,12 +1351,34 @@ python do_qa_patch() {
###########################################################################
# Check for missing ptests
###########################################################################
+ def match_line_in_files(toplevel, filename_glob, line_regex):
+ import pathlib
+ toppath = pathlib.Path(toplevel)
+ for entry in toppath.glob(filename_glob):
+ try:
+ with open(entry, 'r', encoding='utf-8', errors='ignore') as f:
+ for line in f.readlines():
+ if re.match(line_regex, line):
+ return True
+ except FileNotFoundError:
+ # Broken symlink in source
+ pass
+ return False
+
srcdir = d.getVar('S')
if not bb.utils.contains('DISTRO_FEATURES', 'ptest', True, False, d):
pass
elif bb.data.inherits_class('ptest', d):
bb.note("Package %s QA: skipping unimplemented-ptest: ptest implementation detected" % d.getVar('PN'))
+ # Detect perl Test:: based tests
+ elif os.path.exists(os.path.join(srcdir, "t")) and any(filename.endswith('.t') for filename in os.listdir(os.path.join(srcdir, 't'))):
+ oe.qa.handle_error("unimplemented-ptest", "%s: perl Test:: based tests detected" % d.getVar('PN'), d)
+
+ # Detect pytest-based tests
+ elif match_line_in_files(srcdir, "**/*.py", r'\s*(?:import\s*pytest|from\s*pytest)'):
+ oe.qa.handle_error("unimplemented-ptest", "%s: pytest-based tests detected" % d.getVar('PN'), d)
+
oe.qa.exit_if_errors(d)
}