* lisp/play/5x5.el (5x5-new-game, 5x5-randomize):
[emacs.git] / test / cedet / semantic-utest.el
bloba9a7c765f2b78a97ce0ddf035d1c353618feb939
1 ;;; semantic-utest.el --- Tests for semantic's parsing system.
3 ;;; Copyright (C) 2003-2004, 2007-2011 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
22 ;;; Commentary:
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.
29 (require 'semantic)
31 (load-file "cedet-utests.el")
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.")
38 (defun semantic-utest-fname (name)
39 "Create a filename for NAME in /tmp."
40 (expand-file-name name semantic-utest-temp-directory))
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;; Data for C tests
45 (defvar semantic-utest-C-buffer-contents
46 "/* Test file for C language for Unit Tests */
48 #include <stdio.h>
49 #include \"sutest.h\"
51 struct mystruct1 {
52 int slot11;
53 char slot12;
54 float slot13;
57 int var1;
59 float funp1(char arg11, char arg12);
61 char fun2(int arg_21, int arg_22) /*1*/
63 struct mystruct1 *ms1 = malloc(sizeof(struct mystruct1));
65 char sv = calc_sv(var1);
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;
77 printf(\"SV = %d\\n\", sv);
79 /* Memory Leak */
80 ms1.slot1 = sv;
82 return 'A' + sv;
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.")
89 (defvar semantic-utest-C-h-buffer-contents
90 "/* Test file for C language header file for Unit Tests */
92 int calc_sv(int);
95 "Contents of a C header file buffer initialized by this unit test.")
97 (defvar semantic-utest-C-filename (semantic-utest-fname "sutest.c")
98 "File to open and erase during this test for C.")
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")
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.")
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 ;; Data for Python tests
161 (defvar semantic-utest-Python-buffer-contents
163 def fun1(a,b,c):
164 return a
166 def fun2(a,b,c): #1
167 return b
173 ; "pyhon test case. notice that python is indentation sensitive
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")))
202 "List of expected tag names for Python.")
206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208 ;; Data for Java tests
210 (defvar semantic-utest-Java-buffer-contents
212 class JavaTest{
213 void fun1(int a,int b){
214 return a;
217 void fun2(int a,int b){ //1
218 return b;
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."
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 ;; Data for Javascript tests
264 (defvar semantic-utest-Javascript-buffer-contents
266 function fun1(a, b){
267 return a;
270 function fun2(a,b){ //1
271 return b;
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")))
297 "List of expected tag names for Javascript.")
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
303 ;; Data for Makefile tests
305 (defvar semantic-utest-Makefile-buffer-contents
308 \techo t1
310 t2:t1 #1
311 \techo t2
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.")
327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ;; Data for Scheme tests
331 (defvar semantic-utest-Scheme-buffer-contents
333 (define fun1 2)
335 (define fun2 3 ;1
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")))
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350 ;; Data for Html tests
352 (defvar semantic-utest-Html-buffer-contents
354 <html>
355 <body>
356 <h1>hello</h1>
357 </body><!--1-->
358 </html>
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")))
370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
372 ;; Data for PHP tests
374 (defvar semantic-utest-PHP-buffer-contents
375 "<?php
377 function fun1(){
378 return \"fun1\";
381 function fun2($arg1){
382 $output = \"argument to fun2: \" . $arg1;
383 return $output;
386 class aClass {
387 public function fun1($a, $b){
388 return $a;
391 public function fun2($a, $b){
392 return $b;
395 ?> "
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"))))
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"))))
412 (overlay 153 204 "phptest.php"))
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"))
420 (overlay 209 260 "phptest.php"))) :type "class")
422 (overlay 135 262 "phptest.php"))
424 "Expected results from the PHP Unit test"
427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
429 ;; Data for Csharp C# tests
431 (defvar semantic-utest-Csharp-buffer-contents
433 class someClass {
434 int fun1(int a, int b) {
435 return a; }
436 int fun2(int a, int b) {
437 return b; }
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")))
475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
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))
503 (semantic-fetch-tags)
504 (set-buffer buff)
506 ;; Turn off a range of modes
507 (semantic-idle-scheduler-mode -1)
509 ;; Turn on some modes
510 (semantic-highlight-edits-mode 1)
512 ;; Update tags, and show it.
513 (semantic-fetch-tags)
515 (switch-to-buffer buff)
516 (sit-for 0)
518 ;; Run the tests.
519 ;;(message "First parsing test.")
520 (semantic-utest-verify-names semantic-utest-C-name-contents)
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)
526 (set-buffer-modified-p nil)
527 ;; Clean up
528 ;; (kill-buffer buff)
529 ;; (kill-buffer buff2)
531 (message "All C tests passed.")
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))
550 ;; Turn off a range of modes
551 (semantic-idle-scheduler-mode -1)
553 ;; Turn on some modes
554 (semantic-highlight-edits-mode 1)
556 ;; Update tags, and show it.
557 (semantic-fetch-tags)
558 (switch-to-buffer buff)
559 (sit-for 0)
561 ;; Run the tests.
562 ;;(message "First parsing test %s." testname)
563 (semantic-utest-verify-names name-contents)
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)
569 (set-buffer-modified-p nil)
570 ;; Clean up
571 ;; (kill-buffer buff)
573 (message "All %s tests passed." testname)
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."))
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."))
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")
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")
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")
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-->")
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."))
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."))
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
633 ;; stubs
635 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
636 ; stuff for Erlang
637 ;;-module(hello).
638 ;-export([hello_world/0]).
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")
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")
654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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)
680 (cedet-utest-log-shutdown "multi-lang parsing")
683 ;;; Buffer contents validation
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)
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)
700 (equal (car attr1) (car attr2)))))
702 (if (not res)
703 (error "TAG INTERNAL DIFF: %S %S"
704 (car attr1) (car attr2)))
706 (setq attr1 (cdr attr1)
707 attr2 (cdr attr2)))
708 res))
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)
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)
739 (when table (error "Items extra: %S"
740 (mapcar 'semantic-tag-name table)))
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.
748 JAVE this thing would need to be recursive to handle java and csharp"
749 (let ((names name-contents)
750 (table (semantic-fetch-tags))
752 (semantic-utest-taglists-equivalent-p table names skipnames)
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")
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"))))
779 ;;; Kill indicator line
781 (defvar semantic-utest-last-kill-text nil
782 "The text from the last kill.")
784 (defvar semantic-utest-last-kill-pos nil
785 "The position of the last kill.")
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)
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)
809 ;;; EDITING TESTS
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
822 ;"#<overlay from \\([0-9]+\\) to \\([0-9]+\\) in \\([^>]*\\)>"
823 ;#<overlay from \([0-9]+\) to \([0-9]+\) in \([^>]*\)>
824 ;(overlay \1 \2 "\3")
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
834 ;; Mail from Eric:
835 ;; Many items in the checklist look like:
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.
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.
851 ;; Another that might be automatable:
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.
858 ;; Anyway, those are some ideas. Any effort you put it will be helpful!
860 ;; Thanks
861 ;; Eric
863 ;; -----------
867 ;;; semantic-utest.el ends here