mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-18 23:07:07 -05:00
Merge pull request #5780 from MrMha/fix/conventions-duplicate-source-tokens
Merged while @adriadam10 is away; his requested change is in place.
This commit is contained in:
2 files changed
+42
-2
No files matched your search
@@ -179,10 +179,17 @@ class Check:
|
||||
result = subprocess.run(["git", "-c", "core.quotePath=false", "grep", "-nE", "--full-name", pattern, self.head, "--", ":(top)core/libs/prx"], capture_output=True, encoding="utf-8", errors="replace")
|
||||
hits = [line.split(":", 3)[1:] for line in filter(None, result.stdout.split("\n"))]
|
||||
self.read(path for path, _, _ in hits)
|
||||
sources = {}
|
||||
for path, number, text in hits:
|
||||
name = EXPORT.search(text).group(1)
|
||||
if path not in sources:
|
||||
sources[path] = cpp_text(self.show(path)).split("\n")
|
||||
source = sources[path]
|
||||
match = next((match for match in EXPORT.finditer(source[int(number) - 1]) if match.group(1) in exports), None)
|
||||
if match is None:
|
||||
continue
|
||||
name = match.group(1)
|
||||
own, own_number = exports[name]
|
||||
if library(path) != library(own) and "tests" not in PurePosixPath(path).parts and function_body(self.show(path).splitlines(), int(number) - 1) is not None:
|
||||
if library(path) != library(own) and "tests" not in PurePosixPath(path).parts and function_body(source, int(number) - 1) is not None:
|
||||
self.report("duplicate-export", own, own_number, f"{name} is also in {library(path)}")
|
||||
|
||||
def build(self):
|
||||
|
||||
@@ -63,6 +63,39 @@ class WrappedDeclarationTests(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
|
||||
self.assertIn("[duplicate-export]", result.stdout)
|
||||
|
||||
def test_multiline_raw_literal_is_not_a_duplicate(self):
|
||||
source = 'const char* example = R"example(\n' + DEFINITION + ')example";\n'
|
||||
result = self.check("Export.cpp", source)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertNotIn("[duplicate-export]", result.stdout)
|
||||
|
||||
def test_block_comment_is_not_a_duplicate(self):
|
||||
result = self.check("Export.cpp", "/*\n" + DEFINITION + "*/\n")
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertNotIn("[duplicate-export]", result.stdout)
|
||||
|
||||
def test_literal_before_unrelated_export_is_not_a_duplicate(self):
|
||||
source = 'const char* example = "APS5_VABI sceFooBar()"; int APS5_VABI sceOther() { return 1; }\n'
|
||||
result = self.check("Export.cpp", source)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertNotIn("[duplicate-export]", result.stdout)
|
||||
|
||||
def test_line_comment_before_definition_is_not_a_duplicate(self):
|
||||
result = self.check("Export.cpp", "// " + DEFINITION + "int unrelated() { return 42; }\n")
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertNotIn("[duplicate-export]", result.stdout)
|
||||
|
||||
def test_definition_after_unicode_raw_literal_is_a_duplicate(self):
|
||||
source = 'const char* text = R"text(first\u2028+middle\u2029+last)text";\n' + DEFINITION
|
||||
result = self.check("Export.cpp", source)
|
||||
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
|
||||
self.assertIn("[duplicate-export]", result.stdout)
|
||||
|
||||
def test_definition_after_commented_example_is_a_duplicate(self):
|
||||
result = self.check("Export.cpp", "/*\n" + DEFINITION + "*/\n" + DEFINITION)
|
||||
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
|
||||
self.assertEqual(result.stdout.count("[duplicate-export]"), 1, result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user