You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
import json
|
|
import subprocess
|
|
|
|
class PackageTest:
|
|
def __init__(self):
|
|
self.status = ""
|
|
self.tests = []
|
|
self.totaltime = 0
|
|
|
|
res = {}
|
|
|
|
output = subprocess.run(["go","test","-count=1","-json","./..."], capture_output=True, text=True)
|
|
|
|
output = str(output.stdout)
|
|
output = output.split('\n')
|
|
|
|
for line in output[:-1]:
|
|
# parse the json
|
|
parsed = json.loads(line)
|
|
action = parsed["Action"]
|
|
|
|
# skip
|
|
if action in ["start", "output", "run"]:
|
|
continue
|
|
|
|
# create blank if doesn't exist
|
|
if parsed["Package"] not in res:
|
|
res[parsed["Package"]] = PackageTest()
|
|
|
|
pkg = res[parsed["Package"]]
|
|
|
|
if "Test" not in parsed:
|
|
# top level package result
|
|
pkg.status = action
|
|
if "Elapsed" in parsed:
|
|
pkg.totaltime = parsed["Elapsed"]
|
|
else:
|
|
# individual test
|
|
pkg.tests.append((parsed["Test"],parsed["Action"],parsed["Elapsed"]))
|
|
|
|
# generating output from parsed json
|
|
total = 0
|
|
for name, info in res.items():
|
|
pkgname = name.split('/')
|
|
pkgname = '/'.join(name.split('/')[1:])
|
|
if info.status == "skip":
|
|
print("Skipped %s" % (pkgname))
|
|
continue
|
|
|
|
print("\nTesting %s:" % (pkgname))
|
|
|
|
passed = 0
|
|
total = 0
|
|
|
|
for test in info.tests:
|
|
total += 1
|
|
out = []
|
|
if test[1] == "pass":
|
|
passed += 1
|
|
out = [" " + test[0] + ":",'\033[32mpass\033[0m ','(' + str(test[2]) + 's)']
|
|
elif test[1] == "fail":
|
|
out = [" " + test[0] + ":",'\033[31mfail\033[0m ','(' + str(test[2]) + 's)']
|
|
|
|
print(f"{out[0] : <30}{out[1] : >5}{out[2] : >8}")
|
|
|
|
result = ""
|
|
if info.status == "pass":
|
|
result = "\033[32mPASSED\033[0m"
|
|
else:
|
|
result = "\033[31mFAILED\033[0m"
|
|
|
|
print("summary:\n\t%s (%d/%d in %.3fs)" % (result, passed, total, info.totaltime))
|
|
|
|
|
|
# print("OVERALL:\n\tSkipped %d/%d\n\tFailed %d/%d\n\tPassed %d/%d\n" % (skippedTests, totalTests, failedTests, totalTests, passedTests, totalTests))
|
|
|
|
|