2016-02-05 01:37:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
# Copyright (C) 2016 Andrew Hamilton. All rights reserved.
|
|
|
|
|
# Licensed under the Artistic License 2.0.
|
|
|
|
|
|
|
|
|
|
import contextlib
|
|
|
|
|
import os
|
|
|
|
|
import unittest
|
|
|
|
|
import unittest.mock
|
|
|
|
|
|
|
|
|
|
import fill3
|
|
|
|
|
import golden
|
|
|
|
|
import tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VIGIL_ROOT = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def widget_to_string(widget):
|
|
|
|
|
appearance = widget.appearance_min()
|
|
|
|
|
return str(fill3.join("\n", appearance))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
def chdir(path):
|
|
|
|
|
old_cwd = os.getcwd()
|
|
|
|
|
os.chdir(path)
|
|
|
|
|
try:
|
|
|
|
|
yield
|
|
|
|
|
finally:
|
|
|
|
|
os.chdir(old_cwd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def result_path(tool, input_filename):
|
|
|
|
|
filename = tool.__qualname__ + "-" + input_filename.replace(".", "_")
|
|
|
|
|
return os.path.join(VIGIL_ROOT, "golden-files", "results", filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_tool(tool, input_filename):
|
|
|
|
|
with chdir(os.path.join(VIGIL_ROOT, "golden-files")):
|
|
|
|
|
return tool(os.path.join(".", "input", input_filename))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolsTestCase(unittest.TestCase):
|
|
|
|
|
|
2016-02-10 01:25:45 +00:00
|
|
|
def _test_tool(self, tool, sub_tests):
|
|
|
|
|
for input_filename, expected_status in sub_tests:
|
2016-02-08 21:55:22 +00:00
|
|
|
with self.subTest(input_filename=input_filename):
|
|
|
|
|
status, result = run_tool(tool, input_filename)
|
|
|
|
|
golden_path = result_path(tool, input_filename)
|
|
|
|
|
golden.assertGolden(widget_to_string(result), golden_path)
|
|
|
|
|
self.assertEqual(status, expected_status)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_metadata(self):
|
|
|
|
|
mock_stat_result = unittest.mock.Mock(
|
|
|
|
|
st_mode=0o755, st_mtime=1454282045, st_ctime=1454282045,
|
|
|
|
|
st_atime=1454282047, st_size=12, st_uid=1111, st_gid=1111,
|
|
|
|
|
st_nlink=2)
|
|
|
|
|
mock_pw_entry = unittest.mock.Mock(pw_name="foo")
|
|
|
|
|
with unittest.mock.patch.object(os, "stat",
|
|
|
|
|
return_value=mock_stat_result):
|
|
|
|
|
with unittest.mock.patch.object(tools.pwd, "getpwuid",
|
|
|
|
|
return_value=mock_pw_entry):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.metadata,
|
|
|
|
|
[("hi3.py", tools.Status.normal)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_contents(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.contents, [("hi3.py", tools.Status.normal)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
2016-02-10 01:33:51 +00:00
|
|
|
HI_OK = [("hi3.py", tools.Status.ok), ("hi.py", tools.Status.ok)]
|
|
|
|
|
|
2016-02-05 01:37:51 +00:00
|
|
|
def test_python_syntax(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.python_syntax, self.HI_OK)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
2016-02-10 09:10:40 +00:00
|
|
|
def test_python_unittests(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.python_unittests,
|
|
|
|
|
[("hi3.py", tools.Status.not_applicable),
|
|
|
|
|
("hi.py", tools.Status.not_applicable)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
2016-02-10 01:33:51 +00:00
|
|
|
HI_NORMAL = [("hi3.py", tools.Status.normal),
|
|
|
|
|
("hi.py", tools.Status.normal)]
|
|
|
|
|
|
2016-02-05 01:37:51 +00:00
|
|
|
def test_pydoc(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.pydoc, self.HI_NORMAL)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_python_coverage(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.python_coverage, self.HI_NORMAL)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
2016-02-10 09:10:40 +00:00
|
|
|
# Not testing python_profile, because it is non-deterministic.
|
|
|
|
|
|
2016-02-05 01:37:51 +00:00
|
|
|
def test_pep8(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.pep8, self.HI_OK)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_pyflakes(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.pyflakes, self.HI_OK)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_pylint(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.pylint, self.HI_OK)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_python_gut(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.python_gut, self.HI_NORMAL)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_python_modulefinder(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.python_modulefinder, self.HI_NORMAL)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_python_mccable(self):
|
2016-02-10 01:33:51 +00:00
|
|
|
self._test_tool(tools.python_mccabe, self.HI_OK)
|
2016-02-05 01:37:51 +00:00
|
|
|
|
2016-02-10 19:30:30 +00:00
|
|
|
def test_disassemble_pyc(self):
|
|
|
|
|
self._test_tool(tools.disassemble_pyc,
|
|
|
|
|
[("hi3.cpython-34.pyc", tools.Status.normal)])
|
|
|
|
|
|
2016-02-05 01:37:51 +00:00
|
|
|
def test_perl_syntax(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.perl_syntax, [("perl.pl", tools.Status.ok)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_perldoc(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.perldoc,
|
|
|
|
|
[("perl.pl", tools.Status.not_applicable),
|
|
|
|
|
("contents.pod", tools.Status.normal)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_perltidy(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.perltidy, [("perl.pl", tools.Status.normal)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
def test_perl6_syntax(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.perl6_syntax,
|
|
|
|
|
[("perl6.p6", tools.Status.problem)])
|
2016-02-08 21:55:22 +00:00
|
|
|
|
|
|
|
|
def test_antic(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.antic,
|
|
|
|
|
[("closure-util.java", tools.Status.problem)])
|
2016-02-08 21:55:22 +00:00
|
|
|
|
2016-02-10 00:59:26 +00:00
|
|
|
def test_jlint(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.jlint, [("javaversion.class", tools.Status.ok)])
|
2016-02-10 00:59:26 +00:00
|
|
|
|
2016-02-08 21:55:22 +00:00
|
|
|
def test_uncrustify(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.uncrustify,
|
|
|
|
|
[("closure-util.java", tools.Status.problem),
|
|
|
|
|
("hello.c", tools.Status.normal),
|
|
|
|
|
("hello.h", tools.Status.normal),
|
|
|
|
|
("hello.cpp", tools.Status.normal)])
|
2016-02-08 21:55:22 +00:00
|
|
|
|
|
|
|
|
def test_splint(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.splint, [("hello.c", tools.Status.ok),
|
|
|
|
|
("hello.h", tools.Status.ok)])
|
2016-02-05 01:37:51 +00:00
|
|
|
|
2016-02-10 01:25:45 +00:00
|
|
|
def test_objdump_headers(self):
|
|
|
|
|
self._test_tool(tools.objdump_headers,
|
|
|
|
|
[("Mcrt1.o", tools.Status.normal)])
|
|
|
|
|
|
|
|
|
|
def test_objdump_disassemble(self):
|
|
|
|
|
self._test_tool(tools.objdump_disassemble,
|
|
|
|
|
[("Mcrt1.o", tools.Status.problem)])
|
|
|
|
|
|
|
|
|
|
def test_readelf(self):
|
|
|
|
|
self._test_tool(tools.readelf, [("Mcrt1.o", tools.Status.normal)])
|
2016-02-09 22:46:14 +00:00
|
|
|
|
2016-02-09 22:18:46 +00:00
|
|
|
def test_unzip(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.unzip, [("hi.zip", tools.Status.normal)])
|
2016-02-09 22:18:46 +00:00
|
|
|
|
2016-02-09 22:23:29 +00:00
|
|
|
def test_tar_gz(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.tar_gz, [("hi.tar.gz", tools.Status.normal),
|
|
|
|
|
("hi.tgz", tools.Status.normal)])
|
2016-02-09 22:23:29 +00:00
|
|
|
|
2016-02-09 22:26:38 +00:00
|
|
|
def test_tar_bz2(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.tar_bz2, [("hi.tar.bz2", tools.Status.normal)])
|
2016-02-09 22:26:38 +00:00
|
|
|
|
2016-02-09 22:56:36 +00:00
|
|
|
def test_nm(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.nm, [("libieee.a", tools.Status.normal),
|
|
|
|
|
("libpcprofile.so", tools.Status.normal)])
|
2016-02-09 22:56:36 +00:00
|
|
|
|
2016-02-10 00:47:16 +00:00
|
|
|
def test_pdf2txt(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.pdf2txt, [("standard.pdf", tools.Status.normal)])
|
2016-02-10 00:47:16 +00:00
|
|
|
|
2016-02-09 21:38:33 +00:00
|
|
|
def test_html_syntax(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.html_syntax, [("hi.html", tools.Status.problem)])
|
2016-02-09 21:38:33 +00:00
|
|
|
|
|
|
|
|
def test_tidy(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.tidy, [("hi.html", tools.Status.normal)])
|
2016-02-09 21:38:33 +00:00
|
|
|
|
|
|
|
|
def test_html2text(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.html2text, [("hi.html", tools.Status.normal)])
|
2016-02-09 21:38:33 +00:00
|
|
|
|
2016-02-09 21:44:12 +00:00
|
|
|
def test_bcpp(self):
|
2016-02-10 01:25:45 +00:00
|
|
|
self._test_tool(tools.bcpp, [("hello.cpp", tools.Status.normal)])
|
2016-02-09 21:44:12 +00:00
|
|
|
|
2016-02-09 21:48:09 +00:00
|
|
|
def test_php5_syntax(self):
|
2016-02-10 09:04:29 +00:00
|
|
|
self._test_tool(tools.php5_syntax, [("root.php", tools.Status.ok)])
|
2016-02-09 21:48:09 +00:00
|
|
|
|
2016-02-05 01:37:51 +00:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
golden.main()
|