[−][src]Struct lang_tester::LangTester
Implementations
impl LangTester
[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(&mut self, test_dir: &str) -> &mut Self
[src]
Specify the directory where test files are contained. Note that this directory will be searched recursively (i.e. subdirectories and their contents will also be considered as potential test files).
pub fn test_threads(&mut self, test_threads: usize) -> &mut Self
[src]
Specify the number of simultaneous running test cases. Defaults to using all available CPUs.
pub fn test_file_filter<F>(&mut self, test_file_filter: F) -> &mut Self where
F: 'static + Fn(&Path) -> bool,
[src]
F: 'static + Fn(&Path) -> bool,
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.:
LangTester::new() ... .test_file_filter(|p| p.extension().unwrap().to_str().unwrap() == "rs") ...
Note that lang_tester
recursively searches directories for files.
pub fn test_extract<F>(&mut self, test_extract: F) -> &mut Self where
F: 'static + Fn(&str) -> Option<String> + Send + Sync,
[src]
F: 'static + Fn(&str) -> Option<String> + Send + Sync,
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 data is extracted from the test file is entirely up to the user, though a common convention is to store the test data in a comment at the beginning of the test file. For example, for Rust code one could use a function along the lines of the following:
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 fm_options<F>(&mut self, fm_options: F) -> &mut Self where
F: 'static + for<'a> Fn(&'a Path, TestStream, FMBuilder<'a>) -> FMBuilder<'a> + Send + Sync,
[src]
F: 'static + for<'a> Fn(&'a Path, TestStream, FMBuilder<'a>) -> FMBuilder<'a> + Send + Sync,
Specify a function which sets options for the fm
library.
fm
is used for the fuzzy matching in lang_tester
. This function can be used to override
fm
's defaults for a given test file (passed as Path
) and a given testing stream (stderr
or stdout, passed as TestStream
) when executing a command for that file: it is passed a
FMBuilder
and must return a FMBuilder
.
For example, to make use of fm
's "name matcher" option such that all instances of $1
must match the same value (without precisely specifying what that value is) one could use
the following:
LangTester::new() ... .fm_options(|_, _, fmb| { let ptn_re = Regex::new(r"\$.+?\b").unwrap(); let text_re = Regex::new(r".+?\b").unwrap(); fmb.name_matcher(Some((ptn_re, text_re))) })
pub fn test_cmds<F>(&mut self, test_cmds: F) -> &mut Self where
F: 'static + Fn(&Path) -> Vec<(&str, Command)> + Send + Sync,
[src]
F: 'static + Fn(&Path) -> Vec<(&str, Command)> + Send + Sync,
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, test commands starting with
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 test data such as:
Compiler:
status: success
stderr:
stdout:
Run-time:
status: failure
stderr:
...
Error at line 10
...
pub fn use_cmdline_args(&mut self, use_cmdline_args: bool) -> &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 !RefUnwindSafe for LangTester
impl !Send for LangTester
impl !Sync for LangTester
impl Unpin for LangTester
impl !UnwindSafe for LangTester
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,