[−][src]Struct lang_tester::LangTester
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 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_file_filter<F>(&'a mut self, test_file_filter: F) -> &'a 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") ...
pub fn test_extract<F>(&'a mut self, test_extract: F) -> &'a 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 test_cmds<F>(&'a mut self, test_cmds: F) -> &'a 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(&'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>
impl<'a> Unpin for LangTester<'a>
impl<'a> !UnwindSafe for LangTester<'a>
impl<'a> !RefUnwindSafe for LangTester<'a>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,