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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
use std::process::ExitStatus;
use std::{collections::HashSet, io};
///
/// # Calculate the time of the test function
///
pub trait Take {
///
/// # run assertion
///
/// - `t` The test
///
fn assert_that(&mut self, t: bool) -> bool;
///
/// # Run assert and measure execution time
///
/// - `t` The test
/// - `s` The success output message
/// - `e` The error output message
///
fn take(&mut self, t: bool, s: &str, e: &str) -> &mut Self;
///
///
/// # Run a assert and mesure the time
///
/// - `t` The test
/// - `s` The success output message
/// - `e` The error output message
///
fn check(&mut self, t: bool, s: &str, e: &str);
}
///
/// # Add theory useful method
///
pub trait Theory {
///
/// # A theory must be equal to false
///
/// - `callback` The callback to execute
///
fn chaos(&mut self, callback: &dyn Fn() -> bool) -> &mut Self;
///
/// # Test a theory
///
/// - `expected` The expect callback result
/// - `callback` The callback to execute
///
fn theory<T: PartialEq>(&mut self, expected: T, callback: &dyn Fn() -> T) -> &mut Self;
}
///
/// # Assertion to expect a failure
///
pub trait Failure {
///
/// # Check if a command exit status is a failure code
///
/// - `callbacks` The callbacks to check
///
fn command_fail(
&mut self,
callbacks: Vec<&dyn Fn() -> Result<ExitStatus, io::Error>>,
) -> &mut Self;
///
/// # Check if a callbacks return false
///
/// - `callbacks` The callbacks to check
///
fn fail(&mut self, callbacks: Vec<&dyn Fn() -> bool>) -> &mut Self;
}
///
/// # Expectations to expect a success
///
pub trait Success {
///
/// # Check if a command success
///
/// - `callbacks` The callbacks to check
///
fn run(&mut self, callbacks: Vec<&dyn Fn() -> Result<ExitStatus, io::Error>>) -> &mut Self;
///
/// # Check if a callbacks return true
///
/// - `callbacks` The callbacks to check
///
fn success(&mut self, callbacks: Vec<&dyn Fn() -> bool>) -> &mut Self;
}
///
/// # The method to implements for a new struct
///
pub trait Testable {
///
/// - `sleep_time` The sleep time
///
fn new(sleep_time: u64) -> Self;
///
/// # Check if a pattern matches values
///
/// - `pattern` The pattern to match
/// - `values` The values to check
///
fn matches(&mut self, pattern: &str, values: Vec<String>) -> &mut Self;
///
/// # check if a pattern a the x index equal a value listing in values
///
/// - `pattern` The pattern to match
/// - `x` The index to match
/// - `values` The values
///
fn capture(&mut self, pattern: &str, x: &str, key: usize, values: Vec<String>) -> &mut Self;
///
/// # Constructor
///
/// - `callbacks` The vec list of callback
/// - `describe` The description
///
fn it(describe: &str, sleep_time: u64, callbacks: Vec<&dyn Fn(&mut Self) -> &mut Self>);
///
/// # Assert if callback return true
///
/// - `f` The callback
///
fn ok(&mut self, f: &dyn Fn() -> bool) -> &mut Self;
///
/// # Assert if callback return false
///
/// - `f` The callback
///
///
fn ko(&mut self, f: &dyn Fn() -> bool) -> &mut Self;
///
/// # Check if test pass
///
/// - `test` The test assertion
///
///
fn assert(&mut self, test: bool) -> bool;
///
/// # Check if a and b are equals
///
/// - `a` The first value
/// - `b` The second value
///
fn equals<T: PartialEq>(&mut self, a: T, b: T) -> &mut Self;
///
/// # Check if a and b are unequals
///
/// - `a` The first value
/// - `b` The second value
///
fn unequals<T: PartialEq>(&mut self, a: T, b: T) -> &mut Self;
///
/// # Check if a are superior to min
///
/// - `a` The first value
/// - `min` The minimum value
///
fn superior<T: PartialOrd>(&mut self, a: T, min: T) -> &mut Self;
///
/// # Check if a are inferior to max
///
/// - `a` The first value
/// - `max` The maximum value
///
fn inferior<T: PartialOrd>(&mut self, a: T, max: T) -> &mut Self;
///
/// # Check if a are between min and max
///
/// - `a` The first value
/// - `min` The minimum value
/// - `max` The maximum value
///
fn between<T: PartialOrd>(&mut self, a: T, min: T, max: T) -> &mut Self;
///
/// # Check if a vector contains a value
///
/// - `a` The vector
/// - `b` The value to check
///
fn vec_contains<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Self;
///
/// # Check if p is a program
///
/// - `p` The program path
///
fn program(&mut self, p: &str) -> &mut Self;
///
/// # Check if p is not a program
///
/// - `p` The program to test
///
///
fn not_program(&mut self, p: &str) -> &mut Self;
///
/// # Check if a vector not contains a value
///
/// - `a` The vector
/// - `b` The value to check
///
fn vec_no_contains<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Self;
///
/// # Check if a option contains a value
///
/// - `a` The vector
/// - `b` The value to check
///
fn option_contains<T: PartialEq>(&mut self, a: Option<T>, b: T) -> &mut Self;
///
/// # Check if a hash contains a string
///
/// - `a` The hash
/// - `b` The value to find
///
fn hash_contains(&mut self, a: &mut HashSet<String>, b: String) -> &mut Self;
///
/// # Check if a sting contains a substring
///
/// - `a` The string
/// - `b` The substring
///
fn string_contains(&mut self, a: &str, b: &str) -> &mut Self;
///
/// # Check if a file contains a value
///
/// - `f` The file
/// - `v` The value to check
///
fn file_contains(&mut self, f: &str, v: &str) -> &mut Self;
///
/// # Check if a paths exists
///
/// - `p` The path to test
///
fn exists(&mut self, p: &str) -> &mut Self;
///
/// # Check if a path not exist
///
/// - `p` The path to check the no existence
///
fn not_exists(&mut self, p: &str) -> &mut Self;
///
/// # Check if a string begin with the expected value
///
/// - `actual` The actual value
/// - `expected` The expected value
///
fn begin_with(&mut self, actual: &str, expected: &str) -> &mut Self;
///
/// # Check if a string finnish with the expected value
///
/// - `actual` The actual value
/// - `expected` The expected value
///
fn end_with(&mut self, actual: &str, expected: &str) -> &mut Self;
///
/// # Show assertions
///
fn end(&mut self) -> bool;
}