Bug 1591195 - [lint.shellcheck] Ensure shellcheck subprocess output is returned as text, r=sylvestre

This also adds a test which would have caught the issue.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Halberstadt 2019-10-25 17:41:24 +00:00
parent b6ddb7ea53
commit 6368d98850
5 changed files with 31 additions and 0 deletions

View File

@ -27,6 +27,7 @@ results = []
class ShellcheckProcess(ProcessHandlerMixin):
def __init__(self, config, *args, **kwargs):
self.config = config
kwargs['universal_newlines'] = True
kwargs['processOutputLine'] = [self.process_line]
ProcessHandlerMixin.__init__(self, *args, **kwargs)

View File

@ -0,0 +1,3 @@
#!/bin/sh
hello="Hello world"
echo $1

View File

@ -0,0 +1,2 @@
#!/bin/sh
echo "Hello world"

View File

@ -12,3 +12,4 @@ skip-if = os == "win"
[test_file_whitespace.py]
[test_file_license.py]
[test_lintpref.py]
[test_shellcheck.py]

View File

@ -0,0 +1,24 @@
import pytest
import mozunit
from mozfile import which
LINTER = 'shellcheck'
pytestmark = pytest.mark.skipif(not which('shellcheck'), reason="shellcheck is not installed")
def test_basic(lint, paths):
results = lint(paths())
print(results)
assert len(results) == 2
assert "hello appears unused" in results[0].message
assert results[0].level == "error"
assert results[0].relpath == "bad.sh"
assert "Double quote to prevent" in results[1].message
assert results[1].level == "error"
assert results[1].relpath == "bad.sh"
if __name__ == '__main__':
mozunit.main()