Run the [RunCommand]: - for [RunCommand::Print], print the returned values from invoking the function. - for [RunCommand::Run], compare the returned values from the invoked function and return an `Err` with a descriptive string if the comparison fails. Accepts a function used for invoking the actual execution of the command. This function, `invoked_fn`, is passed the _function name_ and _function
(&self, invoke_fn: F)
| 29 | /// Accepts a function used for invoking the actual execution of the command. This function, |
| 30 | /// `invoked_fn`, is passed the _function name_ and _function arguments_ of the [Invocation]. |
| 31 | pub fn run<F>(&self, invoke_fn: F) -> Result<(), String> |
| 32 | where |
| 33 | F: FnOnce(&str, &[DataValue]) -> Result<Vec<DataValue>, String>, |
| 34 | { |
| 35 | match self { |
| 36 | RunCommand::Print(invoke) => { |
| 37 | let actual = invoke_fn(&invoke.func, &invoke.args)?; |
| 38 | println!("{} -> {}", invoke, DisplayDataValues(&actual)) |
| 39 | } |
| 40 | RunCommand::Run(invoke, compare, expected) => { |
| 41 | let actual = invoke_fn(&invoke.func, &invoke.args)?; |
| 42 | let matched = Self::compare_results(compare, &actual, expected); |
| 43 | if !matched { |
| 44 | let actual = DisplayDataValues(&actual); |
| 45 | return Err(format!("Failed test: {self}, actual: {actual}")); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | Ok(()) |
| 50 | } |
| 51 | |
| 52 | fn compare_results( |
| 53 | compare: &Comparison, |
nothing calls this directly
no test coverage detected