]> code.delx.au - gnu-emacs-elpa/blob - test/test-regexp-trepan.el
Add stock Python debugger.
[gnu-emacs-elpa] / test / test-regexp-trepan.el
1 (require 'test-unit)
2 (load-file "../dbgr/debugger/trepan/init.el")
3
4 (test-unit-clear-contexts)
5
6
7 (setq bps-pat (gethash "brkpt-set" dbgr-trepan-pat-hash))
8 (setq dbg-bt-pat (gethash "debugger-backtrace" dbgr-trepan-pat-hash))
9 (setq prompt-pat (gethash "prompt" dbgr-trepan-pat-hash))
10 (setq lang-bt-pat (gethash "lang-backtrace" dbgr-trepan-pat-hash))
11 (setq ctrl-pat (gethash "control-frame" dbgr-trepan-pat-hash))
12
13 (defun loc-match(text var)
14 (string-match (dbgr-loc-pat-regexp var) text)
15 )
16
17 (defun prompt-match(prompt-str)
18 (assert-equal 0 (loc-match prompt-str prompt-pat)
19 (format "valid prompt %s" prompt-str))
20 )
21
22 ;; FIXME: we get a void variable somewhere in here when running
23 ;; even though we define it in lexical-let. Dunno why.
24 ;; setq however will workaround this.
25 (setq text " from /usr/local/bin/irb:12:in `<main>'")
26 (context "traceback location matching"
27 (tag regexp-trepan)
28 (lexical-let ((text " from /usr/local/bin/irb:12:in `<main>'"))
29 (specify "basic traceback location"
30 (assert-t (numberp (loc-match text lang-bt-pat))))
31 (specify "extract traceback file name"
32 (assert-equal "/usr/local/bin/irb"
33 (match-string (dbgr-loc-pat-file-group lang-bt-pat)
34 text)))
35 (specify "extract traceback line number"
36 (assert-equal "12"
37 (match-string (dbgr-loc-pat-line-group
38 lang-bt-pat)
39 text)))
40 )
41
42 (specify "debugger-backtrace"
43 (setq s1 "--> #0 METHOD Object#require(path) in file <internal:lib/require> at line 28
44 #1 TOP Object#<top /tmp/linecache.rb> in file /tmp/linecache.rb
45 ")
46 (setq frame-re (dbgr-loc-pat-regexp dbg-bt-pat))
47 (setq num-group (dbgr-loc-pat-num dbg-bt-pat))
48 (setq file-group (dbgr-loc-pat-file-group dbg-bt-pat))
49 (setq line-group (dbgr-loc-pat-line-group dbg-bt-pat))
50 (assert-equal 0 (string-match frame-re s1))
51 (assert-equal "0" (substring s1
52 (match-beginning num-group)
53 (match-end num-group)))
54 (assert-equal "<internal:lib/require>"
55 (substring s1
56 (match-beginning file-group)
57 (match-end file-group)))
58 (assert-equal "28"
59 (substring s1
60 (match-beginning line-group)
61 (match-end line-group)))
62 (setq pos (match-end 0))
63
64 (assert-equal 77 (string-match frame-re s1 pos))
65 (assert-equal "1" (substring s1
66 (match-beginning num-group)
67 (match-end num-group)))
68 (assert-equal "/tmp/linecache.rb"
69 (substring s1
70 (match-beginning file-group)
71 (match-end file-group)))
72 )
73
74 (specify "prompt"
75 (prompt-match "(trepan): ")
76 (prompt-match "((trepan)): ")
77 (prompt-match "((trepan@55)): ")
78 (prompt-match "((trepan@main)): ")
79 (assert-nil (loc-match "trepan:" prompt-pat)
80 (format "invalid prompt %s" prompt-str))
81 )
82
83 (specify "control-frame"
84 (assert-equal 0 (loc-match
85 "c:0026 p:0181 s:0136 b:0136 l:000135 d:000135 METHOD /trepan-0.0.1/app/frame.rb:132 "
86 ctrl-pat)
87 )
88 (assert-equal 0 (loc-match
89 "c:0030 p:0041 s:0144 b:0144 l:00226c d:00226c METHOD /gems/trepan-0.0.1/processor/eval.rb:15 "
90 ctrl-pat)
91 )
92 (assert-equal 0 (loc-match
93 "c:0015 p:0139 s:0070 b:0070 l:000063 d:000069 BLOCK /gems/app/core.rb:121"
94 ctrl-pat)
95 )
96 )
97
98 (lexical-let ((text "Breakpoint 1 set at VM offset 2 of instruction sequence \"<top /usr/local/bin/irb>\",
99 line 9 in file /usr/local/bin/irb.
100 "))
101 (specify "basic breakpoint location"
102 (assert-t (numberp (loc-match text bps-pat))))
103 (specify "extract breakpoint file name"
104 (assert-equal "/usr/local/bin/irb"
105 (match-string (dbgr-loc-pat-file-group
106 bps-pat) text)))
107 (specify "extract breakpoint line number"
108 (assert-equal "9"
109 (match-string (dbgr-loc-pat-line-group
110 bps-pat) text)))
111 )
112 )
113
114 (test-unit "regexp-trepan")
115