[][src]Struct lang_tester::LangTester

pub struct LangTester<'a> { /* fields omitted */ }

Methods

impl<'a> LangTester<'a>[src]

pub fn new() -> Self[src]

Create a new LangTester with default options. Note that, at a minimum, you need to call test_dir, test_extract, and test_cmds.

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

Specify the directory where tests are contained in. Note that this directory will be searched recursively (i.e. subdirectories and their contents will also be considered as potential tests).

pub fn test_file_filter<F>(&'a mut self, test_file_filter: F) -> &'a mut Self where
    F: 'static + Fn(&Path) -> bool
[src]

If test_file_filter is specified, only files for which it returns true will be considered tests. A common use of this is to filter files based on filename extensions e.g.:

This example is not tested
LangTester::new()
    ...
    .test_file_filter(|p| p.extension().unwrap().to_str().unwrap() == "rs")
    ...

pub fn test_extract<F>(&'a mut self, test_extract: F) -> &'a mut Self where
    F: 'static + Fn(&str) -> Option<String> + Send
[src]

Specify a function which can extract the test data for lang_tester from a test file. This function is passed a &str and must return a String.

How the test is extracted from the file is entirely up to the user, though a common convention is to store the test in a comment at the beginning of the file. For example, for Rust code one could use a function along the lines of the following:

This example is not tested
LangTester::new()
    ...
    .test_extract(|s| {
        Some(
            s.lines()
                // Skip non-commented lines at the start of the file.
                .skip_while(|l| !l.starts_with("//"))
                // Extract consecutive commented lines.
                .take_while(|l| l.starts_with("//"))
                .map(|l| &l[2..])
                .collect::<Vec<_>>()
                .join("\n"),
        )
    })
    ...

pub fn test_cmds<F>(&'a mut self, test_cmds: F) -> &'a mut Self where
    F: 'static + Fn(&Path) -> Vec<(&str, Command)> + Send
[src]

Specify a function which takes a Path to a test file and returns a vector containing 1 or more (<name>, <[Command](https://doc.rust-lang.org/std/process/struct.Command.html)>) pairs. The commands will be executed in order on the test file: for each executed command, tests starting with ` will be checked. For example, if your pipeline requires separate compilation and linking, you might specify something along the lines of the following:

This example is not tested
let tempdir = ...; // A `Path` to a temporary directory.
LangTester::new()
    ...
    .test_cmds(|p| {
        let mut exe = PathBuf::new();
        exe.push(&tempdir);
        exe.push(p.file_stem().unwrap());
        let mut compiler = Command::new("rustc");
        compiler.args(&["-o", exe.to_str().unwrap(), p.to_str().unwrap()]);
        let runtime = Command::new(exe);
        vec![("Compiler", compiler), ("Run-time", runtime)]
    })
    ...

and then have tests such as:

Compiler:
  status: success
  stderr:
  stdout:

Run-time:
  status: failure
  stderr:
    ...
    Error at line 10
    ...

pub fn use_cmdline_args(&'a mut self, use_cmdline_args: bool) -> &'a mut Self[src]

If set to true, this reads arguments from std::env::args() and interprets them in the same way as normal cargo test files. For example if you have tests "ab" and "cd" but only want to run the latter:

$ <test bin> c

As this suggests, a simple substring search is used to decide which tests to run.

You can get help on lang_tester's options:

$ <test bin> --help

This option defaults to true.

pub fn run(&mut self)[src]

Run all the lang tests.

Auto Trait Implementations

impl<'a> !Send for LangTester<'a>

impl<'a> !Sync for LangTester<'a>

Blanket Implementations

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[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]