diff options
| author | Ryan Scott <[email protected]> | 2013-05-12 18:42:21 +1000 |
|---|---|---|
| committer | Ryan Scott <[email protected]> | 2013-05-12 18:42:21 +1000 |
| commit | 0d4227ac04832a3bb4010d701ebda2c97c034da6 (patch) | |
| tree | bfb1207c125d3b22afea7b1571c04b99888e8752 /test | |
| parent | 37e3643f8f048d8387419a43abc51236eadbeb1e (diff) | |
| download | mruby-0d4227ac04832a3bb4010d701ebda2c97c034da6.tar.gz mruby-0d4227ac04832a3bb4010d701ebda2c97c034da6.zip | |
Implemented ObjectSpace.count_objects to count the number of allocated objects for each type
Diffstat (limited to 'test')
| -rw-r--r-- | test/assert.rb | 21 | ||||
| -rw-r--r-- | test/t/objectspace.rb | 19 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/assert.rb b/test/assert.rb index a69066828..cb2e28b89 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -86,6 +86,19 @@ def assert_true(ret, msg = nil, diff = nil) ret end +def assert_false(ret, msg = nil, diff = nil) + if $mrbtest_assert + $mrbtest_assert_idx += 1 + if ret + msg = "Expected #{ret.inspect} to be false" unless msg + diff = assertion_diff(false, ret) unless diff + + $mrbtest_assert.push([$mrbtest_assert_idx, msg, diff]) + end + end + !ret +end + def assert_equal(exp, act, msg = nil) msg = "Expected to be equal" unless msg diff = assertion_diff(exp, act) @@ -136,6 +149,14 @@ def assert_raise(*exp) end ## +# Fails unless +obj+ is a kind of +cls+. +def assert_kind_of(cls, obj, msg = nil) + msg = "Expected #{obj.inspect} to be a kind of #{cls}, not #{obj.class}" unless msg + diff = assertion_diff(cls, obj.class) + assert_true(obj.kind_of?(cls), msg, diff) +end + +## # Report the test result and print all assertions # which were reported broken. def report() diff --git a/test/t/objectspace.rb b/test/t/objectspace.rb new file mode 100644 index 000000000..bf79da902 --- /dev/null +++ b/test/t/objectspace.rb @@ -0,0 +1,19 @@ + +assert('ObjectSpace.count_objects') do + h = {} + ObjectSpace.count_objects(h) + assert_kind_of(Hash, h) + assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) }) + assert_true(h.values.all? {|x| x.is_a?(Integer) }) + + h = ObjectSpace.count_objects + assert_kind_of(Hash, h) + assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) }) + assert_true(h.values.all? {|x| x.is_a?(Integer) }) + + assert_raise(TypeError) { ObjectSpace.count_objects(1) } + + h0 = {:MRB_TT_FOO=>1000} + h = ObjectSpace.count_objects(h0) + assert_false(h0.has_key?(:MRB_TT_FOO)) + end
\ No newline at end of file |
