1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::path::{Path, PathBuf};

use steps::TestStepFactory;

#[derive(PartialEq)]
pub enum Mode {
    BuildFail,
    BuildSuccess,
    Expand,
}

#[derive(PartialEq)]
pub enum Profile {
    Debug,
    Release,
}

pub struct Config {
    pub mode: Mode,

    pub base_dir: PathBuf,
    pub target: Option<String>,
    pub profile: Profile,

    pub cargo_env: Vec<(String, String)>,
    pub cargo_command: String,

    pub crates_filter: Box<Fn(&Path) -> bool>,
    pub additional_steps: Vec<Box<TestStepFactory>>,
}

impl Config {
    pub fn new<P: AsRef<Path>>(mode: Mode, base_dir: P) -> Self {
        Config {
            mode,

            base_dir: base_dir.as_ref().into(),
            target: None,
            profile: Profile::Release,

            cargo_env: vec![],
            cargo_command: "cargo".into(),

            crates_filter: Box::new(|_| true),
            additional_steps: vec![],
        }
    }

    pub fn add_cargo_env<S: Into<String>>(&mut self, key: S, value: S) {
        self.cargo_env.push((key.into(), value.into()));
    }
}