Skip to content

Commit

Permalink
CI: Fix tests for macOS
Browse files Browse the repository at this point in the history
OS.execute, when called on macOS, seems to
return output with ANSI sequences inserted
(color codes for errors, specifically). This breaks
our error matcher.
  • Loading branch information
YuriSizov committed Jan 25, 2025
1 parent 978bb0f commit 22a2273
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/TestBase.gd
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,23 @@ func _run_subscript(path: String, arguments: PackedStringArray) -> String:

var output := []
OS.execute(exec_path, exec_args, output, true)
var raw_output := output[0]

# Strip ANSI escape sequences (seem to be injected on macOS specifically).
# Roughly based on https://github.com/chalk/ansi-regex. We can't use \u unicode escapes,
# but \x work just as well for our case.
var ansi_patterns := [
"[\\x1b\\x9b][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\x07|\\x1b\\x5c|\\x9c))",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
]
var ansi_re := RegEx.new()
ansi_re.compile("|".join(ansi_patterns))
raw_output = ansi_re.sub(raw_output, "", true)

# Normalize the EOL sequences.
return output[0].replace("\r", "")
raw_output = raw_output.replace("\r", "")

return raw_output


func _extract_godot_errors(buffer: String) -> String:
Expand Down

0 comments on commit 22a2273

Please sign in to comment.