Skip to content

Commit

Permalink
gh-177 unit testing the new CEDET version
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew O. Smith committed Jun 28, 2015
1 parent c61f92b commit 736dcda
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 39 deletions.
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

### Makefile for malabar-mode
##
## Copyright (c) 2009, 2010 Espen Wiborg <[email protected]>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA.
##

EMACS=emacs

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

all: testr

testr:
# cd $(mkfile_dir) && $(EMACS) -Q --batch -l src/test/lisp/init.el -l src/test/lisp/all-tests.el
cd $(mkfile_dir) && $(EMACS) -Q --batch -f toggle-debug-on-error -l src/test/lisp/init.el -l src/test/lisp/init-malabar.el -l src/test/lisp/all-tests.el

2 changes: 1 addition & 1 deletion src/main/lisp/malabar-ede-gradle.el
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
(ede-project-autoload "malabar-gradle"
:name "MALABAR GRADLE"
:file 'ede/gradle
:proj-file "build.gradle"
:proj-file "build.gradle"
;:proj-root 'ede-maven2-project-root
:load-type 'malabar-gradle-load
:class-sym 'ede-malabar-gradle-project
Expand Down
2 changes: 1 addition & 1 deletion src/main/lisp/malabar-ede-maven.el
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
(ede-project-autoload "malabar-maven2"
:name "MALABAR MAVEN2"
:file 'ede/maven2
;:proj-file "pom.xml"
:proj-file "pom.xml"
;:proj-root 'ede-maven2-project-root
;:load-type 'malabar-maven2-load
;:class-sym 'ede-malabar-maven2-project
Expand Down
2 changes: 1 addition & 1 deletion src/main/lisp/malabar-import.el
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ in the list."
(let ((a-package (malabar-get-package-of class-a))
(b-package (malabar-get-package-of class-b)))
(let ((a-package-successors (member a-package malabar-import-precedence-order))
(b-package-successors (member b-package malabar-import-precedence-order)))
(b-package-successors (member b-package malabar-import-precedence-order)))
(or (member b-package a-package-successors)
(and a-package-successors
(null b-package-successors))))))
Expand Down
5 changes: 3 additions & 2 deletions src/main/lisp/malabar-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(eval-when-compile
(require 'cl))
(require 'gud)
(require 'dash)
(require 'inf-groovy)
;(require 'semantic/db-javap)
(require 'url-vars)
Expand All @@ -54,8 +55,8 @@
(require 'malabar-project)
(require 'malabar-reflection)
(require 'malabar-http)
(require 'malabar-ede-maven)
(require 'malabar-ede-gradle)
;(require 'malabar-ede-maven)
;(require 'malabar-ede-gradle)
(require 'malabar-mode-autoloads)


Expand Down
92 changes: 58 additions & 34 deletions src/test/lisp/elk-test.el
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
;;; elk-test.el --- Emacs Lisp testing framework
;;
;; Copyright (C) 2006,2008 Nikolaj Schumacher
;; Copyright (C) 2006-2009 Nikolaj Schumacher
;;
;; Author: Nikolaj Schumacher <bugs * nschum de>
;; Version: 0.3
;; Version: 0.3.2
;; Keywords: lisp
;; URL: http://nschum.de/src/emacs/guess-style/
;; Compatibility: GNU Emacs 22.x
;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
;; Package-Requires: ((fringe-helper "0.1.1"))
;;
;; This file is NOT part of GNU Emacs.
;;
Expand All @@ -25,7 +26,7 @@
;;
;;; Commentary:
;;
;; elk-test requires fringe-helper.el, which is available at:
;; For best visualization, install fringe-helper, which is available at:
;; http://nschum.de/src/emacs/fringe-helper/
;;
;; Use `deftest' to define a test and `elk-test-group' to define test groups.
Expand Down Expand Up @@ -83,6 +84,12 @@
;;
;;; Change Log:
;;
;; 2009-03-21 (0.3.2)
;; Made fringe-helper dependency optional.
;; Removed dependency on CL functions.
;; Fixed deftest highlighting.
;; Added `elk-test-result-context-lines'.
;;
;; 2008-06-15 (0.3)
;; Added `elk-test-result-follow-mode'.
;; Switched to using button package for links.
Expand Down Expand Up @@ -110,7 +117,7 @@
;;; Code:

(eval-when-compile (require 'cl))
(require 'fringe-helper)
(require 'fringe-helper nil t)
(require 'newcomment)
(require 'eldoc)
(require 'compile)
Expand Down Expand Up @@ -186,6 +193,12 @@
:type '(choice (const :tag "Off" nil)
(const :tag "On" t)))

(defcustom elk-test-result-context-lines compilation-context-lines
"Display this many lines of leading context before the current message.
See `compilation-context-lines'."
:group 'test-case
:type '(choice integer (const :tag "No window scrolling" nil)))

(defvar elk-test-result-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap "q" 'bury-buffer)
Expand All @@ -199,6 +212,9 @@
"Remove all tests from memory."
(setq elk-test-alist nil))

(defsubst elk-test-mapcan (func sequence)
(apply 'nconc (mapcar func sequence)))

(defun elk-test-run (name &optional string-result)
"Run the test case defined as NAME.
The result is a list of errors strings, unless STRING-RESULT is set, in which
Expand All @@ -211,9 +227,9 @@ case a message describing the errors or success is displayed and returned."
(error "Undefined test <%s>" name)
(setq error-list (if (equal (car test-or-group) 'group)
;; is test group
(mapcar 'elk-test-run (cdr test-or-group))
(elk-test-mapcan 'elk-test-run (cdr test-or-group))
;; is simple test
(cons name (elk-test-run-internal test-or-group))))
(elk-test-run-internal test-or-group)))
(if (or string-result (interactive-p))
(message (if error-list
(mapconcat 'identity error-list "\n")
Expand Down Expand Up @@ -422,7 +438,7 @@ The resulting group can be run by calling `elk-test-run' with parameter NAME."
name))

(defconst elk-test-font-lock-keywords
`(("(\\_<\\(deftest\\)\\_>" 1 'font-lock-deftest)
`(("(\\_<\\(deftest\\)\\_>" 1 'elk-test-deftest)
(,(concat "(\\_<" (regexp-opt '("assert-equal" "assert-eq" "assert-eql"
"assert-nonnil" "assert-t" "assert-nil"
"assert-error" "assert-that") t)
Expand Down Expand Up @@ -493,25 +509,26 @@ If the state is set to 'success, a hook will be installed to switch to
:visible `(buffer-live-p ,buf)))
(elk-test-buffer-list))
"-" .
,(mapcan (lambda (buffer-errors)
(mapcar (lambda (err)
(vector
(concat (cadr err) " - "
(elk-test-shorten-string (cdar (cddr err))))
`(lambda ()
(interactive)
(push-mark)
(switch-to-buffer ,(car buffer-errors))
(goto-char ,(caar (cddr err))))))
(cdr buffer-errors)))
errors)))
,(elk-test-mapcan
(lambda (buffer-errors)
(mapcar (lambda (err)
(vector
(concat (cadr err) " - "
(elk-test-shorten-string (cdar (cddr err))))
`(lambda ()
(interactive)
(push-mark)
(switch-to-buffer ,(car buffer-errors))
(goto-char ,(caar (cddr err))))))
(cdr buffer-errors)))
errors)))
(easy-menu-add elk-test-menu))

(defun elk-test-buffer-list ()
"List all buffers in `elk-test-mode'."
(mapcan (lambda (b) (when (with-current-buffer b
(eq major-mode 'elk-test-mode))
(cons b nil)))
(elk-test-mapcan (lambda (b) (when (with-current-buffer b
(eq major-mode 'elk-test-mode))
(cons b nil)))
(buffer-list)))

(defun elk-test-run-all-buffers (&optional show-results)
Expand Down Expand Up @@ -539,28 +556,34 @@ If the state is set to 'success, a hook will be installed to switch to
(defvar elk-test-fringe-regions nil)
(make-variable-buffer-local 'elk-test-fringe-regions)

(defvar elk-test-regions nil)
(make-variable-buffer-local 'elk-test-regions)

(defun elk-test-unmark-failures ()
"Remove all highlighting from buffer."
(interactive)
(while elk-test-fringe-regions
(fringe-helper-remove (pop elk-test-fringe-regions))))
(when (fboundp 'fringe-helper-remove)
(mapc 'fringe-helper-remove elk-test-fringe-regions))
(mapc 'delete-overlay elk-test-regions)
(setq elk-test-fringe-regions nil
elk-test-regions nil))

(defun elk-test-mark-failures (failures which-side)
"Highlight failed tests."
(elk-test-unmark-failures)
(save-excursion
(dolist (failure failures)
(dolist (form (cddr failure))
(when (and which-side window-system)
(push (fringe-helper-insert-region (caar form) (cdar form)
'filled-square which-side
'elk-test-fringe)
elk-test-fringe-regions))
(and which-side window-system (fboundp 'fringe-helper-insert-region)
(push (fringe-helper-insert-region (caar form) (cdar form)
'filled-square which-side
'elk-test-fringe)
elk-test-fringe-regions))
(push (make-overlay (caar form) (cdar form))
elk-test-fringe-regions)
(overlay-put (car elk-test-fringe-regions)
elk-test-regions)
(overlay-put (car elk-test-regions)
'elk-test-error (cdr form))
(overlay-put (car elk-test-fringe-regions)
(overlay-put (car elk-test-regions)
'face 'elk-test-failed-region)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -644,7 +667,8 @@ This function is suitable for use as `eldoc-documentation-function'."
(defun elk-test-jump (buffer region from)
(let ((msg (copy-marker from))
(mk (make-marker))
(end-mk (make-marker)))
(end-mk (make-marker))
(compilation-context-lines elk-test-result-context-lines))
(set-marker mk (car region) buffer)
(set-marker end-mk (cdr region) buffer)
(compilation-goto-locus msg mk end-mk)
Expand Down
5 changes: 5 additions & 0 deletions src/test/lisp/init-malabar.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(load-file "src/main/lisp/malabar-mode.el")
(activate-malabar-mode)
(malabar-run-groovy)

(find-file "src/test/project/basic/src/main/java/com/software_ninja/App.java")
68 changes: 68 additions & 0 deletions src/test/lisp/malabar-mode.elk
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
;;; -*- emacs-lisp -*-
;; Copyright (c) 2009 Espen Wiborg <[email protected]>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301 USA.
;;

;; Stub
(provide 'semantic)

(deftest "buffer name"
(with-current-buffer (get-buffer "App.java")
(assert-equal "App.java" (buffer-name))))

(deftest "malabar-project variable malabar-mode-project-name"
(with-current-buffer (get-buffer "App.java")
(assert-equal "basic" malabar-mode-project-name)))

(deftest "malabar-project variable malabar-mode-project-manager"
(with-current-buffer (get-buffer "App.java")
(assert-equal "maven" malabar-mode-project-manager)))

(deftest "malabar-project variable malabar-mode-project-dir"
(with-current-buffer (get-buffer "App.java")
(assert-equal (expand-file-name "src/test/project/basic/" (getenv "PWD"))
(expand-file-name malabar-mode-project-dir))))

(deftest "malabar-project variable malabar-mode-project-parser"
(with-current-buffer (get-buffer "App.java")
(assert-equal "java" malabar-mode-project-parser)))




(deftest "malabar-fully-qualified-class-name-kill-ring-save"
(with-current-buffer (get-buffer "App.java")
(assert-equal "Copied com.software_ninja.App" (malabar-fully-qualified-class-name-kill-ring-save))))


;;;
;;; HTTP Stuff
;;;

(deftest "malabar-http-compile-file App.java"
(with-current-buffer (get-buffer "App.java")
(let ((result-buffer (malabar-http-compile-file)))
(with-current-buffer result-buffer
(assert-equal "" (buffer-string))))))


(deftest "malabar-http-compile-file App.java fail"
(with-current-buffer (get-buffer "App.java")

(let ((result-buffer (malabar-http-compile-file)))
(with-current-buffer result-buffer
(assert-equal "" (buffer-string))))))

0 comments on commit 736dcda

Please sign in to comment.