From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lee B Newsgroups: gmane.emacs.bugs Subject: bug#23139: [PATCH] test/automated/abbrev-tests.el Date: Tue, 29 Mar 2016 13:04:40 +0900 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1459224323 22748 80.91.229.3 (29 Mar 2016 04:05:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Mar 2016 04:05:23 +0000 (UTC) To: 23139@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 29 06:05:13 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1akktz-0004lC-AX for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Mar 2016 06:05:11 +0200 Original-Received: from localhost ([::1]:44344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akkty-0002FE-Eq for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Mar 2016 00:05:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akktu-0002Cq-QN for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:05:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akktq-0000Z8-OJ for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:05:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akktq-0000Z2-Jt for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1akktq-0006YN-BK for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lee B Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Mar 2016 04:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23139 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.145922429925177 (code B ref -1); Tue, 29 Mar 2016 04:05:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Mar 2016 04:04:59 +0000 Original-Received: from localhost ([127.0.0.1]:42708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1akktm-0006Y1-Do for submit@debbugs.gnu.org; Tue, 29 Mar 2016 00:04:58 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:35819) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1akktk-0006Xl-6a for submit@debbugs.gnu.org; Tue, 29 Mar 2016 00:04:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akktd-0000TX-8b for submit@debbugs.gnu.org; Tue, 29 Mar 2016 00:04:51 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:34857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akktd-0000TT-4s for submit@debbugs.gnu.org; Tue, 29 Mar 2016 00:04:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akktb-0002B2-D8 for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:04:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akktX-0000SD-A7 for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:04:47 -0400 Original-Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:35152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akktW-0000R8-Vd for bug-gnu-emacs@gnu.org; Tue, 29 Mar 2016 00:04:43 -0400 Original-Received: by mail-pf0-x22c.google.com with SMTP id n5so4233406pfn.2 for ; Mon, 28 Mar 2016 21:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version; bh=uIqOoWEuhooViFDtY72K/UX0/OXvtQSkFhYhpRoRhWM=; b=sSLdYU9/EsW5jd5kcvkia2yrhPZpOZ9KP3086mrp63xvxiGdZbWER+yvHzx0beEUoO EGO6DrujvpRtjjA2qk0J29WNSHE818WASdJDC8rBMLYwQG7TZjuQAlu7wPlfXadbbEPQ FdX760070qcUpTACy+uXtaVRjF9cWqwYjFHLLVcWmQchCxx2aQJLVmP8Xi1us1DSuDQI EVJwE1qlA4BhOLYxA7l3VtwLa3HVmB/8s6z+qhxv79ePv1+7/YZeBoaSeB7h46q74pCv vkeHUomhbs6v6/5F7XlpER+TFc95fdFELxBNQvMUSQYIt9TZMC22P9Ci0k5+CLXsbqa6 ATRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=uIqOoWEuhooViFDtY72K/UX0/OXvtQSkFhYhpRoRhWM=; b=Wq2P5BaILEn4l4XHLlovCg9LMZilJkgm85PxNOznLaSSJ3oZ6R+aTwnP7lqEgzVG3L J4jyzlxSGH/gtpPn6lmmn0LlIRUW1WSPqjOoqXPAW6EWf8kDOhzy4lgnqivOeD2KqRLv w2N5Gf4xs6RPO6yi/4owtGWNBpCpnsah7anLBFDMKL3jXz/aADo+bF+BUHCsmU/Ny9a7 7rMuxyr/4VnmeN6uDJZDpBntuQLm/W95o4dKmXqs8s/akbXGwSyzM/W991d5RmqGZRbb 2dreK239IFjCnTrmRf9eZQL7Hcve/WwgndpkfZb6XM2Gkg08yVPrJpBLXAE8TkdCFz7j 8ltg== X-Gm-Message-State: AD7BkJKLGpOhZpFvdlRcB4rmizdF9XU57E/5i3BI5/xmjzBqSB0etJpPdWT1dil1176RDQ== X-Received: by 10.98.42.207 with SMTP id q198mr60474pfq.103.1459224281420; Mon, 28 Mar 2016 21:04:41 -0700 (PDT) Original-Received: from mbp.local (122x212x176x138.ap122.ftth.ucom.ne.jp. [122.212.176.138]) by smtp.gmail.com with ESMTPSA id r5sm39034801pap.7.2016.03.28.21.04.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Mar 2016 21:04:40 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:115681 Archived-At: --=-=-= Content-Type: text/plain Hello, Attached is a patch for the emacs-25 branch test/automated/abbrev-tests.el. It comprises a couple of tests copied from the master branch, minor modifications and a bunch of new tests. In the abbrev-table-p-test, I've commented out a check that works in master but not in emacs-25 (and vice-versa) - pointers on how to fix this would be greatly appreciated. Any other hints and advice also welcome :-) Thanks, Lee. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=0001-Copy-tests-from-master-modify-test-add-tests.patch Content-Description: abbrev-tests.el patch >From 1cab871c6bcc77906d76f93bd361a0f4fefa849e Mon Sep 17 00:00:00 2001 From: Lee Bochicchio Date: Sat, 26 Mar 2016 05:28:18 +0900 Subject: [PATCH] abbrev-tests copy tests from master, modify test, add tests * test/automated/abbrev-tests.el (abbrev-table-p-test) (abbrev-make-abbrev-table-test, abbrev-table-get-put-test) (abbrev-table-empty-p-test): Copy from master. (clear-abbrev-table-test): Use 'abbrev-expansion'. (list-abbrevs-test, prepare-abbrev-list-buffer-test, insert-abbrevs-test) (edit-abbrevs-test, define-abbrevs-test, read-write-abbrev-file-test) (abbrev-edit-save-to-file-test): New tests. --- test/automated/abbrev-tests.el | 184 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 172 insertions(+), 12 deletions(-) diff --git a/test/automated/abbrev-tests.el b/test/automated/abbrev-tests.el index 66413c5..dbd1804 100644 --- a/test/automated/abbrev-tests.el +++ b/test/automated/abbrev-tests.el @@ -1,6 +1,6 @@ -;;; abbrev-tests.el --- Test suite for abbrevs. +;;; abbrev-tests.el --- Test suite for abbrevs -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2016 Free Software Foundation, Inc. +;; Copyright (C) 2015 Free Software Foundation, Inc. ;; Author: Eli Zaretskii ;; Keywords: abbrevs @@ -29,6 +29,7 @@ (require 'ert) (require 'abbrev) +(require 'obarray) (require 'seq) ;; set up test abbrev table and abbrev entry @@ -38,6 +39,38 @@ setup-test-abbrev-table (abbrev-table-put ert-test-abbrevs :ert-test "ert-test-value") ert-test-abbrevs) +(ert-deftest abbrev-table-p-test () + (should-not (abbrev-table-p 42)) + (should-not (abbrev-table-p "aoeu")) + (should-not (abbrev-table-p '())) + ;; master + ;;(should-not (abbrev-table-p [])) + (should-error (abbrev-table-p [])) + ;; Missing :abbrev-table-modiff counter: + (should-not (abbrev-table-p (obarray-make))) + (let* ((table (obarray-make))) + (abbrev-table-put table :abbrev-table-modiff 42) + (should (abbrev-table-p table)))) + +(ert-deftest abbrev-make-abbrev-table-test () + ;; Table without properties: + (let ((table (make-abbrev-table))) + (should (abbrev-table-p table)) + (should (= (length table) obarray-default-size))) + ;; Table with one property 'foo with value 'bar: + (let ((table (make-abbrev-table '(foo bar)))) + (should (abbrev-table-p table)) + (should (= (length table) obarray-default-size)) + (should (eq (abbrev-table-get table 'foo) 'bar)))) + +(ert-deftest abbrev-table-get-put-test () + (let ((table (make-abbrev-table))) + (should-not (abbrev-table-get table 'foo)) + (should (= (abbrev-table-put table 'foo 42) 42)) + (should (= (abbrev-table-get table 'foo) 42)) + (should (eq (abbrev-table-put table 'foo 'bar) 'bar)) + (should (eq (abbrev-table-get table 'foo) 'bar)))) + (ert-deftest copy-abbrev-table-test () (defvar foo-abbrev-table nil) ; Avoid compiler warning (define-abbrev-table 'foo-abbrev-table @@ -51,6 +84,17 @@ setup-test-abbrev-table (should (abbrev-table-p new-foo-abbrev-table))) (should-not (string-equal (buffer-name) "*Backtrace*"))) +(ert-deftest abbrev-table-empty-p-test () + (should-error (abbrev-table-empty-p 42)) + (should-error (abbrev-table-empty-p "aoeu")) + (should-error (abbrev-table-empty-p '())) + (should-error (abbrev-table-empty-p [])) + ;; Missing :abbrev-table-modiff counter: + (should-error (abbrev-table-empty-p (obarray-make))) + (let* ((table (obarray-make))) + (abbrev-table-put table :abbrev-table-modiff 42) + (should (abbrev-table-empty-p table)))) + (ert-deftest kill-all-abbrevs-test () "Test undefining all defined abbrevs" (unless noninteractive @@ -80,19 +124,135 @@ setup-test-abbrev-table (ert-deftest clear-abbrev-table-test () "Test clearing single abbrev table" (let ((ert-test-abbrevs (setup-test-abbrev-table))) - (should (equal "a-e-t" (symbol-name - (abbrev-symbol "a-e-t" ert-test-abbrevs)))) - (should (equal "abbrev-ert-test" (symbol-value - (abbrev-symbol "a-e-t" ert-test-abbrevs)))) + (should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs))) + (clear-abbrev-table ert-test-abbrevs) + (should (equal nil (abbrev-expansion "a-e-t" ert-test-abbrevs))) + (should (equal t (abbrev-table-empty-p ert-test-abbrevs))))) + +(ert-deftest list-abbrevs-test () + "Test generation of abbrev list buffer" + ;; Somewhat redundant as prepare-abbrev-list-buffer is also tested. + ;; all abbrevs + (let ((abbrev-buffer (prepare-abbrev-list-buffer))) + (should (equal "*Abbrevs*" (buffer-name abbrev-buffer))) + (kill-buffer abbrev-buffer)) + ;; mode-specific abbrevs + (let ((abbrev-buffer (prepare-abbrev-list-buffer t))) + (should (equal "*Abbrevs*" (buffer-name abbrev-buffer))) + (kill-buffer abbrev-buffer))) + +(ert-deftest prepare-abbrev-list-buffer-test () + "Test generation of abbrev list buffer" + ;; all abbrevs + (let ((ert-test-abbrevs (setup-test-abbrev-table))) + (with-current-buffer (prepare-abbrev-list-buffer) + ;; Check for a couple of abbrev-table names in buffer. + (should (and (progn + (goto-char (point-min)) + (search-forward (symbol-name (abbrev-table-name ert-test-abbrevs)))) + (progn + (goto-char (point-min)) + (search-forward "global-abbrev-table")))) + (should (equal 'edit-abbrevs-mode major-mode)) + (kill-buffer "*Abbrevs*"))) + + ;; mode-specific abbrevs (temp buffer uses fundamental-mode) + (with-temp-buffer + (prepare-abbrev-list-buffer t) + (with-current-buffer "*Abbrevs*" + (should (progn + (goto-char (point-min)) + (search-forward "fundamental-mode-abbrev-table"))) + (should-error (progn + (goto-char (point-min)) + (search-forward "global-abbrev-table"))) + (should-not (equal 'edit-abbrevs-mode major-mode)) + (kill-buffer "*Abbrevs*")))) + +(ert-deftest insert-abbrevs-test () + "Test inserting abbrev definitions into buffer" + (with-temp-buffer + (insert-abbrevs) + (should (progn + (goto-char (point-min)) + (search-forward "global-abbrev-table"))))) + +(ert-deftest edit-abbrevs-test () + "Test editing abbrevs from buffer" + (defvar ert-edit-abbrevs-test-table nil) + (let ((ert-test-abbrevs (setup-test-abbrev-table))) + (with-temp-buffer + ;; insert test table and new abbrev, redefine, check definition + (goto-char (point-min)) + (insert "(ert-edit-abbrevs-test-table)\n") + (insert "\n" "\"e-a-t\"\t" "0\t" "\"edit-abbrevs-test\"\n") + ;; check test table before redefine + (should (equal "abbrev-ert-test" + (abbrev-expansion "a-e-t" ert-test-abbrevs))) + (edit-abbrevs-redefine) + (should-not (abbrev-expansion "a-e-t" ert-test-abbrevs)) + (should (equal "edit-abbrevs-test" + (abbrev-expansion "e-a-t" ert-edit-abbrevs-test-table)))))) + +(ert-deftest define-abbrevs-test () + "Test defining abbrevs from buffer" + (defvar ert-bad-abbrev-table nil) + (defvar ert-good-abbrev-table nil) + (defvar ert-redefine-abbrev-table nil) + (with-temp-buffer + ;; insert bad abbrev data and attempt define + (goto-char (point-min)) + (insert "ert-bad-abbrev-table\n") + (insert "\n" "\"b-a-t\"\t" "0\t" "\n") + (should-not (define-abbrevs)) + (should (equal nil (abbrev-expansion "b-a-t" ert-bad-abbrev-table))) + (delete-region (point-min) (point-max)) + ;; try with valid abbrev data + (goto-char (point-min)) + (insert "(ert-good-abbrev-table)\n") + (insert "\n" "\"g-a-t\"\t" "0\t" "\"good-abbrev-table\"\n") + (define-abbrevs) + (should (equal "good-abbrev-table" + (abbrev-expansion "g-a-t" ert-good-abbrev-table))) + ;; redefine from buffer + (delete-region (point-min) (point-max)) + (insert "(ert-redefine-abbrev-table)\n") + (insert "\n" "\"r-a-t\"\t" "0\t" "\"redefine-abbrev-table\"\n") + ;; arg = kill-all-abbrevs + (define-abbrevs t) + (should (equal "redefine-abbrev-table" + (abbrev-expansion "r-a-t" ert-redefine-abbrev-table))) + (should (equal nil (abbrev-expansion "g-a-t" ert-good-abbrev-table))))) +(ert-deftest read-write-abbrev-file-test () + "Test reading and writing abbrevs from file" + (let ((temp-test-file (make-temp-file "ert-abbrev-test")) + (ert-test-abbrevs (setup-test-abbrev-table))) + (write-abbrev-file temp-test-file) (clear-abbrev-table ert-test-abbrevs) + (should (abbrev-table-empty-p ert-test-abbrevs)) + (read-abbrev-file temp-test-file) + (should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs))) + (delete-file temp-test-file))) - (should (equal "nil" (symbol-name - (abbrev-symbol "a-e-t" ert-test-abbrevs)))) - (should (equal nil (symbol-value - (abbrev-symbol "a-e-t" ert-test-abbrevs)))) - (should (equal t (abbrev-table-empty-p ert-test-abbrevs))))) +(ert-deftest abbrev-edit-save-to-file-test () + "Test saving abbrev definitions in buffer to file" + (defvar ert-save-test-table nil) + (let ((temp-test-file (make-temp-file "ert-abbrev-test")) + (ert-test-abbrevs (setup-test-abbrev-table))) + (with-temp-buffer + (goto-char (point-min)) + (insert "(ert-save-test-table)\n") + (insert "\n" "\"s-a-t\"\t" "0\t" "\"save-abbrevs-test\"\n") + (should (equal "abbrev-ert-test" + (abbrev-expansion "a-e-t" ert-test-abbrevs))) + ;; clears abbrev tables + (abbrev-edit-save-to-file temp-test-file) + (should-not (abbrev-expansion "a-e-t" ert-test-abbrevs)) + (read-abbrev-file temp-test-file) + (should (equal "save-abbrevs-test" + (abbrev-expansion "s-a-t" ert-save-test-table))) + (delete-file temp-test-file)))) (provide 'abbrev-tests) - ;;; abbrev-tests.el ends here -- 2.7.2.333.g70bd996 --=-=-=--