|
|
[WIP] The documentation is coming there. |
|
|
\ No newline at end of file |
|
|
This crate is in alpha state. It is fully usable, but one can (rightfully) think that there are incomplete or missing features. The maintainer would be very happy if he was given some feedback, issues, pull requests, etc.
|
|
|
__________
|
|
|
|
|
|
|
|
|
`fluid` is a crate to make the tests more readable and easier to write, inspired by [xUnit](https://xunit.github.io/).
|
|
|
It is still in an unstable state. Be adviced that in future alphas — let alone in the release — it could/will be very different.
|
|
|
|
|
|
Get started
|
|
|
-----------
|
|
|
|
|
|
Do not forget that everything related to this crate must be used only
|
|
|
within a test config (*i.e.*, with a `#[cfg(test)]` attribute). Otherwise,
|
|
|
you are mixing your library sources with your tests.
|
|
|
|
|
|
Add the crate in your Cargo.toml:
|
|
|
|
|
|
```toml
|
|
|
[dev-dependencies]
|
|
|
fluid = "0.3"
|
|
|
```
|
|
|
|
|
|
Reference the crate in your main file:
|
|
|
|
|
|
```rust
|
|
|
#[cfg(test)] extern crate fluid;
|
|
|
```
|
|
|
|
|
|
Import the needed content in scope of your test files:
|
|
|
|
|
|
```rust
|
|
|
use fluid::prelude::*;
|
|
|
```
|
|
|
|
|
|
You can then write [your tests](assertions):
|
|
|
|
|
|
### Fact
|
|
|
|
|
|
|
|
|
```rust
|
|
|
#[fact]
|
|
|
fn cerberus_has_3_heads() {
|
|
|
number_of_faces("Cerberus").should().be_equal_to(3);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
[More about facts](fact).
|
|
|
|
|
|
### Theory
|
|
|
|
|
|
```rust
|
|
|
#[theory]
|
|
|
#[case("Cerberus", 3)]
|
|
|
#[case("Hydra", 7)]
|
|
|
#[case("Janus", 2)]
|
|
|
#[case("Normal guy", 1)]
|
|
|
fn each_creature_has_a_correct_number_of_faces(name: &str, nbr_faces: u8) {
|
|
|
number_of_faces(name).should().be_equal_to(nbr_faces);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
[More about theories](theory).
|
|
|
|
|
|
Goals
|
|
|
-----
|
|
|
|
|
|
The current goals are to provide:
|
|
|
- `[DONE]` Easily readable tests: they should be read like english sentences.
|
|
|
- `[DONE]` Nice and understandable error messages.
|
|
|
- `[TODO]` The most possible useful assertions for common cases: numbers, `Iterators`, `Options`, `Results`, etc.
|
|
|
- `[TODO]` A full test framework that launches the tests, displays the failures, etc. This will be released only when this feature is stabilized.
|
|
|
|
|
|
Non-goals:
|
|
|
|
|
|
- Run the tests fast: under the hood, there are some code generation at compile-time, especially for the `#[theory]` tests. This will never be as fast as the standard tests.
|
|
|
|
|
|
Known bugs/limitations
|
|
|
----------------------
|
|
|
|
|
|
- Stringification of the left element is not perfect when the procedural macros are used.
|
|
|
That is because there is no way to render the token as they were written by the user (as far as I know).
|
|
|
|
|
|
- For now, a theory stops at the first failed case. Is it a desirable behavior?
|
|
|
If not, how to implement that? Maybe with a module with a function per case.
|
|
|
|
|
|
- Hygiene issue. For now, every span is located at the macro call site.
|
|
|
|
|
|
- Let the possibility for the users to create their own assertions.
|
|
|
|
|
|
- Maybe, add some fixture/setup capacities. |