branch: scratch/editorconfig-cc
commit d4ab913044c1527ed19a06c551b9e0b93922572e
Author: 10sr <8.slas...@gmail.com>
Commit: Stefan Monnier <monn...@iro.umontreal.ca>

    Refactoring & add editorconfig-2-mode for beta test (#248)
    
    * Remove file type experimental feature temporarily
    
    * Do some refactors
    
    * Ignore failures of tests for file type feature
    
    * Make editorconfig-get-properties-function accept one argument
    
    * Implement editorconfig--advice-find-file-noselect
    
    * Define editorconfig-error
    
    * Implement advices
    
    * Update adviced function body
    
    * Update function name
    
    * Refactor exclude functions
    
    * Add more error handlings
    
    * Refactor editorconfig--advice-find-file-noselect
    
    * Add editorconfig-2-mode
    
    * Add nadvice to dependency list
    
    * Use display-warning instead of message for debug log
    
    * Update README
    
    * Fix editorconfig-2-mode for read-only-mode
    
    * Add test for editorconfig-2-mode
---
 Makefile                                         |   4 +-
 README.md                                        |  23 +-
 editorconfig.el                                  | 346 +++++++++++++----------
 ert-tests/{editorconfig.el => editorconfig-2.el} |  64 +++--
 ert-tests/editorconfig.el                        |  13 +-
 5 files changed, 260 insertions(+), 190 deletions(-)

diff --git a/Makefile b/Makefile
index 74dbfdd153..1fbf12d7a4 100644
--- a/Makefile
+++ b/Makefile
@@ -15,11 +15,11 @@ MAIN_SRC = editorconfig.el
 SRCS = $(wildcard $(PROJECT_ROOT_DIR)/*.el)
 OBJS = $(SRCS:.el=.elc)
 
+.PHONY: all clean test test-travis test-ert test-core test-metadata sandbox 
doc info
+
 $(OBJS): %.elc: %.el
        $(EMACS) $(BATCHFLAGS) -f batch-byte-compile $^
 
-.PHONY: all clean test test-travis test-ert test-core test-metadata sandbox 
doc info
-
 
 doc: doc/editorconfig.texi
 
diff --git a/README.md b/README.md
index f6f4dede7f..7619162717 100644
--- a/README.md
+++ b/README.md
@@ -42,25 +42,16 @@ following:
 
 * `charset`
 * `max_line_length`
-* `file_type_ext` (Experimental)
-* `file_type_emacs` (Experimental)
+* <del>`file_type_ext` (Experimental)</del> (See below)
+* <del>`file_type_emacs` (Experimental)</del> (See below)
 
 
-### File Type
+### <del>File Type (file_type_ext, file_type_emacs)</del>
 
-This plugin has experimental supports for `file_type_ext` and
-`file_type_emacs`, which specify "file types" for files.
-As for Emacs, it means `major-mode` can be set.
-
-**file_type_ext** When it is set to `md` for `a.txt`, for example,
-`major-mode` will be decided as if the file name would be `a.txt.md`
-(and thus `markdown-mode` is likely to be used).
-
-**file_type_emacs** When it is set to `markdown` for `a.txt`,
-`markdown-mode`  will be enabled when opening `a.txt`.
-
-These property are experimental and their meanings might change in the
-future updates. When both are specified, `file_type_ext` takes precedence.
+File-type feature is currently disabled, because this package is now undergoing
+big internal refactoring.
+For those who want this functionality,
+please consider using 
[editorconfig-custom-majormode](https://github.com/10sr/editorconfig-custom-majormode-el).
 
 
 ## Customize
diff --git a/editorconfig.el b/editorconfig.el
index 508020a75c..a1ddcb9d36 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -5,7 +5,7 @@
 ;; Author: EditorConfig Team <editorcon...@googlegroups.com>
 ;; Version: 0.8.1
 ;; URL: https://github.com/editorconfig/editorconfig-emacs#readme
-;; Package-Requires: ((cl-lib "0.5") (emacs "24"))
+;; Package-Requires: ((cl-lib "0.5") (nadvice "0.3") (emacs "24"))
 
 ;; See
 ;; http://github.com/editorconfig/editorconfig-emacs/graphs/contributors
@@ -39,6 +39,7 @@
 
 ;;; Code:
 (require 'cl-lib)
+(require 'nadvice)
 (eval-when-compile
   (require 'rx)
   (defvar tex-indent-basic)
@@ -48,7 +49,7 @@
 
 (declare-function editorconfig-core-get-properties-hash
                   "editorconfig-core"
-                  nil)
+                  (&optional file confname confversion))
 
 (defgroup editorconfig nil
   "EditorConfig Emacs Plugin.
@@ -67,7 +68,7 @@ coding styles between different editors and IDEs."
   "editorconfig"
   "Path to EditorConfig executable.
 
-Used by `editorconfig-call-editorconfig-exec'."
+Used by `editorconfig--execute-editorconfig-exec'."
   :type 'string
   :group 'editorconfig)
 
@@ -77,12 +78,12 @@ Used by `editorconfig-call-editorconfig-exec'."
   "0.5")
 (defcustom editorconfig-get-properties-function
   'editorconfig-core-get-properties-hash
-  "A function which gets EditorConofig properties for current buffer.
+  "A function which gets EditorConfig properties for specified file.
 
-This function will be called with no argument and should return a
-hash object containing properties, or nil if any core program is
-not available.  Keys of this hash should be symbols of properties, and values
-should be strings of their values.
+This function will be called with one argument, full path of the target file,
+and should return a hash object containing properties, or nil if any core
+program is not available.  Keys of this hash should be symbols of properties,
+and values should be strings of their values.
 
 
 For example, if you always want to use built-in core library instead
@@ -305,6 +306,28 @@ number - `lisp-indent-offset' is not set only if 
indent_size is
 (defconst editorconfig-unset-value "unset"
   "String of value used to unset properties in .editorconfig .")
 
+(define-error 'editorconfig-error
+  "Error thrown from editorconfig lib")
+
+(defun editorconfig-error (&rest args)
+  "Signal an `editorconfig-error'.
+Make a message by passing ARGS to `format-message'."
+  (signal 'editorconfig-error (list (apply #'format-message args))))
+
+(defun editorconfig--disabled-for-filename (filename)
+  "Return non-nil when EditorConfig is disabled for FILENAME."
+  (cl-assert (stringp filename))
+  (cl-loop for regexp in editorconfig-exclude-regexps
+           if (string-match regexp filename) return t
+           finally return nil))
+
+(defun editorconfig--disabled-for-majormode (majormode)
+  "Return non-nil when Editorconfig is disabled for MAJORMODE."
+  (cl-assert majormode)
+  (or (editorconfig--provided-mode-derived-p majormode 'special-mode)
+      (memq majormode
+            editorconfig-exclude-modes)))
+
 (defun editorconfig-string-integer-p (string)
   "Return non-nil if STRING represents integer."
   (and (stringp string)
@@ -345,9 +368,9 @@ number - `lisp-indent-offset' is not set only if 
indent_size is
      'permanent-local
      t)
 
-(cl-defun editorconfig-set-coding-system (end-of-line charset)
-  "Set buffer coding system by END-OF-LINE and CHARSET."
-  (let* ((eol (cond
+(defun editorconfig-merge-coding-systems (end-of-line charset)
+  "Return merged coding system symbol of END-OF-LINE and CHARSET."
+  (let ((eol (cond
                ((equal end-of-line "lf") 'undecided-unix)
                ((equal end-of-line "cr") 'undecided-mac)
                ((equal end-of-line "crlf") 'undecided-dos)
@@ -358,15 +381,20 @@ number - `lisp-indent-offset' is not set only if 
indent_size is
               ((equal charset "utf-8-bom") 'utf-8-with-signature)
               ((equal charset "utf-16be") 'utf-16be-with-signature)
               ((equal charset "utf-16le") 'utf-16le-with-signature)
-              (t 'undecided)))
-         (coding-system (merge-coding-systems cs eol)))
+              (t 'undecided))))
+    (merge-coding-systems cs eol)))
+
+(cl-defun editorconfig-set-coding-system (end-of-line charset)
+  "Set buffer coding system by END-OF-LINE and CHARSET."
+  (let ((coding-system (editorconfig-merge-coding-systems end-of-line
+                                                          charset)))
     (when (eq coding-system 'undecided)
       (cl-return-from editorconfig-set-coding-system))
     (unless (file-readable-p buffer-file-name)
       (set-buffer-file-coding-system coding-system)
       (cl-return-from editorconfig-set-coding-system))
-    (unless (eq coding-system
-                editorconfig--apply-coding-system-currently)
+    (unless (memq coding-system
+                  (coding-system-aliases 
editorconfig--apply-coding-system-currently))
       ;; Revert functions might call editorconfig-apply again
       (unwind-protect
           (progn
@@ -399,12 +427,6 @@ to non-nil when FINAL-NEWLINE is true."
              (> (string-to-number length) 0))
     (setq fill-column (string-to-number length))))
 
-(defvar editorconfig-file-type-emacs-whitelist
-  (append (mapcar 'car
-                  editorconfig-indentation-alist)
-          '(conf-mode))
-  "List of known `major-mode' that can be used for file_type_emacs value.")
-
 ;; Emacs<26 does not have provided-mode-derived-p
 (defun editorconfig--provided-mode-derived-p (mode &rest modes)
   "Non-nil if MODE is derived from one of MODES.
@@ -417,113 +439,76 @@ If you just want to check `major-mode', use 
`derived-mode-p'."
     mode))
 
 
-(defun editorconfig-set-major-mode-from-name (filetype)
-  "Set buffer `major-mode' by FILETYPE.
-
-FILETYPE should be s string like `\"ini\"`, if not nil or empty string."
-  (let ((mode (and filetype
-                   (not (string= filetype
-                                 ""))
-                   (intern (concat filetype
-                                   "-mode")))))
-    (when mode
-      (if (fboundp mode)
-          (if (apply 'editorconfig--provided-mode-derived-p mode
-                     editorconfig-file-type-emacs-whitelist)
-              (editorconfig-apply-major-mode-safely mode)
-            (display-warning :error (format "Major-mode `%S' is not listed in 
`%S'"
-                                            mode
-                                            
'editorconfig-file-type-emacs-whitelist)))
-        (display-warning :error (format "Major-mode `%S' not found"
-                                        mode))
-        nil))))
-
-(defvar editorconfig--apply-major-mode-currently nil
-  "Used internally.")
-(make-variable-buffer-local 'editorconfig--apply-major-mode-currently)
-(put 'editorconfig--apply-major-mode-currently
-     'permanent-local
-     t)
+(defun editorconfig--execute-editorconfig-exec (filename)
+  "Execute EditorConfig core with FILENAME and return output."
+  (if filename
+      (with-temp-buffer
+        (setq default-directory "/")
+        (if (eq 0
+                (call-process editorconfig-exec-path nil t nil filename))
+            (buffer-string)
+          (editorconfig-error (buffer-string))))
+    ""))
 
-(defun editorconfig-apply-major-mode-safely (mode)
-  "Set `major-mode' to MODE.
-Normally `editorconfig-apply' will be hooked so that it runs when changing
-`major-mode', so there is a possibility that MODE is called infinitely if
-MODE is called naively from inside of `editorconfig-apply'.
-This function will avoid such cases and set `major-mode' safely.
-
-Just checking current `major-mode' value is not enough, because it can be
-different from MODE value (for example, `conf-mode' will set `major-mode' to
-`conf-unix-mode' or another conf mode)."
-  (cl-assert mode)
-  (when (and (not (eq mode
-                      editorconfig--apply-major-mode-currently))
-             (not (eq mode
-                      major-mode))
-             (not (derived-mode-p mode)))
-    (unwind-protect
-        (progn
-          (setq editorconfig--apply-major-mode-currently
-                mode)
-          (funcall mode))
-      (setq editorconfig--apply-major-mode-currently
-            nil))))
-
-(defun editorconfig--find-mode-from-ext (ext &optional filename)
-  "Get suitable `major-mode' from EXT and FILENAME.
-If FILENAME is omitted filename of current buffer is used."
-  (cl-assert ext)
-  (cl-assert (not (string= ext "")))
-  (let* ((name (concat (or filename
-                           buffer-file-name)
-                       "."
-                       ext)))
-    (assoc-default name
-                   auto-mode-alist
-                   'string-match)))
-
-(defun editorconfig-set-major-mode-from-ext (ext)
-  "Set buffer `major-mode' by EXT.
-
-EXT should be a string like `\"ini\"`, if not nil or empty string."
-  (cl-assert buffer-file-name)
-  (when (and ext
-             (not (string= ext ""))
-             (not (string= ext editorconfig-unset-value)))
-
-    (let ((mode (editorconfig--find-mode-from-ext ext
-                                                  buffer-file-name)))
-      (if mode
-          (editorconfig-apply-major-mode-safely mode)
-        (display-warning :error (format "Major-mode for `%s' not found"
-                                        ext))
-        nil))))
-
-(defun editorconfig-call-editorconfig-exec ()
+(defun editorconfig--parse-properties (props-string)
   )
 
-(defun editorconfig-parse-properties (props-string)
-  )
-
-(defun editorconfig-get-properties-from-exec ()
-  "Get EditorConfig properties of current buffer.
+(defun editorconfig-get-properties-from-exec (filename)
+  "Get EditorConfig properties of file FILENAME.
 
 This function uses value of `editorconfig-exec-path' to get properties."
   (if (executable-find editorconfig-exec-path)
-      (editorconfig-parse-properties (editorconfig-call-editorconfig-exec))
-    (error "Unable to find editorconfig executable")))
+      (editorconfig--parse-properties (editorconfig--execute-editorconfig-exec 
filename))
+    (editorconfig-error "Unable to find editorconfig executable")))
 
-(defun editorconfig-get-properties ()
-  "Get EditorConfig properties of current buffer.
+(defun editorconfig-get-properties (filename)
+  "Get EditorConfig properties for file FILENAME.
 
 It calls `editorconfig-get-properties-from-exec' if
 `editorconfig-exec-path' is found, otherwise
 `editorconfig-core-get-properties-hash'."
   (if (and (executable-find editorconfig-exec-path)
            (not (file-remote-p buffer-file-name)))
-      (editorconfig-get-propergies-from-exec)
+      (editorconfig-get-properties-from-exec filename)
     (require 'editorconfig-core)
-    (editorconfig-core-get-properties-hash)))
+    (editorconfig-core-get-properties-hash filename)))
+
+(defun editorconfig-call-get-properties-function (filename)
+  "Call `editorconfig-get-properties-function' with FILENAME and return result.
+
+This function also removes 'unset'ted properties and calls
+`editorconfig-hack-properties-functions'."
+  (unless (functionp editorconfig-get-properties-function)
+    (editorconfig-error "Invalid editorconfig-get-properties-function value"))
+  (if (stringp filename)
+      (setq filename (expand-file-name filename))
+    (editorconfig-error "Invalid argument: %S" filename))
+  (let ((props nil))
+    (condition-case err
+        (setq props (funcall editorconfig-get-properties-function
+                             filename))
+      (error
+       (editorconfig-error "Error from editorconfig-get-properties-function: 
%S"
+                           err)))
+    (cl-loop for k being the hash-keys of props using (hash-values v)
+             when (equal v "unset") do (remhash k props))
+    (condition-case err
+        (run-hook-with-args 'editorconfig-hack-properties-functions props)
+      (error
+       (display-warning 'editorconfig-hack-properties-functions
+                        (concat (error-message-string err)
+                                ". Abort running hook.")
+                        :warning)))
+    props))
+
+(defun editorconfig-set-variables (props)
+  "Set buffer variables according to EditorConfig PROPS."
+  (editorconfig-set-indentation (gethash 'indent_style props)
+                                (gethash 'indent_size props)
+                                (gethash 'tab_width props))
+  (editorconfig-set-trailing-nl (gethash 'insert_final_newline props))
+  (editorconfig-set-trailing-ws (gethash 'trim_trailing_whitespace props))
+  (editorconfig-set-line-length (gethash 'max_line_length props)))
 
 ;;;###autoload
 (defun editorconfig-apply ()
@@ -536,31 +521,19 @@ Use `editorconfig-mode-apply' instead to make use of 
these variables."
   (when buffer-file-name
     (condition-case err
         (progn
-          (unless (functionp editorconfig-get-properties-function)
-            (error "Invalid editorconfig-get-properties-function value"))
-          (let ((props (funcall editorconfig-get-properties-function)))
-            (progn
-              (condition-case err
-                  (run-hook-with-args 'editorconfig-hack-properties-functions 
props)
-                (error
-                 (display-warning 'editorconfig-hack-properties-functions
-                                  (concat (error-message-string err)
-                                          ". Abort running hook.")
-                                  :warning)))
-              (setq editorconfig-properties-hash props)
-              (editorconfig-set-coding-system
-               (gethash 'end_of_line props)
-               (gethash 'charset props))
-              (editorconfig-set-line-length (gethash 'max_line_length props))
-              (editorconfig-set-major-mode-from-name (gethash 'file_type_emacs 
props))
-              (editorconfig-set-major-mode-from-ext (gethash 'file_type_ext 
props))
-              (condition-case err
-                  (run-hook-with-args 'editorconfig-after-apply-functions 
props)
-                (error
-                 (display-warning 'editorconfig-after-apply-functions
-                                  (concat (error-message-string err)
-                                          ". Stop running hook.")
-                                  :warning))))))
+          (let ((props (editorconfig-call-get-properties-function 
buffer-file-name)))
+            (setq editorconfig-properties-hash props)
+            (editorconfig-set-variables props)
+            (editorconfig-set-coding-system
+             (gethash 'end_of_line props)
+             (gethash 'charset props))
+            (condition-case err
+                (run-hook-with-args 'editorconfig-after-apply-functions props)
+              (error
+               (display-warning 'editorconfig-after-apply-functions
+                                (concat (error-message-string err)
+                                        ". Stop running hook.")
+                                :warning)))))
       (error
        (display-warning 'editorconfig
                         (concat (error-message-string err)
@@ -575,14 +548,79 @@ This function does nothing when the major mode is listed 
in
 any of regexps in `editorconfig-exclude-regexps'."
   (interactive)
   (when (and major-mode
-             (not (memq major-mode
-                        editorconfig-exclude-modes))
+             (not (editorconfig--disabled-for-majormode major-mode))
              buffer-file-name
-             (not (cl-loop for regexp in editorconfig-exclude-regexps
-                           if (string-match regexp buffer-file-name) return t
-                           finally return nil)))
+             (not (editorconfig--disabled-for-filename buffer-file-name)))
     (editorconfig-apply)))
 
+(defvar editorconfig--cons-filename-codingsystem nil
+  "Used interally.")
+
+(defun editorconfig--advice-insert-file-contents (f filename &rest args)
+  "Set `coding-system-for-read'.
+This function should be adviced to `insert-file-contents'"
+  (display-warning '(editorconfig editorconfig--advice-insert-file-contents)
+                   (format ": %S %S %S"
+                           filename args
+                           editorconfig--cons-filename-codingsystem)
+                   :debug)
+  (if (and (stringp filename)
+           (stringp (car editorconfig--cons-filename-codingsystem))
+           (string= (expand-file-name filename)
+                    (car editorconfig--cons-filename-codingsystem))
+           (cdr editorconfig--cons-filename-codingsystem)
+           (not (eq (cdr editorconfig--cons-filename-codingsystem)
+                    'undecided)))
+      (let (
+            (coding-system-for-read (cdr 
editorconfig--cons-filename-codingsystem))
+            ;; (coding-system-for-read 'undecided)
+            )
+        (apply f filename args))
+    (apply f filename args)))
+
+(defun editorconfig--advice-find-file-noselect (f filename &rest args)
+  "Get EditorConfig properties and apply them to buffer to be visited.
+
+This function should be adviced to `find-file-noselect'.
+F is this function, and FILENAME and ARGS are arguments passed to F."
+  (let ((props nil)
+        (coding-system nil)
+        (ret nil))
+    (condition-case err
+        (when (and (stringp filename)
+                   (not (editorconfig--disabled-for-filename filename)))
+          (setq props (editorconfig-call-get-properties-function filename))
+          (setq coding-system
+                (editorconfig-merge-coding-systems (gethash 'end_of_line props)
+                                                   (gethash 'charset props))))
+      (error
+       (display-warning 'editorconfig
+                        (format "Failed to get properties, styles will not be 
applied: %S"
+                                err)
+                        :warning)))
+
+    (let ((editorconfig--cons-filename-codingsystem (cons (expand-file-name 
filename)
+                                                            coding-system)))
+      (setq ret (apply f filename args)))
+
+    (condition-case err
+        (with-current-buffer ret
+          (when (and props
+                     ;; filename has already been checked
+                     (not (editorconfig--disabled-for-majormode major-mode)))
+            (setq editorconfig-properties-hash props)
+            (editorconfig-set-variables props)
+            (condition-case err
+                (run-hook-with-args 'editorconfig-after-apply-functions props)
+              (error
+               (display-warning 'editorconfig
+                                (format "Error while running 
`editorconfig-after-apply-functions': %S"
+                                        err))))))
+      (error
+       (display-warning 'editorconfig
+                        (format "Error while setting variables from 
EditorConfig: %S" err))))
+    ret))
+
 ;;;###autoload
 (define-minor-mode editorconfig-mode
   "Toggle EditorConfig feature.
@@ -605,6 +643,26 @@ To disable EditorConfig in some buffers, modify
         (add-hook hook 'editorconfig-mode-apply)
       (remove-hook hook 'editorconfig-mode-apply))))
 
+(define-minor-mode editorconfig-2-mode
+  "Toggle EditorConfig feature.
+
+This function is provided temporarily for beta testing, and not well tested 
yet.
+Currently this can cause unexpected behaviors like kill emacs processes and
+destroying your files, so please use with caution if you enable this instead of
+ `editorconfig-mode'."
+  :global t
+  :lighter editorconfig-mode-lighter
+  (if editorconfig-2-mode
+      (progn
+        (advice-add 'find-file-noselect :around 
'editorconfig--advice-find-file-noselect)
+        (advice-add 'insert-file-contents :around 
'editorconfig--advice-insert-file-contents)
+        (add-hook 'read-only-mode-hook
+                  'editorconfig-mode-apply))
+    (advice-remove 'find-file-noselect 
'editorconfig--advice-find-file-noselect)
+    (advice-remove 'insert-file-contents 
'editorconfig--advice-insert-file-contents)
+    (remove-hook 'read-only-mode-hook
+              'editorconfig-mode-apply)))
+
 
 ;; Tools
 ;; Some useful commands for users, not required for EditorConfig to work
diff --git a/ert-tests/editorconfig.el b/ert-tests/editorconfig-2.el
similarity index 71%
copy from ert-tests/editorconfig.el
copy to ert-tests/editorconfig-2.el
index cd3665360c..348ec49c0e 100644
--- a/ert-tests/editorconfig.el
+++ b/ert-tests/editorconfig-2.el
@@ -1,10 +1,13 @@
+(require 'editorconfig)
+
 (defun display-warning (type message &optional level buffer-name)
   "When testing overwrite this function to throw error when called."
-  (error "display-warning called: %S %S %S %S"
-         type
-         message
-         level
-         buffer-name))
+  (unless (eq level :debug)
+    (error "display-warning called: %S %S %S %S"
+           type
+           message
+           level
+           buffer-name)))
 
 (defmacro with-visit-file (path &rest body)
   "Visit PATH and evaluate BODY."
@@ -14,6 +17,19 @@
        ,@body)
      (kill-buffer buf)))
 
+;;; interactive
+
+(ert-deftest interactive-test-01 nil
+  "This test should not run on Travis"
+  :tags '(:interactive)
+  (should t))
+
+;;; noninteractive, will run on Travis
+
+(ert-deftest has-feature-01 nil
+  "minimally working - provides 'editorconfig"
+  (should (featurep 'editorconfig)))
+
 (defvar editorconfig-ert-dir
   (concat default-directory
           "ert-tests/plugin-tests/test_files/"))
@@ -22,9 +38,9 @@
   (concat default-directory
           "ert-tests/test_files_secondary/"))
 
-(ert-deftest test-editorconfig nil
+(ert-deftest test-editorconfig-2 nil
   "Check if properties are applied."
-  (editorconfig-mode 1)
+  (editorconfig-2-mode 1)
 
   (with-visit-file (concat editorconfig-ert-dir
                            "3_space.txt")
@@ -36,10 +52,10 @@
     (should (eq python-indent-offset 4))
     (should (eq tab-width 8))
     (should (eq indent-tabs-mode nil)))
-  (editorconfig-mode -1))
+  (editorconfig-2-mode -1))
 
-(ert-deftest test-lisp-use-default-indent nil
-  (editorconfig-mode 1)
+(ert-deftest test-lisp-use-default-indent-2 nil
+  (editorconfig-2-mode 1)
 
   (with-visit-file (concat editorconfig-secondary-ert-dir
                            "2_space.el")
@@ -59,10 +75,10 @@
     (with-visit-file (concat editorconfig-secondary-ert-dir
                              "2_space.el")
       (should (eq lisp-indent-offset 2))))
-  (editorconfig-mode -1))
+  (editorconfig-2-mode -1))
 
-(ert-deftest test-trim-trailing-ws nil
-  (editorconfig-mode 1)
+(ert-deftest test-trim-trailing-ws-2 nil
+  (editorconfig-2-mode 1)
   (with-visit-file (concat editorconfig-ert-dir
                            "trim.txt")
     (should (memq 'delete-trailing-whitespace
@@ -72,17 +88,19 @@
     (read-only-mode 1)
     (should (not (memq 'delete-trailing-whitespace
                        write-file-functions))))
-  (editorconfig-mode -1))
+  (editorconfig-2-mode -1))
 
-(ert-deftest test-file-type-emacs nil
-  (editorconfig-mode 1)
+(ert-deftest test-file-type-emacs-2 nil
+  :expected-result t  ;; Ignore failure
+  (editorconfig-2-mode 1)
   (with-visit-file (concat editorconfig-secondary-ert-dir
                            "c.txt")
     (should (eq major-mode 'conf-unix-mode)))
-  (editorconfig-mode -1))
+  (editorconfig-2-mode -1))
 
-(ert-deftest test-file-type-ext nil
-  (editorconfig-mode 1)
+(ert-deftest test-file-type-ext-2 nil
+  :expected-result t  ;; Ignore failure
+  (editorconfig-2-mode 1)
   (with-visit-file (concat editorconfig-secondary-ert-dir
                            "a.txt")
     (should (eq major-mode 'conf-unix-mode)))
@@ -91,10 +109,10 @@
                            "bin/perlscript")
     (should (eq major-mode 'perl-mode))
     (should (eq perl-indent-level 5)))
-  (editorconfig-mode -1))
+  (editorconfig-2-mode -1))
 
-(ert-deftest test-hack-properties-functions nil
-  (editorconfig-mode 1)
+(ert-deftest test-hack-properties-functions-2 nil
+  (editorconfig-2-mode 1)
   (add-hook 'editorconfig-hack-properties-functions
             (lambda (props)
               (puthash 'indent_size "5" props)))
@@ -102,4 +120,4 @@
                            "4_space.py")
     (should (eq python-indent-offset 5)))
   (setq editorconfig-hack-properties-functions nil)
-  (editorconfig-mode -1))
+  (editorconfig-2-mode -1))
diff --git a/ert-tests/editorconfig.el b/ert-tests/editorconfig.el
index cd3665360c..4d3745e98f 100644
--- a/ert-tests/editorconfig.el
+++ b/ert-tests/editorconfig.el
@@ -1,10 +1,11 @@
 (defun display-warning (type message &optional level buffer-name)
   "When testing overwrite this function to throw error when called."
-  (error "display-warning called: %S %S %S %S"
-         type
-         message
-         level
-         buffer-name))
+  (unless (eq level :debug)
+    (error "display-warning called: %S %S %S %S"
+           type
+           message
+           level
+           buffer-name)))
 
 (defmacro with-visit-file (path &rest body)
   "Visit PATH and evaluate BODY."
@@ -75,6 +76,7 @@
   (editorconfig-mode -1))
 
 (ert-deftest test-file-type-emacs nil
+  :expected-result t  ;; Ignore failure
   (editorconfig-mode 1)
   (with-visit-file (concat editorconfig-secondary-ert-dir
                            "c.txt")
@@ -82,6 +84,7 @@
   (editorconfig-mode -1))
 
 (ert-deftest test-file-type-ext nil
+  :expected-result t  ;; Ignore failure
   (editorconfig-mode 1)
   (with-visit-file (concat editorconfig-secondary-ert-dir
                            "a.txt")

Reply via email to