1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! A library for writing assertions on methods, function and closure calls.
//!
//! Racetrack allows for tracking direct and indirect calls to methods. It's inspired by Jest's `fn()` and `spyOn`.
//! The library consists of the tracker, which handles assertions, as well as a proc-macro that allows for automatic tracking injection into methods.
//!
//! # Usage
//!
//! The intended usage is with the proc macro.
//!
//! ```
//! # use std::sync::Arc;
//! use racetrack::{Tracker, track_with};
//!
//! struct TrackedStruct(Arc<Tracker>);
//!
//! #[track_with(0)]
//! impl TrackedStruct {
//!     fn tracked_fn(&self, arg: String) {}
//! }
//!
//! let tracker = Tracker::new();
//! let tracked = TrackedStruct(tracker.clone());
//! tracked.tracked_fn("Test".to_string());
//!
//! tracker
//!     .assert_that("TrackedStruct::tracked_fn")
//!     .was_called_once()
//!     .with(("Test".to_string()));
//! ```
//!
//! However, this has some caviats. All arguments and the return type must implement `ToOwned` and
//! it may not work if you have very specific requirements.
//! So, alternatively, you can use the tracker manually:
//!
//! ```
//! # use std::sync::Arc;
//! use racetrack::{Tracker, CallInfo};
//!
//! struct TrackedStruct(Arc<Tracker>);
//!
//! impl TrackedStruct {
//!     fn tracked_fn(&self, arg: String) {
//!         let call_info = CallInfo {
//!             arguments: Some(Box::new(arg)),
//!             returned: None
//!         };
//!         self.0.log_call("my_fn", call_info);
//!     }
//! }
//!
//! let tracker = Tracker::new();
//! let tracked = TrackedStruct(tracker.clone());
//! tracked.tracked_fn("Test".to_string());
//!
//! tracker
//!     .assert_that("my_fn")
//!     .was_called_once()
//!     .with("Test".to_string());
//! ```

pub mod tracker;

pub use tracker::{Tracker, CallInfo};
pub use racetrack_proc_macro::track_with;