venantius / ultra

A Leiningen plugin for a superior development environment
Eclipse Public License 1.0
1.24k stars 35 forks source link

Flush diff output #78

Closed emlyn closed 6 years ago

emlyn commented 7 years ago

When tests take a while to run, the diff output is not displayed immediately on failing tests, because it doesn't end in a newline. I've added a flush in these cases so that the output is visible as soon as the test fails (or maybe it would be better to add a newline at the end?)

venantius commented 7 years ago

Interesting. Can you provide a test case that I can use to try this out?

emlyn commented 7 years ago

Sure, I'll try to put together a minimal case and let you know.

emlyn commented 7 years ago

Here's a demo of the issue: https://github.com/emlyn/ultratest The output (of lein test) with the current version of ultra looks like:

screen shot 2017-09-13 at 23 01 03

Notice the output from the long running test (on stderr) between the expected/actual output and the diff output. With this PR it looks like:

screen shot 2017-09-13 at 23 01 43

There is still some messing up with indenting, so I tried making sure the last output is a println instead of a print (instead of flushing), and then I get:

screen shot 2017-09-13 at 23 02 02

Which looks better, so I'm pushing that change to this PR, but maybe there's a reason that the output doesn't end in a newline, and this breaks something else.

emlyn commented 7 years ago

Ping @venantius, in case you didn't see the above.

venantius commented 7 years ago

Hey -- sorry, haven't forgotten this, just a little buried with work. Will try to get you a review this weekend.

venantius commented 6 years ago

Okay I just pulled your patch and did some fussing with it. I'd like to preserve the existing newlines but obviously would prefer to avoid the unusual indentation. I believe this patch, applied to your current work, should suffice:

diff --git a/src/ultra/test/diff.clj b/src/ultra/test/diff.clj
index 0e8746c..d7e1c78 100644
--- a/src/ultra/test/diff.clj
+++ b/src/ultra/test/diff.clj
@@ -71,7 +71,7 @@
   [a b actual expected]
   (print-expected actual expected)
   (print "\n    diff:")
-  (println (str-diff/clean-difform-str a b)))
+  (print (str-diff/clean-difform-str a b)))

 (defmethod prn-diffs ::wrong-class
   [a b actual expected]
@@ -86,7 +86,7 @@
                                    (class b)))]
       (println (clojure.string/trim (indent a 10)))
       (print "     was: ")
-      (println (indent b 10)))))
+      (print (indent b 10)))))

 (defmethod prn-diffs ::diff-vecs
   [a b actual expected]
@@ -114,5 +114,5 @@
   (when b
     (print (ansi/sgr " + " :green))
     (let [b (with-out-str (cprint b))]
-      (print (indent b 12))))
-  (println))
+      (print (s/trimr (indent b 12)))
+      (println))))
emlyn commented 6 years ago

That seems to work, thanks! I've applied it to my branch.