Skip to content

Commit e839186

Browse files
authored
GD-369: Fix failure report coloring on GdUnit console output (#372)
# Why The failure report has colored diffs but wrong placed # What - Fix ident handling on RTL - rework on background effect for RTL - fix small error when spy on a node where has no parent
1 parent e4728e9 commit e839186

File tree

6 files changed

+126
-176
lines changed

6 files changed

+126
-176
lines changed

addons/gdUnit3/src/asserts/GdAssertMessages.gd

+2-9
Original file line numberDiff line numberDiff line change
@@ -426,21 +426,14 @@ static func colorDiff(value :String) -> String:
426426
result.append_array(format_chars(additional_chars, ADD_COLOR))
427427
return result.get_string_from_ascii()
428428

429-
430429
static func format_chars(characters :PoolByteArray, type :Color) -> PoolByteArray:
431430
var result := PoolByteArray()
432431
if characters.size() == 0:
433432
return result
434433
if characters.size() == 1 and characters[0] == 10:
435-
if type == ADD_COLOR:
436-
result.append_array(("[bg color=#%s]\n<--empty line-->[/bg]" % [type.to_html()]).to_utf8())
437-
else:
438-
result.append_array(("[bg color=#%s][s]\n<--empty line-->[/s][/bg]" % type.to_html()).to_utf8())
434+
result.append_array(("[bg color=#%s]<NL>[/bg]" % type.to_html()).to_utf8())
439435
return result
440-
if type == ADD_COLOR:
441-
result.append_array(("[bg color=#%s]%s[/bg]" % [type.to_html(), characters.get_string_from_ascii()]).to_utf8())
442-
else:
443-
result.append_array(("[bg color=#%s]%s[/bg]" % [type.to_html(), characters.get_string_from_ascii()]).to_utf8())
436+
result.append_array(("[bg color=#%s]%s[/bg]" % [type.to_html(), characters.get_string_from_ascii()]).to_utf8())
444437
return result
445438

446439
static func humanized(value :String) -> String:

addons/gdUnit3/src/spy/GdUnitSpyBuilder.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ static func spy_on_scene(caller :Object, scene :Node, memory_pool, debug_write)
197197
scene.__set_caller(caller)
198198
return GdUnitTools.register_auto_free(scene, memory_pool)
199199

200-
const EXCLUDE_PROPERTIES_TO_COPY = ["script", "type"]
200+
const EXCLUDE_PROPERTIES_TO_COPY = ["script", "type", "get_global_transform", "rect_global_position"]
201201

202202
static func copy_properties(source :Object, dest :Object) -> void:
203203
for property in source.get_property_list():
204204
var property_name = property["name"]
205-
var property_value = source.get(property_name)
206205
if EXCLUDE_PROPERTIES_TO_COPY.has(property_name):
207206
continue
207+
var property_value = source.get(property_name)
208208
#if dest.get(property_name) == null:
209209
# prints("|%s|" % property_name, source.get(property_name))
210210

addons/gdUnit3/src/ui/GdUnitConsole.gd

+32-25
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ func _on_event_test_suite(event :GdUnitEvent):
6868
output.newline()
6969
output.push_color(Color.lightgreen.to_html())
7070
output.append_bbcode("Test Run Summary:")
71+
output.pop()
7172
output.push_color(_text_color.to_html())
7273
output.push_indent(1)
7374
output.append_bbcode("| %d total | %d error | %d failed | %d skipped | %d orphans |\n" % [_summary["total_count"], _summary["error_count"], _summary["failed_count"], _summary["skipped_count"], _summary["orphan_nodes"]])
75+
output.newline()
7476
output.pop_indent(1)
77+
output.pop()
7578
GdUnitEvent.TESTSUITE_BEFORE:
7679
init_statistics(event)
7780
output.append_bbcode("Run Test Suite: %s" % event._suite_name)
@@ -80,50 +83,54 @@ func _on_event_test_suite(event :GdUnitEvent):
8083
if event.is_success():
8184
output.push_color(Color.lightgreen.to_html())
8285
output.append_bbcode("[wave]PASSED[/wave]")
86+
output.pop()
8387
else:
8488
output.push_color(Color.firebrick.to_html())
8589
output.append_bbcode("[shake rate=5 level=10][b]FAILED[/b][/shake]")
86-
output.pop_indent(1)
90+
output.pop()
8791
output.append_bbcode(" %+12s" % LocalTime.elapsed(event.elapsed_time()))
8892
output.newline()
8993
output.push_color(_text_color.to_html())
9094
output.push_indent(1)
9195
output.append_bbcode("| %d total | %d error | %d failed | %d skipped | %d orphans |\n" % [_statistics["total_count"], _statistics["error_count"], _statistics["failed_count"], _statistics["skipped_count"], _statistics["orphan_nodes"]])
9296
output.pop_indent(1)
93-
output.pop_indent(1)
97+
output.pop()
9498
output.newline()
9599
GdUnitEvent.TESTCASE_BEFORE:
96100
var spaces = "-%d" % (80 - event._suite_name.length())
97101
output.push_indent(1)
98102
output.append_bbcode(("[color=#" + _engine_type_color.to_html() + "]%s[/color]:[color=#" + _function_color.to_html() + "]%"+spaces+"s[/color]") % [event._suite_name, event._test_name])
99-
output.pop_indent(1)
100103
GdUnitEvent.TESTCASE_AFTER:
101104
var reports := event.reports()
102105
update_statistics(event)
103-
if not output.text.ends_with("\n"):
104-
if event.is_success():
105-
output.push_color(Color.lightgreen.to_html())
106-
output.append_bbcode("PASSED")
107-
output.pop_indent(1)
108-
output.append_bbcode(" %+12s" % LocalTime.elapsed(event.elapsed_time()))
109-
else:
110-
if event.is_skipped():
111-
output.push_color(Color.goldenrod.to_html())
112-
output.append_bbcode("SKIPPED")
113-
if event.is_error() or event.is_failed():
114-
output.push_color(Color.firebrick.to_html())
115-
output.append_bbcode("FAILED")
116-
output.pop_indent(1)
117-
output.append_bbcode(" %+12s" % LocalTime.elapsed(event.elapsed_time()))
106+
if event.is_success():
107+
output.push_color(Color.lightgreen.to_html())
108+
output.append_bbcode("PASSED")
109+
output.pop()
110+
output.append_bbcode(" %+12s" % LocalTime.elapsed(event.elapsed_time()))
111+
output.newline()
112+
output.pop_indent(1)
113+
else:
114+
if event.is_skipped():
115+
output.push_color(Color.goldenrod.to_html())
116+
output.append_bbcode("SKIPPED")
117+
output.pop()
118+
if event.is_error() or event.is_failed():
119+
output.push_color(Color.firebrick.to_html())
120+
output.append_bbcode("FAILED")
121+
output.pop()
122+
output.append_bbcode(" %+12s" % LocalTime.elapsed(event.elapsed_time()))
123+
output.newline()
124+
output.push_color(_text_color.to_html())
125+
var report :GdUnitReport = null if reports.empty() else reports[0]
126+
if report:
127+
output.push_indent(1)
128+
output.append_bbcode("line %d %s" % [report._line_number, report._message])
118129
output.newline()
119-
output.push_color(_text_color.to_html())
120-
var report :GdUnitReport = null if reports.empty() else reports[0]
121-
if report:
122-
output.push_indent(2)
123-
output.append_bbcode("line %d %s" % [report._line_number, report._message])
124-
output.pop_indent(2)
125130
output.pop_indent(1)
126-
output.newline()
131+
output.pop_indent(1)
132+
output.pop()
133+
127134

128135
func _on_client_connected(client_id :int) -> void:
129136
output.clear()

addons/gdUnit3/src/ui/parts/RichTextEffectBackground.gd

+54-58
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This effect works currently only with mono fonts
22

33
# MIT License
4-
# Copyright (c) 2020 Mike Schulze
4+
# Copyright (c) 2023 Mike Schulze
55
# https://github.com/MikeSchulze/gdUnit3/blob/master/LICENSE
66

77
extends RichTextEffect
@@ -10,106 +10,102 @@ class_name RichTextEffectBackground
1010
var bbcode = "bg"
1111

1212
var _label: WeakRef
13-
var _char_size :Vector2
14-
var _tab_size : int
15-
var _indent := Dictionary()
16-
var diff_sub_color := Color(0, 0, 0, 0)
13+
var _char_size := Vector2(8, 16)
14+
var _margin := Vector2.ZERO
15+
var _tab_size :int
16+
var _diff_sub_color := Color(0, 0, 0, 0)
1717
var _cache := Dictionary()
1818

19+
class CharacterInfo:
20+
var _position :Vector2
21+
var _size :Vector2
22+
23+
func _init(position :Vector2, size :Vector2):
24+
_position = position
25+
_size = size
26+
27+
1928
func set_source(label :RichTextLabel) -> void:
2029
_label = weakref(label)
2130
init_properties()
2231

32+
2333
func init_properties() :
2434
_cache.clear()
2535
# determine character size
26-
var char_width := 8
27-
var char_height := 16
2836
var custom_font = _label.get_ref().get("custom_fonts/mono_font")
2937
if custom_font is Font:
30-
char_height = custom_font.get_height()
31-
char_width = custom_font.get_char_size(23).x
32-
_char_size = Vector2(char_width, char_height)
38+
_char_size = Vector2(custom_font.get_char_size(23).x, custom_font.get_height())
3339
_tab_size = _label.get_ref().tab_size
40+
_margin = Vector2(4, 4)
3441

35-
func push_indent(line :int, indent :int) -> void:
36-
_indent[line] = indent
37-
38-
func pop_indent(line :int, indent :int) -> void:
39-
_indent[line+1] = -indent
40-
_cache.clear()
41-
42-
func reset() -> void:
43-
_cache.clear()
44-
_indent.clear()
45-
46-
func get_text_rect(control :Control) -> Rect2:
47-
var style : StyleBox = control.get_stylebox("normal")
48-
return Rect2(style.get_offset(), control.get_size() - style.get_minimum_size())
4942

5043
func _process_custom_fx(char_fx: CharFXTransform) -> bool:
5144
var label = _label.get_ref() as RichTextLabel
5245
var scroll = label.get_v_scroll()
53-
var position := get_char_position(char_fx.absolute_index, label.get_text())
54-
55-
# padding
56-
position += Vector2(4, 4)
46+
var char_info :CharacterInfo = get_char_position(char_fx, label.get_text())
47+
var position := char_info._position
48+
# margin
49+
position += _margin
5750
# sync with scroll positon
5851
position.y -= scroll.value
59-
var color = char_fx.env.get("color", diff_sub_color) as Color
52+
var color = char_fx.env.get("color", _diff_sub_color) as Color
6053
# lower the alpha for better backround
6154
color.a = .3
62-
label.draw_rect(Rect2(position, _char_size), color)
63-
55+
label.draw_rect(Rect2(position, char_info._size), color)
6456
# increase the color lightning of the character (for better visualisation on background)
6557
char_fx.color = char_fx.color.lightened(.8)
6658
return true
6759

60+
6861
func _build_char_mapping(text :String) -> Dictionary:
6962
_cache.clear()
7063
var line_height := get_line_height()
7164
var line_index := 0
72-
var char_offset := 0
73-
var y_offset := 0
74-
var last_ident := 0
65+
var char_index := 0
7566

76-
# replace all tabs, otherwise it will results in invalid background coloring
77-
for line in text.replace("\t", "").split("\n"):
67+
for line in text.split("\n"):
68+
var position = Vector2(0, line_height * line_index)
69+
for cp in line.length():
70+
var char_size := char_size(line, cp)
71+
_cache[char_index] = CharacterInfo.new(position, char_size)
72+
#prints( "line:%d:%d" % [line_index, char_index], "'%s' (%d)" % [text[char_index], text.ord_at(char_index)], position, "ident", last_ident)#, "tab:", text[text_index] == "\t", char_size)
73+
char_index += 1
74+
position.x += char_size.x
7875
line_index += 1
79-
# build line x_offset by current line indent
80-
last_ident = get_line_indent(line_index, last_ident)
81-
var x_offset = last_ident * _tab_size
82-
83-
for x in line.length():
84-
var char_index = char_offset + x
85-
_cache[char_index] = Vector2((x_offset + x)*_char_size.x, y_offset)
86-
# calculate next line offsets
87-
y_offset += line_height
88-
char_offset += line.length()
8976
return _cache
9077

91-
func get_char_position(char_index :int, text :String ) -> Vector2:
78+
79+
func char_size(line :String, index :int) -> Vector2:
80+
var character := line.ord_at(index)
81+
match character:
82+
9: return Vector2(_tab_size * _char_size.x, _char_size.y)
83+
_: return _char_size
84+
return _char_size
85+
86+
87+
func get_char_position(char_fx: CharFXTransform, text :String ) -> CharacterInfo:
9288
if _cache.empty():
9389
_build_char_mapping(text)
94-
return _cache.get(char_index, Vector2.ONE)
90+
return _cache.get(char_fx.absolute_index, CharacterInfo.new(Vector2.ZERO, _char_size))
9591

96-
func get_line_indent(line :int, last_indent := 0) -> int:
97-
var line_indent = _indent.get(line, 0)
98-
if line_indent == 0:
99-
return last_indent
100-
if line_indent < 0:
101-
return last_indent + line_indent
102-
return line_indent
10392

10493
func get_line_height() -> int:
10594
var label = _label.get_ref() as RichTextLabel
10695
var line_separation = label.get("custom_constants/line_separation")
10796
if not line_separation:
10897
line_separation = 1
109-
return get_char_size().y + line_separation
98+
return _char_size.y + line_separation
99+
100+
101+
func get_text_rect(control :Control) -> Rect2:
102+
var style : StyleBox = control.get_stylebox("normal")
103+
return Rect2(style.get_offset(), control.get_size() - style.get_minimum_size())
104+
105+
106+
func reset() -> void:
107+
_cache.clear()
110108

111-
func get_char_size() -> Vector2:
112-
return _char_size
113109

114110
func _notification(what):
115111
if what == EditorSettings.NOTIFICATION_EDITOR_SETTINGS_CHANGED:

addons/gdUnit3/src/ui/parts/RichTextLabelExt.gd

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Custom RichTextLabel with custom background colors
22
# MIT License
3-
# Copyright (c) 2020 Mike Schulze
3+
# Copyright (c) 2023 Mike Schulze
44
# https://github.com/MikeSchulze/gdUnit3/blob/master/LICENSE
55

66
tool
@@ -30,28 +30,30 @@ func _update_ui_settings():
3030

3131
func set_bbcode(code) -> void:
3232
.parse_bbcode(code)
33+
_effect.reset()
3334
updateMinSize()
3435

35-
func append_bbcode(text :String):
36-
# replace all tabs, it results in invalid background coloring
37-
var error := .append_bbcode(text.replace("\t", ""))
36+
func append_bbcode(bbcode :String):
37+
# using own ident implementation because the original has issues with ident + leading tabs
38+
if _indent != 0:
39+
var line = text.split("\n")[-1]
40+
if line.length() == 0:
41+
for i in _indent:
42+
bbcode = bbcode.indent("\t")
43+
var error := .append_bbcode(bbcode)
44+
_effect.reset()
3845
updateMinSize()
3946
return error
4047

4148
func push_indent(indent :int) -> void:
42-
.push_indent(indent)
4349
if _effect:
4450
_indent += indent
45-
_effect.push_indent(get_line_count(), _indent)
4651
if _indent > _max_indent:
4752
_max_indent = _indent
4853

4954
func pop_indent(indent :int) -> void:
50-
if _indent-indent >= 0:
51-
.pop()
52-
if _effect:
53-
_indent -= indent
54-
_effect.pop_indent(get_line_count(), _indent)
55+
if _effect:
56+
_indent -= indent
5557

5658
# updates the label minmum size by the longest line content
5759
# to fit the full text to on line, to avoid line wrapping
@@ -70,3 +72,4 @@ func updateMinSize() -> void:
7072
rect_min_size = line_size
7173
# add extra spacing of 40px for possible scrollbar
7274
rect_min_size.x += 40
75+

0 commit comments

Comments
 (0)