Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions rust_slim/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

Develop Slim Fixtures for rust applications. Based on the [Slim Protocol](https://fitnesse.org/FitNesse/UserGuide/WritingAcceptanceTests/SliM/SlimProtocol.html) of fitnesse [fitnesse](https://fitnesse.org) .

This is not 100% compliant with the slim protocol right now. Here are some of the features that are known to not be implemented:

It can only handle string symbols and it cannot.
It does not support a SUT for features.
It does not support Actors.
It does not support using the STOUD and STDIN for comunication.
This is not 100% compliant with the SliM protocol yet. Remaining work includes
instruction timeouts, stop and ignore batch control, standard input/output
transport with fixture-output tunneling, and the optional HTML hash converter.

This is currently in an unstable version. The general API can change in the next versions.

Expand All @@ -21,3 +18,9 @@ argument and `IntoSlimValue` to convert the method result. These conversions
preserve protocol lists, null, void, and in-process object handles. The old
`ToSlimResultString` trait remains available as a string conversion helper,
but it does not preserve those structured values.

Manual fixtures must also implement `Constructor::construct` and return
`Result<Self, ConstructorError>`. The `#[fixture]` macro generates a zero-argument
constructor for `Default` fixtures. Mark one or more associated functions with
`#[slim(constructor)]` to expose typed constructors of different arities, and
mark an `&mut self` accessor with `#[slim(sut)]` to provide a System Under Test.
47 changes: 38 additions & 9 deletions rust_slim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
//!
//! #[fixture]
//! impl Calculator {
//! #[slim(constructor)]
//! pub fn new() -> Self {
//! Self::default()
//! }
//!
//! pub fn set_a(&mut self, a: i64) {
//! self.a = a
//! }
Expand Down Expand Up @@ -68,6 +73,11 @@
//! #
//! # #[fixture]
//! # impl Calculator {
//! # #[slim(constructor)]
//! # pub fn new() -> Self {
//! # Self::default()
//! # }
//! #
//! # pub fn set_a(&mut self, a: i64) {
//! # self.a = a
//! # }
Expand Down Expand Up @@ -136,6 +146,20 @@ pub trait SlimFixture {
method: &str,
args: Vec<SlimValue>,
) -> Result<SlimValue, ExecuteMethodError>;

/// Tries the fixture's System Under Test after a method is not found on
/// the fixture itself. Fixtures without an SUT keep the default, which
/// deliberately looks like a missing method to the dispatcher.
fn execute_system_under_test(
&mut self,
method: &str,
_args: Vec<SlimValue>,
) -> Result<SlimValue, ExecuteMethodError> {
Err(ExecuteMethodError::MethodNotFound {
method: method.into(),
class: "SystemUnderTest".into(),
})
}
}

/// ClassPath that will be used in the construction of the fixture.
Expand All @@ -155,18 +179,23 @@ pub trait ClassPath {
fn class_path() -> String;
}

/// Trait used to construct the fixture. It is auto-implemented for fixtures that also implement Default.
/// Trait used to construct a fixture from SliM constructor arguments.
///
/// Implementations must report an arity mismatch as [`ConstructorError::NoConstructor`],
/// conversion failures as [`ConstructorError::ArgumentParsingError`], and an
/// error from the constructor itself as [`ConstructorError::CouldNotInvoke`].
pub trait Constructor {
fn construct(args: Vec<SlimValue>) -> Self;
fn construct(args: Vec<SlimValue>) -> Result<Self, ConstructorError>
where
Self: Sized;
}

impl<T> Constructor for T
where
T: Default,
{
fn construct(_args: Vec<SlimValue>) -> T {
T::default()
}
/// Failure while selecting, converting for, or invoking a fixture constructor.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ConstructorError {
NoConstructor,
ArgumentParsingError(String),
CouldNotInvoke(String),
}

/// Error that can happen while trying to execute a method in a feature.
Expand Down
Loading
Loading