Mercurial > emacs
comparison test/cedet/semantic-utest.el @ 105267:c99cf31de3f2
Add CEDET tests.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 28 Sep 2009 23:23:31 +0000 |
parents | e480034314ce |
children | 7f4c7f5c0eba |
comparison
equal
deleted
inserted
replaced
105266:c02e98221afe | 105267:c99cf31de3f2 |
---|---|
1 ;;; semantic-utest.el --- Tests for semantic's parsing system. | |
2 | |
3 ;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation, either version 3 of the License, or | |
12 ;; (at your option) any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
21 | |
22 ;;; Commentary: | |
23 ;; | |
24 ;; Semantic's parsing and partial parsing system is pretty complex. | |
25 ;; These unit tests attempt to emulate semantic's partial reparsing | |
26 ;; and full reparsing system, and anything else I may feel the urge | |
27 ;; to write a test for. | |
28 | |
29 (require 'semantic) | |
30 | |
31 (load-file "cedet-utests.el") | |
32 | |
33 (defvar semantic-utest-temp-directory (if (fboundp 'temp-directory) | |
34 (temp-directory) | |
35 temporary-file-directory) | |
36 "Temporary directory to use when creating files.") | |
37 | |
38 (defun semantic-utest-fname (name) | |
39 "Create a filename for NAME in /tmp." | |
40 (expand-file-name name semantic-utest-temp-directory)) | |
41 | |
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
43 ;; Data for C tests | |
44 | |
45 (defvar semantic-utest-C-buffer-contents | |
46 "/* Test file for C language for Unit Tests */ | |
47 | |
48 #include <stdio.h> | |
49 #include \"sutest.h\" | |
50 | |
51 struct mystruct1 { | |
52 int slot11; | |
53 char slot12; | |
54 float slot13; | |
55 }; | |
56 | |
57 int var1; | |
58 | |
59 float funp1(char arg11, char arg12); | |
60 | |
61 char fun2(int arg_21, int arg_22) /*1*/ | |
62 { | |
63 struct mystruct1 *ms1 = malloc(sizeof(struct mystruct1)); | |
64 | |
65 char sv = calc_sv(var1); | |
66 | |
67 if (var1 == 0) { | |
68 sv = 1; | |
69 } else if (arg_21 == 0) { | |
70 sv = 2; | |
71 } else if (arg_22 == 0) { | |
72 sv = 3; | |
73 } else { | |
74 sv = 4; | |
75 } | |
76 | |
77 printf(\"SV = %d\\n\", sv); | |
78 | |
79 /* Memory Leak */ | |
80 ms1.slot1 = sv; | |
81 | |
82 return 'A' + sv; | |
83 } | |
84 " | |
85 "Contents of a C buffer initialized by this unit test. | |
86 Be sure to change `semantic-utest-C-name-contents' when you | |
87 change this variable.") | |
88 | |
89 (defvar semantic-utest-C-h-buffer-contents | |
90 "/* Test file for C language header file for Unit Tests */ | |
91 | |
92 int calc_sv(int); | |
93 | |
94 " | |
95 "Contents of a C header file buffer initialized by this unit test.") | |
96 | |
97 (defvar semantic-utest-C-filename (semantic-utest-fname "sutest.c") | |
98 "File to open and erase during this test for C.") | |
99 | |
100 (defvar semantic-utest-C-filename-h | |
101 (concat (file-name-sans-extension semantic-utest-C-filename) | |
102 ".h") | |
103 "Header file filename for C") | |
104 | |
105 | |
106 (defvar semantic-utest-C-name-contents | |
107 '(("stdio.h" include | |
108 (:system-flag t) | |
109 nil (overlay 48 66 "sutest.c")) | |
110 ("sutest.h" include nil nil (overlay 67 86 "sutest.c")) | |
111 ("mystruct1" type | |
112 (:members | |
113 (("slot11" variable | |
114 (:type "int") | |
115 (reparse-symbol classsubparts) | |
116 (overlay 109 120 "sutest.c")) | |
117 ("slot12" variable | |
118 (:type "char") | |
119 (reparse-symbol classsubparts) | |
120 (overlay 123 135 "sutest.c")) | |
121 ("slot13" variable | |
122 (:type "float") | |
123 (reparse-symbol classsubparts) | |
124 (overlay 138 151 "sutest.c"))) | |
125 :type "struct") | |
126 nil (overlay 88 154 "sutest.c")) | |
127 ("var1" variable | |
128 (:type "int") | |
129 nil (overlay 156 165 "sutest.c")) | |
130 ("funp1" function | |
131 (:prototype-flag t :arguments | |
132 (("arg11" variable | |
133 (:type "char") | |
134 (reparse-symbol arg-sub-list) | |
135 (overlay 179 190 "sutest.c")) | |
136 ("arg12" variable | |
137 (:type "char") | |
138 (reparse-symbol arg-sub-list) | |
139 (overlay 191 202 "sutest.c"))) | |
140 :type "float") | |
141 nil (overlay 167 203 "sutest.c")) | |
142 ("fun2" function | |
143 (:arguments | |
144 (("arg_21" variable | |
145 (:type "int") | |
146 (reparse-symbol arg-sub-list) | |
147 (overlay 215 226 "sutest.c")) | |
148 ("arg_22" variable | |
149 (:type "int") | |
150 (reparse-symbol arg-sub-list) | |
151 (overlay 227 238 "sutest.c"))) | |
152 :type "char") | |
153 nil (overlay 205 566 "sutest.c"))) | |
154 "List of expected tag names for C.") | |
155 | |
156 | |
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
159 ;; Data for Python tests | |
160 | |
161 (defvar semantic-utest-Python-buffer-contents | |
162 " | |
163 def fun1(a,b,c): | |
164 return a | |
165 | |
166 def fun2(a,b,c): #1 | |
167 return b | |
168 | |
169 " | |
170 | |
171 | |
172 ) | |
173 ; "pyhon test case. notice that python is indentation sensitive | |
174 | |
175 | |
176 (defvar semantic-utest-Python-name-contents | |
177 '(("fun1" function | |
178 (:arguments | |
179 (("a" variable nil | |
180 (reparse-symbol function_parameters) | |
181 (overlay 10 11 "tst.py")) | |
182 ("b" variable nil | |
183 (reparse-symbol function_parameters) | |
184 (overlay 12 13 "tst.py")) | |
185 ("c" variable nil | |
186 (reparse-symbol function_parameters) | |
187 (overlay 14 15 "tst.py")))) | |
188 nil (overlay 1 31 "tst.py")) | |
189 ("fun2" function | |
190 (:arguments | |
191 (("a" variable nil | |
192 (reparse-symbol function_parameters) | |
193 (overlay 41 42 "tst.py")) | |
194 ("b" variable nil | |
195 (reparse-symbol function_parameters) | |
196 (overlay 43 44 "tst.py")) | |
197 ("c" variable nil | |
198 (reparse-symbol function_parameters) | |
199 (overlay 45 46 "tst.py")))) | |
200 nil (overlay 32 65 "tst.py"))) | |
201 | |
202 "List of expected tag names for Python.") | |
203 | |
204 | |
205 | |
206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
208 ;; Data for Java tests | |
209 | |
210 (defvar semantic-utest-Java-buffer-contents | |
211 " | |
212 class JavaTest{ | |
213 void fun1(int a,int b){ | |
214 return a; | |
215 } | |
216 | |
217 void fun2(int a,int b){ //1 | |
218 return b; | |
219 } | |
220 | |
221 } | |
222 " | |
223 ) | |
224 | |
225 (defvar semantic-utest-Java-name-contents | |
226 '(("JavaTest" type | |
227 (:members | |
228 (("fun1" function | |
229 (:arguments | |
230 (("a" variable | |
231 (:type "int") | |
232 (reparse-symbol formal_parameters) | |
233 (overlay 30 35 "JavaTest.java")) | |
234 ("b" variable | |
235 (:type "int") | |
236 (reparse-symbol formal_parameters) | |
237 (overlay 36 41 "JavaTest.java"))) | |
238 :type "void") | |
239 (reparse-symbol class_member_declaration) | |
240 (overlay 20 61 "JavaTest.java")) | |
241 ("fun2" function | |
242 (:arguments | |
243 (("a" variable | |
244 (:type "int") | |
245 (reparse-symbol formal_parameters) | |
246 (overlay 75 80 "JavaTest.java")) | |
247 ("b" variable | |
248 (:type "int") | |
249 (reparse-symbol formal_parameters) | |
250 (overlay 81 86 "JavaTest.java"))) | |
251 :type "void") | |
252 (reparse-symbol class_member_declaration) | |
253 (overlay 65 110 "JavaTest.java"))) | |
254 :type "class") | |
255 nil (overlay 2 113 "JavaTest.java"))) | |
256 "List of expected tag names for Java." | |
257 ) | |
258 | |
259 | |
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
262 ;; Data for Javascript tests | |
263 | |
264 (defvar semantic-utest-Javascript-buffer-contents | |
265 " | |
266 function fun1(a, b){ | |
267 return a; | |
268 } | |
269 | |
270 function fun2(a,b){ //1 | |
271 return b; | |
272 } | |
273 " | |
274 ) | |
275 | |
276 | |
277 (defvar semantic-utest-Javascript-name-contents | |
278 '(("fun1" function | |
279 (:arguments | |
280 (("a" variable nil | |
281 (reparse-symbol FormalParameterList) | |
282 (overlay 15 16 "tst.js")) | |
283 ("b" variable nil | |
284 (reparse-symbol FormalParameterList) | |
285 (overlay 18 19 "tst.js")))) | |
286 nil (overlay 1 39 "tst.js")) | |
287 ("fun2" function | |
288 (:arguments | |
289 (("a" variable nil | |
290 (reparse-symbol FormalParameterList) | |
291 (overlay 55 56 "tst.js")) | |
292 ("b" variable nil | |
293 (reparse-symbol FormalParameterList) | |
294 (overlay 57 58 "tst.js")))) | |
295 nil (overlay 41 82 "tst.js"))) | |
296 | |
297 "List of expected tag names for Javascript.") | |
298 | |
299 | |
300 | |
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
303 ;; Data for Makefile tests | |
304 | |
305 (defvar semantic-utest-Makefile-buffer-contents | |
306 " | |
307 t1: | |
308 \techo t1 | |
309 | |
310 t2:t1 #1 | |
311 \techo t2 | |
312 | |
313 | |
314 " | |
315 ) | |
316 | |
317 | |
318 (defvar semantic-utest-Makefile-name-contents | |
319 '(("t1" function nil nil (overlay 1 9 "Makefile")) | |
320 ("t2" function | |
321 (:arguments | |
322 ("t1")) | |
323 nil (overlay 18 28 "Makefile"))) | |
324 "List of expected tag names for Makefile.") | |
325 | |
326 | |
327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
329 ;; Data for Scheme tests | |
330 | |
331 (defvar semantic-utest-Scheme-buffer-contents | |
332 " | |
333 (define fun1 2) | |
334 | |
335 (define fun2 3 ;1 | |
336 ) | |
337 ") | |
338 | |
339 (defvar semantic-utest-Scheme-name-contents | |
340 '(("fun1" variable | |
341 (:default-value ("2")) | |
342 nil (overlay 3 18 "tst.scm")) | |
343 ("fun2" variable | |
344 (:default-value ("3")) | |
345 nil (overlay 21 55 "tst.scm"))) | |
346 ) | |
347 | |
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
350 ;; Data for Html tests | |
351 | |
352 (defvar semantic-utest-Html-buffer-contents | |
353 " | |
354 <html> | |
355 <body> | |
356 <h1>hello</h1> | |
357 </body><!--1--> | |
358 </html> | |
359 " | |
360 ) | |
361 | |
362 (defvar semantic-utest-Html-name-contents | |
363 '(("hello" section | |
364 (:members | |
365 (("hello" section nil nil (overlay 21 24 "tst.html")))) | |
366 nil (overlay 10 15 "tst.html"))) | |
367 ) | |
368 | |
369 | |
370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
372 ;; Data for PHP tests | |
373 | |
374 (defvar semantic-utest-PHP-buffer-contents | |
375 "<?php | |
376 | |
377 function fun1(){ | |
378 return \"fun1\"; | |
379 } | |
380 | |
381 function fun2($arg1){ | |
382 $output = \"argument to fun2: \" . $arg1; | |
383 return $output; | |
384 } | |
385 | |
386 class aClass { | |
387 public function fun1($a, $b){ | |
388 return $a; | |
389 } | |
390 | |
391 public function fun2($a, $b){ | |
392 return $b; | |
393 } | |
394 } | |
395 ?> " | |
396 ) | |
397 | |
398 (defvar semantic-utest-PHP-name-contents | |
399 '(("fun1" function nil | |
400 nil (overlay 9 45 "phptest.php")) | |
401 ("fun2" function | |
402 (:arguments (("$arg1" variable nil (reparse-symbol formal_parameters) (overlay 61 66 "phptest.php")))) | |
403 nil | |
404 (overlay 47 132 "phptest.php")) | |
405 ("aClass" type | |
406 (:members (("fun1" function | |
407 (:typemodifiers ("public") :arguments | |
408 (("$a" variable nil (reparse-symbol formal_parameters) (overlay 174 176 "phptest.php")) | |
409 ("$b" variable nil (reparse-symbol formal_parameters) (overlay 178 180 "phptest.php")))) | |
410 | |
411 nil | |
412 (overlay 153 204 "phptest.php")) | |
413 | |
414 ("fun2" function | |
415 (:typemodifiers ("public") :arguments | |
416 (("$a" variable nil (reparse-symbol formal_parameters) (overlay 230 232 "phptest.php")) | |
417 ("$b" variable nil (reparse-symbol formal_parameters) (overlay 234 236 "phptest.php")) | |
418 )) | |
419 nil | |
420 (overlay 209 260 "phptest.php"))) :type "class") | |
421 nil | |
422 (overlay 135 262 "phptest.php")) | |
423 ) | |
424 "Expected results from the PHP Unit test" | |
425 ) | |
426 | |
427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
429 ;; Data for Csharp C# tests | |
430 | |
431 (defvar semantic-utest-Csharp-buffer-contents | |
432 " | |
433 class someClass { | |
434 int fun1(int a, int b) { | |
435 return a; } | |
436 int fun2(int a, int b) { | |
437 return b; } | |
438 } | |
439 ") | |
440 | |
441 (defvar semantic-utest-Csharp-name-contents | |
442 '(("someClass" type | |
443 (:members | |
444 (("fun1" function | |
445 (:arguments | |
446 (("a" variable | |
447 (:type "int") | |
448 (reparse-symbol formal_parameters) | |
449 (overlay 30 35 "tst.cs")) | |
450 ("b" variable | |
451 (:type "int") | |
452 (reparse-symbol formal_parameters) | |
453 (overlay 37 42 "tst.cs"))) | |
454 :type "int") | |
455 (reparse-symbol class_member_declaration) | |
456 (overlay 21 61 "tst.cs")) | |
457 ("fun2" function | |
458 (:arguments | |
459 (("a" variable | |
460 (:type "int") | |
461 (reparse-symbol formal_parameters) | |
462 (overlay 73 78 "tst.cs")) | |
463 ("b" variable | |
464 (:type "int") | |
465 (reparse-symbol formal_parameters) | |
466 (overlay 80 85 "tst.cs"))) | |
467 :type "int") | |
468 (reparse-symbol class_member_declaration) | |
469 (overlay 64 104 "tst.cs"))) | |
470 :type "class") | |
471 nil (overlay 1 106 "tst.cs"))) | |
472 ) | |
473 | |
474 | |
475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
477 | |
478 | |
479 | |
480 (defun semantic-utest-makebuffer (filename contents) | |
481 "Create a buffer for FILENAME for use in a unit test. | |
482 Pre-fill the buffer with CONTENTS." | |
483 (let ((buff (semantic-find-file-noselect filename))) | |
484 (set-buffer buff) | |
485 (setq buffer-offer-save nil) | |
486 (font-lock-mode -1) ;; Font lock has issues in Emacs 23 | |
487 (toggle-read-only -1) ;; In case /tmp doesn't exist. | |
488 (erase-buffer) | |
489 (insert contents) | |
490 ;(semantic-fetch-tags) ;JAVE could this go here? | |
491 (set-buffer-modified-p nil) | |
492 buff | |
493 ) | |
494 ) | |
495 | |
496 (defun semantic-utest-C () | |
497 "Run semantic's C unit test." | |
498 (interactive) | |
499 (save-excursion | |
500 (let ((buff (semantic-utest-makebuffer semantic-utest-C-filename semantic-utest-C-buffer-contents)) | |
501 (buff2 (semantic-utest-makebuffer semantic-utest-C-filename-h semantic-utest-C-h-buffer-contents)) | |
502 ) | |
503 (semantic-fetch-tags) | |
504 (set-buffer buff) | |
505 | |
506 ;; Turn off a range of modes | |
507 (semantic-idle-scheduler-mode -1) | |
508 | |
509 ;; Turn on some modes | |
510 (semantic-highlight-edits-mode 1) | |
511 | |
512 ;; Update tags, and show it. | |
513 (semantic-fetch-tags) | |
514 | |
515 (switch-to-buffer buff) | |
516 (sit-for 0) | |
517 | |
518 ;; Run the tests. | |
519 ;;(message "First parsing test.") | |
520 (semantic-utest-verify-names semantic-utest-C-name-contents) | |
521 | |
522 ;;(message "Invalid tag test.") | |
523 (semantic-utest-last-invalid semantic-utest-C-name-contents '("fun2") "/\\*1\\*/" "/* Deleted this line */") | |
524 (semantic-utest-verify-names semantic-utest-C-name-contents) | |
525 | |
526 (set-buffer-modified-p nil) | |
527 ;; Clean up | |
528 ;; (kill-buffer buff) | |
529 ;; (kill-buffer buff2) | |
530 )) | |
531 (message "All C tests passed.") | |
532 ) | |
533 | |
534 | |
535 | |
536 | |
537 (defun semantic-utest-generic (testname filename contents name-contents names-removed killme insertme) | |
538 "Generic unit test according to template. | |
539 Should work for languages withouth .h files, python javascript java. | |
540 TESTNAME is the name of the test. | |
541 FILENAME is the name of the file to create. | |
542 CONTENTS is the contents of the file to test. | |
543 NAME-CONTENTS is the list of names that should be in the contents. | |
544 NAMES-REMOVED is the list of names that gets removed in the removal step. | |
545 KILLME is the name of items to be killed. | |
546 INSERTME is the text to be inserted after the deletion." | |
547 (save-excursion | |
548 (let ((buff (semantic-utest-makebuffer filename contents)) | |
549 ) | |
550 ;; Turn off a range of modes | |
551 (semantic-idle-scheduler-mode -1) | |
552 | |
553 ;; Turn on some modes | |
554 (semantic-highlight-edits-mode 1) | |
555 | |
556 ;; Update tags, and show it. | |
557 (semantic-fetch-tags) | |
558 (switch-to-buffer buff) | |
559 (sit-for 0) | |
560 | |
561 ;; Run the tests. | |
562 ;;(message "First parsing test %s." testname) | |
563 (semantic-utest-verify-names name-contents) | |
564 | |
565 ;;(message "Invalid tag test %s." testname) | |
566 (semantic-utest-last-invalid name-contents names-removed killme insertme) | |
567 (semantic-utest-verify-names name-contents) | |
568 | |
569 (set-buffer-modified-p nil) | |
570 ;; Clean up | |
571 ;; (kill-buffer buff) | |
572 )) | |
573 (message "All %s tests passed." testname) | |
574 ) | |
575 | |
576 (defun semantic-utest-Python() | |
577 (interactive) | |
578 (if (fboundp 'python-mode) | |
579 (semantic-utest-generic "Python" (semantic-utest-fname "pytest.py") semantic-utest-Python-buffer-contents semantic-utest-Python-name-contents '("fun2") "#1" "#deleted line") | |
580 (message "Skilling Python test: NO major mode.")) | |
581 ) | |
582 | |
583 | |
584 (defun semantic-utest-Javascript() | |
585 (interactive) | |
586 (if (fboundp 'javascript-mode) | |
587 (semantic-utest-generic "Javascript" (semantic-utest-fname "javascripttest.js") semantic-utest-Javascript-buffer-contents semantic-utest-Javascript-name-contents '("fun2") "//1" "//deleted line") | |
588 (message "Skipping JavaScript test: NO major mode.")) | |
589 ) | |
590 | |
591 (defun semantic-utest-Java() | |
592 (interactive) | |
593 ;; If JDE is installed, it might mess things up depending on the version | |
594 ;; that was installed. | |
595 (let ((auto-mode-alist '(("\\.java\\'" . java-mode)))) | |
596 (semantic-utest-generic "Java" (semantic-utest-fname "JavaTest.java") semantic-utest-Java-buffer-contents semantic-utest-Java-name-contents '("fun2") "//1" "//deleted line") | |
597 )) | |
598 | |
599 (defun semantic-utest-Makefile() | |
600 (interactive) | |
601 (semantic-utest-generic "Makefile" (semantic-utest-fname "Makefile") semantic-utest-Makefile-buffer-contents semantic-utest-Makefile-name-contents '("fun2") "#1" "#deleted line") | |
602 ) | |
603 | |
604 (defun semantic-utest-Scheme() | |
605 (interactive) | |
606 (semantic-utest-generic "Scheme" (semantic-utest-fname "tst.scm") semantic-utest-Scheme-buffer-contents semantic-utest-Scheme-name-contents '("fun2") ";1" ";deleted line") | |
607 ) | |
608 | |
609 | |
610 (defun semantic-utest-Html() | |
611 (interactive) | |
612 ;; Disable html-helper auto-fill-in mode. | |
613 (let ((html-helper-build-new-buffer nil)) | |
614 (semantic-utest-generic "HTML" (semantic-utest-fname "tst.html") semantic-utest-Html-buffer-contents semantic-utest-Html-name-contents '("fun2") "<!--1-->" "<!--deleted line-->") | |
615 )) | |
616 | |
617 (defun semantic-utest-PHP() | |
618 (interactive) | |
619 (if (fboundp 'php-mode) | |
620 (semantic-utest-generic "PHP" (semantic-utest-fname "phptest.php") semantic-utest-PHP-buffer-contents semantic-utest-PHP-name-contents '("fun1") "fun2" "%^@") | |
621 (message "Skipping PHP Test. No php-mode loaded.")) | |
622 ) | |
623 | |
624 ;look at http://mfgames.com/linux/csharp-mode | |
625 (defun semantic-utest-Csharp() ;; hmm i dont even know how to edit a scharp file. need a csharp mode implementation i suppose | |
626 (interactive) | |
627 (if (fboundp 'csharp-mode) | |
628 (semantic-utest-generic "C#" (semantic-utest-fname "csharptest.cs") semantic-utest-Csharp-buffer-contents semantic-utest-Csharp-name-contents '("fun2") "//1" "//deleted line") | |
629 (message "Skipping C# test. No csharp-mode loaded.")) | |
630 ) | |
631 | |
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
633 ;; stubs | |
634 | |
635 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
636 ; stuff for Erlang | |
637 ;;-module(hello). | |
638 ;-export([hello_world/0]). | |
639 ; | |
640 ;hello_world()-> | |
641 ; io:format("Hello World ~n"). | |
642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
643 ;(defun semantic-utest-Erlang() | |
644 ; (interactive) | |
645 ; (semantic-utest-generic "Erlang" (semantic-utest-fname "tst.erl") semantic-utest-Erlang-buffer-contents semantic-utest-Erlang-name-contents '("fun2") "//1" "//deleted line") | |
646 ; ) | |
647 ; | |
648 ;;texi is also supported | |
649 ;(defun semantic-utest-Texi() | |
650 ; (interactive) | |
651 ; (semantic-utest-generic "texi" (semantic-utest-fname "tst.texi") semantic-utest-Texi-buffer-contents semantic-utest-Texi-name-contents '("fun2") "//1" "//deleted line") | |
652 ; ) | |
653 | |
654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
655 | |
656 ;;;###autoload | |
657 (defun semantic-utest-main() | |
658 (interactive) | |
659 "call all utests" | |
660 (cedet-utest-log-start "multi-lang parsing") | |
661 (cedet-utest-log " * C tests...") | |
662 (semantic-utest-C) | |
663 (cedet-utest-log " * Python tests...") | |
664 (semantic-utest-Python) | |
665 (cedet-utest-log " * Java tests...") | |
666 (semantic-utest-Java) | |
667 (cedet-utest-log " * Javascript tests...") | |
668 (semantic-utest-Javascript) | |
669 (cedet-utest-log " * Makefile tests...") | |
670 (semantic-utest-Makefile) | |
671 (cedet-utest-log " * Scheme tests...") | |
672 (semantic-utest-Scheme) | |
673 (cedet-utest-log " * Html tests...") | |
674 (semantic-utest-Html) | |
675 (cedet-utest-log " * PHP tests...") | |
676 (semantic-utest-PHP) | |
677 (cedet-utest-log " * Csharp tests...") | |
678 (semantic-utest-Csharp) | |
679 | |
680 (cedet-utest-log-shutdown "multi-lang parsing") | |
681 ) | |
682 | |
683 ;;; Buffer contents validation | |
684 ;; | |
685 (defun semantic-utest-match-attributes (attr1 attr2 skipnames) | |
686 "Compare attribute lists ATTR1 and ATTR2. | |
687 Argument SKIPNAMES is a list of names that may be child nodes to skip." | |
688 (let ((res t)) | |
689 (while (and res attr1 attr2) | |
690 | |
691 ;; Compare | |
692 (setq res | |
693 (cond ((and (listp (car attr1)) | |
694 (semantic-tag-p (car (car attr1)))) | |
695 ;; Compare the list of tags... | |
696 (semantic-utest-taglists-equivalent-p | |
697 (car attr2) (car attr1) skipnames) | |
698 ) | |
699 (t | |
700 (equal (car attr1) (car attr2))))) | |
701 | |
702 (if (not res) | |
703 (error "TAG INTERNAL DIFF: %S %S" | |
704 (car attr1) (car attr2))) | |
705 | |
706 (setq attr1 (cdr attr1) | |
707 attr2 (cdr attr2))) | |
708 res)) | |
709 | |
710 (defun semantic-utest-equivalent-tag-p (tag1 tag2 skipnames) | |
711 "Determine if TAG1 and TAG2 are the same. | |
712 SKIPNAMES includes lists of possible child nodes that should be missing." | |
713 (and (equal (semantic-tag-name tag1) (semantic-tag-name tag2)) | |
714 (semantic-tag-of-class-p tag1 (semantic-tag-class tag2)) | |
715 (semantic-utest-match-attributes | |
716 (semantic-tag-attributes tag1) (semantic-tag-attributes tag2) | |
717 skipnames) | |
718 )) | |
719 | |
720 (defun semantic-utest-taglists-equivalent-p (table names skipnames) | |
721 "Compare TABLE and NAMES, where skipnames allow list1 to be different. | |
722 SKIPNAMES is a list of names that should be skipped in the NAMES list." | |
723 (let ((SN skipnames)) | |
724 (while SN | |
725 (setq names (remove (car SN) names)) | |
726 (setq SN (cdr SN)))) | |
727 (while (and names table) | |
728 (if (not (semantic-utest-equivalent-tag-p (car names) | |
729 (car table) | |
730 skipnames)) | |
731 (error "Expected %s, found %s" | |
732 (semantic-format-tag-prototype (car names)) | |
733 (semantic-format-tag-prototype (car table)))) | |
734 (setq names (cdr names) | |
735 table (cdr table))) | |
736 (when names (error "Items forgotten: %S" | |
737 (mapcar 'semantic-tag-name names) | |
738 )) | |
739 (when table (error "Items extra: %S" | |
740 (mapcar 'semantic-tag-name table))) | |
741 t) | |
742 | |
743 (defun semantic-utest-verify-names (name-contents &optional skipnames) | |
744 "Verify the names of the test buffer from NAME-CONTENTS. | |
745 Argument SKIPNAMES is a list of names that should be skipped | |
746 when analyzing the file. | |
747 | |
748 JAVE this thing would need to be recursive to handle java and csharp" | |
749 (let ((names name-contents) | |
750 (table (semantic-fetch-tags)) | |
751 ) | |
752 (semantic-utest-taglists-equivalent-p table names skipnames) | |
753 )) | |
754 | |
755 ;;;;;;;;;;;;;;;;;;;;;;;; | |
756 ; JAVE redefine a new validation function | |
757 ; is not quite as good as the old one yet | |
758 (defun semantic-utest-verify-names-jave (name-contents &optional skipnames) | |
759 "JAVE version of `semantic-utest-verify-names'. | |
760 NAME-CONTENTS is a sample of the tags buffer to test against. | |
761 SKIPNAMES is a list of names to remove from NAME-CONTENTS" | |
762 (assert (semantic-utest-verify-names-2 name-contents (semantic-fetch-tags)) | |
763 nil "failed test") | |
764 ) | |
765 | |
766 (defun semantic-utest-verify-names-2 (l1 l2) | |
767 (cond ( (and (consp l1) (equal (car l1) 'overlay)) | |
768 (overlayp l2)) | |
769 ((not (consp l1)) | |
770 (equal l1 l2)) | |
771 ((consp l1) | |
772 (and (semantic-utest-verify-names-2 (car l1) (car l2)) (semantic-utest-verify-names-2 (cdr l1) (cdr l2)))) | |
773 (t (error "internal error")))) | |
774 | |
775 | |
776 | |
777 | |
778 | |
779 ;;; Kill indicator line | |
780 ;; | |
781 (defvar semantic-utest-last-kill-text nil | |
782 "The text from the last kill.") | |
783 | |
784 (defvar semantic-utest-last-kill-pos nil | |
785 "The position of the last kill.") | |
786 | |
787 (defun semantic-utest-kill-indicator ( killme insertme) | |
788 "Kill the line with KILLME on it and insert INSERTME in its place." | |
789 (goto-char (point-min)) | |
790 ; (re-search-forward (concat "/\\*" indicator "\\*/")); JAVE this isnt generic enough for different lagnuages | |
791 (re-search-forward killme) | |
792 (beginning-of-line) | |
793 (setq semantic-utest-last-kill-pos (point)) | |
794 (setq semantic-utest-last-kill-text | |
795 (buffer-substring (point) (point-at-eol))) | |
796 (delete-region (point) (point-at-eol)) | |
797 (insert insertme) | |
798 (sit-for 0) | |
799 ) | |
800 | |
801 (defun semantic-utest-unkill-indicator () | |
802 "Unkill the last indicator." | |
803 (goto-char semantic-utest-last-kill-pos) | |
804 (delete-region (point) (point-at-eol)) | |
805 (insert semantic-utest-last-kill-text) | |
806 (sit-for 0) | |
807 ) | |
808 | |
809 ;;; EDITING TESTS | |
810 ;; | |
811 | |
812 (defun semantic-utest-last-invalid (name-contents names-removed killme insertme) | |
813 "Make the last fcn invalid." | |
814 (semantic-utest-kill-indicator killme insertme) | |
815 ; (semantic-utest-verify-names name-contents names-removed); verify its gone ;new validator doesnt handle skipnames yet | |
816 (semantic-utest-unkill-indicator);put back killed stuff | |
817 ) | |
818 | |
819 | |
820 | |
821 | |
822 ;"#<overlay from \\([0-9]+\\) to \\([0-9]+\\) in \\([^>]*\\)>" | |
823 ;#<overlay from \([0-9]+\) to \([0-9]+\) in \([^>]*\)> | |
824 ;(overlay \1 \2 "\3") | |
825 | |
826 | |
827 ;; JAVE | |
828 ;; these are some unit tests for cedet that I got from Eric and modified a bit for: | |
829 ;; python | |
830 ;; javascript | |
831 ;; java | |
832 ;; I tried to generalize the structure of the tests a bit to make it easier to add languages | |
833 | |
834 ;; Mail from Eric: | |
835 ;; Many items in the checklist look like: | |
836 | |
837 ;; M-x global-semantic-highlight-edits-mode RET | |
838 ;; - Edit a file. See the highlight of newly inserted text. | |
839 ;; - Customize `semantic-edits-verbose-flag' to be non-nil. | |
840 ;; - Wait for the idle scheduler, it should clean up the edits. | |
841 ;; - observe messages from incremental parser. Do they relate | |
842 ;; to the edits? | |
843 ;; - M-x bovinate RET - verify your changes are reflected. | |
844 | |
845 ;; It's all about watching the behavior. Timers go off, things get | |
846 ;; cleaned up, you type in new changes, etc. An example I tried to | |
847 ;; do is below, but covers only 1 language, and not very well at that. | |
848 ;; I seem to remember seeing a unit test framework going by one of the | |
849 ;; lists. I'm not sure if that would help. | |
850 | |
851 ;; Another that might be automatable: | |
852 | |
853 ;; M-x semantic-analyze-current-context RET | |
854 ;; - Do this in different contexts in your language | |
855 ;; files. Verify that reasonable results are returned | |
856 ;; such as identification of assignments, function arguments, etc. | |
857 | |
858 ;; Anyway, those are some ideas. Any effort you put it will be helpful! | |
859 | |
860 ;; Thanks | |
861 ;; Eric | |
862 | |
863 ;; ----------- | |
864 | |
865 | |
866 | |
867 ;;; semantic-utest.el ends here |