summaryrefslogtreecommitdiffstats
path: root/tools/lint/test/test_rustfmt.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /tools/lint/test/test_rustfmt.py
parentInitial commit. (diff)
downloadfirefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.tar.xz
firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/test/test_rustfmt.py')
-rw-r--r--tools/lint/test/test_rustfmt.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tools/lint/test/test_rustfmt.py b/tools/lint/test/test_rustfmt.py
new file mode 100644
index 0000000000..c176a2695d
--- /dev/null
+++ b/tools/lint/test/test_rustfmt.py
@@ -0,0 +1,70 @@
+import mozunit
+
+LINTER = "rustfmt"
+fixed = 0
+
+
+def test_good(lint, config, paths):
+ results = lint(paths("subdir/good.rs"))
+ print(results)
+ assert len(results) == 0
+
+
+def test_basic(lint, config, paths):
+ results = lint(paths("subdir/bad.rs"))
+ print(results)
+ assert len(results) >= 1
+
+ assert "Reformat rust" in results[0].message
+ assert results[0].level == "warning"
+ assert results[0].lineno == 4
+ assert "bad.rs" in results[0].path
+ assert "Print text to the console" in results[0].diff
+
+
+def test_dir(lint, config, paths):
+ results = lint(paths("subdir/"))
+ print(results)
+ assert len(results) >= 4
+
+ assert "Reformat rust" in results[0].message
+ assert results[0].level == "warning"
+ assert results[0].lineno == 4
+ assert "bad.rs" in results[0].path
+ assert "Print text to the console" in results[0].diff
+
+ assert "Reformat rust" in results[1].message
+ assert results[1].level == "warning"
+ assert results[1].lineno == 4
+ assert "bad2.rs" in results[1].path
+ assert "Print text to the console" in results[1].diff
+
+
+def test_fix(lint, create_temp_file):
+
+ contents = """fn main() {
+ // Statements here are executed when the compiled binary is called
+
+ // Print text to the console
+ println!("Hello World!");
+ let mut a;
+ let mut b=1;
+ let mut vec = Vec::new();
+ vec.push(1);
+ vec.push(2);
+
+
+ for x in 5..10 - 5 {
+ a = x;
+ }
+
+ }
+"""
+
+ path = create_temp_file(contents, "bad.rs")
+ lint([path], fix=True)
+ assert fixed == 3
+
+
+if __name__ == "__main__":
+ mozunit.main()