branch: elpa/logview commit 15507f7ee2b79246a1a3097268c67ef3756d5abf Author: Paul Pogonyshev <pogonys...@gmail.com> Commit: Paul Pogonyshev <pogonys...@gmail.com>
Add a couple of simple regression tests, including one for issue #2. --- .gitignore | 1 + .travis.yml | 18 +++++++++++ run-tests.sh | 44 ++++++++++++++++++++++++++ test/log4j/en-1.log | 1 + test/log4j/it-1.log | 1 + test/log4j/parens-in-thread-name.log | 2 ++ test/logview.el | 60 ++++++++++++++++++++++++++++++++++++ 7 files changed, 127 insertions(+) diff --git a/.gitignore b/.gitignore index c531d9867f..e5c14b91f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.elc +local-environment.el diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..f67ebd734f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: emacs-lisp + +before_install: + # For Emacs 25. + - sudo add-apt-repository ppa:kelleyk/emacs -y + # For snapshot builds. + - sudo add-apt-repository ppa:ubuntu-elisp/ppa -y + - sudo apt-get update -q + - sudo apt-get install -q -y ${EMACS} + +env: + - EMACS=emacs25 + - EMACS=emacs-snapshot + +script: + - echo "(add-to-list 'package-archives '(\"melpa\" . \"http://stable.melpa.org/packages/\") t)" >> ./local-environment.el + - echo "(unless (require 'datetime nil t) (package-install 'datetime))" >> ./local-environment.el + - ./run-tests.sh diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000000..0a7ecd83e8 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,44 @@ +#! /bin/sh + +# Usage: ./run-tests.sh [ERT-SELECTOR] +# +# You can also set EMACS and ERT_SELECTOR variables in the +# environment. If ERT_SELECTOR is empty (both on command line and in +# environment), it defaults to t (i.e., everything). + +# If `local-environment.el' exists, it is loaded before `logview.el'. +# Can be used e.g. to make package dependencies loadable. By the time +# `local-environment.el' is loaded, Emacs packaging system is already +# initialized. + +set -e + +OWN_DIRECTORY=$(dirname $0) + +if [ -z "$EMACS" ]; then + EMACS=emacs +fi + +if [ -n "$1" ]; then + ERT_SELECTOR=$1 +fi + +if [ -z "$ERT_SELECTOR" ]; then + ERT_SELECTOR=t +fi + +$EMACS --batch \ + --eval "(message \"Using Emacs %s\" (emacs-version))" \ + --eval "(progn (require 'package) (package-initialize))" \ + --directory "$OWN_DIRECTORY" \ + --eval "(when (locate-file \"local-environment.el\" (list (car load-path))) (load \"local-environment.el\" nil t t))" \ + --load logview.el \ + --load test/logview.el \ + --eval "(ert-run-tests-batch-and-exit (quote ${ERT_SELECTOR}))" + +$EMACS --batch \ + --eval "(progn (require 'package) (package-initialize))" \ + --directory "$OWN_DIRECTORY" \ + --eval "(when (locate-file \"local-environment.el\" (list (car load-path))) (load \"local-environment.el\" nil t t))" \ + --eval "(setq byte-compile-error-on-warn t)" \ + --eval "(batch-byte-compile)" logview.el diff --git a/test/log4j/en-1.log b/test/log4j/en-1.log new file mode 100644 index 0000000000..8c15b2d0d1 --- /dev/null +++ b/test/log4j/en-1.log @@ -0,0 +1 @@ +2010-03-10 20:03:44.332 [thread 1] INFO my.Class - a message diff --git a/test/log4j/it-1.log b/test/log4j/it-1.log new file mode 100644 index 0000000000..597ee2169c --- /dev/null +++ b/test/log4j/it-1.log @@ -0,0 +1 @@ +27-set-2011 4.58.59 [thread 1] INFO my.Class - a message diff --git a/test/log4j/parens-in-thread-name.log b/test/log4j/parens-in-thread-name.log new file mode 100644 index 0000000000..31b2a0509f --- /dev/null +++ b/test/log4j/parens-in-thread-name.log @@ -0,0 +1,2 @@ +2010-03-10 20:03:44.332 [thread[1]] INFO my.Class - message 1 +2010-03-10 20:03:44.336 [thread(1)] INFO my.Class - message 2 diff --git a/test/logview.el b/test/logview.el new file mode 100644 index 0000000000..9555193234 --- /dev/null +++ b/test/logview.el @@ -0,0 +1,60 @@ +;;; -*- lexical-binding: t -*- + +;; Copyright (C) 2018 Paul Pogonyshev + +;; 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 3 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, see http://www.gnu.org/licenses. + + +(require 'logview) +(require 'ert) +(require 'cus-edit) + + +(defvar logview--test-directory (file-name-directory (or load-file-name (buffer-file-name)))) + + +(defmacro logview--test-with-file (filename &rest body) + (declare (debug (form body)) + (indent 1)) + ;; We do the following to avoid customizations influence testing + ;; results. Of course, this has no visible effect when running + ;; tests from command line, as customization never takes place in + ;; this case to begin with. + (let (erase-customizations) + (dolist (customizable (custom-group-members 'logview nil)) + (when (eq (cadr customizable) 'custom-variable) + (push (list (car customizable) (macroexp-quote (eval (car (get (car customizable) 'standard-value)) t))) erase-customizations))) + `(let (,@erase-customizations + (inhibit-message t)) + (with-temp-buffer + (insert-file (expand-file-name ,filename logview--test-directory)) + (logview-mode) + ,@body)))) + + +(ert-deftest logview-test-log4j-standard-1 () + (logview--test-with-file "log4j/en-1.log" + (should (equal logview--submode-name "SLF4J")))) + +(ert-deftest logview-test-log4j-national-timestamp-1 () + (logview--test-with-file "log4j/it-1.log" + (should (equal logview--submode-name "SLF4J")))) + +;; Issue #2. +(ert-deftest logview-test-log4j-parens-in-thread-name () + (logview--test-with-file "log4j/parens-in-thread-name.log" + (should (equal logview--submode-name "SLF4J")) + ;; Make sure that the second line is also recognized as an entry. + ;; If it isn't, this will signal an error. + (logview-next-entry)))