Mocksmith

Struct Mocksmith 

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

Mocksmith is a struct for generating Google Mock mocks for C++ classes.

Implementations§

Source§

impl Mocksmith

Source

pub fn new(log_write: Option<Box<dyn Write>>, verbose: bool) -> Result<Self>

Creates a new Mocksmith instance.

The function fails if another thread already holds an instance, since Clang can only be used from one thread.

Source

pub fn new_when_available() -> Result<Self>

Creates a new Mocksmith instance.

The function waits for any other thread holding an instance to release its instance before returning since Clang can only be used from one thread. If a thread using Mocksmith panics, the poisoning is cleared.

Source

pub fn include_path<P>(self, include_path: P) -> Self
where P: AsRef<Path>,

Adds an include path to the list of paths to search for headers. If no include paths are set, the current directory is used.

Source

pub fn include_paths(self, include_paths: &[PathBuf]) -> Self

Adds include paths to the list of paths to search for headers. If no include paths are set, the current directory is used.

Source

pub fn methods_to_mock(self, methods: MethodsToMockStrategy) -> Self

Sets which methods to mock in the classes. Default is AllVirtual, which mocks all virtual methods.

Source

pub fn class_filter_fun(self, filter: impl Fn(&str) -> bool + 'static) -> Self

Sets a function to filter which classes to mock. The function takes the name of a class and should return true if the class should be mocked.

Source

pub fn ignore_errors(self, value: bool) -> Self

Errors detected by Clang during parsing normally causes mock generation to fail. Setting this option disables which may be useful, e.g., when not able to provide all the include paths. Beware that this may lead to unknown types in arguments being referred to as int in generated mocks, and entire methods and classes being ignored (when return value of method is unknown).

Source

pub fn cpp_standard(self, standard: Option<String>) -> Self

Sets the C++ standard to use when parsing the source header files. Default is “c++17”.

Source

pub fn additional_clang_args(self, args: Vec<String>) -> Self

Sets additional arguments to the clang C++ parser.

Source

pub fn parse_function_bodies(self, value: bool) -> Self

For easy testability of parser warnings.

Source

pub fn msvc_allow_overriding_deprecated_methods(self, value: bool) -> Self

Sets whether to add MSVC pragma to allow overriding methods marked as deprecated. If it is not added mocked methods marked as deprecated will cause compilation warnings. The pragma is only added when generating headers. Default is false.

Source

pub fn simplified_nested_namespaces(self, value: bool) -> Self

Controls whether to use C++17 style nested namespace declarations with colon separation or older style. Default is true.

Source

pub fn indent_str(self, indent: String) -> Self

Sets the string to use for indentation for the generated code. Default is 2 spaces.

Source

pub fn mock_name_fun(self, name_mock: impl Fn(&str) -> String + 'static) -> Self

Sets a custom function to generate mock names based on class names.

Source

pub fn create_mocks_for_file<P>(&self, file: P) -> Result<Vec<Mock>>
where P: AsRef<Path>,

Generates mocks for classes in the given file. If no appropriate classes to mock are found, an empty vector is returned.

Source

pub fn create_mocks_from_string(&self, content: &str) -> Result<Vec<Mock>>

Generates mocks for classes in the given string. If no appropriate classes to mock are found, an empty vector is returned.

Source

pub fn create_mock_header_for_files<P>(&self, files: &[P]) -> Result<MockHeader>
where P: AsRef<Path>,

Generate the contents for a header file with mocks for classes in the give file. If no appropriate classes to mock are found, an error is returned.

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.