Skip to content

Commit 2f64f19

Browse files
committed
added tests for testing attached classes edge case
1 parent e0742a9 commit 2f64f19

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

examples/c_struct_interface/c_struct_interface.rubex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ class Music attach mp3info
4545
return data$.mp3info.id
4646
end
4747
end
48+

lib/rubex/ast/top_statement/klass/attached_klass.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def write_alloc_c_function(code)
131131
# TODO: modify for supporting inheritance
132132
def member_struct_allocations
133133
c_name = @scope.find(@attached_type).c_name
134-
#binding.pry
135134
"data->#{Rubex::POINTER_PREFIX + @attached_type} = (#{c_name}*)xmalloc(sizeof(#{c_name}));\n"
136135
end
137136

spec/binding_ptr_args_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
end
2121
end
2222

23-
context "Black Box testing", hell: true do
23+
context "Black Box testing" do
2424
it "compiles and checks for valid output" do
2525
setup_and_teardown_compiled_files(test_case) do |dir|
2626
require_relative "#{dir}/#{test_case}.#{os_extension}"

spec/c_struct_interface_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
end
1616
end
1717

18-
context ".compile" do
18+
context ".compile", hell: true do
1919
it "generates valid C code" do
2020
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
21+
puts c
2122
end
2223
end
2324

24-
context "Black Box testing" do
25+
context "Black Box testing", hell: true do
2526
it "compiles and checks for valid output" do
2627
setup_and_teardown_compiled_files(test_case) do |dir|
2728
require_relative "#{dir}/#{test_case}.#{os_extension}"
@@ -32,6 +33,10 @@
3233
expect(m.title) .to eq("CAFO")
3334
expect(m.id) .to eq(id)
3435
expect(m.id_i) .to eq(id + 1)
36+
37+
t = A.new
38+
39+
expect(t.foo).to eq(55)
3540
end
3641
end
3742
end

spec/fixtures/c_struct_interface/c_struct_interface.rubex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,22 @@ class Music attach mp3info
4141
return inc_id()
4242
end
4343
end
44+
45+
struct test
46+
int *a
47+
end
48+
49+
class A attach test
50+
cfunc void allocate
51+
data$.test.a = <int*>xmalloc(sizeof(int)*100)
52+
end
53+
54+
def foo
55+
data$.test.a[3] = 55
56+
return data$.test.a
57+
end
58+
59+
cfunc void deallocate
60+
xfree(data$.test.a)
61+
end
62+
end

spec/no_gil_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
end
2121
end
2222

23-
context "Black Box testing", hell: true do
23+
context "Black Box testing" do
2424
it "compiles and checks for valid output" do
2525
setup_and_teardown_compiled_files(test_case) do |dir|
2626
require_relative "#{dir}/#{test_case}.#{os_extension}"

0 commit comments

Comments
 (0)