Skip to main content

flux_dev/
lib.rs

1//! Shared development utilities for `xtask` and `tests`.
2
3use std::{
4    path::{Path, PathBuf},
5    str::FromStr,
6};
7
8pub fn default_flags(sysroot: &Path, extern_args: Vec<String>) -> Vec<String> {
9    let mut flags = vec![
10        "--crate-type=rlib".to_string(),
11        "--edition=2021".to_string(),
12        // Transitive deps ignore `--extern`, so they still need a search path.
13        "-L".to_string(),
14        sysroot.display().to_string(),
15    ];
16    flags.extend(extern_args);
17    flags.push("-Fverify=on".to_string());
18    flags.push(format!("-Fsysroot={}", sysroot.display()));
19    flags
20}
21
22#[derive(Clone, Copy, Debug)]
23pub enum Suite {
24    Basic,
25    WithDeps,
26}
27
28impl Suite {
29    pub const ALL: &[Suite] = &[Suite::Basic, Suite::WithDeps];
30
31    pub fn name(self) -> &'static str {
32        match self {
33            Suite::Basic => "basic",
34            Suite::WithDeps => "with-deps",
35        }
36    }
37
38    pub fn pos_tests(self) -> PathBuf {
39        match self {
40            Suite::Basic => ["tests", "pos"].iter().collect(),
41            Suite::WithDeps => ["tests", "with_deps", "pos"].iter().collect(),
42        }
43    }
44
45    pub fn neg_tests(self) -> PathBuf {
46        match self {
47            Suite::Basic => ["tests", "neg"].iter().collect(),
48            Suite::WithDeps => ["tests", "with_deps", "neg"].iter().collect(),
49        }
50    }
51}
52
53impl FromStr for Suite {
54    type Err = &'static str;
55
56    fn from_str(s: &str) -> Result<Self, Self::Err> {
57        match s {
58            "basic" => Ok(Suite::Basic),
59            "with-deps" => Ok(Suite::WithDeps),
60            _ => Err("expected one of: basic, with-deps"),
61        }
62    }
63}