|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import sys |
| 3 | +import re |
| 4 | + |
| 5 | + |
| 6 | +def parse_line(line): |
| 7 | + """ |
| 8 | + Parses a single line of input to extract the test result and description. |
| 9 | +
|
| 10 | + Args: |
| 11 | + line (str): A single line of input. |
| 12 | +
|
| 13 | + Returns: |
| 14 | + tuple: A tuple containing the result and description. |
| 15 | + """ |
| 16 | + |
| 17 | + if not line.startswith("ok") and not line.startswith("not ok"): |
| 18 | + return None, None |
| 19 | + |
| 20 | + parts = re.split(r" \d+ - ", line) |
| 21 | + if len(parts) < 2: |
| 22 | + raise ValueError(f"Invalid line format: {line}") |
| 23 | + |
| 24 | + result = "pass" if parts[0] == "ok" else "fail" |
| 25 | + description = parts[1].strip() |
| 26 | + |
| 27 | + if "# skip" in description.lower(): |
| 28 | + result = "skip" |
| 29 | + description = description.split("# skip")[0].strip() |
| 30 | + |
| 31 | + return result, description |
| 32 | + |
| 33 | + |
| 34 | +def sanitize_description(description): |
| 35 | + """ |
| 36 | + Sanitizes the description by replacing spaces with dashes, removing special characters, and avoiding double dashes. |
| 37 | +
|
| 38 | + Args: |
| 39 | + description (str): The test description. |
| 40 | +
|
| 41 | + Returns: |
| 42 | + str: The sanitized description. |
| 43 | + """ |
| 44 | + description = description.replace(" ", "-") |
| 45 | + description = re.sub(r"[^a-zA-Z0-9_-]+", "", description) # Slugify |
| 46 | + description = re.sub( |
| 47 | + r"-+", "-", description |
| 48 | + ) # Replace multiple dashes with a single dash |
| 49 | + return description |
| 50 | + |
| 51 | + |
| 52 | +def main(): |
| 53 | + """ |
| 54 | + Main function to parse input, process each line, and output the results. |
| 55 | + """ |
| 56 | + lines = sys.stdin.readlines() |
| 57 | + |
| 58 | + for line in lines: |
| 59 | + result, description = parse_line(line) |
| 60 | + |
| 61 | + if not result or not description: |
| 62 | + continue |
| 63 | + |
| 64 | + print(f"{sanitize_description(description)} {result}") |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + main() |
0 commit comments