B
Brian Marick
I think I have found a bug in marshaling in version "ruby 1.8.1
(2003-10-31) [powerpc-darwin]". It's difficult to describe in
words, but I have a failing test.
It seems to require a subclass of Array that adds an instance
variable, an object of that class, and another object that refers to
the first object. Change any of those facts, and you do *not* get this
failure upon loading the marshaled data:
1) Error:
test_marshaling(SessionTests):
EOFError: End of file reached
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:32:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:32:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
`open'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:52:in
`test_marshaling'
Here is the Test::Unit test. I hope it's reasonably clear. It's a
drastically stripped-down version of the original code+test.
Is this a true bug?
========== snip ================
require 'pp'
# Inherit from some user-defined class, and the test passes
class RecordList < Array
def initialize
super
@next_record_id = 0 # Delete this line, and the test passes.
end
end
class ActiveJobManager
def initialize(all_records)
@all_records = all_records # Delete this line, and the test passes
end
end
class Session
def initialize(user)
@user = user
@records = RecordList.new
# Use the following instead of the above, and the test passes.
# @records = []
@active_job_manager = ActiveJobManager.new(@records)
# Use the following instead of the above, and the test passes.
# @active_job_manager = ActiveJobManager.new([])
end
def load
@records, @active_job_manager = File.open(@user, "r") { | f |
Marshal.load(f)
}
end
def save
File.open(@user, "w") { | f |
Marshal.dump([@records, @active_job_manager], f)
}
end
end
class SessionTests < Test::Unit::TestCase
TEST_USER = "marshal-test-data"
def test_marshaling
File.delete(TEST_USER) if FileTest.exists?(TEST_USER)
@session = Session.new(TEST_USER)
@session.save
pp @session.load
end
end
-----
Brian Marick
Consulting, training, contracting, and research
Focused on the intersection of testing, programming, and design
(e-mail address removed), (e-mail address removed)
www.testing.com, www.visibleworkings.com
(2003-10-31) [powerpc-darwin]". It's difficult to describe in
words, but I have a failing test.
It seems to require a subclass of Array that adds an instance
variable, an object of that class, and another object that refers to
the first object. Change any of those facts, and you do *not* get this
failure upon loading the marshaled data:
1) Error:
test_marshaling(SessionTests):
EOFError: End of file reached
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:32:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:32:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
`open'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:52:in
`test_marshaling'
Here is the Test::Unit test. I hope it's reasonably clear. It's a
drastically stripped-down version of the original code+test.
Is this a true bug?
========== snip ================
require 'pp'
# Inherit from some user-defined class, and the test passes
class RecordList < Array
def initialize
super
@next_record_id = 0 # Delete this line, and the test passes.
end
end
class ActiveJobManager
def initialize(all_records)
@all_records = all_records # Delete this line, and the test passes
end
end
class Session
def initialize(user)
@user = user
@records = RecordList.new
# Use the following instead of the above, and the test passes.
# @records = []
@active_job_manager = ActiveJobManager.new(@records)
# Use the following instead of the above, and the test passes.
# @active_job_manager = ActiveJobManager.new([])
end
def load
@records, @active_job_manager = File.open(@user, "r") { | f |
Marshal.load(f)
}
end
def save
File.open(@user, "w") { | f |
Marshal.dump([@records, @active_job_manager], f)
}
end
end
class SessionTests < Test::Unit::TestCase
TEST_USER = "marshal-test-data"
def test_marshaling
File.delete(TEST_USER) if FileTest.exists?(TEST_USER)
@session = Session.new(TEST_USER)
@session.save
pp @session.load
end
end
-----
Brian Marick
Consulting, training, contracting, and research
Focused on the intersection of testing, programming, and design
(e-mail address removed), (e-mail address removed)
www.testing.com, www.visibleworkings.com