@@ -571,3 +571,66 @@ def test_duplicate_s_function(caplog):
571
571
(N , 'endfunction' )]
572
572
573
573
assert not caplog .records
574
+
575
+
576
+ @pytest .mark .parametrize ("defined_at" , (- 1 , 1 ))
577
+ def test_handles_unmatched_defined (defined_at , caplog ):
578
+ from covimerage import Profile
579
+
580
+ file_object = StringIO (textwrap .dedent (
581
+ """
582
+ SCRIPT invalid_defined.vim
583
+ Sourced 1 time
584
+ Total time: 0.000037
585
+ Self time: 0.000032
586
+
587
+ count total (s) self (s)
588
+ 1 0.000015 execute "function! F_via_execute_1()\\ nreturn 0\\ nendfunction"
589
+ 1 0.000011 0.000007 call F_via_execute_1()
590
+ 1 0.000006 0.000005 call F_via_execute_1()
591
+
592
+ FUNCTION F_via_execute_1()
593
+ Defined: invalid_defined.vim line {defined_at}
594
+ Called 2 times
595
+ Total time: 0.000005
596
+ Self time: 0.000005
597
+
598
+ count total (s) self (s)
599
+ 2 0.000003 return 0
600
+
601
+ FUNCTIONS SORTED ON TOTAL TIME
602
+ count total (s) self (s) function
603
+ 2 0.000005 F_via_execute_1()
604
+
605
+ FUNCTIONS SORTED ON SELF TIME
606
+ count total (s) self (s) function
607
+ 2 0.000005 F_via_execute_1()
608
+ """ .format (
609
+ defined_at = defined_at
610
+ )))
611
+
612
+ p = Profile (file_object )
613
+ p .parse ()
614
+
615
+ assert len (p .scripts ) == 1
616
+ s = p .scripts [0 ]
617
+
618
+ assert [(l .count , l .line ) for l in s .lines .values ()
619
+ if not l .line .startswith ('"' )] == [
620
+ (1 , 'execute "function! F_via_execute_1()\\ nreturn 0\\ nendfunction"' ),
621
+ (1 , 'call F_via_execute_1()' ),
622
+ (1 , 'call F_via_execute_1()' ),
623
+ ]
624
+
625
+ logmsgs = [x [1 :] for x in caplog .record_tuples ]
626
+ if defined_at == - 1 :
627
+ assert logmsgs == [
628
+ (30 , "Could not find script line for function F_via_execute_1 (-1, 1)" ),
629
+ (40 , "Could not find source for function: F_via_execute_1" ),
630
+ ]
631
+ else :
632
+ assert defined_at == 1
633
+ assert logmsgs == [
634
+ (30 , "Script line does not match function line, ignoring: 'call F_via_execute_1()' != 'return 0'." ),
635
+ (40 , "Could not find source for function: F_via_execute_1" ),
636
+ ]
0 commit comments