Skip to content

Commit 71609c5

Browse files
committed
move test to integration test
1 parent beda310 commit 71609c5

File tree

4 files changed

+63
-78
lines changed

4 files changed

+63
-78
lines changed

src/formatting/cargo_toml.rs

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -334,78 +334,3 @@ impl VisitMut for FormatInlineTable {
334334
});
335335
}
336336
}
337-
338-
#[cfg(test)]
339-
mod tests {
340-
use super::*;
341-
342-
#[test]
343-
fn cargo_toml() {
344-
#[rustfmt::skip]
345-
let s = r#"
346-
347-
348-
[[bin]]
349-
"aa" = 1
350-
'bb' = 2
351-
"啊"=1
352-
[package]
353-
version = 1
354-
description = "a\nb\nhaha"
355-
name = 3
356-
357-
# comment 1
358-
359-
arr1 = [1,
360-
2,3]
361-
362-
# comment 2
363-
364-
arr2 = ["11111111111111111111111111111111111111111111111111111111111111111111111111111111","1111111111111111111111111111111111111111111111111111111111111111111111111111111"]
365-
366-
[dependencies]
367-
extremely_long_crate_name_goes_here = {path = "extremely_long_path_name_goes_right_here",version = "4.5.6"}
368-
crate1 = { path = "crate1",version = "1.2.3" }
369-
370-
[[bin]]
371-
d = "git-rustfmt"
372-
c = "src/git-rustfmt/main.rs""#;
373-
374-
let formatted = format_cargo_toml_inner(s, &Default::default()).unwrap();
375-
376-
#[rustfmt::skip]
377-
let expected = r#"[package]
378-
name = 3
379-
version = 1
380-
# comment 1
381-
arr1 = [1, 2, 3]
382-
# comment 2
383-
arr2 = [
384-
"11111111111111111111111111111111111111111111111111111111111111111111111111111111",
385-
"1111111111111111111111111111111111111111111111111111111111111111111111111111111"
386-
]
387-
description = """
388-
a
389-
b
390-
haha"""
391-
392-
[[bin]]
393-
aa = 1
394-
bb = 2
395-
"啊" = 1
396-
397-
[[bin]]
398-
c = "src/git-rustfmt/main.rs"
399-
d = "git-rustfmt"
400-
401-
[dependencies]
402-
crate1 = { path = "crate1", version = "1.2.3" }
403-
404-
[dependencies.extremely_long_crate_name_goes_here]
405-
path = "extremely_long_path_name_goes_right_here"
406-
version = "4.5.6"
407-
"#;
408-
409-
assert_eq!(formatted, expected);
410-
}
411-
}

src/test/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ fn is_file_skip(path: &Path) -> bool {
9595
.any(|file_path| is_subpath(path, file_path))
9696
}
9797

98-
// Returns a `Vec` containing `PathBuf`s of files with an `rs` extension in the
99-
// given path. The `recursive` argument controls if files from subdirectories
98+
// Returns a `Vec` containing `PathBuf`s of files with an `rs` extension or a `Cargo.toml` filename
99+
// in the given path. The `recursive` argument controls if files from subdirectories
100100
// are also returned.
101101
fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
102102
let mut files = vec![];
@@ -109,7 +109,10 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
109109
let path = entry.path();
110110
if path.is_dir() && recursive {
111111
files.append(&mut get_test_files(&path, recursive));
112-
} else if path.extension().map_or(false, |f| f == "rs") && !is_file_skip(&path) {
112+
} else if (path.extension().map_or(false, |f| f == "rs")
113+
|| path.file_name().map_or(false, |f| f == "Cargo.toml"))
114+
&& !is_file_skip(&path)
115+
{
113116
files.push(path);
114117
}
115118
}

tests/source/cargo-toml/1/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
3+
[[bin]]
4+
"aa" = 1
5+
'bb' = 2
6+
"啊"=1
7+
[package]
8+
version = 1
9+
description = "a\nb\nhaha"
10+
name = 3
11+
12+
# comment 1
13+
14+
arr1 = [1,
15+
2,3]
16+
17+
# comment 2
18+
19+
arr2 = ["11111111111111111111111111111111111111111111111111111111111111111111111111111111","1111111111111111111111111111111111111111111111111111111111111111111111111111111"]
20+
21+
[dependencies]
22+
extremely_long_crate_name_goes_here = {path = "extremely_long_path_name_goes_right_here",version = "4.5.6"}
23+
crate1 = { path = "crate1",version = "1.2.3" }
24+
25+
[[bin]]
26+
d = "git-rustfmt"
27+
c = "src/git-rustfmt/main.rs"

tests/target/cargo-toml/1/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = 3
3+
version = 1
4+
# comment 1
5+
arr1 = [1, 2, 3]
6+
# comment 2
7+
arr2 = [
8+
"11111111111111111111111111111111111111111111111111111111111111111111111111111111",
9+
"1111111111111111111111111111111111111111111111111111111111111111111111111111111"
10+
]
11+
description = """
12+
a
13+
b
14+
haha"""
15+
16+
[[bin]]
17+
aa = 1
18+
bb = 2
19+
"啊" = 1
20+
21+
[[bin]]
22+
c = "src/git-rustfmt/main.rs"
23+
d = "git-rustfmt"
24+
25+
[dependencies]
26+
crate1 = { path = "crate1", version = "1.2.3" }
27+
28+
[dependencies.extremely_long_crate_name_goes_here]
29+
path = "extremely_long_path_name_goes_right_here"
30+
version = "4.5.6"

0 commit comments

Comments
 (0)