From d20870ad98614ce35aa8a27e998108ad00130387 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 11 Sep 2019 20:59:32 +0000 Subject: [PATCH] Bug 1579845 - Add a test to the mozlint check: file-whitespace r=ahal Differential Revision: https://phabricator.services.mozilla.com/D45445 --HG-- extra : moz-landing-system : lando --- .../lint/test/files/file-whitespace/bad-windows.c | 3 +++ tools/lint/test/files/file-whitespace/bad.c | 3 +++ tools/lint/test/files/file-whitespace/bad.js | 3 +++ tools/lint/test/files/file-whitespace/good.c | 1 + tools/lint/test/files/file-whitespace/good.js | 5 ++++ tools/lint/test/python.ini | 1 + tools/lint/test/test_file_whitespace.py | 29 ++++++++++++++++++++++ 7 files changed, 45 insertions(+) create mode 100644 tools/lint/test/files/file-whitespace/bad-windows.c create mode 100644 tools/lint/test/files/file-whitespace/bad.c create mode 100755 tools/lint/test/files/file-whitespace/bad.js create mode 100644 tools/lint/test/files/file-whitespace/good.c create mode 100755 tools/lint/test/files/file-whitespace/good.js create mode 100644 tools/lint/test/test_file_whitespace.py diff --git a/tools/lint/test/files/file-whitespace/bad-windows.c b/tools/lint/test/files/file-whitespace/bad-windows.c new file mode 100644 index 000000000000..70d4c697b9fa --- /dev/null +++ b/tools/lint/test/files/file-whitespace/bad-windows.c @@ -0,0 +1,3 @@ +int main(){ + return 42; +} diff --git a/tools/lint/test/files/file-whitespace/bad.c b/tools/lint/test/files/file-whitespace/bad.c new file mode 100644 index 000000000000..4309b1f55d0e --- /dev/null +++ b/tools/lint/test/files/file-whitespace/bad.c @@ -0,0 +1,3 @@ +int main() { +return 0; +} diff --git a/tools/lint/test/files/file-whitespace/bad.js b/tools/lint/test/files/file-whitespace/bad.js new file mode 100755 index 000000000000..3441696ef189 --- /dev/null +++ b/tools/lint/test/files/file-whitespace/bad.js @@ -0,0 +1,3 @@ +# Nothing too + + diff --git a/tools/lint/test/files/file-whitespace/good.c b/tools/lint/test/files/file-whitespace/good.c new file mode 100644 index 000000000000..76e8197013aa --- /dev/null +++ b/tools/lint/test/files/file-whitespace/good.c @@ -0,0 +1 @@ +int main() { return 0; } diff --git a/tools/lint/test/files/file-whitespace/good.js b/tools/lint/test/files/file-whitespace/good.js new file mode 100755 index 000000000000..8149c0d4f34e --- /dev/null +++ b/tools/lint/test/files/file-whitespace/good.js @@ -0,0 +1,5 @@ +#!/usr/bin/env node + + +# Nothing + diff --git a/tools/lint/test/python.ini b/tools/lint/test/python.ini index 26878083ce89..70225cc5395d 100644 --- a/tools/lint/test/python.ini +++ b/tools/lint/test/python.ini @@ -8,3 +8,4 @@ skip-if = os == "win" || os == "mac" # node not installed on worker skip-if = os == "mac" # pip unable to find 'flake8==3.5.0' [test_file_perm.py] skip-if = os == "win" +[test_file_whitespace.py] diff --git a/tools/lint/test/test_file_whitespace.py b/tools/lint/test/test_file_whitespace.py new file mode 100644 index 000000000000..02305280d587 --- /dev/null +++ b/tools/lint/test/test_file_whitespace.py @@ -0,0 +1,29 @@ +from __future__ import absolute_import, print_function + +import mozunit + +LINTER = 'file-whitespace' + + +def test_lint_file_whitespace(lint, paths): + results = lint(paths()) + print(results) + assert len(results) == 3 + + assert "Windows line return" in results[0].message + assert results[0].level == "error" + assert "bad-windows.c" in results[0].relpath + + assert "Trailing whitespace" in results[1].message + assert results[1].level == "error" + assert "bad.c" in results[1].relpath + assert results[1].lineno == 1 + + assert "Trailing whitespace" in results[2].message + assert results[2].level == "error" + assert "bad.c" in results[2].relpath + assert results[2].lineno == 2 + + +if __name__ == '__main__': + mozunit.main() -- 2.11.4.GIT