Created
January 13, 2011 18:39
-
-
Save elskwid/778366 to your computer and use it in GitHub Desktop.
Test some aspects of marshalling using JRuby 1.6RC1
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
require 'test/unit' | |
require 'tempfile' | |
require 'ostruct' | |
class Test::Unit::TestCase | |
def marshalled(obj) | |
tmp = Tempfile.new('marshal') | |
tmp.puts Marshal.dump(obj) | |
tmp.close | |
File.open(tmp.path, 'r'){|f| Marshal.load(f)} | |
end | |
end | |
class BasicClass | |
attr_accessor :name | |
end | |
class TestMarshal < Test::Unit::TestCase | |
def setup | |
# | |
end | |
def test_string | |
s = "the string" | |
assert_equal s, marshalled(s) | |
end | |
def test_integer | |
n = 2 | |
assert_equal n, marshalled(n) | |
end | |
def test_float | |
n = 1.2 | |
assert_equal n, marshalled(n) | |
end | |
def test_basic_class | |
bc = BasicClass.new | |
bc.name = "basic_class" | |
mbc = marshalled(bc) | |
assert mbc.is_a? BasicClass | |
assert_equal bc.name, mbc.name | |
end | |
def test_basic_openstruct | |
os = OpenStruct.new | |
os.name ="openstruct" | |
os.num = 5 | |
mos = marshalled(os) | |
assert mos.is_a? OpenStruct | |
assert_equal os.name, mos.name | |
assert_equal os.num, mos.num | |
end | |
def test_less_basic_openstruct | |
os = OpenStruct.new | |
os.name = "openstruct2" | |
os.obj = BasicClass.new | |
os.obj.name = "enclosed_object" | |
mos = marshalled(os) | |
assert mos.is_a? OpenStruct | |
assert_equal os.name, mos.name | |
assert mos.obj.is_a? BasicClass | |
assert_equal os.obj.name, mos.obj.name | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can get this to pass on Windows if I change the marshalled helper to look like this:
Notice that passing the
file
to Marshal.load is no good while doingfile.read
works.