#!/bin/python import os, sys from io import StringIO as buf from subprocess import PIPE, Popen root = "/home/nolln/root/test" def usage(): print("usage:") print("runtest [dir | file]*") def run(bin): print(f">Test of {os.path.basename(bin)}") cmd = Popen(bin, stdout=PIPE, stderr=PIPE) out, err = cmd.communicate() print(">>output:") for line in buf(out.decode('utf-8')).readlines(): print(f" {line.strip()}") if len(err) > 0: print(">>errors:") for line in buf(err.decode('utf-8')).readlines(): print(f" {line.strip()}") print(f">>[OK]") def walk(dir): for root, _, bins in os.walk(dir): for bin in bins: run(f"{root}/{bin}") def main(args): for arg in args: dir = f"{root}/{arg}" if os.path.isdir(dir): if not os.path.exists(dir): raise ValueError(f"directory '{dir}' does not exist") print(f"Running tests of {arg}") print("---------------------------------------------------") walk(dir) else: bin = dir if not os.path.exists(bin): raise ValueError(f"binary '{bin}' does not exist") run(bin) if __name__ == "__main__": if len(sys.argv) == 1: usage() main(sys.argv[1:])