Bug 1615903 - Add unit tests for rustfmt r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D63028

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sylvestre Ledru 2020-02-21 18:28:49 +00:00
Родитель 903ecdfd29
Коммит a5ae0686ba
5 изменённых файлов: 85 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,16 @@
fn main() {
// Statements here are executed when the compiled binary is called
// Print text to the console
println!("Hello World!");
// Clippy detects this as a swap and considers this as an error
let mut a =
1;
let mut b=1;
a =
b;
b = a;
}

Просмотреть файл

@ -0,0 +1,17 @@
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;
}
}

Просмотреть файл

@ -0,0 +1,6 @@
fn main() {
// Statements here are executed when the compiled binary is called
// Print text to the console
println!("Hello World!");
}

Просмотреть файл

@ -19,3 +19,5 @@ skip-if = os == "win" || os == "mac" # codespell installed on Linux
[test_yaml.py]
[test_clippy.py]
skip-if = os == "win" || os == "mac" # only installed on Linux
[test_rustfmt.py]
skip-if = os == "win" || os == "mac" # only installed on Linux

Просмотреть файл

@ -0,0 +1,44 @@
import mozunit
LINTER = 'rustfmt'
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
if __name__ == '__main__':
mozunit.main()