[][src]Struct retest::Test

pub struct Test { /* fields omitted */ }

Represents a single test which can be generated or retested.

Create a new test using new(). Override its defaults using the builder methods, and finally call build().

New Tests should be passed to the Plan::push() method.

See also the builders example.

Methods

impl Test[src]

pub fn new<P: AsRef<Path>>(app: P) -> Test[src]

Returns a new Test.

Creates a new Test with the application to test set to the given app.

The given app should either be in the PATH or should include a path. For example: Path::new(env!("CARGO_TARGET_DIR")).join("myapp.exe").

The Test's defaults are for an expected error code/error level of 0, no arguments for the application to test, no stdin to be fed into the application, no stdout to be captured from the application, and for expected and actual outputs to be compared using the DiffKind that retest itself determines.

All the defaults can be overridden using the Test's methods.

pub fn args(&mut self, args: &[&str]) -> &mut Self[src]

Sets the command line arguments to be passed to the application to test.

If one of these arguments is the filename of a file which you want to generate or retest, then its name must be prefixed with $OUT_PATH, e.g., .args(&["-o", "$OUT_PATH/123.png"]). When generating, $OUT_PATH is replaced by the expected path, and when retesting by the actual path.

Note that retest can compare either a single output file or the application to test's stdout (captured to a file), but not both at the same time. If you need to test both, then create two separate tests. This is because each comparison may need to be done differently. For example the output file might be compared as an image and the stdout as text.

See also stdout().

pub fn name(&mut self, name: &str) -> &mut Self[src]

Sets the Test's name.

This is used when logging passed tests and in all cases when logging output is at the “debug” level.

pub fn exit_code(&mut self, exit_code: i32) -> &mut Self[src]

Sets the expected exit code/error level when the application to test is run.

pub fn wait(&mut self, wait: f64) -> &mut Self[src]

Sets how long (in seconds) to wait before running the application to test.

The default is 0.0, i.e., don't wait.

This option can be useful if a test sometimes “outruns” the operating system causing it to needlessly fail, and which can be cured by a small wait.

pub fn stdin_redirect(&mut self, stdin: &[u8]) -> &mut Self[src]

Sets the raw bytes to be passed to the application to test's stdin.

Note that if you use this method and subsequently use the Plan::rt() method, the returned retest plan file (.rt) format string will have a STDIN placeholder for each test this method is used on. For example:

This example is not tested
STDIN: ///87 raw bytes///

This is because the bytes are fed directly into the method rather than read from a file as happens when using a retest plan file (.rt).

pub fn stdout<P: AsRef<Path>>(&mut self, stdout: P) -> &mut Self[src]

Sets the name of the file to capture the application to test's stdout to.

This file will be written to the expected path when generating, or to the actual path when retesting.

Note that retest can compare either a single output file or the application to test's stdout (captured to a file), but not both at the same time. If you need to test both, then create two separate tests. This is because each comparison may need to be done differently. For example the output file might be compared as an image and the stdout as text.

See also args().

pub fn diff(&mut self, diff: DiffKind) -> &mut Self[src]

Sets how retest comparisons between expecteds and actuals is done.

By default, the Plan::retest() method guesses what kind of comparison to do when comparing an expected output with an actual output during a retest run.

For files with no suffix it assumes DiffKind::Binary, and for files with suffix .jsn or .json it assumes DiffKind::Json (and compares the JSON data, ignoring irrelevant whitespace). For common image formats it assumes DiffKind::Image and compares pixel for pixel; otherwise it assumes DiffKind::Text and compares text (but ignores line-endings).

You can force retest to use the comparison mode of your choice for a particular test by passing a DiffKind to this method.

Or you can make Plan::retest() use an external tool to do the comparison by passing the tool's name (e.g., pass DiffKind::custom("diff") on Unix, to use the diff tool). The tool must return 0 if the compared files are (or are considered to be) the same, or non-zero otherwise.

Or you can force retest not to compare output (i.e., if you only want to check the exit status/error level) by passing DiffKind::No.

pub fn diff_args(&mut self, args: &[&str]) -> &mut Self[src]

Sets the command line arguments to pass to an external tool if one is specified using the diff() method.

Normally you will need at least two arguments giving the names of the two files to compare, e.g., ["$EXPECTED_PATH/test05.dat", "$ACTUAL_PATH/test05.dat"]. At runtime these paths are replaced with rt_expected and rt_actual as appropriate, or to the path(s) set using Plan::expected_path() or Plan::actual_path().

pub fn build(&mut self) -> Self[src]

Returns the built Test ready to be passed to Plan::push().

Trait Implementations

impl Clone for Test[src]

impl Debug for Test[src]

impl Display for Test[src]

Auto Trait Implementations

impl Send for Test

impl Unpin for Test

impl Sync for Test

impl UnwindSafe for Test

impl RefUnwindSafe for Test

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SetParameter for T