comparison src/testdir/test_debugger.vim @ 21687:83b618c0315d v8.2.1393

patch 8.2.1393: insufficient testing for script debugging Commit: https://github.com/vim/vim/commit/b7f4fa517793b0fe1a4895781b4cba451d60d7c2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 8 14:41:52 2020 +0200 patch 8.2.1393: insufficient testing for script debugging Problem: Insufficient testing for script debugging. Solution: Add more tests. (Ben Jackson)
author Bram Moolenaar <Bram@vim.org>
date Sat, 08 Aug 2020 14:45:04 +0200
parents 6b2a5418cbc3
children 08940efa6b4e
comparison
equal deleted inserted replaced
21686:fd10a80c797f 21687:83b618c0315d
1 " Tests for the Vim script debug commands 1 " Tests for the Vim script debug commands
2 2
3 source shared.vim 3 source shared.vim
4 source screendump.vim 4 source screendump.vim
5 source check.vim 5 source check.vim
6
7 CheckRunVimInTerminal
8
9 func CheckCWD()
10 " Check that the longer lines don't wrap due to the length of the script name
11 " in cwd
12 let script_len = len( getcwd() .. '/Xtest1.vim' )
13 let longest_line = len( 'Breakpoint in "" line 1' )
14 if script_len > ( 75 - longest_line )
15 throw 'Skipped: Your CWD has too many characters'
16 endif
17 endfunc
18 command! -nargs=0 -bar CheckCWD call CheckCWD()
6 19
7 func CheckDbgOutput(buf, lines, options = {}) 20 func CheckDbgOutput(buf, lines, options = {})
8 " Verify the expected output 21 " Verify the expected output
9 let lnum = 20 - len(a:lines) 22 let lnum = 20 - len(a:lines)
10 for l in a:lines 23 for l in a:lines
32 endif 45 endif
33 endfunc 46 endfunc
34 47
35 " Debugger tests 48 " Debugger tests
36 func Test_Debugger() 49 func Test_Debugger()
37 CheckRunVimInTerminal
38
39 " Create a Vim script with some functions 50 " Create a Vim script with some functions
40 let lines =<< trim END 51 let lines =<< trim END
41 func Foo() 52 func Foo()
42 let var1 = 1 53 let var1 = 1
43 let var2 = Bar(var1) + 9 54 let var2 = Bar(var1) + 9
327 338
328 call delete('Xtest.vim') 339 call delete('Xtest.vim')
329 endfunc 340 endfunc
330 341
331 func Test_Backtrace_Through_Source() 342 func Test_Backtrace_Through_Source()
332 CheckRunVimInTerminal 343 CheckCWD
333
334 let file1 =<< trim END 344 let file1 =<< trim END
335 func SourceAnotherFile() 345 func SourceAnotherFile()
336 source Xtest2.vim 346 source Xtest2.vim
337 endfunc 347 endfunc
338 348
388 \ ' 3 function GlobalFunction[1]', 398 \ ' 3 function GlobalFunction[1]',
389 \ ' 2 CallAFunction[1]', 399 \ ' 2 CallAFunction[1]',
390 \ ' 1 SourceAnotherFile[1]', 400 \ ' 1 SourceAnotherFile[1]',
391 \ '->0 script ' .. getcwd() .. '/Xtest2.vim', 401 \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
392 \ 'line 1: func DoAThing()']) 402 \ 'line 1: func DoAThing()'])
403
404 call RunDbgCmd( buf, 'up' )
405 call RunDbgCmd( buf, 'backtrace', [
406 \ '>backtrace',
407 \ ' 3 function GlobalFunction[1]',
408 \ ' 2 CallAFunction[1]',
409 \ '->1 SourceAnotherFile[1]',
410 \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
411 \ 'line 1: func DoAThing()' ] )
412
413 call RunDbgCmd( buf, 'up' )
414 call RunDbgCmd( buf, 'backtrace', [
415 \ '>backtrace',
416 \ ' 3 function GlobalFunction[1]',
417 \ '->2 CallAFunction[1]',
418 \ ' 1 SourceAnotherFile[1]',
419 \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
420 \ 'line 1: func DoAThing()' ] )
421
422 call RunDbgCmd( buf, 'up' )
423 call RunDbgCmd( buf, 'backtrace', [
424 \ '>backtrace',
425 \ '->3 function GlobalFunction[1]',
426 \ ' 2 CallAFunction[1]',
427 \ ' 1 SourceAnotherFile[1]',
428 \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
429 \ 'line 1: func DoAThing()' ] )
430
431 call RunDbgCmd( buf, 'up', [ 'frame at highest level: 3' ] )
432 call RunDbgCmd( buf, 'backtrace', [
433 \ '>backtrace',
434 \ '->3 function GlobalFunction[1]',
435 \ ' 2 CallAFunction[1]',
436 \ ' 1 SourceAnotherFile[1]',
437 \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
438 \ 'line 1: func DoAThing()' ] )
439
440 call RunDbgCmd( buf, 'down' )
441 call RunDbgCmd( buf, 'backtrace', [
442 \ '>backtrace',
443 \ ' 3 function GlobalFunction[1]',
444 \ '->2 CallAFunction[1]',
445 \ ' 1 SourceAnotherFile[1]',
446 \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
447 \ 'line 1: func DoAThing()' ] )
448
449 call RunDbgCmd( buf, 'down' )
450 call RunDbgCmd( buf, 'backtrace', [
451 \ '>backtrace',
452 \ ' 3 function GlobalFunction[1]',
453 \ ' 2 CallAFunction[1]',
454 \ '->1 SourceAnotherFile[1]',
455 \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
456 \ 'line 1: func DoAThing()' ] )
457
458 call RunDbgCmd( buf, 'down' )
459 call RunDbgCmd( buf, 'backtrace', [
460 \ '>backtrace',
461 \ ' 3 function GlobalFunction[1]',
462 \ ' 2 CallAFunction[1]',
463 \ ' 1 SourceAnotherFile[1]',
464 \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
465 \ 'line 1: func DoAThing()' ] )
466
467 call RunDbgCmd( buf, 'down', [ 'frame is zero' ] )
393 468
394 " step until we have another meaninfgul trace 469 " step until we have another meaninfgul trace
395 call RunDbgCmd(buf, 'step', ['line 5: func File2Function()']) 470 call RunDbgCmd(buf, 'step', ['line 5: func File2Function()'])
396 call RunDbgCmd(buf, 'step', ['line 9: call File2Function()']) 471 call RunDbgCmd(buf, 'step', ['line 9: call File2Function()'])
397 call RunDbgCmd(buf, 'backtrace', [ 472 call RunDbgCmd(buf, 'backtrace', [
438 call delete('Xtest1.vim') 513 call delete('Xtest1.vim')
439 call delete('Xtest2.vim') 514 call delete('Xtest2.vim')
440 endfunc 515 endfunc
441 516
442 func Test_Backtrace_Autocmd() 517 func Test_Backtrace_Autocmd()
443 CheckRunVimInTerminal 518 CheckCWD
444
445 let file1 =<< trim END 519 let file1 =<< trim END
446 func SourceAnotherFile() 520 func SourceAnotherFile()
447 source Xtest2.vim 521 source Xtest2.vim
448 endfunc 522 endfunc
449 523
601 call delete('Xtest1.vim') 675 call delete('Xtest1.vim')
602 call delete('Xtest2.vim') 676 call delete('Xtest2.vim')
603 endfunc 677 endfunc
604 678
605 func Test_Backtrace_CmdLine() 679 func Test_Backtrace_CmdLine()
606 CheckRunVimInTerminal 680 CheckCWD
607
608 let file1 =<< trim END 681 let file1 =<< trim END
609 func SourceAnotherFile() 682 func SourceAnotherFile()
610 source Xtest2.vim 683 source Xtest2.vim
611 endfunc 684 endfunc
612 685
662 call delete('Xtest1.vim') 735 call delete('Xtest1.vim')
663 call delete('Xtest2.vim') 736 call delete('Xtest2.vim')
664 endfunc 737 endfunc
665 738
666 func Test_Backtrace_DefFunction() 739 func Test_Backtrace_DefFunction()
667 CheckRunVimInTerminal 740 CheckCWD
668
669 let file1 =<< trim END 741 let file1 =<< trim END
670 vim9script 742 vim9script
671 import File2Function from './Xtest2.vim' 743 import File2Function from './Xtest2.vim'
672 744
673 def SourceAnotherFile() 745 def SourceAnotherFile()
753 825
754 call StopVimInTerminal(buf) 826 call StopVimInTerminal(buf)
755 call delete('Xtest1.vim') 827 call delete('Xtest1.vim')
756 call delete('Xtest2.vim') 828 call delete('Xtest2.vim')
757 endfunc 829 endfunc
830
831 func Test_debug_backtrace_level()
832 CheckCWD
833 let lines =<< trim END
834 let s:file1_var = 'file1'
835 let g:global_var = 'global'
836
837 func s:File1Func( arg )
838 let s:file1_var .= a:arg
839 let local_var = s:file1_var .. ' test1'
840 let g:global_var .= local_var
841 source Xtest2.vim
842 endfunc
843
844 call s:File1Func( 'arg1' )
845 END
846 call writefile(lines, 'Xtest1.vim')
847
848 let lines =<< trim END
849 let s:file2_var = 'file2'
850
851 func s:File2Func( arg )
852 let s:file2_var .= a:arg
853 let local_var = s:file2_var .. ' test2'
854 let g:global_var .= local_var
855 endfunc
856
857 call s:File2Func( 'arg2' )
858 END
859 call writefile(lines, 'Xtest2.vim')
860
861 let file1 = getcwd() .. '/Xtest1.vim'
862 let file2 = getcwd() .. '/Xtest2.vim'
863
864 " set a breakpoint and source file1.vim
865 let buf = RunVimInTerminal(
866 \ '-c "breakadd file 1 Xtest1.vim" -S Xtest1.vim',
867 \ #{ wait_for_ruler: 0 } )
868
869 call CheckDbgOutput(buf, [
870 \ 'Breakpoint in "' .. file1 .. '" line 1',
871 \ 'Entering Debug mode. Type "cont" to continue.',
872 \ 'command line..script ' .. file1,
873 \ 'line 1: let s:file1_var = ''file1'''
874 \ ])
875
876 " step throught the initial declarations
877 call RunDbgCmd(buf, 'step', [ 'line 2: let g:global_var = ''global''' ] )
878 call RunDbgCmd(buf, 'step', [ 'line 4: func s:File1Func( arg )' ] )
879 call RunDbgCmd(buf, 'echo s:file1_var', [ 'file1' ] )
880 call RunDbgCmd(buf, 'echo g:global_var', [ 'global' ] )
881 call RunDbgCmd(buf, 'echo global_var', [ 'global' ] )
882
883 " step in to the first function
884 call RunDbgCmd(buf, 'step', [ 'line 11: call s:File1Func( ''arg1'' )' ] )
885 call RunDbgCmd(buf, 'step', [ 'line 1: let s:file1_var .= a:arg' ] )
886 call RunDbgCmd(buf, 'echo a:arg', [ 'arg1' ] )
887 call RunDbgCmd(buf, 'echo s:file1_var', [ 'file1' ] )
888 call RunDbgCmd(buf, 'echo g:global_var', [ 'global' ] )
889 call RunDbgCmd(buf,
890 \'echo global_var',
891 \[ 'E121: Undefined variable: global_var' ] )
892 call RunDbgCmd(buf,
893 \'echo local_var',
894 \[ 'E121: Undefined variable: local_var' ] )
895 call RunDbgCmd(buf,
896 \'echo l:local_var',
897 \[ 'E121: Undefined variable: l:local_var' ] )
898
899 " backtrace up
900 call RunDbgCmd(buf, 'backtrace', [
901 \ '\V>backtrace',
902 \ '\V 2 command line',
903 \ '\V 1 script ' .. file1 .. '[11]',
904 \ '\V->0 function <SNR>\.\*_File1Func',
905 \ '\Vline 1: let s:file1_var .= a:arg',
906 \ ],
907 \ #{ match: 'pattern' } )
908 call RunDbgCmd(buf, 'up', [ '>up' ] )
909
910 call RunDbgCmd(buf, 'backtrace', [
911 \ '\V>backtrace',
912 \ '\V 2 command line',
913 \ '\V->1 script ' .. file1 .. '[11]',
914 \ '\V 0 function <SNR>\.\*_File1Func',
915 \ '\Vline 1: let s:file1_var .= a:arg',
916 \ ],
917 \ #{ match: 'pattern' } )
918
919 " Expression evaluation in the script frame (not the function frame)
920 " FIXME: Unexpected in this scope (a: should not be visibnle)
921 call RunDbgCmd(buf, 'echo a:arg', [ 'arg1' ] )
922 call RunDbgCmd(buf, 'echo s:file1_var', [ 'file1' ] )
923 call RunDbgCmd(buf, 'echo g:global_var', [ 'global' ] )
924 " FIXME: Unexpected in this scope (global should be found)
925 call RunDbgCmd(buf,
926 \'echo global_var',
927 \[ 'E121: Undefined variable: global_var' ] )
928 call RunDbgCmd(buf,
929 \'echo local_var',
930 \[ 'E121: Undefined variable: local_var' ] )
931 call RunDbgCmd(buf,
932 \'echo l:local_var',
933 \[ 'E121: Undefined variable: l:local_var' ] )
934
935
936 " step while backtraced jumps to the latest frame
937 call RunDbgCmd(buf, 'step', [
938 \ 'line 2: let local_var = s:file1_var .. '' test1''' ] )
939 call RunDbgCmd(buf, 'backtrace', [
940 \ '\V>backtrace',
941 \ '\V 2 command line',
942 \ '\V 1 script ' .. file1 .. '[11]',
943 \ '\V->0 function <SNR>\.\*_File1Func',
944 \ '\Vline 2: let local_var = s:file1_var .. '' test1''',
945 \ ],
946 \ #{ match: 'pattern' } )
947
948 call RunDbgCmd(buf, 'step', [ 'line 3: let g:global_var .= local_var' ] )
949 call RunDbgCmd(buf, 'echo local_var', [ 'file1arg1 test1' ] )
950 call RunDbgCmd(buf, 'echo l:local_var', [ 'file1arg1 test1' ] )
951
952 call RunDbgCmd(buf, 'step', [ 'line 4: source Xtest2.vim' ] )
953 call RunDbgCmd(buf, 'step', [ 'line 1: let s:file2_var = ''file2''' ] )
954 call RunDbgCmd(buf, 'backtrace', [
955 \ '\V>backtrace',
956 \ '\V 3 command line',
957 \ '\V 2 script ' .. file1 .. '[11]',
958 \ '\V 1 function <SNR>\.\*_File1Func[4]',
959 \ '\V->0 script ' .. file2,
960 \ '\Vline 1: let s:file2_var = ''file2''',
961 \ ],
962 \ #{ match: 'pattern' } )
963
964 " Expression evaluation in the script frame file2 (not the function frame)
965 call RunDbgCmd(buf, 'echo a:arg', [ 'E121: Undefined variable: a:arg' ] )
966 call RunDbgCmd(buf,
967 \ 'echo s:file1_var',
968 \ [ 'E121: Undefined variable: s:file1_var' ] )
969 call RunDbgCmd(buf, 'echo g:global_var', [ 'globalfile1arg1 test1' ] )
970 call RunDbgCmd(buf, 'echo global_var', [ 'globalfile1arg1 test1' ] )
971 call RunDbgCmd(buf,
972 \'echo local_var',
973 \[ 'E121: Undefined variable: local_var' ] )
974 call RunDbgCmd(buf,
975 \'echo l:local_var',
976 \[ 'E121: Undefined variable: l:local_var' ] )
977 call RunDbgCmd(buf,
978 \ 'echo s:file2_var',
979 \ [ 'E121: Undefined variable: s:file2_var' ] )
980
981 call RunDbgCmd(buf, 'step', [ 'line 3: func s:File2Func( arg )' ] )
982 call RunDbgCmd(buf, 'echo s:file2_var', [ 'file2' ] )
983
984 " Up the stack to the other script context
985 call RunDbgCmd(buf, 'up')
986 call RunDbgCmd(buf, 'backtrace', [
987 \ '\V>backtrace',
988 \ '\V 3 command line',
989 \ '\V 2 script ' .. file1 .. '[11]',
990 \ '\V->1 function <SNR>\.\*_File1Func[4]',
991 \ '\V 0 script ' .. file2,
992 \ '\Vline 3: func s:File2Func( arg )',
993 \ ],
994 \ #{ match: 'pattern' } )
995 " FIXME: Unexpected. Should see the a: and l: dicts from File1Func
996 call RunDbgCmd(buf, 'echo a:arg', [ 'E121: Undefined variable: a:arg' ] )
997 call RunDbgCmd(buf,
998 \ 'echo l:local_var',
999 \ [ 'E121: Undefined variable: l:local_var' ] )
1000
1001 call RunDbgCmd(buf, 'up')
1002 call RunDbgCmd(buf, 'backtrace', [
1003 \ '\V>backtrace',
1004 \ '\V 3 command line',
1005 \ '\V->2 script ' .. file1 .. '[11]',
1006 \ '\V 1 function <SNR>\.\*_File1Func[4]',
1007 \ '\V 0 script ' .. file2,
1008 \ '\Vline 3: func s:File2Func( arg )',
1009 \ ],
1010 \ #{ match: 'pattern' } )
1011
1012 " FIXME: Unexpected (wrong script vars are used)
1013 call RunDbgCmd(buf,
1014 \ 'echo s:file1_var',
1015 \ [ 'E121: Undefined variable: s:file1_var' ] )
1016 call RunDbgCmd(buf, 'echo s:file2_var', [ 'file2' ] )
1017
1018 call StopVimInTerminal(buf)
1019 call delete('Xtest1.vim')
1020 call delete('Xtest2.vim')
1021 endfunc