tests: add support to junit output for marking what tests were excluded and all files that were processed
[ci skip]
This commit is contained in:
6
tests.mk
6
tests.mk
@@ -81,8 +81,10 @@ lint:
|
|||||||
# these are disabled due to their expansive existence in the codebase. we should clean it up though
|
# these are disabled due to their expansive existence in the codebase. we should clean it up though
|
||||||
@cat tests/shellcheck-exclude | sed -n -e '/^# SC/p'
|
@cat tests/shellcheck-exclude | sed -n -e '/^# SC/p'
|
||||||
@echo linting...
|
@echo linting...
|
||||||
@mkdir -p test-results/shellcheck
|
@mkdir -p test-results/shellcheck tmp/shellcheck
|
||||||
@$(QUIET) find . -not -path '*/\.*' -not -path './debian/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' | xargs shellcheck -e $(shell cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' | cut -d' ' -f2 | paste -d, -s) | tests/shellcheck-to-junit --output test-results/shellcheck/results.xml
|
@$(QUIET) find . -not -path '*/\.*' -not -path './debian/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' > tmp/shellcheck/test-files
|
||||||
|
@$(QUIET) cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' | cut -d' ' -f2 | paste -d, -s > tmp/shellcheck/exclude
|
||||||
|
@$(QUIET) cat tmp/shellcheck/test-files | xargs shellcheck -e $(shell cat tmp/shellcheck/exclude) | tests/shellcheck-to-junit --output test-results/shellcheck/results.xml --files tmp/shellcheck/test-files --exclude $(shell cat tmp/shellcheck/exclude)
|
||||||
|
|
||||||
ci-go-coverage:
|
ci-go-coverage:
|
||||||
docker run --rm -ti \
|
docker run --rm -ti \
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ def process_lines(lines):
|
|||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
def output_junit(files, output=None):
|
def output_junit(files, args):
|
||||||
timestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
|
timestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
|
||||||
failures = 0
|
failures = 0
|
||||||
for file, data in files.items():
|
for file, data in files.items():
|
||||||
@@ -99,9 +99,14 @@ def output_junit(files, output=None):
|
|||||||
for issue in issue_data.get('issues', []):
|
for issue in issue_data.get('issues', []):
|
||||||
failures += 1
|
failures += 1
|
||||||
|
|
||||||
|
tests = 0
|
||||||
|
if args.files:
|
||||||
|
with open(args.files, 'r') as f:
|
||||||
|
tests = len(f.readlines())
|
||||||
|
|
||||||
root = ElementTree.Element("testsuite",
|
root = ElementTree.Element("testsuite",
|
||||||
name="shellcheck",
|
name="shellcheck",
|
||||||
tests="0",
|
tests="{0}".format(tests),
|
||||||
failures="{0}".format(failures),
|
failures="{0}".format(failures),
|
||||||
errors="0",
|
errors="0",
|
||||||
skipped="0",
|
skipped="0",
|
||||||
@@ -109,32 +114,50 @@ def output_junit(files, output=None):
|
|||||||
time="0",
|
time="0",
|
||||||
hostname=socket.gethostname())
|
hostname=socket.gethostname())
|
||||||
|
|
||||||
ElementTree.SubElement(root, "properties")
|
properties = ElementTree.SubElement(root, "properties")
|
||||||
for file, data in files.items():
|
if args.exclude:
|
||||||
for line, issue_data in data.items():
|
ElementTree.SubElement(properties,
|
||||||
code = issue_data.get('code')
|
"property",
|
||||||
for issue in issue_data.get('issues', []):
|
name="exclude",
|
||||||
testcase = ElementTree.SubElement(root,
|
value=args.exclude)
|
||||||
"testcase",
|
|
||||||
classname=file,
|
if args.files:
|
||||||
name=file,
|
with open(args.files, 'r') as f:
|
||||||
time="0")
|
lines = f.readlines()
|
||||||
shellcheck_id = issue.get('shellcheck_id')
|
for i in range(len(lines)):
|
||||||
message = 'line {0}: {1}'.format(line, issue.get('message'))
|
file = lines[i].rstrip().replace('./', '')
|
||||||
original_message = issue.get('original_message')
|
data = files.get(file, None)
|
||||||
e = ElementTree.Element("failure",
|
if data:
|
||||||
type=shellcheck_id,
|
for line, issue_data in data.items():
|
||||||
message=message)
|
code = issue_data.get('code')
|
||||||
cdata = CDATA("\n".join([code, original_message]))
|
for issue in issue_data.get('issues', []):
|
||||||
e.append(cdata)
|
testcase = ElementTree.SubElement(root,
|
||||||
testcase.append(e)
|
"testcase",
|
||||||
|
classname=file,
|
||||||
|
name=file,
|
||||||
|
time="0")
|
||||||
|
shellcheck_id = issue.get('shellcheck_id')
|
||||||
|
message = 'line {0}: {1}'.format(
|
||||||
|
line, issue.get('message'))
|
||||||
|
original_message = issue.get('original_message')
|
||||||
|
e = ElementTree.Element("failure",
|
||||||
|
type=shellcheck_id,
|
||||||
|
message=message)
|
||||||
|
cdata = CDATA("\n".join([code, original_message]))
|
||||||
|
e.append(cdata)
|
||||||
|
testcase.append(e)
|
||||||
|
ElementTree.SubElement(root,
|
||||||
|
"testcase",
|
||||||
|
classname=file,
|
||||||
|
name=file,
|
||||||
|
time="0")
|
||||||
|
|
||||||
ElementTree.SubElement(root, "system-out")
|
ElementTree.SubElement(root, "system-out")
|
||||||
ElementTree.SubElement(root, "system-err")
|
ElementTree.SubElement(root, "system-err")
|
||||||
|
|
||||||
content = ElementTree.tostring(root, encoding='UTF-8', method='xml')
|
content = ElementTree.tostring(root, encoding='UTF-8', method='xml')
|
||||||
if output:
|
if args.output:
|
||||||
with open(output, 'w') as f:
|
with open(args.output, 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
|
||||||
@@ -146,12 +169,22 @@ def main():
|
|||||||
action='store',
|
action='store',
|
||||||
default=None,
|
default=None,
|
||||||
help='file to write shellcheck output')
|
help='file to write shellcheck output')
|
||||||
|
parser.add_argument('--files',
|
||||||
|
dest='files',
|
||||||
|
action='store',
|
||||||
|
default=None,
|
||||||
|
help='a file containing a list of all files processed by shellcheck')
|
||||||
|
parser.add_argument('--exclude',
|
||||||
|
dest='exclude',
|
||||||
|
action='store',
|
||||||
|
default=None,
|
||||||
|
help='a comma-separated list of rules being excluded by shellcheck')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
lines = read_in()
|
lines = read_in()
|
||||||
files = process_lines(lines)
|
files = process_lines(lines)
|
||||||
files = collections.OrderedDict(sorted(files.items()))
|
files = collections.OrderedDict(sorted(files.items()))
|
||||||
output_junit(files, args.output)
|
output_junit(files, args)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
print(line)
|
print(line)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user