]>
git.proxmox.com Git - rustc.git/blob - src/tools/rustfmt/tests/cargo-fmt/main.rs
1 // Integration tests for cargo-fmt.
4 use std
::process
::Command
;
6 /// Run the cargo-fmt executable and return its output.
7 fn cargo_fmt(args
: &[&str]) -> (String
, String
) {
8 let mut bin_dir
= env
::current_exe().unwrap();
9 bin_dir
.pop(); // chop off test exe name
10 if bin_dir
.ends_with("deps") {
13 let cmd
= bin_dir
.join(format
!("cargo-fmt{}", env
::consts
::EXE_SUFFIX
));
15 // Ensure cargo-fmt runs the rustfmt binary from the local target dir.
16 let path
= env
::var_os("PATH").unwrap_or_default();
17 let mut paths
= env
::split_paths(&path
).collect
::<Vec
<_
>>();
18 paths
.insert(0, bin_dir
);
19 let new_path
= env
::join_paths(paths
).unwrap();
21 match Command
::new(&cmd
).args(args
).env("PATH", new_path
).output() {
23 String
::from_utf8(output
.stdout
).expect("utf-8"),
24 String
::from_utf8(output
.stderr
).expect("utf-8"),
26 Err(e
) => panic
!("failed to run `{:?} {:?}`: {}", cmd
, args
, e
),
30 macro_rules
! assert_that
{
31 ($args
:expr
, $check
:ident $check_args
:tt
) => {
32 let (stdout
, stderr
) = cargo_fmt($args
);
33 if !stdout
.$check$check_args
{
35 "Output not expected for cargo-fmt {:?}\n\
41 stringify
!($check_args
),
52 assert_that
!(&["--version"], starts_with("rustfmt "));
53 assert_that
!(&["--version"], starts_with("rustfmt "));
54 assert_that
!(&["--", "-V"], starts_with("rustfmt "));
55 assert_that
!(&["--", "--version"], starts_with("rustfmt "));
62 &["--", "--print-config", "current", "."],
63 contains("max_width = ")
70 assert_that
!(&["--", "--help"], contains("Format Rust code"));
71 assert_that
!(&["--", "-h"], contains("Format Rust code"));
72 assert_that
!(&["--", "--help=config"], contains("Configuration Options:"));