From ed009281365363135bb92e13b3f3e0f08afd2e3d Mon Sep 17 00:00:00 2001 From: Alys Brooks Date: Fri, 5 May 2023 20:22:41 -0500 Subject: [PATCH 1/6] Redo test as a vector of lines instead of a string. This test is difficult to work with as-is because it's one big string, and deep-diff2 (currently) shows only that two strings differ, and not the substrings in particular that cause the mismatch. --- test/unit/kaocha/watch_test.clj | 36 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/test/unit/kaocha/watch_test.clj b/test/unit/kaocha/watch_test.clj index e5678cf9..954a46af 100644 --- a/test/unit/kaocha/watch_test.clj +++ b/test/unit/kaocha/watch_test.clj @@ -13,7 +13,9 @@ [kaocha.config :as config] [clojure.test :as t] [clojure.string :as str] - [slingshot.slingshot :refer [try+]]) + [slingshot.slingshot :refer [try+]] + [matcher-combinators.matchers :as matchers] + ) (:import (java.io File))) (require 'matcher-combinators.test) @@ -131,15 +133,29 @@ (w/qput q :finish) (Thread/sleep 100) - (is (str/includes? - @out-str - (str/replace - (str/replace - "[(F)]\n\nFAIL in foo.bar-test/xxx-test (bar_test.clj:1)\nExpected:\n :xxx\nActual:\n -:xxx +:yyy\n1 tests, 1 assertions, 1 failures.\n\nbin/kaocha --config-file PATH --focus 'foo.bar-test/xxx-test'\n\n[watch] Reloading #{foo.bar-test}\n[watch] Re-running failed tests #{:foo.bar-test/xxx-test}\n[(F)]\n\nFAIL in foo.bar-test/xxx-test (bar_test.clj:1)\nExpected:\n :xxx\nActual:\n -:xxx +:zzz" - "foo" - prefix) - "PATH" - (str config-file)))))) + (is (match? + (matchers/embeds + ["[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:yyy" + "1 tests, 1 assertions, 1 failures." + "" + (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) + "" + (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) + (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) + "[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:zzz"]) + (str/split-lines @out-str))))) (deftest ignore-files-merged (let [{:keys [_config-file test-dir] :as m} (integration/test-dir-setup {})] From 82efa11cffdc5656fe2669aa192c2e597a8ff159 Mon Sep 17 00:00:00 2001 From: Alys Brooks Date: Wed, 10 May 2023 21:42:49 -0500 Subject: [PATCH 2/6] Fix up style issue. --- test/unit/kaocha/watch_test.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/kaocha/watch_test.clj b/test/unit/kaocha/watch_test.clj index 954a46af..3f587662 100644 --- a/test/unit/kaocha/watch_test.clj +++ b/test/unit/kaocha/watch_test.clj @@ -14,8 +14,7 @@ [clojure.test :as t] [clojure.string :as str] [slingshot.slingshot :refer [try+]] - [matcher-combinators.matchers :as matchers] - ) + [matcher-combinators.matchers :as matchers]) (:import (java.io File))) (require 'matcher-combinators.test) From 86d69d0433a3780a9d557d18ea86b67135c51abe Mon Sep 17 00:00:00 2001 From: Alys Brooks Date: Fri, 28 Jul 2023 21:50:02 -0500 Subject: [PATCH 3/6] Split test into two. It seems to run into quadratic behavior if I try to compare every line. This is slightly less accurate of a test, though. --- test/unit/kaocha/watch_test.clj | 50 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/test/unit/kaocha/watch_test.clj b/test/unit/kaocha/watch_test.clj index 3f587662..28c4d345 100644 --- a/test/unit/kaocha/watch_test.clj +++ b/test/unit/kaocha/watch_test.clj @@ -132,29 +132,33 @@ (w/qput q :finish) (Thread/sleep 100) - (is (match? - (matchers/embeds - ["[(F)]" - "" - (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) - "Expected:" - " :xxx" - "Actual:" - " -:xxx +:yyy" - "1 tests, 1 assertions, 1 failures." - "" - (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) - "" - (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) - (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) - "[(F)]" - "" - (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) - "Expected:" - " :xxx" - "Actual:" - " -:xxx +:zzz"]) - (str/split-lines @out-str))))) + (let [split-str (str/split-lines @out-str)] + (is (match? + (matchers/embeds + ["[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:yyy" + "1 tests, 1 assertions, 1 failures."]) + split-str)) + + (is (match? + (matchers/embeds + [(format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) + "" + (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) + (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) + "[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:zzz" ]) + split-str))))) (deftest ignore-files-merged (let [{:keys [_config-file test-dir] :as m} (integration/test-dir-setup {})] From f37c8883de2290373e7460f1541ec2dd73d58503 Mon Sep 17 00:00:00 2001 From: Alys Brooks Date: Fri, 28 Jul 2023 22:09:32 -0500 Subject: [PATCH 4/6] Switch from embeds to equals to improve messages Artificially dividing it up produced weird errors when there was a mismach. Using equals results in more coherent diffs and only required adding a few lines. I also didn't have that much confidence that a different change in test output wouidn't trigger a long delay. This does make the test slightly more fragile, as any thing added to the beginning of the output or the end of the output will cause this to fail. Also, if there's more lines in the output than in the test, you don't get a great diff either. --- test/unit/kaocha/watch_test.clj | 55 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/test/unit/kaocha/watch_test.clj b/test/unit/kaocha/watch_test.clj index 28c4d345..da6ce3d8 100644 --- a/test/unit/kaocha/watch_test.clj +++ b/test/unit/kaocha/watch_test.clj @@ -111,6 +111,7 @@ (assoc-in [:kaocha/cli-options :config-file] (str config-file)) (assoc-in [:kaocha/tests 0 :kaocha/source-paths] []) (assoc-in [:kaocha/tests 0 :kaocha/test-paths] [(str test-dir)])) + ;; _ (println config) prefix (str (gensym "foo")) finish? (atom false) q (w/make-queue) @@ -132,33 +133,33 @@ (w/qput q :finish) (Thread/sleep 100) - (let [split-str (str/split-lines @out-str)] - (is (match? - (matchers/embeds - ["[(F)]" - "" - (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) - "Expected:" - " :xxx" - "Actual:" - " -:xxx +:yyy" - "1 tests, 1 assertions, 1 failures."]) - split-str)) - - (is (match? - (matchers/embeds - [(format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) - "" - (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) - (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) - "[(F)]" - "" - (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) - "Expected:" - " :xxx" - "Actual:" - " -:xxx +:zzz" ]) - split-str))))) + (is (match? + (matchers/equals + ["[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual: " + " -:xxx +:yyy" + "1 tests, 1 assertions, 1 failures." + "" + (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) + "" + (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) + (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) + "[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:zzz" + "1 tests, 1 assertions, 1 failures." + "" + (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) + ]) + (str/split-lines @out-str))))) (deftest ignore-files-merged (let [{:keys [_config-file test-dir] :as m} (integration/test-dir-setup {})] From 924ffd7ba67cd34687543c23e0c7214fd6dbf5b4 Mon Sep 17 00:00:00 2001 From: Alys Brooks Date: Fri, 28 Jul 2023 22:16:34 -0500 Subject: [PATCH 5/6] Switch from matcher-combinators to regular equality. --- test/unit/kaocha/watch_test.clj | 53 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/test/unit/kaocha/watch_test.clj b/test/unit/kaocha/watch_test.clj index da6ce3d8..5ea424fc 100644 --- a/test/unit/kaocha/watch_test.clj +++ b/test/unit/kaocha/watch_test.clj @@ -133,33 +133,32 @@ (w/qput q :finish) (Thread/sleep 100) - (is (match? - (matchers/equals - ["[(F)]" - "" - (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) - "Expected:" - " :xxx" - "Actual: " - " -:xxx +:yyy" - "1 tests, 1 assertions, 1 failures." - "" - (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) - "" - (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) - (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) - "[(F)]" - "" - (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) - "Expected:" - " :xxx" - "Actual:" - " -:xxx +:zzz" - "1 tests, 1 assertions, 1 failures." - "" - (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) - ]) - (str/split-lines @out-str))))) + (is (= + ["[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:yyy" + "1 tests, 1 assertions, 1 failures." + "" + (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) + "" + (str/replace "[watch] Reloading #{foo.bar-test}" "foo" prefix) + (str/replace "[watch] Re-running failed tests #{:foo.bar-test/xxx-test}" "foo" prefix) + "[(F)]" + "" + (str/replace "FAIL in foo.bar-test/xxx-test (bar_test.clj:1)" "foo" prefix) + "Expected:" + " :xxx" + "Actual:" + " -:xxx +:zzz" + "1 tests, 1 assertions, 1 failures." + "" + (format "bin/kaocha --config-file %s --focus '%s.bar-test/xxx-test'" (str config-file) prefix) + ] + (str/split-lines @out-str))))) (deftest ignore-files-merged (let [{:keys [_config-file test-dir] :as m} (integration/test-dir-setup {})] From bf4d9f8ffb5a2115aeb832b17d09adb8fd4d2488 Mon Sep 17 00:00:00 2001 From: joanne cheng Date: Mon, 22 Sep 2025 11:29:17 +0200 Subject: [PATCH 6/6] remove println --- test/unit/kaocha/watch_test.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/kaocha/watch_test.clj b/test/unit/kaocha/watch_test.clj index 5ea424fc..475a7ca9 100644 --- a/test/unit/kaocha/watch_test.clj +++ b/test/unit/kaocha/watch_test.clj @@ -111,7 +111,6 @@ (assoc-in [:kaocha/cli-options :config-file] (str config-file)) (assoc-in [:kaocha/tests 0 :kaocha/source-paths] []) (assoc-in [:kaocha/tests 0 :kaocha/test-paths] [(str test-dir)])) - ;; _ (println config) prefix (str (gensym "foo")) finish? (atom false) q (w/make-queue)