Skip to content

Commit af76309

Browse files
committed
Fix logic
Signed-off-by: Arthur Chan <[email protected]>
1 parent f9faf79 commit af76309

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

tests/tree-sitter-frontend/cpp/test-project-1/sample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace OuterNamespace {
3232
}
3333

3434
void MyClass::memberFunction(int x) {
35-
if (x > 0) {
35+
if (isPositive(x)) {
3636
std::cout << "Positive value: " << x << std::endl;
3737
} else {
3838
std::cout << "Non-positive value: " << x << std::endl;

tests/tree-sitter-frontend/test-tree-sitter-frontend.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,10 @@
3434
{
3535
'language': 'c++',
3636
'project': {
37-
'cpp/test-project-1': [
38-
{
39-
'name':'LLVMFuzzerTestOneInput',
40-
'depth': 0
41-
},
42-
{
43-
'name':'OuterNamespace::MyClass::memberFunction',
44-
'depth': 1
45-
}
46-
]
37+
'cpp/test-project-1': {
38+
'count': 5,
39+
'reaches': ' isPositive'
40+
}
4741
}
4842
}
4943
]
@@ -53,22 +47,16 @@ def test_tree_sitter_frontend():
5347
language = testcase.get('language')
5448
project = testcase.get('project')
5549

56-
for dir, sample_list in project.items():
50+
for dir, sample_map in project.items():
5751
calltrees = oss_fuzz.analyse_folder(language, dir, entrypoints.get(language))
5852

59-
function_depth_map = {}
53+
found = False
6054
for calltree in calltrees:
61-
for line in calltree.split('\n'):
62-
depth = 0
63-
while line.startswith(" "):
64-
depth += 1
65-
line = line[2:]
66-
func_name = line.split(' ')[0]
67-
function_depth_map[func_name] = depth
55+
count = sample_map['count']
56+
reaches = sample_map['reaches']
57+
lines = calltree.split('\n')[1:]
6858

69-
for items in sample_list:
70-
name = items.get('name')
71-
depth = items.get('depth')
72-
73-
assert function_depth_map.get(name) == depth
59+
if len(lines) == count and reaches in calltree:
60+
found = True
7461

62+
assert found

0 commit comments

Comments
 (0)