(scheme-in-list): Add a fallback to create an error tag.
[cedet.git] / tests / cit-globalref.el
blob7a74607304de6caa944fc7453cc04611f8a8ad6f
1 ;;; cit-globalref.el --- Test GNU Global being used for finding references
2 ;;
3 ;; Copyright (C) 2013, 2014 Eric M. Ludlam
4 ;;
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
6 ;;
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see http://www.gnu.org/licenses/.
20 ;;; Commentary:
22 ;; Using srcs by Barry OReilly, test out GNU Global running against
23 ;; the src, then use the symref tool to find a deep tag (A::B::MyFcn)
24 ;; where the namespaces appear all over. Can we find the right symbol
25 ;; without loading all the crazy code?
27 ;;; Code:
29 (defvar cit-integ-target-globalref
30 (expand-file-name "edeproj_ede_globalref" cedet-integ-base)
31 "Root of the EDE project integration tests for the ede/java-root project.")
33 (defvar cit-integ-globalref-subdir "integ_src/globalref/"
34 "Directory of files to copy into the tmp project dir.")
36 (defvar cit-integ-globalref-srcdir
37 (expand-file-name
38 cit-integ-globalref-subdir
39 (file-name-directory (locate-library "cit-globalref")))
40 "The source directory for the JAVA root sources.")
44 (defun cit-globalref-test ()
45 "Test the use of GNU Global and minimal file loading."
46 ;; Make sure we can use GNU Global.
47 (if (not (cedet-gnu-global-version-check t))
48 (error "WARNING: Failed cedet-gnu-global-version-check "))
50 ;; Create directory for the project
51 (message "Globalref test in: %S" cit-integ-target-globalref)
52 (cit-make-dir cit-integ-target-globalref)
54 ;; Copy source files into the globalref directory
55 (condition-case nil
56 ;; Emacs 24.2
57 (copy-directory (file-name-as-directory cit-integ-globalref-srcdir) cit-integ-target-globalref t t t)
59 ;; Emacs 23
60 (error
61 (copy-directory (file-name-as-directory cit-integ-globalref-srcdir) cit-integ-target-globalref t t)))
63 ;; Create the ede-java-root-project class directly.
64 (ede-cpp-root-project
65 "TESTGLOBALREF"
66 :file (expand-file-name "README" cit-integ-target-globalref)
67 :include-path '( "/inc" )
70 ;; Bootstrap GNU Global in the test directory
71 (cedet-gnu-global-create/update-database
72 (file-name-as-directory cit-integ-target-globalref))
74 ;; Enable GNU Global Database
75 (semanticdb-enable-gnu-global-databases 'c-mode)
76 (semanticdb-enable-gnu-global-databases 'c++-mode)
78 ;; Setup file loading/logging in C files.
79 (add-hook 'c-mode-common-hook 'cit-globalref-cmode-hook)
81 ;; Hook into the system.
82 (find-file (cit-file-globalref "inc/Util.hh"))
84 ;; Quick check - basics working???
85 (when (not (member "inc/Util.hh" cit-globalref-file-log))
86 (error "Basic logging failed. Skipping globalref test."))
88 (setq cit-globalref-file-log nil) ;; Reset
90 ;; Do a generic semanticdb search for the symbol w/out prototypes.
91 (let ((ans (semanticdb-find-tags-by-name "myUtilFunc"))
93 (when (not (= (semanticdb-find-result-length ans) 1))
94 (error "Global should have returned only 1 tag for myUtilFunc"))
95 ;;(message "Answer: %S" (semanticdb-fast-strip-find-results ans))
97 (when (not (= (length cit-globalref-file-log) 1))
98 (error "Global should have only loaded 1 file for myUtilFunc"))
100 (setq cit-globalref-file-log nil) ;; Reset
101 (semantic-symref-cleanup-recent-buffers-fcn) ;; Simulate end of command
104 ;; Now do a full search for the impl with proto-impl toggle.
105 (goto-char (point-min))
106 (re-search-forward "myUtilFun")
107 (semantic-analyze-proto-impl-toggle)
109 (when (not (string= (buffer-name) "Util.cc"))
110 (message "Jumped to: [%S]" (buffer-name))
111 (error "proto-impl-toggle failed to find Util.cc"))
113 (message "Jump to myUtilFun success.")
115 ;; The only file it needed to find
116 (when (not (equal cit-globalref-file-log '("test/ManagerTest.cc" "src/Manager.cc" "src/Util.cc")))
117 (message "Too many/wrong files searched, should have only found src/Util.cc, test/ManagerTest.cc, and src/Manager.cc")
118 (error "Found %S" cit-globalref-file-log))
120 ;; Debug reporting.
121 (message "Files loaded in globalref test: %S"
122 cit-globalref-file-log)
124 (setq cit-globalref-file-log nil) ;; Reset
125 (semantic-symref-cleanup-recent-buffers-fcn) ;; Simulate end of command
127 ;; Now make sure some of the buffers weren't left hanging around.
128 (when (get-file-buffer "test/ManagerTest.cc")
129 (error "Buffer left open for test/ManagerTest.cc"))
131 ;;; Now Check for the impl for a symbol not in a namespace.
132 ;; Now do a full search for the impl with proto-impl toggle.
133 (find-file (cit-file-globalref "inc/Util.hh"))
134 (goto-char (point-min))
135 (re-search-forward "myUtilFuncNoNS")
136 (semantic-analyze-proto-impl-toggle)
138 (when (not (string= (buffer-name) "Util.cc"))
139 (message "Jumped to: [%S]" (buffer-name))
140 (error "proto-impl-toggle failed to find Util.cc"))
142 (message "Jump to myUtilFunNoNS success.")
144 ;; The only file it needed to find
145 (when (not (equal cit-globalref-file-log nil)) ;; '("src/Util.cc")))
146 (message "Too many files searched, should have found files in buffers.")
147 (error "Found %S" cit-globalref-file-log))
149 ;; Debug reporting.
150 (message "Files loaded in globalref no NS test: %S"
151 cit-globalref-file-log)
153 (setq cit-globalref-file-log nil) ;; Reset
154 (semantic-symref-cleanup-recent-buffers-fcn) ;; Simulate end of command
156 ;; Now make sure some of the buffers weren't left hanging around.
157 (when (get-file-buffer "test/Util.cc")
158 (error "Buffer left open for test/Util.cc"))
162 (defvar cit-globalref-file-log nil
163 "Log of all the C files pulled into Emacs.")
165 (defun cit-globalref-cmode-hook ()
166 "Hook to run in C mode.
167 Logs all the C files initailized in Emacs."
168 (let ((fname
169 (condition-case nil
170 (if (string-match cit-integ-target-globalref (buffer-file-name))
171 (file-relative-name (buffer-file-name)
172 (file-name-as-directory
173 cit-integ-target-globalref))
174 (buffer-file-name))
175 ;; Use condition case so I can debug from here.
176 (error (buffer-file-name)))))
177 (push fname cit-globalref-file-log)))
179 (defun cit-file-globalref (filename)
180 "Return a testing filename.
181 Append FILENAME to the target directory."
182 (expand-file-name filename cit-integ-target-globalref))
184 (provide 'cit-globalref)
186 ;;; cit-globalref.el ends here