Open GoogleCodeExporter opened 8 years ago
I'd just like to add a comment that this one would be a great one to get fixed
because as far as I can see, this is the only issue that stops Test::Unit from
working. I discovered this when experimenting with the strscan tests from the
MRI. I
was pleasantly surprised to see that Test::Unit seems to 'just work' when the
tests
pass. However when a test fails, pp is used for reporting. I did a bit of
digging
and worked out that pp is using thread-local variables to preserve state. That
is
where the rb_thread_current reference comes in. As a **temporary** hack I re-
implemented 2 methods in PP as below - and I can now run the strscan Test::Unit
tests without modification. Oh happy day!
require 'pp'
class PP
# TEMPORARY HACK - NOT THREAD SAFE
@threadvars = {}
def guard_inspect_key
@threadvars = {} unless @threadvars
if @threadvars[InspectKey] == nil
@threadvars[InspectKey] = []
end
save = @threadvars[InspectKey]
begin
@threadvars[InspectKey] = []
yield
ensure
@threadvars[InspectKey] = save
end
end
def pp(obj)
id = obj.__id__
@threadvars = {} unless @threadvars
if @threadvars[InspectKey].include? id
group {obj.pretty_print_cycle self}
return
end
begin
@threadvars[InspectKey] << id
group {obj.pretty_print self}
ensure
@threadvars[InspectKey].pop unless PP.sharing_detection
end
end
end
Original comment by djl_davi...@rifraf.net
on 1 Oct 2007 at 8:42
Original issue reported on code.google.com by
sanxiyn
on 30 Sep 2007 at 2:19