File: ext.rs

package info (click to toggle)
rust-cargo 0.91.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,860 kB
  • sloc: javascript: 426; sh: 315; python: 88; xml: 21; makefile: 6
file content (49 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (5)
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
use std::path::PathBuf;

use cargo_test_support::{ArgLineCommandExt, Execs, Project, TestEnvCommandExt, compare};

pub trait CargoProjectExt {
    /// Creates a `ProcessBuilder` to run cargo.
    ///
    /// Arguments can be separated by spaces.
    ///
    /// For `cargo run`, see [`Project::rename_run`].
    ///
    /// # Example:
    ///
    /// ```no_run
    /// # let p = cargo_test_support::project().build();
    /// p.cargo("build --bin foo").run();
    /// ```
    fn cargo(&self, cmd: &str) -> Execs;
}

impl CargoProjectExt for Project {
    fn cargo(&self, cmd: &str) -> Execs {
        let cargo = cargo_exe();
        let mut execs = self.process(&cargo);
        execs.env("CARGO", cargo);
        execs.arg_line(cmd);
        execs
    }
}

/// Path to the cargo binary
pub fn cargo_exe() -> PathBuf {
    snapbox::cmd::cargo_bin!("cargo").to_path_buf()
}

/// Test the cargo command
pub trait CargoCommandExt {
    fn cargo_ui() -> Self;
}

impl CargoCommandExt for snapbox::cmd::Command {
    fn cargo_ui() -> Self {
        Self::new(cargo_exe())
            .with_assert(compare::assert_ui())
            .env("CARGO_TERM_COLOR", "always")
            .env("CARGO_TERM_HYPERLINKS", "true")
            .test_env()
    }
}