Git Product home page Git Product logo

Comments (9)

purcell avatar purcell commented on July 29, 2024

This works fine for me with the latest clojure-mode (and Emacs nightly). How would one reproduce your issue?

from clojure-mode.

the-kenny avatar the-kenny commented on July 29, 2024

Just updates to latest clojure-mode. Still doesn't work.

Consider this test file (opened with clojure-test-mode active)

(ns foo
  (:use clojure.test))

(deftest foo
  (is (= 42 23)))

When not narrowed, C-, will correctly highlight the last line red. If you narrow the buffer to the deftest (highlight the whole deftest block and type M-x narrow-to-region), and then execute M-x clojure-test-run-tests (C-,), the line doesn't get highlighted red.

from clojure-mode.

purcell avatar purcell commented on July 29, 2024

Aha, I see what you mean now - thanks. If you narrow to a region containing multiple failing tests, does it only fail to highlight the final test? ie. is it just a problem with the last line in the narrowed region?

from clojure-mode.

the-kenny avatar the-kenny commented on July 29, 2024

No, it fails to highlight all lines. It starts counting lines at the current (point-min). This is a problem in narrowed buffers, as (point-min) is != 0.

Thus, if a test in the 5th line of the file fails, it highlights the 5th line of the buffer, regardless if it's narrowed or now. I'll take a look at it now and probably write a small path if it isn't too complicated.

from clojure-mode.

the-kenny avatar the-kenny commented on July 29, 2024

Fix: Wrap everything in clojure-test-extract-result in save-restriction and un-narrow (widen) the buffer before highlighting. The (widen) fixes the line-numbering and save-restriction re-narrows the buffer when the function returns.

Patch:

diff --git a/clojure-test-mode.el b/clojure-test-mode.el
index 3583615..5b77792 100644
--- a/clojure-test-mode.el
+++ b/clojure-test-mode.el
@@ -240,17 +240,19 @@

 (defun clojure-test-extract-result (result)
   "Parse the result from a single test. May contain multiple is blocks."
-  (dolist (is-result (rest result))
-    (unless (member (aref is-result 0) clojure-test-ignore-results)
-      (incf clojure-test-count)
-      (destructuring-bind (event msg expected actual line) (coerce is-result 'list)
-        (if (equal :fail event)
-            (progn (incf clojure-test-failure-count)
-                   (clojure-test-highlight-problem
-                    line event (format "Expected %s, got %s" expected actual)))
-          (when (equal :error event)
-            (incf clojure-test-error-count)
-            (clojure-test-highlight-problem line event actual)))))))
+  (save-restriction
+    (widen)
+    (dolist (is-result (rest result))
+      (unless (member (aref is-result 0) clojure-test-ignore-results)
+        (incf clojure-test-count)
+        (destructuring-bind (event msg expected actual line) (coerce is-result 'list)
+          (if (equal :fail event)
+              (progn (incf clojure-test-failure-count)
+                     (clojure-test-highlight-problem
+                      line event (format "Expected %s, got %s" expected actual)))
+            (when (equal :error event)
+              (incf clojure-test-error-count)
+              (clojure-test-highlight-problem line event actual))))))))


 (defun clojure-test-highlight-problem (line event message)

from clojure-mode.

purcell avatar purcell commented on July 29, 2024

Does the following also work?

diff --git a/clojure-test-mode.el b/clojure-test-mode.el
index 3583615..1d76d77 100644
--- a/clojure-test-mode.el
+++ b/clojure-test-mode.el
@@ -255,7 +255,7 @@

 (defun clojure-test-highlight-problem (line event message)
   (save-excursion
-    (goto-char (point-min)) (forward-line (1- line))
+    (goto-line line)
     (let ((beg (point)))
       (end-of-line)
       (let ((overlay (make-overlay beg (point))))

from clojure-mode.

purcell avatar purcell commented on July 29, 2024

Rather than guessing, I set things up to try out my fix, and it seems to do the trick.

from clojure-mode.

the-kenny avatar the-kenny commented on July 29, 2024

Yup, your's seems to work, as well as mine. I wasn't guessing, of course. I tried my patch before submitting as well.

Your patch looks cleaner, though ;-)

from clojure-mode.

purcell avatar purcell commented on July 29, 2024

I figured you'd tried out your patch, so I thought I'd do you the courtesy of trying out mine. :-)

I've filed a pull request, #37.

from clojure-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.