uniffi_testing

Struct UniFFITestHelper

Source
pub struct UniFFITestHelper { /* private fields */ }
Expand description

Struct for running fixture and example tests for bindings generators

Expectations:

  • Used from a integration test (a .rs file in the tests/ directory)
  • The working directory is the project root for the bindings crate. This is the normal case for test code, just make sure you don’t cd somewhere else.
  • The bindings crate has a dev-dependency on the fixture crate
  • The fixture crate produces a cdylib library
  • The fixture crate, and any external-crates, has 1 UDL file in it’s src/ directory

Implementations§

Source§

impl UniFFITestHelper

Source

pub fn new(name: &str) -> Result<Self>

Source

pub fn create_out_dir( &self, temp_dir: impl AsRef<Utf8Path>, script_path: impl AsRef<Utf8Path>, ) -> Result<Utf8PathBuf>

Create at out_dir for testing

This directory can be used for:

  • Generated bindings files (usually via the --out-dir param)
  • cdylib libraries that the bindings depend on
  • Anything else that’s useful for testing

This directory typically created as a subdirectory of CARGO_TARGET_TMPDIR when running an integration test.

We use the script path to create a hash included in the outpuit directory. This avoids path collutions when 2 scripts run against the same fixture.

Source

pub fn copy_cdylib_to_out_dir( &self, out_dir: impl AsRef<Utf8Path>, ) -> Result<Utf8PathBuf>

Copy the cdylib for a fixture into the out_dir

This is typically needed for the bindings to open it when running the tests

Returns the path to the copied library

Source

pub fn cdylib_path(&self) -> Result<Utf8PathBuf>

Get the path to the cdylib file for this package

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.