| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 103479a commit 3d05e3d
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1322,13 +1322,13 @@ else | |||
| 1322 | 1322 | CPPLINT_QUIET = --quiet | |
| 1323 | 1323 | endif | |
| 1324 | 1324 | .PHONY: lint-cpp | |
| 1325 | - # Lints the C++ code with cpplint.py and check-imports.py. | ||
| 1325 | + # Lints the C++ code with cpplint.py and checkimports.py. | ||
| 1326 | 1326 | lint-cpp: tools/.cpplintstamp | |
| 1327 | 1327 | ||
| 1328 | 1328 | tools/.cpplintstamp: $(LINT_CPP_FILES) | |
| 1329 | 1329 | @echo "Running C++ linter..." | |
| 1330 | 1330 | @$(PYTHON) tools/cpplint.py $(CPPLINT_QUIET) $? | |
| 1331 | - @$(PYTHON) tools/check-imports.py | ||
| 1331 | + @$(PYTHON) tools/checkimports.py | ||
| 1332 | 1332 | @touch $@ | |
| 1333 | 1333 | ||
| 1334 | 1334 | .PHONY: lint-addon-docs | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + using v8::MaybeLocal; | ||
| 2 | + using v8::Array; | ||
| 3 | + using v8::Local; | ||
| 4 | + | ||
| 5 | + MaybeLocal<Array> CreateObject() const { | ||
| 6 | + return MaybeLocal<Array>(); | ||
| 7 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + using v8::Array; | ||
| 2 | + using v8::Local; | ||
| 3 | + using v8::MaybeLocal; | ||
| 4 | + | ||
| 5 | + MaybeLocal<Array> CreateObject() const { | ||
| 6 | + return MaybeLocal<Array>(); | ||
| 7 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + using v8::MaybeLocal; | ||
| 2 | + using v8::Array; | ||
| 3 | + | ||
| 4 | + MaybeLocal<Array> CreateObject() const { | ||
| 5 | + return MaybeLocal<Array>(); | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + using v8::Context; | ||
| 2 | + | ||
| 3 | + static void MyMethod(void) { | ||
| 4 | + return; | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + using v8::Array; | ||
| 2 | + using v8::MaybeLocal; | ||
| 3 | + | ||
| 4 | + MaybeLocal<Array> CreateObject() const { | ||
| 5 | + return MaybeLocal<Array>(); | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,77 @@ | |||
| 1 | + import unittest | ||
| 2 | + import sys | ||
| 3 | + from contextlib import contextmanager | ||
| 4 | + from os import path | ||
| 5 | + sys.path.append(path.abspath(path.join(path.dirname(__file__), | ||
| 6 | + '..', '..', 'tools'))) | ||
| 7 | + try: | ||
| 8 | + from StringIO import StringIO | ||
| 9 | + except ImportError: | ||
| 10 | + from io import StringIO | ||
| 11 | + | ||
| 12 | + from checkimports import is_valid | ||
| 13 | + | ||
| 14 | + @contextmanager | ||
| 15 | + def captured_output(): | ||
| 16 | + tmp_out, tmp_err = StringIO(), StringIO() | ||
| 17 | + old_out, old_err = sys.stdout, sys.stderr | ||
| 18 | + try: | ||
| 19 | + sys.stdout, sys.stderr = tmp_out, tmp_err | ||
| 20 | + yield sys.stdout, sys.stderr | ||
| 21 | + finally: | ||
| 22 | + sys.stdout, sys.stderr = old_out, old_err | ||
| 23 | + tmp_out.close() | ||
| 24 | + tmp_err.close() | ||
| 25 | + | ||
| 26 | + class CheckImportsTest(unittest.TestCase): | ||
| 27 | + fixturesDir = path.join(path.dirname(__file__), '..', '..', | ||
| 28 | + 'test', 'fixtures', 'tools', 'checkimports') | ||
| 29 | + | ||
| 30 | + def test_unused_and_unsorted(self): | ||
| 31 | + with captured_output() as (out, err): | ||
| 32 | + self.assertEqual(is_valid(path.join(self.fixturesDir, 'invalid.cc')), | ||
| 33 | + False) | ||
| 34 | + output = out.getvalue() | ||
| 35 | + self.assertIn('does not use "Local"', output); | ||
| 36 | + self.assertIn('using statements aren\'t sorted in', output); | ||
| 37 | + self.assertIn('Line 1: Actual: v8::MaybeLocal, Expected: v8::Array', | ||
| 38 | + output); | ||
| 39 | + self.assertIn('Line 2: Actual: v8::Array, Expected: v8::Local', | ||
| 40 | + output); | ||
| 41 | + self.assertIn('Line 3: Actual: v8::Local, Expected: v8::MaybeLocal', | ||
| 42 | + output); | ||
| 43 | + | ||
| 44 | + def test_unused_complex(self): | ||
| 45 | + with captured_output() as (out, err): | ||
| 46 | + self.assertEqual(is_valid(path.join(self.fixturesDir, 'maybe.cc')), | ||
| 47 | + False) | ||
| 48 | + output = out.getvalue() | ||
| 49 | + self.assertIn('does not use "Local"', output); | ||
| 50 | + | ||
| 51 | + def test_unused_simple(self): | ||
| 52 | + with captured_output() as (out, err): | ||
| 53 | + self.assertEqual(is_valid(path.join(self.fixturesDir, 'unused.cc')), | ||
| 54 | + False) | ||
| 55 | + output = out.getvalue() | ||
| 56 | + self.assertIn('does not use "Context"', output); | ||
| 57 | + | ||
| 58 | + def test_unsorted(self): | ||
| 59 | + with captured_output() as (out, err): | ||
| 60 | + self.assertEqual(is_valid(path.join(self.fixturesDir, 'unsorted.cc')), | ||
| 61 | + False) | ||
| 62 | + output = out.getvalue() | ||
| 63 | + self.assertIn('using statements aren\'t sorted in', output); | ||
| 64 | + self.assertIn('Line 1: Actual: v8::MaybeLocal, Expected: v8::Array', | ||
| 65 | + output); | ||
| 66 | + self.assertIn('Line 2: Actual: v8::Array, Expected: v8::MaybeLocal', | ||
| 67 | + output); | ||
| 68 | + | ||
| 69 | + def test_valid(self): | ||
| 70 | + with captured_output() as (out, err): | ||
| 71 | + self.assertEqual(is_valid(path.join(self.fixturesDir, 'valid.cc')), | ||
| 72 | + True) | ||
| 73 | + output = out.getvalue() | ||
| 74 | + self.assertEqual(output, ''); | ||
| 75 | + | ||
| 76 | + if __name__ == '__main__': | ||
| 77 | + unittest.main() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | 10 | def do_exist(file_name, lines, imported): | |
| 11 | 11 | if not any(not re.match('using \w+::{0};'.format(imported), line) and | |
| 12 | - re.search(imported, line) for line in lines): | ||
| 12 | + re.search('\\b{0}\\b'.format(imported), line) for line in lines): | ||
| 13 | 13 | print('File "{0}" does not use "{1}"'.format(file_name, imported)) | |
| 14 | 14 | return False | |
| 15 | 15 | return True | |
@@ -40,4 +40,6 @@ def is_valid(file_name): | |||
| 40 | 40 | else: | |
| 41 | 41 | return valid | |
| 42 | 42 | ||
| 43 | - sys.exit(0 if all(map(is_valid, glob.iglob('src/*.cc'))) else 1) | ||
| 43 | + if __name__ == '__main__': | ||
| 44 | + files = glob.iglob(sys.argv[1] if len(sys.argv) > 1 else 'src/*.cc') | ||
| 45 | + sys.exit(0 if all(map(is_valid, files)) else 1) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments