File: cargo_output.rs

package info (click to toggle)
rust-vergen 8.3.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: makefile: 2
file content (177 lines) | stat: -rw-r--r-- 6,049 bytes parent folder | download | duplicates (2)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#[cfg(feature = "cargo")]
mod test_build {
    use anyhow::Result;
    use cargo_metadata::DependencyKind;
    use lazy_static::lazy_static;
    use regex::Regex;
    use std::env;
    use vergen::EmitBuilder;

    lazy_static! {
        static ref CARGO_DEBUG_RE_STR: &'static str =
            r"cargo:rustc-env=VERGEN_CARGO_DEBUG=(true|false)";
        static ref CARGO_FEA_RE_STR: &'static str =
            r"cargo:rustc-env=VERGEN_CARGO_FEATURES=[a-zA-Z0-9-_]+,[a-zA-Z0-9-_]+";
        static ref CARGO_OPT_LEVEL_RE_STR: &'static str =
            r"cargo:rustc-env=VERGEN_CARGO_OPT_LEVEL=\d{1}";
        static ref CARGO_TT_RE_STR: &'static str =
            r"cargo:rustc-env=VERGEN_CARGO_TARGET_TRIPLE=[a-zA-Z0-9-_]+";
        static ref CARGO_DEP_RE_STR: &'static str = r"cargo:rustc-env=VERGEN_CARGO_DEPENDENCIES=.*";
        static ref CARGO_DEP_NAME_RE_STR: &'static str =
            r"(?m)^cargo:rustc-env=VERGEN_CARGO_DEPENDENCIES=anyhow 1\.0\.[0-9]{2,}$";
        static ref CARGO_DEP_DK_RE_STR: &'static str =
            r"(?m)^cargo:rustc-env=VERGEN_CARGO_DEPENDENCIES=gix 0\.63\.[0-9]{1,}$";
        static ref CARGO_DEP_RV_RE_STR: &'static str =
            r"(?m)^cargo:rustc-env=VERGEN_CARGO_DEPENDENCIES=rustversion 1\.0\.[0-9]{2,}$";
        static ref CARGO_REGEX: Regex = {
            let re_str = [
                *CARGO_DEBUG_RE_STR,
                *CARGO_FEA_RE_STR,
                *CARGO_OPT_LEVEL_RE_STR,
                *CARGO_TT_RE_STR,
                *CARGO_DEP_RE_STR,
            ]
            .join("\n");
            Regex::new(&re_str).unwrap()
        };
        static ref CARGO_REGEX_NO_DEP: Regex = {
            let re_str = [
                *CARGO_DEBUG_RE_STR,
                *CARGO_FEA_RE_STR,
                *CARGO_OPT_LEVEL_RE_STR,
                *CARGO_TT_RE_STR,
            ]
            .join("\n");
            Regex::new(&re_str).unwrap()
        };
        static ref CARGO_REGEX_NAME: Regex = Regex::new(&CARGO_DEP_NAME_RE_STR).unwrap();
        static ref CARGO_REGEX_DK: Regex = Regex::new(&CARGO_DEP_DK_RE_STR).unwrap();
        static ref CARGO_REGEX_RV: Regex = Regex::new(&CARGO_DEP_RV_RE_STR).unwrap();
    }

    fn setup() {
        env::set_var("CARGO_FEATURE_BUILD", "build");
        env::set_var("CARGO_FEATURE_GIT", "git");
        env::set_var("DEBUG", "true");
        env::set_var("OPT_LEVEL", "1");
        env::set_var("TARGET", "x86_64-unknown-linux-gnu");
    }

    fn teardown() {
        env::remove_var("CARGO_FEATURE_BUILD");
        env::remove_var("CARGO_FEATURE_GIT");
        env::remove_var("DEBUG");
        env::remove_var("OPT_LEVEL");
        env::remove_var("TARGET");
    }

    const DISABLED_OUTPUT: &str = r"";

    #[test]
    #[serial_test::serial]
    fn cargo_all_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .all_cargo()
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert!(CARGO_REGEX.is_match(&output));
        teardown();
        Ok(())
    }

    #[test]
    #[serial_test::serial]
    fn cargo_disabled_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .all_cargo()
            .disable_cargo()
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert_eq!(DISABLED_OUTPUT, output);
        teardown();
        Ok(())
    }

    #[test]
    #[serial_test::serial]
    fn cargo_all_idempotent_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .idempotent()
            .all_cargo()
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert!(CARGO_REGEX.is_match(&output));
        teardown();
        Ok(())
    }

    #[test]
    #[serial_test::serial]
    fn cargo_all_name_filter_none_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .all_cargo()
            .cargo_dependencies_name_filter(Some("blah"))
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert!(CARGO_REGEX_NO_DEP.is_match(&output));
        teardown();
        Ok(())
    }

    #[test]
    #[serial_test::serial]
    fn cargo_all_name_filter_some_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .all_cargo()
            .cargo_dependencies_name_filter(Some("anyhow"))
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert!(CARGO_REGEX.is_match(&output));
        //assert!(CARGO_REGEX_NAME.is_match(&output));
        teardown();
        Ok(())
    }

    #[test]
    #[serial_test::serial]
    fn cargo_all_dep_kind_filter_none_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .all_cargo()
            .cargo_dependencies_dep_kind_filter(Some(DependencyKind::Build))
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert!(CARGO_REGEX_NO_DEP.is_match(&output));
        //assert!(CARGO_REGEX_RV.is_match(&output));
        teardown();
        Ok(())
    }

    #[test]
    #[serial_test::serial]
    fn cargo_all_dep_kind_filter_some_output() -> Result<()> {
        setup();
        let mut stdout_buf = vec![];
        EmitBuilder::builder()
            .all_cargo()
            .cargo_dependencies_name_filter(Some("gix"))
            .cargo_dependencies_dep_kind_filter(Some(DependencyKind::Development))
            .emit_to(&mut stdout_buf)?;
        let output = String::from_utf8_lossy(&stdout_buf);
        //assert!(CARGO_REGEX.is_match(&output));
        //assert!(CARGO_REGEX_DK.is_match(&output));
        teardown();
        Ok(())
    }
}