RustQ.Test (rustq v1.0.0-rc.1)

Copy Markdown View Source

ExUnit helpers for RustQ-generated defrust and defnif modules.

Use this module from consumer tests:

defmodule MyApp.NativeTest do
  use RustQ.Test, async: true

  test "generates and exports the native boundary" do
    assert_defrust MyApp.Native, :sum_impl, "fn sum_impl"
    assert_defnif MyApp.Native, :sum, 1, ~r/fn sum.*Vec<f64>/
    assert_rust_valid MyApp.Native
  end
end

String expectations perform substring matches; regex expectations use Regex.match?/2. Assertions render one generated function at a time so failures remain focused.

Summary

Functions

Asserts that a defnif is exported, marked as a Rustler NIF, and matches generated Rust.

Asserts that a named defrust/defrustp function matches a string or regex.

Asserts that a generated module's complete Rust source matches a string or regex.

Asserts that all generated Rust items for a module parse as valid Rust.

Renders one generated Rust function by name or raises.

Returns whether a generated function carries the Rustler NIF attribute.

Returns a generated module's complete Rust source or raises.

Functions

assert_defnif(module, function, arity, expected)

(macro)

Asserts that a defnif is exported, marked as a Rustler NIF, and matches generated Rust.

assert_defrust(module, function, expected)

(macro)

Asserts that a named defrust/defrustp function matches a string or regex.

assert_rust(module, expected)

(macro)

Asserts that a generated module's complete Rust source matches a string or regex.

assert_rust_valid(module)

(macro)

Asserts that all generated Rust items for a module parse as valid Rust.

function_source!(module, function)

@spec function_source!(module(), atom()) :: String.t()

Renders one generated Rust function by name or raises.

nif?(module, function)

@spec nif?(module(), atom()) :: boolean()

Returns whether a generated function carries the Rustler NIF attribute.

source!(module)

@spec source!(module()) :: String.t()

Returns a generated module's complete Rust source or raises.