aboutsummaryrefslogtreecommitdiff
path: root/prettier.py
blob: ce8a839ac2fc1102d0d91811fc574a18462a0cdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import sys
import re
import argparse


def green(*strings):
    return "".join([f"\033[32m{s}\033[0m" for s in strings])


def red(*strings):
    return "".join([f"\033[31m{s}\033[0m" for s in strings])


def parse_args():
    parser = argparse.ArgumentParser( prog="ft_printf test", description="A ~quicker tester for ft_printf")
    parser.add_argument("-v", "--verbose",
                        help="increase verbosity", action="store_true")
    parser.add_argument("-q", "--quiet",
                        help="decrease vebosity", action="store_true")
    parser.add_argument("-l", "--no-log",
                        help="disable result log", action="store_true")
    parser.add_argument("-c", "--no-clear", help="disable terminal clear before output")
    parser.add_argument("-i", "--interactive", help="print fail as them come",
                        action="store_true")
    parser.add_argument("-f", "--output-file", help="output file name")
    return vars(parser.parse_args(sys.argv[1:]))


def print_log_ko(ko, options):
    print(f"- [{red(ko['type'])}] ft_printf({ko['args']})")
    if options["verbose"]:
        print("   expected: ", ko["expected"])
        print("   actual:   ", ko["actual"])
        print()

def create_logs_entry(logs, key):
    logs[key] = {}
    logs[key]["ok_counter"] = 0
    logs[key]["ko_counter"] = 0
    logs[key]["ko_info"] = []

def parse():
    logs = {}
    for line in sys.stdin:
        line = line.strip()
        if line[:2] == "OK":
            l = logs.get(line[4:])
            if l is None:
                print("\n\n", line[4:], ": ", sep="", end="")
                create_logs_entry(logs, line[4:])
            logs[line[4:]]["ok_counter"] += 1
            if (logs[line[4:]]["ok_counter"] + logs[line[4:]]["ko_counter"]) % 10 == 0:
                print("\n", ''.join([" " for _ in range(1 + len(line[4:]))]), end="")
            print(green("[OK] "), end="")
            continue
        m = re.search("^KO: \[(SEGFAULT|COMPARE)\]: (.*): expected: (.*) got: (.*)$", line)
        if m is None:
            print(line)
            print("PARSING ERROR")
            continue
        l = logs.get(m.group(2))
        if l is None:
            print("\n")
            create_logs_entry(logs, m.group(2))
        l["ko_counter"] += 1
        l["ko_info"].append({
            "type": m.group(1),
            "expected": m.group(3),
            "actual": m.group(4),
        })
        if (l["ok_counter"] + l["ko_counter"]) % 10 == 0:
            print("\n", ''.join([" " for _ in range(1 + len(m.group(2)))]), end="")
        print(red("[KO] "), end="")
    return logs

if __name__ == "__main__":
    os.system("clear")
    logs = parse()
    print("\n")
    for k, v in logs.items():
        for e in v["ko_info"]:
            if e['type'] == "SEGFAULT":
                print(f"{k} : {red(SEGFAULT)}")
            elif e['type'] == "COMPARE":
                print(f"{k}:\n    {green('expected: ', e['expected'])}\n    {red('actual: ', e['actual'])}")