From aef4b64cd2f5bc3ef806fb7201d51bfae71113a8 Mon Sep 17 00:00:00 2001 From: Henry Cox Date: Thu, 19 Dec 2024 06:21:41 -0500 Subject: [PATCH] Python Coverage.py version differences. GitHub regression fixes. Signed-off-by: Henry Cox --- .github/workflows/run_test_suite.yml | 21 ++++++++------------- bin/py2lcov | 3 +-- bin/xml2lcov | 2 +- bin/xml2lcovutil.py | 24 ++++++++++++++++++------ tests/bin/test_run | 2 ++ tests/gendiffcov/errs/msgtest.sh | 3 +++ tests/lcov/errs/errs.sh | 1 + tests/py2lcov/py2lcov.sh | 28 ++++++++++++++-------------- 8 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.github/workflows/run_test_suite.yml b/.github/workflows/run_test_suite.yml index 471bc74..f26916d 100644 --- a/.github/workflows/run_test_suite.yml +++ b/.github/workflows/run_test_suite.yml @@ -81,19 +81,7 @@ jobs: - name: make check run: |- set -x -o pipefail - # NOTE: There are two things going on in this hackery: - # - So far "make check" exits with code 0 despite failures — - # see issue #348 — so we need a more manual approach to detect - # failing tests - # - We compare the number of failing tests to the known status - # quo — see issue #343 — so that - # - we have a chance for a green CI while also - # - we will notice when more of the existing tests start - # to fail. - make check |& tee /dev/stderr \ - | grep -F ' failed, ' | tee /dev/stderr \ - | grep -F -q ', 1 failed, ' \ - || { echo 'Number of tests expected to fail^^ does not match -- did you break an existing test?' >&2 ; false ; } + make check - name: Upload test log as an artifact uses: actions/upload-artifact@v4 @@ -101,3 +89,10 @@ jobs: name: "lcov-${{ github.sha }}-${{ runner.os }}-test-log" # .zip path: tests/test.log if-no-files-found: error + + - name: Upload test directory shrapnel as an artifact + uses: actions/upload-artifact@v4 + with: + name: "lcov-${{ github.sha }}-${{ runner.os }}-shrapnel" # .zip + path: tests + #if-no-files-found: error diff --git a/bin/py2lcov b/bin/py2lcov index ff15747..a22a974 100755 --- a/bin/py2lcov +++ b/bin/py2lcov @@ -140,7 +140,7 @@ Example: help="specify the test name for the TN: entry in LCOV .info file") parser.add_argument('-e', '--exclude', dest='excludePatterns', default='', help="specify the exclude file patterns separated by ','") - parser.add_argument('-v', '--verbose', dest='verbose', default=False, action='store_true', + parser.add_argument('-v', '--verbose', dest='verbose', default=0, action='count', help="print debug messages") parser.add_argument('--version-script', dest='version', help="version extract callback") @@ -195,7 +195,6 @@ Example: env["COVERAGE_FILE"] = f cmd = [args.cover_cmd, "xml", "-o", xml] try: - #x = subprocess.run(cmd, capture_output=True, shell=False, check=True, env=env) x = subprocess.run(cmd, shell=False, check=True, stdout=True, stderr=True, env=env) except subprocess.CalledProcessError as err: print("Error: error during XML conversion of %s: %s" % ( diff --git a/bin/xml2lcov b/bin/xml2lcov index 46dcb4e..ae53501 100755 --- a/bin/xml2lcov +++ b/bin/xml2lcov @@ -80,7 +80,7 @@ Example: help="specify the test name for the TN: entry in LCOV .info file") parser.add_argument('-e', '--exclude', dest='excludePatterns', default='', help="specify the exclude file patterns separated by ','") - parser.add_argument('-v', '--verbose', dest='verbose', default=False, action='store_true', + parser.add_argument('-v', '--verbose', dest='verbose', default=0, action='count', help="print debug messages") parser.add_argument('--version-script', dest='version', help="version extract callback") diff --git a/bin/xml2lcovutil.py b/bin/xml2lcovutil.py index 129ac3e..260a0eb 100644 --- a/bin/xml2lcovutil.py +++ b/bin/xml2lcovutil.py @@ -152,9 +152,14 @@ def process_xml_file(self, xml_file): for source in root[0]: # keep track of number of times we use each source_path to find # some file. Unused source paths are likely a problem. - source_paths.append([source.text, 0]) if self._args.verbose: - print("source: " + source.text) + print("source: '%s'" %(source.text)) + # unclear why the Coverage.py version on GitHub node + # generates empty sources + if source.text == None: + print("skipping empty source (???)") + continue + source_paths.append([source.text, 0]) else: print("Error: parse xml fail: no 'sources' in %s" %(xml_file)) sys.exit(1) @@ -174,17 +179,24 @@ def process_xml_file(self, xml_file): # name="." means current directory # name=".folder1.folder2" means external module or directory # name="abc" means internal module or directory - isExternal = (package.attrib['name'].startswith('.') and package.attrib['name'] != '.') + pname = package.attrib['name'] + if self._args.verbose: + print("package: '%s'" % (pname)) + isExternal = (pname.startswith('.') and pname != '.') #pdb.set_trace() for classes in package: for fileNode in classes: - if self._args.excludePatterns and any([fnmatch.fnmatchcase(fileNode.attrib['filename'], ef) for ef in self._excludePatterns]): + name = fileNode.attrib['filename'] + if self._args.excludePatterns and any([fnmatch.fnmatchcase(name, ef) for ef in self._excludePatterns]): if self._args.verbose: - print("%s is excluded" % fileNode.attrib['filename']) + print("%s is excluded" % name) continue - name = fileNode.attrib['filename'] + if self._args.verbose > 1: + print(" file: %s" % (name)) if not isExternal: for s in source_paths: + if self._args.verbose > 1: + print(" check src_path (%s %d)" % (s[0], s[1])) path = os.path.join(s[0], name) if os.path.exists(path): name = path diff --git a/tests/bin/test_run b/tests/bin/test_run index a39381f..4fb87b7 100755 --- a/tests/bin/test_run +++ b/tests/bin/test_run @@ -157,3 +157,5 @@ fi [ ! -z "$ELAPSED" ] && t_detail "TIME" "${ELAPSED}ms" >>"$LOGFILE" [ ! -z "$RESIDENT" ] && t_detail "MEM" "${RESIDENT}kB" >>"$LOGFILE" t_detail "RESULT" "$RESULT" >> "$LOGFILE" + +exit $RC diff --git a/tests/gendiffcov/errs/msgtest.sh b/tests/gendiffcov/errs/msgtest.sh index 6e4a1ac..9b6cf21 100755 --- a/tests/gendiffcov/errs/msgtest.sh +++ b/tests/gendiffcov/errs/msgtest.sh @@ -817,6 +817,9 @@ if [ 0 != $? ] ; then exit 1 fi fi +if [ -d mycache ] ; then + find mycache -type f -exec chmod ugo+r {} \; +fi echo "Tests passed" diff --git a/tests/lcov/errs/errs.sh b/tests/lcov/errs/errs.sh index 7d1c57e..5c31de2 100755 --- a/tests/lcov/errs/errs.sh +++ b/tests/lcov/errs/errs.sh @@ -305,6 +305,7 @@ if [ 0 != ${PIPESTATUS[0]} ] ; then exit $status fi fi +chmod ugo+rx emptyDir # data consistency errors: # - function marked 'hit' but no contained lines are hit diff --git a/tests/py2lcov/py2lcov.sh b/tests/py2lcov/py2lcov.sh index 94c8d4a..860d31d 100755 --- a/tests/py2lcov/py2lcov.sh +++ b/tests/py2lcov/py2lcov.sh @@ -1,5 +1,5 @@ #!/bin/bash -set +x +set -x CLEAN_ONLY=0 COVER= @@ -154,7 +154,7 @@ if [ 0 != $? ] ; then fi # some corner cases: -COVERAGE_FILE=./functions.dat $CMD run --branch ./test.py +COVERAGE_FILE=./functions.dat $CMD run --branch ./test.py -v -v if [ 0 != $? ] ; then echo "coverage functions failed" if [ 0 == $KEEP_GOING ] ; then @@ -182,19 +182,19 @@ done # look for expected location and function hit counts: for d in \ 'FN functions.info' \ - 'FNL:0,10,12' \ - 'FNA:0,0,unusedFunc' \ - 'FNL:1,2,7' \ - 'FNA:1,1,enter' \ - 'FNL:0,10,18' \ - 'FNA:0,0,main.localfunc' \ - 'FNL:1,12,16' \ - 'FNA:1,0,main.localfunc.nested1' \ - 'FNL:2,13,14' \ - 'FNA:2,0,main.localfunc.nested1.nested2' \ - 'FNL:3,5,18' \ + 'FNL:[0-9],10,12' \ + 'FNA:[0-9],0,unusedFunc' \ + 'FNL:[0-9],2,7' \ + 'FNA:[0-9],1,enter' \ + 'FNL:[0-9],10,18' \ + 'FNA:[0-9],0,main.localfunc' \ + 'FNL:[0-9],12,16' \ + 'FNA:[0-9],0,main.localfunc.nested1' \ + 'FNL:[0-9],13,14' \ + 'FNA:[0-9],0,main.localfunc.nested1.nested2' \ + 'FNL:[0-9],5,18' \ ; do - grep $d functions.info + grep -E $d functions.info if [ 0 != $? ] ; then echo "did not find expected function data $d" if [ 0 == $KEEP_GOING ] ; then