diff options
| author | Eric Ludlam | 2019-10-14 20:48:16 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-10-15 11:08:18 -0400 |
| commit | 3f8915a0192fe629dc985909c4acd5f80aa78b60 (patch) | |
| tree | 3cfbd7c21c15209cbadcff3c81ec572236a20a7f | |
| parent | 128f803197c319807de838550270725ecdedbc7c (diff) | |
| download | emacs-3f8915a0192fe629dc985909c4acd5f80aa78b60.tar.gz emacs-3f8915a0192fe629dc985909c4acd5f80aa78b60.zip | |
Copy CEDET/Semantic's tag formatter test suite to be an
automated test.
These tests were copied from CEDET on Sourceforge and adapted to use ERT.
Author: Eric Ludlam <zappo@gnu.org>
| -rw-r--r-- | test/lisp/cedet/semantic-utest-fmt.el | 129 | ||||
| -rw-r--r-- | test/manual/cedet/tests/test-fmt.cpp | 108 | ||||
| -rw-r--r-- | test/manual/cedet/tests/test-fmt.el | 65 |
3 files changed, 302 insertions, 0 deletions
diff --git a/test/lisp/cedet/semantic-utest-fmt.el b/test/lisp/cedet/semantic-utest-fmt.el new file mode 100644 index 00000000000..88d574e105b --- /dev/null +++ b/test/lisp/cedet/semantic-utest-fmt.el | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | ;;; cedet/semantic-utest-fmt.el --- Parsing / Formatting tests | ||
| 2 | |||
| 3 | ;;; Copyright (C) 2003-2004, 2007-2019 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 <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | ;; | ||
| 24 | ;; Unit tests for the formatting feature. | ||
| 25 | ;; | ||
| 26 | ;; Using test code from the tests source directory, parse the source | ||
| 27 | ;; file. After parsing, read the comments for each signature, and | ||
| 28 | ;; make sure that the semantic-tag-format-* functions in question | ||
| 29 | ;; created the desired output. | ||
| 30 | |||
| 31 | (require 'semantic) | ||
| 32 | (require 'semantic/format) | ||
| 33 | |||
| 34 | ;;; Code: | ||
| 35 | |||
| 36 | (defvar cedet-utest-directory | ||
| 37 | (let* ((C (file-name-directory (locate-library "cedet"))) | ||
| 38 | (D (expand-file-name "../../test/manual/cedet/" C))) | ||
| 39 | D) | ||
| 40 | "Location of test files for this test suite.") | ||
| 41 | |||
| 42 | (defvar semantic-fmt-utest-file-list | ||
| 43 | '("tests/test-fmt.cpp" | ||
| 44 | ;; "tests/test-fmt.el" - add this when elisp is support by dflt in Emacs | ||
| 45 | ) | ||
| 46 | "List of files to run unit tests in.") | ||
| 47 | |||
| 48 | (defvar semantic-fmt-utest-error-log-list nil | ||
| 49 | "Log errors during testing in this variable.") | ||
| 50 | |||
| 51 | (ert-deftest semantic-fmt-utest () | ||
| 52 | "Visit all file entries, and run formatting test. | ||
| 53 | Files to visit are in `semantic-fmt-utest-file-list'." | ||
| 54 | (save-current-buffer | ||
| 55 | (semantic-mode 1) | ||
| 56 | (let ((fl semantic-fmt-utest-file-list) | ||
| 57 | (fname nil) | ||
| 58 | ) | ||
| 59 | |||
| 60 | (dolist (FILE fl) | ||
| 61 | |||
| 62 | (save-current-buffer | ||
| 63 | (setq fname (expand-file-name FILE cedet-utest-directory)) | ||
| 64 | |||
| 65 | ;; Make sure we have the files we think we have. | ||
| 66 | (should (file-exists-p fname)) | ||
| 67 | ;; (error "Cannot find unit test file: %s" fname)) | ||
| 68 | |||
| 69 | ;; Run the tests. | ||
| 70 | (let ((fb (find-buffer-visiting fname)) | ||
| 71 | (b (semantic-find-file-noselect fname)) | ||
| 72 | (num 0) | ||
| 73 | (tags nil)) | ||
| 74 | |||
| 75 | (save-current-buffer | ||
| 76 | (set-buffer b) | ||
| 77 | (should (semantic-active-p)) | ||
| 78 | ;;(error "Cannot open %s for format tests" fname)) | ||
| 79 | |||
| 80 | ;; This will force a reparse, removing any chance of semanticdb cache | ||
| 81 | ;; using stale data. | ||
| 82 | (semantic-clear-toplevel-cache) | ||
| 83 | ;; Force the reparse | ||
| 84 | (setq tags (semantic-fetch-tags)) | ||
| 85 | (setq num (length tags)) | ||
| 86 | |||
| 87 | (save-excursion | ||
| 88 | (while tags | ||
| 89 | (let* ((T (car tags)) | ||
| 90 | (start (semantic-tag-end T)) | ||
| 91 | (end (if (cdr tags) | ||
| 92 | (semantic-tag-start (car (cdr tags))) | ||
| 93 | (point-max))) | ||
| 94 | (TESTS nil) | ||
| 95 | ) | ||
| 96 | (goto-char start) | ||
| 97 | ;; Scan the space between tags for all test condition matches. | ||
| 98 | (while (re-search-forward "## \\([a-z-]+\\) \"\\([^\n\"]+\\)\"$" end t) | ||
| 99 | (push (cons (match-string 1) (match-string 2)) TESTS)) | ||
| 100 | (setq TESTS (nreverse TESTS)) | ||
| 101 | |||
| 102 | (dolist (TST TESTS) | ||
| 103 | (let* ( ;; For each test, convert CAR into a semantic-format-tag* fcn | ||
| 104 | (sym (intern (concat "semantic-format-tag-" (car TST)))) | ||
| 105 | ;; Convert the desired result from a string syntax to a string. | ||
| 106 | (desired (cdr TST)) | ||
| 107 | ;; What does the fmt function do? | ||
| 108 | (actual (funcall sym T)) | ||
| 109 | ) | ||
| 110 | (when (not (string= desired actual)) | ||
| 111 | (should-not (list "Desired" desired | ||
| 112 | "Actual" actual | ||
| 113 | "Formatter" (car TST)))) | ||
| 114 | ))) | ||
| 115 | (setq tags (cdr tags))) | ||
| 116 | |||
| 117 | )) | ||
| 118 | |||
| 119 | ;; If it wasn't already in memory, whack it. | ||
| 120 | (when (and b (not fb)) | ||
| 121 | (kill-buffer b))) | ||
| 122 | )) | ||
| 123 | |||
| 124 | ))) | ||
| 125 | |||
| 126 | |||
| 127 | (provide 'cedet/semantic/fmt-utest) | ||
| 128 | |||
| 129 | ;;; semantic-fmt-utest.el ends here | ||
diff --git a/test/manual/cedet/tests/test-fmt.cpp b/test/manual/cedet/tests/test-fmt.cpp new file mode 100644 index 00000000000..c94bcfafbca --- /dev/null +++ b/test/manual/cedet/tests/test-fmt.cpp | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | /** test-fmt.cpp --- Signatures, and format answers for testing | ||
| 2 | * | ||
| 3 | * Copyright (C) 2012, 2016, 2019 Free Software Foundation | ||
| 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 <https://www.gnu.org/licenses/>. | ||
| 21 | */ | ||
| 22 | |||
| 23 | /* | ||
| 24 | * About semantic-fmt-utest : | ||
| 25 | * | ||
| 26 | * These tests validate two features: | ||
| 27 | * 1) The C++ parser can parse the different signatures | ||
| 28 | * 2) The semantic-tag-format-* functions can recreate them. | ||
| 29 | * | ||
| 30 | */ | ||
| 31 | |||
| 32 | void basic_fcn() { } | ||
| 33 | /* | ||
| 34 | * ## name "basic_fcn" | ||
| 35 | * ## abbreviate "basic_fcn()" | ||
| 36 | * ## prototype "void basic_fcn ()" | ||
| 37 | * ## uml-prototype "basic_fcn () : void" | ||
| 38 | */ | ||
| 39 | |||
| 40 | int twoargs_fcn(int a, char b) { } | ||
| 41 | /* | ||
| 42 | * ## name "twoargs_fcn" | ||
| 43 | * ## abbreviate "twoargs_fcn()" | ||
| 44 | * ## prototype "int twoargs_fcn (int a,char b)" | ||
| 45 | * ## uml-prototype "twoargs_fcn (a : int,b : char) : int" | ||
| 46 | */ | ||
| 47 | |||
| 48 | struct moose { | ||
| 49 | int field1; | ||
| 50 | char field2; | ||
| 51 | }; | ||
| 52 | /* | ||
| 53 | * ## name "moose" | ||
| 54 | * ## abbreviate "moose{}" | ||
| 55 | * ## prototype "struct moose {}" | ||
| 56 | * ## uml-prototype "moose{} : struct" | ||
| 57 | */ | ||
| 58 | |||
| 59 | struct moose strct_fcn ( struct moose in, char *out); | ||
| 60 | /* | ||
| 61 | * ## name "strct_fcn" | ||
| 62 | * ## abbreviate "strct_fcn()" | ||
| 63 | * ## prototype "struct moose strct_fcn (struct moose in,char* out)" | ||
| 64 | * ## uml-prototype "strct_fcn (in : struct moose,out : char*) : struct moose" | ||
| 65 | */ | ||
| 66 | |||
| 67 | struct moose *var_one = NULL; | ||
| 68 | /* | ||
| 69 | * ## name "var_one" | ||
| 70 | * ## summarize "Variables: struct moose* var_one[=NULL]" | ||
| 71 | * ## prototype "struct moose* var_one[=NULL]" | ||
| 72 | * ## uml-prototype "var_one : struct moose*" | ||
| 73 | */ | ||
| 74 | |||
| 75 | const int var_two = 1; | ||
| 76 | /* | ||
| 77 | * ## name "var_two" | ||
| 78 | * ## summarize "Variables: const int var_two[=1]" | ||
| 79 | * ## prototype "const int var_two[=1]" | ||
| 80 | * ## uml-prototype "var_two : int" | ||
| 81 | */ | ||
| 82 | |||
| 83 | namespace NS { | ||
| 84 | enum TestEnum {a,b}; | ||
| 85 | } | ||
| 86 | /* | ||
| 87 | * ## name "NS" | ||
| 88 | * ## summarize "Types: namespace NS {}" | ||
| 89 | * ## prototype "namespace NS {}" | ||
| 90 | * ## uml-prototype "NS{} : namespace" | ||
| 91 | */ | ||
| 92 | |||
| 93 | |||
| 94 | // void func_ns_arg(NS::TestEnum v = NS::a); <<--- TODO - bring FIX from CEDET on SF | ||
| 95 | /* | ||
| 96 | * # # name "func_ns_arg" | ||
| 97 | * # # summarize "Functions: void func_ns_arg (NS::TestEnum v[=NS::a])" | ||
| 98 | * # # prototype "void func_ns_arg (NS::TestEnum v[=NS::a])" | ||
| 99 | * # # uml-prototype "func_ns_arg (v : NS::TestEnum) : void" | ||
| 100 | */ | ||
| 101 | |||
| 102 | //int const var_three = 1; | ||
| 103 | /* | ||
| 104 | * # # name "var_three" | ||
| 105 | * # # summarize "Variables: int const var_three" <-- this fails | ||
| 106 | * # # prototype "int const var_three" <-- this fails | ||
| 107 | * # # uml-prototype "var_three : int" | ||
| 108 | */ | ||
diff --git a/test/manual/cedet/tests/test-fmt.el b/test/manual/cedet/tests/test-fmt.el new file mode 100644 index 00000000000..93c04f8e77c --- /dev/null +++ b/test/manual/cedet/tests/test-fmt.el | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | ;;; test-fmt.el --- test semantic tag formatting | ||
| 2 | |||
| 3 | ;;; Copyright (C) 2012, 2019 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 <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | ;; | ||
| 24 | ;; | ||
| 25 | |||
| 26 | ;;; Code: | ||
| 27 | (require 'semantic) | ||
| 28 | ;; | ||
| 29 | ;; ## name "semantic" | ||
| 30 | ;; ## abbreviate "semantic<>" | ||
| 31 | ;; ## summarize "Requires: semantic" | ||
| 32 | |||
| 33 | (defun test-fmt-1 (a) | ||
| 34 | "Function with 1 arg.") | ||
| 35 | ;; | ||
| 36 | ;; ## name "test-fmt-1" | ||
| 37 | ;; ## abbreviate "(test-fmt-1)" | ||
| 38 | ;; ## summarize "Defuns: (test-fmt-1 a)" | ||
| 39 | ;; ## short-doc "Function with 1 arg." | ||
| 40 | ;; ## uml-prototype "(test-fmt-1 a)" <-- That is probably wrong. | ||
| 41 | |||
| 42 | (defvar test-fmt-var nil | ||
| 43 | "Variable test.") | ||
| 44 | ;; | ||
| 45 | ;; ## name "test-fmt-var" | ||
| 46 | ;; ## abbreviate "test-fmt-var" | ||
| 47 | ;; ## summarize "Variables: test-fmt-var" | ||
| 48 | ;; ## short-doc "Variable test." | ||
| 49 | ;; ## uml-prototype "test-fmt-var" | ||
| 50 | |||
| 51 | (defclass test-fmt-class () | ||
| 52 | ((slot1 :initarg :slot1)) | ||
| 53 | "Class for testing.") | ||
| 54 | ;; | ||
| 55 | ;; ## name "test-fmt-class" | ||
| 56 | ;; ## abbreviate "test-fmt-class{}" | ||
| 57 | ;; ## summarize "Types: class test-fmt-class {}" | ||
| 58 | ;; ## short-doc "Class for testing." | ||
| 59 | ;; ## uml-prototype "class test-fmt-class {}" | ||
| 60 | |||
| 61 | |||
| 62 | |||
| 63 | (provide 'test-fmt) | ||
| 64 | |||
| 65 | ;;; test-fmt.el ends here | ||