Skip to content

Commit f830e8e

Browse files
wip
1 parent 029065f commit f830e8e

8 files changed

Lines changed: 37 additions & 20 deletions

File tree

synapse/lib/parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def embedquery(self, meta, kids):
261261

262262
kids[0].astinfo = astinfo
263263

264-
return s_ast.EmbedQuery(astinfo, kids[0].text, kids=kids)
264+
return s_ast.EmbedQuery(astinfo, kids[0].getAstText(), kids=kids)
265265

266266
@lark.v_args(meta=True)
267267
def funccall(self, meta, kids):
@@ -271,8 +271,6 @@ def funccall(self, meta, kids):
271271
argkids = []
272272
kwargkids = []
273273
kwnames = set()
274-
indx = 1
275-
kcnt = len(kids)
276274

277275
todo = collections.deque(kids)
278276

synapse/tests/files/stormcov/dupesubs.storm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@ tee {
1616
} {
1717
[inet:fqdn=argv.com]
1818
}
19-
// coverage: 1, 2, 4, 7, 8, 9, 10, 12, 13, 16, 17
20-
// lines: 1, 2, 4, 5, 7, 8, 9, 10, 12, 13, 14, 17
19+
|
20+
tee
21+
{
22+
[ inet:fqdn=dup00.com ]
23+
}
24+
{
25+
[ inet:fqdn=dup00.com ]
26+
}
27+
// coverage: 1, 2, 4, 7, 8, 9, 10, 12, 13, 16, 17, 20, 21, 22, 24
28+
// lines: 1, 2, 4, 5, 7, 8, 9, 10, 12, 13, 14, 17, 20, 22, 25

synapse/tests/files/stormcov/embedquery.storm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ $eq3 = ${
1111
[ inet:fqdn=vertex.link ]
1212
}
1313
}
14+
$eq4 = ${ [ inet:fqdn=vtx.lk ] }
15+
$eq5 = ${
1416

15-
tee $eq1 $eq2 $eq3
16-
// coverage: 1, 2, 4, 5, 6, 9, 10, 15
17-
// lines: 1, 2, 4, 5, 6, 9, 10, 11, 15
17+
[ inet:fqdn=v.vtx.lk ]
18+
}
19+
tee $eq1 $eq2 $eq3 $eq4 $eq5
20+
// coverage: 1, 2, 4, 5, 6, 9, 10, 14, 15, 17, 19
21+
// lines: 1, 2, 4, 5, 6, 9, 10, 11, 14, 15, 17, 19

synapse/tests/test_lib_grammar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
'try { inet:ip=asdf } catch FooBar as err { } catch * as err { }',
5252
'test:array*[=1.2.3.4]',
5353
'macro.set hehe ${ inet:ip }',
54-
'macro.set hehe ${\n inet:ip\ninet:fqdn }',
5554
'$q=${#foo.bar}',
5655
'metrics.edits.byprop inet:fqdn:domain --newv $lib.null',
5756
'tee // comment',
@@ -841,8 +840,7 @@
841840
'Query: [TryCatch: [Query: [LiftPropBy: [Const: inet:ip, Const: =, Const: asdf]], CatchBlock: [Const: TypeError, Const: err, Query: []]]]',
842841
'Query: [TryCatch: [Query: [LiftPropBy: [Const: inet:ip, Const: =, Const: asdf]], CatchBlock: [Const: FooBar, Const: err, Query: []], CatchBlock: [Const: *, Const: err, Query: []]]]',
843842
'Query: [LiftByArray: [Const: test:array, Const: =, Const: 1.2.3.4]]',
844-
'Query: [CmdOper: [Const: macro.set, List: [Const: hehe, EmbedQuery: inet:ip]]]',
845-
'Query: [CmdOper: [Const: macro.set, List: [Const: hehe, EmbedQuery: inet:ip\ninet:fqdn]]]',
843+
'Query: [CmdOper: [Const: macro.set, List: [Const: hehe, EmbedQuery: inet:ip ]]]',
846844
'Query: [SetVarOper: [Const: q, EmbedQuery: #foo.bar]]',
847845
'Query: [CmdOper: [Const: metrics.edits.byprop, List: [Const: inet:fqdn:domain, Const: --newv, VarDeref: [VarValue: [Const: lib], Const: null]]]]',
848846
'Query: [CmdOper: [Const: tee, Const: ()]]',
@@ -1421,7 +1419,7 @@
14211419
'Query: [SetVarOper: [Const: p, Const: names], LiftPropBy: [Const: entity:contact:name, Const: =, Const: foo], EditPropSet: [RelProp: [VarValue: [Const: p]], Const: ?-=, Const: bar]]',
14221420
'Query: [SetVarOper: [Const: pvar, Const: stuff], LiftProp: [Const: test:arrayprop], FiltOper: [Const: +, ArrayCond: [RelProp: [VarValue: [Const: pvar]], Const: =, Const: neato]]]',
14231421
'Query: [SetVarOper: [Const: pvar, Const: ints], LiftProp: [Const: test:arrayprop], FiltOper: [Const: +, ArrayCond: [RelProp: [VarValue: [Const: pvar]], Const: =, VarValue: [Const: othervar]]]]',
1424-
'Query: [SetVarOper: [Const: foo, DollarExpr: [ExprDict: [Const: foo, EmbedQuery: inet:fqdn]]]]',
1422+
'Query: [SetVarOper: [Const: foo, DollarExpr: [ExprDict: [Const: foo, EmbedQuery: inet:fqdn ]]]]',
14251423
'Query: [EditPropSet: [RelProp: [Const: seen], Const: ?=, DollarExpr: [ExprNode: [VarDeref: [VarValue: [Const: foo], Const: bar], Const: *, Const: 1000]]]]',
14261424
'Query: [EditPropSet: [RelProp: [Const: seen], Const: ?=, DollarExpr: [ExprNode: [RelPropValue: [RelProp: [Const: foo], VirtProps: [Const: virt]], Const: *, Const: 1000]]]]',
14271425
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: foo], EditCondPropSet: [RelProp: [Const: hehe], CondSetOper: [Const: unset], Const: heval]]',

synapse/tests/test_lib_stormlib_macro.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def test_stormlib_macro(self):
8989
name = 'v' * 491
9090
q = '$lib.macro.set($name, ${ help }) return ( $lib.macro.get($name) )'
9191
mdef = await core.callStorm(q, opts={'vars': {'name': name}})
92-
self.eq(mdef.get('storm'), 'help')
92+
self.eq(mdef.get('storm'), ' help ')
9393

9494
badname = 'v' * 492
9595
with self.raises(s_exc.BadArg):
@@ -381,15 +381,15 @@ async def test_stormlib_behold_macro(self):
381381
self.eq('storm:macro:add', addmesg['data']['event'])
382382
macro = addmesg['data']['info']['macro']
383383
self.eq(macro['name'], 'foobar')
384-
self.eq(macro['storm'], 'file:bytes | [+#neato]')
384+
self.eq(macro['storm'], ' file:bytes | [+#neato] ')
385385
self.ne(visi.iden, macro['creator'])
386386
self.nn(macro['iden'])
387387

388388
setmesg = await sock.receive_json()
389389
self.eq('storm:macro:mod', setmesg['data']['event'])
390390
event = setmesg['data']['info']
391391
self.nn(event['macro'])
392-
self.eq(event['info']['storm'], 'inet:ip | [+#burrito]')
392+
self.eq(event['info']['storm'], ' inet:ip | [+#burrito] ')
393393
self.nn(event['info']['updated'])
394394

395395
modmesg = await sock.receive_json()

synapse/tests/test_lib_stormtypes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ async def test_storm_lib_base(self):
687687
self.stormIsInPrint("['1', 2, '3']", mesgs)
688688

689689
mesgs = await core.stormlist('$lib.print(${ $foo=bar })')
690-
self.stormIsInPrint('storm:query: "$foo=bar"', mesgs)
690+
self.stormIsInPrint('storm:query: " $foo=bar "', mesgs)
691691

692692
mesgs = await core.stormlist('$lib.print($lib.set(1,2,3))')
693693
self.stormIsInPrint("'1'", mesgs)
@@ -1055,7 +1055,8 @@ async def test_storm_lib_query(self):
10551055
msgs = await core.stormlist(q)
10561056
fires = [m for m in msgs if m[0] == 'storm:fire']
10571057
self.len(1, fires)
1058-
self.eq(fires[0][1].get('data').get('q'), "$lib.print('fire in the hole')")
1058+
self.eq(fires[0][1].get('data').get('q'),
1059+
" $lib.print('fire in the hole') ")
10591060

10601061
q = '''
10611062
$q=${ [test:int=1 test:int=2] }

synapse/tests/test_utils_stormcov.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ async def test_stormcov_basics(self):
5050
badstorm = s_files.getAssetPath('stormcov/badstorm.storm')
5151
stream.expect(f'Skipping invalid storm file: {badstorm}')
5252

53+
dupesubs = s_files.getAssetPath('stormcov/dupesubs.storm')
54+
stream.expect(f'Duplicate argvquery in {dupesubs} at line 25, coverage will be reported on first instance in {dupesubs} at line 22')
55+
stream.expect(f'Duplicate embedquery in {dupesubs} at line 5, coverage will be reported on first instance in {dupesubs} at line 2')
56+
5357
self.sorteq(list(stormcov.guid_map.values()), stormfiles)
5458
stormcov.reset()
5559

@@ -87,8 +91,8 @@ async def check_cov(filename):
8791

8892
stormcov.reset()
8993

90-
await check_cov('stormcov/dupesubs.storm')
9194
await check_cov('stormcov/embedquery.storm')
95+
await check_cov('stormcov/dupesubs.storm')
9296
await check_cov('stormcov/argvquery.storm')
9397
await check_cov('stormcov/stormctrl.storm')
9498
await check_cov('stormcov/pivot.storm')

synapse/utils/stormcov.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,15 @@ def find_subqueries(self, tree, path):
159159

160160
subg = s_common.guid(str(subq))
161161
line = node.meta.line
162+
offs = 0
163+
if rule == 'embedquery':
164+
line -= 1
165+
offs += 1
162166

163167
if subg in self.subq_map:
164168
(pname, pline) = self.subq_map[subg]
165-
logger.warning(f'Duplicate {rule} in {path} at line {line + 1}, coverage will '
166-
f'be reported on first instance in {pname} at line {pline + 1}')
169+
logger.warning(f'Duplicate {rule} in {path} at line {line + 1 + offs}, coverage will '
170+
f'be reported on first instance in {pname} at line {pline + 1 + offs}')
167171
continue
168172

169173
self.subq_map[subg] = (path, line)

0 commit comments

Comments
 (0)