Contributing
Guidelines for changing ruby-bindgen and its generated-output tests.
Key Files
lib/ruby-bindgen/generators/generator.rb- base class shared by all generatorslib/ruby-bindgen/generators/rice/rice.rb- main AST walker for Rice code generationlib/ruby-bindgen/generators/rice/*.erb- Rice templateslib/ruby-bindgen/generators/ffi/ffi.rb- main AST walker for FFI code generationlib/ruby-bindgen/generators/cmake/cmake.rb- CMake file generatortest/headers/cpp/*.hpp- C++ input headers for teststest/bindings/cpp/*-rb.cpp- expected generated output (golden files)
Run Tests
Run all tests before updating expected files:
bundle exec ruby -Ilib -Itest test/ffi_test.rb
bundle exec ruby -Ilib -Itest test/rice_test.rb
bundle exec ruby -Ilib -Itest test/cmake_test.rb
Run one test:
bundle exec ruby -Ilib -Itest test/rice_test.rb --name test_classes
Important:
- Run cmake_test after rice_test because it scans generated *-rb.cpp files.
Updating Expected Files
Only update expected outputs after all tests pass on current expectations.
UPDATE_EXPECTED=1 bundle exec ruby -Ilib -Itest test/rice_test.rb
UPDATE_EXPECTED=1 bundle exec ruby -Ilib -Itest test/cmake_test.rb
Test Coverage Requirement
Every bug fix should include test coverage:
- Add or adjust headers in
test/headers/cpp/ - Update expected generated outputs in
test/bindings/cpp/
For cross-file typedef issues, use:
- test/headers/cpp/cross_file_base.hpp
- test/headers/cpp/cross_file_derived.hpp
Regenerating opencv-ruby Bindings
Use the project configs in:
- <opencv-ruby>/ext/rice-bindings.yaml
- <opencv-ruby>/ext/cmake-bindings.yaml
Generate with:
cd <ruby-bindgen>
# 1. Generate Rice source files
bundle exec ruby -Ilib bin/ruby-bindgen <opencv-ruby>/ext/rice-bindings.yaml
# 2. Generate CMake files
bundle exec ruby -Ilib bin/ruby-bindgen <opencv-ruby>/ext/cmake-bindings.yaml