Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / tools / lint / test / test_rustfmt.py
blobf1793be38301ef947c7262741468f0acdcf524de
1 import mozunit
3 LINTER = "rustfmt"
4 fixed = 0
7 def test_good(lint, config, paths):
8 results = lint(paths("subdir/good.rs"))
9 print(results)
10 assert len(results) == 0
13 def test_basic(lint, config, paths):
14 results = lint(paths("subdir/bad.rs"))
15 print(results)
16 assert len(results) >= 1
18 assert "Reformat rust" in results[0].message
19 assert results[0].level == "warning"
20 assert results[0].lineno == 4
21 assert "bad.rs" in results[0].path
22 assert "Print text to the console" in results[0].diff
25 def test_dir(lint, config, paths):
26 results = lint(paths("subdir/"))
27 print(results)
28 assert len(results) >= 4
30 assert "Reformat rust" in results[0].message
31 assert results[0].level == "warning"
32 assert results[0].lineno == 4
33 assert "bad.rs" in results[0].path
34 assert "Print text to the console" in results[0].diff
36 assert "Reformat rust" in results[1].message
37 assert results[1].level == "warning"
38 assert results[1].lineno == 4
39 assert "bad2.rs" in results[1].path
40 assert "Print text to the console" in results[1].diff
43 def test_fix(lint, create_temp_file):
44 contents = """fn main() {
45 // Statements here are executed when the compiled binary is called
47 // Print text to the console
48 println!("Hello World!");
49 let mut a;
50 let mut b=1;
51 let mut vec = Vec::new();
52 vec.push(1);
53 vec.push(2);
56 for x in 5..10 - 5 {
57 a = x;
61 """
63 path = create_temp_file(contents, "bad.rs")
64 lint([path], fix=True)
65 assert fixed == 3
68 if __name__ == "__main__":
69 mozunit.main()