From dc62ea38e36b5de47893a60a76d66b7a79bf6437 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sat, 10 Dec 2016 21:36:15 +0100 Subject: [PATCH 1/2] Clean up compile-tests.el Switch to lexical binding. Make checkdoc happy. * test/lisp/progmodes/compile-tests.el (compile--test-error-line) (compile-test-error-regexps): Instead of checking a single Boolean value, use `should' for each attribute of the message to be compared. (compile-tests--test-regexps-data): Document sixth list element TYPE. --- test/lisp/progmodes/compile-tests.el | 68 ++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/test/lisp/progmodes/compile-tests.el b/test/lisp/progmodes/compile-tests.el index 265baf2..631174f 100644 --- a/test/lisp/progmodes/compile-tests.el +++ b/test/lisp/progmodes/compile-tests.el @@ -1,4 +1,4 @@ -;;; compile-tests.el --- Test suite for compile.el. +;;; compile-tests.el --- Test suite for compile.el. -*- lexical-binding: t; -*- ;; Copyright (C) 2011-2016 Free Software Foundation, Inc. @@ -21,6 +21,10 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . +;;; Commentary: + +;; Unit tests for lisp/progmodes/compile.el. + ;;; Code: (require 'ert) @@ -323,15 +327,18 @@ compile-tests--test-regexps-data ("index.html (13:1) Unknown element " 1 1 13 "index.html")) "List of tests for `compilation-error-regexp-alist'. -Each element has the form (STR POS COLUMN LINE FILENAME), where -STR is an error string, POS is the position of the error in STR, -COLUMN and LINE are the reported column and line numbers (or nil) -for that error, and FILENAME is the reported filename. +Each element has the form (STR POS COLUMN LINE FILENAME [TYPE]), +where STR is an error string, POS is the position of the error in +STR, COLUMN and LINE are the reported column and line numbers (or +nil) for that error, FILENAME is the reported filename, and TYPE +is 0 for an information message, 1 for a warning, and 2 for an +error. LINE can also be of the form (LINE . END-LINE) meaning a range of lines. COLUMN can also be of the form (COLUMN . END-COLUMN) meaning a range of columns starting on LINE and ending on -END-LINE, if that matched.") +END-LINE, if that matched. TYPE can be left out, in which case +any message type is accepted.") (defun compile--test-error-line (test) (erase-buffer) @@ -339,35 +346,34 @@ compile--test-error-line (insert (car test)) (compilation-parse-errors (point-min) (point-max)) (let ((msg (get-text-property (nth 1 test) 'compilation-message))) - (when msg - (let ((loc (compilation--message->loc msg)) - (col (nth 2 test)) - (line (nth 3 test)) - (file (nth 4 test)) - (type (nth 5 test)) - end-col end-line) - (if (consp col) - (setq end-col (cdr col) col (car col))) - (if (consp line) - (setq end-line (cdr line) line (car line))) - (and (equal (compilation--loc->col loc) col) - (equal (compilation--loc->line loc) line) - (or (not file) - (equal (caar (compilation--loc->file-struct loc)) file)) - (or (null end-col) - (equal (car (cadr (nth 2 (compilation--loc->file-struct loc)))) - end-col)) - (equal (car (nth 2 (compilation--loc->file-struct loc))) - (or end-line line)) - (or (null type) - (equal type (compilation--message->type msg)))))))) + (should msg) + (let ((loc (compilation--message->loc msg)) + (col (nth 2 test)) + (line (nth 3 test)) + (file (nth 4 test)) + (type (nth 5 test)) + end-col end-line) + (if (consp col) + (setq end-col (cdr col) col (car col))) + (if (consp line) + (setq end-line (cdr line) line (car line))) + (should (equal (compilation--loc->col loc) col)) + (should (equal (compilation--loc->line loc) line)) + (when file + (should (equal (caar (compilation--loc->file-struct loc)) file))) + (when end-col + (should (equal (car (cadr (nth 2 (compilation--loc->file-struct loc)))) + end-col))) + (should (equal (car (nth 2 (compilation--loc->file-struct loc))) + (or end-line line))) + (when type + (should (equal type (compilation--message->type msg))))))) (ert-deftest compile-test-error-regexps () "Test the `compilation-error-regexp-alist' regexps. The test data is in `compile-tests--test-regexps-data'." (with-temp-buffer (font-lock-mode -1) - (dolist (test compile-tests--test-regexps-data) - (should (compile--test-error-line test))))) + (mapc #'compile--test-error-line compile-tests--test-regexps-data))) -;;; compile-tests.el ends here. +;;; compile-tests.el ends here -- 2.8.0.rc3.226.g39d4020