mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-03 12:57:27 +00:00
test_multi_line_return_type_helper_is_pending checks that a return type split over two lines is still a stub wrapper. test_comment_only_lines_leave_no_blank_line_runs checks that the blanked text has no blank-line run; the previous code() leaves one, so that test fails on the previous code.
91 lines
3.8 KiB
Python
91 lines
3.8 KiB
Python
import re
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
import progress
|
|
|
|
|
|
def scan(source):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
library = Path(directory) / "libSceExample"
|
|
library.mkdir()
|
|
(library / "Export.cpp").write_text(source)
|
|
return progress.scan_library(library)
|
|
|
|
|
|
STUB_BODY = "{ NotImplemented_nid_no_patch(__func__); return 0; }\n"
|
|
CALLER = "int APS5_VABI sceExampleCall() { return Helper(); }\n"
|
|
|
|
|
|
class WrapperTests(unittest.TestCase):
|
|
def assertTodo(self, source):
|
|
group = scan(source)
|
|
self.assertEqual(group["done_names"], [])
|
|
self.assertEqual(group["todo_names"], ["sceExampleCall"])
|
|
|
|
def test_non_static_helper_in_anonymous_namespace(self):
|
|
self.assertTodo("namespace {\nint Helper() " + STUB_BODY + "}\n" + CALLER)
|
|
|
|
def test_noexcept_helper(self):
|
|
self.assertTodo("static int Helper() noexcept " + STUB_BODY + CALLER)
|
|
|
|
def test_trailing_return_type_helper(self):
|
|
self.assertTodo("static auto Helper() -> int " + STUB_BODY + CALLER)
|
|
|
|
def test_pointer_next_to_name_helper(self):
|
|
self.assertTodo("static int *Helper() { NotImplemented_nid_no_patch(__func__); return nullptr; }\n" + CALLER)
|
|
|
|
def test_static_helper_still_works(self):
|
|
self.assertTodo("static int Helper() " + STUB_BODY + CALLER)
|
|
|
|
def test_multi_line_return_type_helper_is_pending(self):
|
|
self.assertTodo("static const std::string\n&Helper() " + STUB_BODY + CALLER)
|
|
|
|
def test_comment_only_lines_leave_no_blank_line_runs(self):
|
|
text = "int x;\n// first\n\n" + "/* second */\n" * 3 + "int y;\n"
|
|
self.assertEqual(re.findall(r"\n[ \t]*\n", progress.code(text)), [])
|
|
|
|
def test_nested_helpers_are_pending_in_either_source_order(self):
|
|
for helpers in (
|
|
"int Last() { NotImplemented_nid_no_patch(__func__); return 0; }\n"
|
|
"int Middle() { return Last(); }\nint Helper() { return Middle(); }\n",
|
|
"int Helper() { return Middle(); }\nint Middle() { return Last(); }\n"
|
|
"int Last() { NotImplemented_nid_no_patch(__func__); return 0; }\n",
|
|
):
|
|
with self.subTest(helpers=helpers):
|
|
self.assertTodo(helpers + CALLER)
|
|
|
|
def test_recursive_helper_chain_reaching_stub_is_pending(self):
|
|
self.assertTodo("int Helper() { return Middle(); }\n"
|
|
"int Middle() { if (false) return Helper(); "
|
|
"NotImplemented_nid_no_patch(__func__); return 0; }\n" + CALLER)
|
|
|
|
def test_recursive_helpers_without_stub_stay_done(self):
|
|
group = scan("int Helper() { return Middle(); }\n"
|
|
"int Middle() { return Helper(); }\n" + CALLER)
|
|
self.assertEqual(group["done_names"], ["sceExampleCall"])
|
|
self.assertEqual(group["todo_names"], [])
|
|
|
|
def test_helper_chain_uses_whole_call_identifiers(self):
|
|
group = scan("int Last() { NotImplemented_nid_no_patch(__func__); return 0; }\n"
|
|
"int Helper() { return NotLast(); }\n" + CALLER)
|
|
self.assertEqual(group["done_names"], ["sceExampleCall"])
|
|
self.assertEqual(group["todo_names"], [])
|
|
|
|
def test_overloaded_helper_keeps_each_stub_path(self):
|
|
self.assertTodo("int Helper() { NotImplemented_nid_no_patch(__func__); return 0; }\n"
|
|
"int Helper(int value) { return value; }\n" + CALLER)
|
|
|
|
def test_unrelated_helper_stays_done(self):
|
|
group = scan("namespace {\nint Other() { return 1; }\nint Helper() " + STUB_BODY + "}\n"
|
|
"int APS5_VABI sceExampleCall() { return Other(); }\n")
|
|
self.assertEqual(group["done_names"], ["sceExampleCall"])
|
|
self.assertEqual(group["todo_names"], [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|