aboutsummaryrefslogtreecommitdiff
path: root/prettier.py
blob: 04bb04c03ba7e800cfb9ce0e9d743a2fb74defce (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
87
88
89
90
91
92
93
94
95
96
97
98
# **************************************************************************** #
#                                                                              #
#                                                         :::      ::::::::    #
#    prettier.py                                        :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: cacharle <marvin@42.fr>                    +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2020/02/05 23:04:13 by cacharle          #+#    #+#              #
#    Updated: 2020/12/09 12:56:07 by charles          ###   ########.fr        #
#                                                                              #
# **************************************************************************** #

import os
import sys
import re
import argparse


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


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

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"]) % 15 == 0:
                print("\n", ''.join([" " for _ in range(1 + len(line[4:]))]), end="")
            print(green("[OK] "), end="")
            continue
        m = None
        if line.find("SEGFAULT") != -1:
            name = line[4:line.find("with")]
        else:
            m = re.search("^KO: \[COMPARE\]: (.*): expected: (.*) got: (.*)( with: .*)?$", line)
            if m is None:
                print(line)
                print("PARSING ERROR")
                continue
            name = m.group(1)

        l = logs.get(name)
        if l is None:
            create_logs_entry(logs, name)
            print("\n\n", name, ": ", sep="", end="")
            l = logs.get(name)
        l["ko_counter"] += 1
        if m is None:
            l["ko_info"].append({
                "type": "SEGFAULT",
                "expected": None,
                "actual": None,
                "with": line[line.find("with:") + len("with:"):]
            })
        else:
            l["ko_info"].append({
                "type": "COMPARE",
                "expected": m.group(2),
                "actual": m.group(3),
                "with": None
            })
        if m is not None and m.group(4) is not None:
            l["ko_info"][-1]["with"] = m.group(4)[6:]
        if (l["ok_counter"] + l["ko_counter"]) % 15 == 0:
            print("\n", ''.join([" " for _ in range(1 + len(name))]), end="")
        print(red("[KO] "), end="")
        sys.stdout.flush()
    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("{} : {}".format(k, red('SEGFAULT')))
            elif e['type'] == "COMPARE":
                p = str(k)
                if e["with"] is not None:
                    p += "with {}".format(e['with'])
                print(p, ":\n    {}\n    {}".format(green('expected: ') + e['expected'],
                                                     red('actual: ') + e['actual']))