Skip to main content

BatchRunner

Struct BatchRunner 

Source
pub struct BatchRunner { /* private fields */ }
Available on crate feature dyntest only.
Expand description

批量运行器:串行执行多个 DnyTask,可选超时、仅编译、依赖缓存与逐任务回调。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

§Examples

use lib_unknown::dyntest::{BatchRunner, DnyTask};

let tasks = [DnyTask::new("a", "fn main() {}"), DnyTask::new("b", "fn main() {}")];
let results = BatchRunner::new().only_build(true).run(tasks);
assert_eq!(results.len(), 2);

Implementations§

Source§

impl BatchRunner

Source

pub fn new() -> Self

以默认配置(无超时、编译并运行、不缓存、无回调)创建运行器。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn timeout(self, d: Duration) -> Self

设置单个任务编译 + 运行的总超时,超时后子进程被终止,结果记为 SystemError::Timeout。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn only_build(self, b: bool) -> Self

仅编译不运行。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn use_cache(self, c: bool) -> Self

启用首任务依赖预热缓存(先空跑一次编译,后续任务复用编译缓存)。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn on_result<F>(self, f: F) -> Self
where F: FnMut(String, DnyResult) + 'static,

设置每个任务完成后的回调(参数为任务标识与结果)。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn run<I, T>(self, tasks: I) -> Vec<(String, DnyResult)>
where I: IntoIterator<Item = T>, T: Into<DnyTask>,

串行执行全部任务,返回按输入顺序的 (标识, 结果) 列表;空输入直接返回空列表。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

§Examples
use lib_unknown::dyntest::{BatchRunner, DnyTask};

let results = BatchRunner::new().run([DnyTask::new("a", "fn main() {}")]);
assert!(results[0].1.ok);
§Panics
  • 任务工程目录创建/文件写入失败(磁盘不可写、权限不足)时 panic,源于内部 DnyRun 初始化。

Trait Implementations§

Source§

impl Default for BatchRunner

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.