Created
September 30, 2024 21:55
-
-
Save mrLSD/f06c0a675800477550addacb438081e5 to your computer and use it in GitHub Desktop.
Run swift tests with pretty error printing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| swift test 2>&1 | awk ' | |
| /error:/ { | |
| # Use regular expression to capture required parts | |
| # Regex Breakdown: | |
| # ^(.+\/)?([^:]+\.swift):([0-9]+): error: -\[(.*?)\] : expected to equal <([^>]+)>, got <([^>]+)> | |
| regex = "^(.+\\/)?([^:]+\\.swift):([0-9]+): error: -\\[(.*?)\\] : expected to equal <([^>]+)>, got <([^>]+)>" | |
| if (match($0, regex, m)) { | |
| # m[2]: Filename (e.g., MyTests.swift) | |
| # m[3]: Line number | |
| # m[4]: Test name (e.g., MyTestName | |
| # m[5]: Expected value (e.g., SomeVal) | |
| # m[6]: Got value (e.g., SomeVal) | |
| BOLD = "\033[1m" | |
| GREY = "\033[90m" | |
| RESET = "\033[0m" | |
| # Print Filename:LineNumber in Bold | |
| printf BOLD "%s:%s " RESET, m[2], m[3] | |
| # Print Test Name in Grey | |
| printf GREY "%s" RESET "\n", m[4] | |
| # Print expected value with tab | |
| printf GREY "expect: " RESET | |
| print m[5] | |
| # Print "got: ActualValue" | |
| printf GREY "got: " RESET | |
| print m[6] | |
| print "_________________________________" | |
| } | |
| } | |
| ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment