]> code.delx.au - gnu-emacs-elpa/blob - test/test-regexp-pdb.el
Add stock Python debugger.
[gnu-emacs-elpa] / test / test-regexp-pdb.el
1 (require 'test-unit)
2 (load-file "../dbgr/debugger/pdb/init.el")
3
4 (test-unit-clear-contexts)
5
6
7 (setq bps-pat (gethash "brkpt-set" dbgr-pdb-pat-hash))
8 (setq loc-pat (gethash "loc" dbgr-pdb-pat-hash))
9 (setq prompt-pat (gethash "prompt" dbgr-pdb-pat-hash))
10 (setq tb-pat (gethash "lang-backtrace" dbgr-pdb-pat-hash))
11
12 (defun loc-match(text var)
13 (string-match (dbgr-loc-pat-regexp var) text)
14 )
15
16 (defun prompt-match(prompt-str msg-fmt)
17 (assert-equal 0 (loc-match prompt-str prompt-pat)
18 (format msg-fmt prompt-str))
19 )
20
21 ;; FIXME: we get a void variable somewhere in here when running
22 ;; even though we define it in lexical-let. Dunno why.
23 ;; setq however will workaround this.
24 (setq text " File \"/usr/lib/python2.6/code.py\", line 281, in raw_input")
25 (context "traceback location matching"
26 (tag regexp-pdb)
27 (specify "basic traceback location"
28 (assert-t (numberp (loc-match text tb-pat))))
29 (specify "extract file name"
30 (assert-equal "/usr/lib/python2.6/code.py"
31 (match-string (dbgr-loc-pat-file-group tb-pat)
32 text)
33 (format "Failing file group is %s"
34 (dbgr-loc-pat-file-group tb-pat))))
35 (specify "extract line number"
36 (assert-equal "281"
37 (match-string (dbgr-loc-pat-line-group tb-pat)
38 text))
39 ))
40
41 (context "breakpoint location matching"
42 (tag regexp-pdb)
43 (lexical-let ((text "Breakpoint 1 at /src/git/code/gcd.py:13"))
44 (specify "basic breakpoint location"
45 (assert-t (numberp (loc-match text bps-pat))))
46 (specify "extract breakpoint file name"
47 (assert-equal "/src/git/code/gcd.py"
48 (match-string (dbgr-loc-pat-file-group
49 bps-pat)
50 text)))
51 (specify "extract breakpoint line number"
52 (assert-equal "13"
53 (match-string (dbgr-loc-pat-line-group
54 bps-pat)
55 text)))
56 )
57 )
58
59 (context "prompt matching"
60 (tag regexp-pdb)
61 ;; (lexical-let ((text "(c:\\working\\python\\helloworld.py:30): <module>"))
62 ;; (specify "MS DOS position location"
63 ;; (assert-t (numberp (loc-match text loc-pat))))
64 ;; (specify "extract file name"
65 ;; (assert-equal "c:\\working\\python\\helloworld.py"
66 ;; (match-string (dbgr-loc-pat-file-group loc-pat)
67 ;; text)
68 ;; (format "Failing file group is %s"
69 ;; (dbgr-loc-pat-file-group tb-pat))))
70 ;; (specify "extract line number"
71 ;; (assert-equal "30"
72 ;; (match-string (dbgr-loc-pat-line-group loc-pat)
73 ;; text)))
74
75 ;; )
76 (lexical-let ((text "> /usr/bin/ipython(24)<module>"))
77 (specify "position location"
78 (assert-t (numberp (loc-match text loc-pat))))
79 (specify "extract file name"
80 (assert-equal "/usr/bin/ipython"
81 (match-string (dbgr-loc-pat-file-group loc-pat)
82 text)
83 (format "Failing file group is %s"
84 (dbgr-loc-pat-file-group tb-pat))))
85 (specify "extract line number"
86 (assert-equal "24"
87 (match-string (dbgr-loc-pat-line-group
88 loc-pat)
89 text)))
90
91 )
92
93 (lexical-let ((prompt-str "(Pdb) "))
94 (specify "prompt matching"
95 (prompt-match prompt-str "valid debugger prompt: %s")
96 (setq prompt_str "((Pdb)) ")
97 (prompt-match prompt-str "valid nested debugger prompt: %s")
98 (setq prompt-str "Pdb) ")
99 (assert-nil (numberp (loc-match prompt-str prompt))
100 (format "%s %s" "invalid debugger prompt"
101 prompt-str))
102 )
103 )
104 )
105
106 (test-unit "regexp-pdb")
107