Skip to content

Commit

Permalink
fix macro doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
matsadler committed Feb 19, 2023
1 parent dad12ff commit f7342a2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ jobs:
run: bundle exec rake test

- name: Run tests
run: cargo test
run: cargo test --workspace
3 changes: 1 addition & 2 deletions magnus-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ quote = "1"
syn = { version = "1", features = ["full"] }

[dev-dependencies]
magnus = { path = "../" }

magnus = { path = "../", features = ["embed"] }
14 changes: 10 additions & 4 deletions magnus-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn init(attrs: TokenStream, item: TokenStream) -> TokenStream {
///
/// #[magnus::init]
/// fn init() -> Result<(), magnus::Error> {
/// let shape = define_class("Shape", class:object())?;
/// let shape = define_class("Shape", class::object())?;
/// shape.define_method("area", method!(Shape::area, 0))?;
///
/// let circle = define_class("Circle", shape)?;
Expand Down Expand Up @@ -286,7 +286,7 @@ pub fn derive_data_type_functions(input: TokenStream) -> TokenStream {
///
/// #[magnus::init]
/// fn init() -> Result<(), magnus::Error> {
/// let shape = define_class("Shape", class:object())?;
/// let shape = define_class("Shape", class::object())?;
/// define_class("Circle", shape)?;
/// define_class("Rectangle", shape)?;
/// Ok(())
Expand Down Expand Up @@ -321,6 +321,12 @@ pub fn derive_data_type_functions(input: TokenStream) -> TokenStream {
/// DataTypeFunctions, TypedData,
/// };
///
/// # #[magnus::wrap(class = "Point", free_immediately, size)]
/// # struct Point {
/// # x: isize,
/// # y: isize,
/// # }
/// #
/// #[derive(TypedData)]
/// #[magnus(class = "Line", free_immediatly, mark)]
/// struct Line {
Expand Down Expand Up @@ -356,8 +362,8 @@ pub fn derive_data_type_functions(input: TokenStream) -> TokenStream {
/// #[magnus::init]
/// fn init() -> Result<(), magnus::Error> {
/// let line = define_class("Line", class::object())?;
/// line.define_singleton_method("new", function!(new, 2))?;
/// line.define_method("length", method!(length, 0))?;
/// line.define_singleton_method("new", function!(Line::new, 2))?;
/// line.define_method("length", method!(Line::length, 0))?;
/// Ok(())
/// }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions magnus-macros/src/typed_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn expand_derive_typed_data(input: DeriveInput) -> TokenStream {
let class_for = if !arms.is_empty() {
quote! {
fn class_for(value: &Self) -> magnus::RClass {
use magnus::{class, Module, Class, RClass};
use magnus::{class, Module, Class, RClass, value::ReprValue};
#[allow(unreachable_patterns)]
match value {
#(#arms,)*
Expand Down Expand Up @@ -163,7 +163,7 @@ pub fn expand_derive_typed_data(input: DeriveInput) -> TokenStream {
if read {
accessors.push(quote! {
fn #ident(&self) -> <#ty as magnus::value::OpaqueVal>::Val {
let handle = unsafe { RubyHandle::get_unchecked() };
let handle = unsafe { magnus::ruby_handle::RubyHandle::get_unchecked() };
handle.unwrap_opaque(self.#ident)
}
});
Expand Down
2 changes: 1 addition & 1 deletion test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ for VERSION in $RUBY_VERSIONS; do
eval "$(rbenv init - sh)"
rbenv shell $VERSION
printf "testing Ruby $VERSION..."
if OUTPUT=$(env RUBY="$(rbenv which ruby)" cargo +1.54 test 2>&1); then
if OUTPUT=$(env RUBY="$(rbenv which ruby)" cargo +1.54 test --workspace 2>&1); then
echo
else
ERRORS="$ERRORS\n\n\n$VERSION\n\n$OUTPUT"
Expand Down
4 changes: 2 additions & 2 deletions tests/typed_data_obj.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use magnus::{
class, define_class, embed::init, eval, function, gc, method, prelude::*,
ruby_handle::RubyHandle, typed_data::Obj, value::Opaque, DataTypeFunctions, TypedData,
class, define_class, embed::init, eval, function, gc, method, prelude::*, typed_data::Obj,
value::Opaque, DataTypeFunctions, TypedData,
};

#[magnus::wrap(class = "Point", free_immediatly)]
Expand Down

0 comments on commit f7342a2

Please sign in to comment.