Skip to content

Commit 0d98e3e

Browse files
committed
test: add function tests
1 parent 43c4171 commit 0d98e3e

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

tests/test_function.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def setUp(self):
1212
self.project = scubatrace.Project.create(
1313
str(self.project_path), language=scubatrace.language.C
1414
)
15-
self.file = self.project.files.get("main.c")
16-
assert self.file is not None
15+
file = self.project.files.get("main.c")
16+
assert file is not None
17+
self.file = file
1718
function = self.file.function_by_line(11)
1819
assert function is not None
1920
self.function = function
@@ -22,9 +23,45 @@ def test_function_create(self):
2223
function = scubatrace.Function.create(self.function.node, self.function.parent)
2324
self.assertIsNotNone(function)
2425

26+
def test_function_callees(self):
27+
callees = self.function.callees
28+
self.assertGreater(len(callees), 0)
29+
self.assertIn("sub", [callee.name for callee in callees])
30+
self.assertIn("add", [callee.name for callee in callees])
31+
self.assertIn("printf", [callee.name for callee in callees])
32+
33+
def test_function_callers(self):
34+
function = self.file.function_by_line(4)
35+
self.assertIsNotNone(function)
36+
assert function is not None
37+
callers = function.callers
38+
self.assertGreater(len(callers), 0)
39+
self.assertIn("main", [caller.name for caller in callers])
40+
2541
def test_function_lines(self):
2642
self.assertGreater(len(self.function.lines), 0)
2743

2844
def test_function_parameter_lines(self):
2945
self.assertEqual(len(self.function.parameter_lines), 1)
3046
self.assertEqual(self.function.parameter_lines[0], 9)
47+
48+
def test_function_parameters(self):
49+
parameters = self.function.parameters
50+
self.assertEqual(parameters[0].text, "argc")
51+
self.assertEqual(parameters[1].text, "argv")
52+
53+
def test_function_variables(self):
54+
variables = self.function.variables
55+
self.assertGreater(len(variables), 0)
56+
self.assertEqual(variables[0].text, "argc")
57+
self.assertEqual(variables[1].text, "argv")
58+
self.assertEqual(variables[len(variables) - 1].text, "count")
59+
60+
def test_function_export_cfg_dot(self):
61+
cfg = self.function.export_cfg_dot("cfg.dot", with_cdg=True, with_ddg=True)
62+
self.assertIsNotNone(cfg)
63+
64+
def test_function_slicing_by_lines(self):
65+
stats = self.function.slice_by_lines([14])
66+
self.assertEqual(stats[0].start_line, 9)
67+
self.assertEqual(stats[len(stats) - 1].start_line, 38)

0 commit comments

Comments
 (0)