summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt/tests/cargo-fmt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/rustfmt/tests/cargo-fmt')
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/main.rs98
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/Cargo.toml13
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/Cargo.toml10
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/src/lib.rs7
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/Cargo.toml7
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/src/lib.rs7
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/src/main.rs3
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/Cargo.toml8
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/src/main.rs1
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/Cargo.toml5
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/Cargo.toml6
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/Cargo.toml7
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/Cargo.toml4
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/src/lib.rs1
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/src/lib.rs1
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/src/main.rs1
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/Cargo.toml6
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/src/main.rs1
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/Cargo.toml4
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/src/lib.rs1
20 files changed, 191 insertions, 0 deletions
diff --git a/src/tools/rustfmt/tests/cargo-fmt/main.rs b/src/tools/rustfmt/tests/cargo-fmt/main.rs
new file mode 100644
index 000000000..348876cd2
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/main.rs
@@ -0,0 +1,98 @@
+// Integration tests for cargo-fmt.
+
+use std::env;
+use std::path::Path;
+use std::process::Command;
+
+/// Run the cargo-fmt executable and return its output.
+fn cargo_fmt(args: &[&str]) -> (String, String) {
+ let mut bin_dir = env::current_exe().unwrap();
+ bin_dir.pop(); // chop off test exe name
+ if bin_dir.ends_with("deps") {
+ bin_dir.pop();
+ }
+ let cmd = bin_dir.join(format!("cargo-fmt{}", env::consts::EXE_SUFFIX));
+
+ // Ensure cargo-fmt runs the rustfmt binary from the local target dir.
+ let path = env::var_os("PATH").unwrap_or_default();
+ let mut paths = env::split_paths(&path).collect::<Vec<_>>();
+ paths.insert(0, bin_dir);
+ let new_path = env::join_paths(paths).unwrap();
+
+ match Command::new(&cmd).args(args).env("PATH", new_path).output() {
+ Ok(output) => (
+ String::from_utf8(output.stdout).expect("utf-8"),
+ String::from_utf8(output.stderr).expect("utf-8"),
+ ),
+ Err(e) => panic!("failed to run `{:?} {:?}`: {}", cmd, args, e),
+ }
+}
+
+macro_rules! assert_that {
+ ($args:expr, $check:ident $check_args:tt) => {
+ let (stdout, stderr) = cargo_fmt($args);
+ if !stdout.$check$check_args {
+ panic!(
+ "Output not expected for cargo-fmt {:?}\n\
+ expected: {}{}\n\
+ actual stdout:\n{}\n\
+ actual stderr:\n{}",
+ $args,
+ stringify!($check),
+ stringify!($check_args),
+ stdout,
+ stderr
+ );
+ }
+ };
+}
+
+#[ignore]
+#[test]
+fn version() {
+ assert_that!(&["--version"], starts_with("rustfmt "));
+ assert_that!(&["--version"], starts_with("rustfmt "));
+ assert_that!(&["--", "-V"], starts_with("rustfmt "));
+ assert_that!(&["--", "--version"], starts_with("rustfmt "));
+}
+
+#[ignore]
+#[test]
+fn print_config() {
+ assert_that!(
+ &["--", "--print-config", "current", "."],
+ contains("max_width = ")
+ );
+}
+
+#[ignore]
+#[test]
+fn rustfmt_help() {
+ assert_that!(&["--", "--help"], contains("Format Rust code"));
+ assert_that!(&["--", "-h"], contains("Format Rust code"));
+ assert_that!(&["--", "--help=config"], contains("Configuration Options:"));
+}
+
+#[ignore]
+#[test]
+fn cargo_fmt_out_of_line_test_modules() {
+ // See also https://github.com/rust-lang/rustfmt/issues/5119
+ let expected_modified_files = [
+ "tests/mod-resolver/test-submodule-issue-5119/src/lib.rs",
+ "tests/mod-resolver/test-submodule-issue-5119/tests/test1.rs",
+ "tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub1.rs",
+ "tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub2.rs",
+ "tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/sub4.rs",
+ ];
+ let args = [
+ "-v",
+ "--check",
+ "--manifest-path",
+ "tests/mod-resolver/test-submodule-issue-5119/Cargo.toml",
+ ];
+ let (stdout, _) = cargo_fmt(&args);
+ for file in expected_modified_files {
+ let path = Path::new(file).canonicalize().unwrap();
+ assert!(stdout.contains(&format!("Diff in {}", path.display())))
+ }
+}
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/Cargo.toml
new file mode 100644
index 000000000..315364a64
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "cargo-fmt-test"
+version = "0.1.0"
+authors = ["calebcartwright"]
+edition = "2018"
+
+[dependencies]
+indexmap = "1.0.2"
+
+[workspace]
+members = [
+ "dependency-dir-name",
+] \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/Cargo.toml
new file mode 100644
index 000000000..4493882bf
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "dependency-crate-name"
+version = "0.1.0"
+authors = ["calebcartwright"]
+edition = "2018"
+
+[dependencies]
+subdep-crate-name = { path = "subdep-dir-name" }
+indexmap = "1.0.2"
+rusty-hook = "0.8.4" \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/src/lib.rs b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/src/lib.rs
new file mode 100644
index 000000000..e93b18d72
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/src/lib.rs
@@ -0,0 +1,7 @@
+#[cfg(test)]
+mod tests {
+#[test]
+fn it_works() {
+ assert_eq!(2 + 2, 4);
+}
+}
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/Cargo.toml
new file mode 100644
index 000000000..7dad09f40
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "subdep-crate-name"
+version = "0.1.0"
+authors = ["calebcartwright"]
+edition = "2018"
+
+[dependencies]
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/src/lib.rs b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/src/lib.rs
new file mode 100644
index 000000000..1c08c1c4f
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/dependency-dir-name/subdep-dir-name/src/lib.rs
@@ -0,0 +1,7 @@
+#[cfg(test)]
+mod tests {
+#[test]
+fn sub_test_that_works() {
+ assert_eq!(3 + 3, 6);
+}
+ }
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/src/main.rs b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/src/main.rs
new file mode 100644
index 000000000..f5c339a8d
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/divergent-crate-dir-names/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+println!("Hello, world!");
+}
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/Cargo.toml
new file mode 100644
index 000000000..eaf1d76f9
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "e"
+version = "0.1.0"
+edition = "2018"
+[dependencies]
+c = { path = "../ws/c" }
+
+[workspace]
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/src/main.rs b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/src/main.rs
new file mode 100644
index 000000000..1c26a3895
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/e/src/main.rs
@@ -0,0 +1 @@
+struct E{ }
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/Cargo.toml
new file mode 100644
index 000000000..202739b61
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/Cargo.toml
@@ -0,0 +1,5 @@
+[workspace]
+members = [
+ "a",
+ "b"
+] \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/Cargo.toml
new file mode 100644
index 000000000..712a11344
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "a"
+version = "0.1.0"
+edition = "2018"
+[dependencies]
+d = { path = "./d" }
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/Cargo.toml
new file mode 100644
index 000000000..fb0f06fe5
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "d"
+version = "0.1.0"
+edition = "2018"
+[dependencies]
+e = { path = "../../../e" }
+f = { path = "f" }
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/Cargo.toml
new file mode 100644
index 000000000..5c4fa5617
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "f"
+version = "0.1.0"
+edition = "2018"
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/src/lib.rs b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/src/lib.rs
new file mode 100644
index 000000000..c655c4d5e
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/f/src/lib.rs
@@ -0,0 +1 @@
+struct F{ } \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/src/lib.rs b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/src/lib.rs
new file mode 100644
index 000000000..04e6e4cb9
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/d/src/lib.rs
@@ -0,0 +1 @@
+struct D{ } \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/src/main.rs b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/src/main.rs
new file mode 100644
index 000000000..04e6e4cb9
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/a/src/main.rs
@@ -0,0 +1 @@
+struct D{ } \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/Cargo.toml
new file mode 100644
index 000000000..47a24ff4f
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "b"
+version = "0.1.0"
+edition = "2018"
+[dependencies]
+c = { path = "../c" }
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/src/main.rs b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/src/main.rs
new file mode 100644
index 000000000..4833bbc69
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/b/src/main.rs
@@ -0,0 +1 @@
+struct B{ } \ No newline at end of file
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/Cargo.toml b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/Cargo.toml
new file mode 100644
index 000000000..49fa6c395
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "c"
+version = "0.1.0"
+edition = "2018"
diff --git a/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/src/lib.rs b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/src/lib.rs
new file mode 100644
index 000000000..1245ac91d
--- /dev/null
+++ b/src/tools/rustfmt/tests/cargo-fmt/source/workspaces/path-dep-above/ws/c/src/lib.rs
@@ -0,0 +1 @@
+struct C{ } \ No newline at end of file