Skip to content

Commit

Permalink
add support for formatting files in subdirectories of tests (#3777)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright authored and topecongiro committed Oct 29, 2019
1 parent 09a028b commit d35ebf7
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 45 deletions.
404 changes: 359 additions & 45 deletions src/cargo-fmt/main.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/nested-test-files/empty-tests-dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "empty-tests-dir"
version = "0.1.0"
authors = ["rustfmt devs <awesome@gmail.com>"]

[dependencies]
1 change: 1 addition & 0 deletions tests/nested-test-files/empty-tests-dir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
6 changes: 6 additions & 0 deletions tests/nested-test-files/no-tests-dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "no-tests"
version = "0.1.0"
authors = ["rustfmt devs <awesome@gmail.com>"]

[dependencies]
1 change: 1 addition & 0 deletions tests/nested-test-files/no-tests-dir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
6 changes: 6 additions & 0 deletions tests/nested-test-files/only-root-level-tests-dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "foo"
version = "0.1.0"
authors = ["rustfmt devs <awesome@gmail.com>"]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test2() {
assert!(true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test1() {
assert_eq!(1, 1);
}
7 changes: 7 additions & 0 deletions tests/nested-test-files/root-and-nested-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "root-and-nested-tests"
version = "0.1.0"
authors = ["rustfmt devs <awesome@gmail.com>"]
edition = "2018"

[dependencies]
1 change: 1 addition & 0 deletions tests/nested-test-files/root-and-nested-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
4 changes: 4 additions & 0 deletions tests/nested-test-files/root-and-nested-tests/tests/bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test2() {
assert!(true);
}
4 changes: 4 additions & 0 deletions tests/nested-test-files/root-and-nested-tests/tests/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test1() {
assert_eq!(1, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_truth() {
assert_eq!!(true, true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_false() {
assert_ne!(false, true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_add() {
assert_eq!(9, 4 + 5);
}

1 comment on commit d35ebf7

@calebcartwright
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tests for this failed in one of the Travis jobs for this commit. I can't reproduce it locally on Ubuntu though so I'm hoping it was a spurious failure. I will keep tabs on the jobs though to see if it fails again (and please let me know if anyone sees it failing locally), and if so I'll open a PR to update the test

https://travis-ci.com/rust-lang/rustfmt/jobs/250390989

Please sign in to comment.