From 5330e73a5a66eb773cdfb1470e679485082dbfaf Mon Sep 17 00:00:00 2001 From: Fogus Date: Thu, 19 Dec 2024 11:20:58 -0500 Subject: [PATCH] Commenting out ioc-macro-tests --- .../clojure/core/async/ioc_macros_test.clj | 1158 ++++++++--------- src/test/clojure/clojure/core/async_test.clj | 8 +- .../clojure/clojure/core/pipeline_test.clj | 14 +- 3 files changed, 590 insertions(+), 590 deletions(-) diff --git a/src/test/clojure/clojure/core/async/ioc_macros_test.clj b/src/test/clojure/clojure/core/async/ioc_macros_test.clj index a1c266b..e5b6c44 100644 --- a/src/test/clojure/clojure/core/async/ioc_macros_test.clj +++ b/src/test/clojure/clojure/core/async/ioc_macros_test.clj @@ -8,582 +8,582 @@ [clojure.test :refer :all]) (:import [clojure.lang ExceptionInfo])) -(defn pause [x] - x) - -(defn pause-run [state blk val] - (ioc/aset-all! state ioc/STATE-IDX blk ioc/VALUE-IDX val) - :recur) - - -(defmacro runner - "Creates a runner block. The code inside the body of this macro will be translated - into a state machine. At run time the body will be run as normal. This transform is - only really useful for testing." - [& body] - (let [terminators {`pause `pause-run} - crossing-env (zipmap (keys &env) (repeatedly gensym))] - `(let [captured-bindings# (clojure.lang.Var/getThreadBindingFrame) - ~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~l)]) crossing-env) - state# (~(go/state-machine `(do ~@body) 0 [crossing-env &env] terminators))] - (ioc/aset-all! state# ~ioc/BINDINGS-IDX captured-bindings#) - (ioc/run-state-machine state#) - (ioc/aget-object state# ioc/VALUE-IDX)))) - -(deftest test-try-catch-finally - (testing "Don't endlessly loop when exceptions are thrown" - (is (thrown? Exception - (runner - (loop [] - (try - (pause (throw (Exception. "Ex"))) - (catch ExceptionInfo _ - :retry)))))) - (is (thrown? Throwable - (runner - (loop [] - (try - (pause (throw (Throwable. "Ex"))) - (catch ExceptionInfo _ - :retry)))))) - ;; (is (try ((fn [] (println "Hello") (pause 5))) (catch Exception e))) - (is (= :Throwable - (runner - (try - (pause 5) - (throw (new Throwable)) - (catch Exception _e - :Exception) - (catch Throwable _t - :Throwable)))))) - (testing "finally shouldn't change the return value" - (is (= 1 (runner (try 1 (finally (pause 2))))))) - (testing "exception handlers stack" - (is (= "eee" - (runner - (try - (try - (try - (throw (pause (Exception. "e"))) - (catch Exception e - (pause (throw (Exception. (str (.getMessage e) "e")))))) - (catch Exception e - (throw (throw (Exception. (str (.getMessage e) "e")))))) - (catch Exception e - (.getMessage e))))))) - (testing "exception handlers and the class hierarchy" - (is - (runner - (try - (pause 10) - (throw (RuntimeException.)) - (catch RuntimeException _r - (pause true)) - (catch Exception _e - (pause false))))) - (is - (runner - (try - (pause 10) - (throw (RuntimeException.)) - (catch Exception _e - (pause true)))))) - (testing "don't explode trying to compile this" - (is - (runner - (try - true - (catch Exception e - (pause 1) - e)))))) - - -(defmacro locals-test [] - (if (if (contains? &env :locals) - (get (:locals &env) 'x) - (get &env 'x)) - :pass - :fail)) - - -(deftest runner-tests - (testing "macros add locals to the env" - (is (= :pass - (runner (let [x 42] - (pause (locals-test))))))) - (testing "fn as first arg in sexpr" - (is (= 42 - (runner ((fn [] 42)))))) - (testing "do blocks" - (is (= 42 - (runner (do (pause 42))))) - (is (= 42 - (runner (do (pause 44) - (pause 42)))))) - (testing "if expressions" - (is (= true - (runner (if (pause true) - (pause true) - (pause false))))) - (is (= false - (runner (if (pause false) - (pause true) - (pause false))))) - (is (= true - (runner (when (pause true) - (pause true))))) - (is (= nil - (runner (when (pause false) - (pause true)))))) - - (testing "dot forms" - (is (= 42 (runner (. Long (parseLong "42"))))) - (is (= 42 (runner (. Long parseLong "42"))))) - - (testing "quote" - (is (= '(1 2 3) - (runner (pause '(1 2 3)))))) - - (testing "loop expressions" - (is (= 100 - (runner (loop [x 0] - (if (< x 100) - (recur (inc (pause x))) - (pause x)))))) - (is (= 100 - (runner (loop [x (pause 0)] - (if (< x 100) - (recur (inc (pause x))) - (pause x)))))) - (is (= [:b :a] - (runner (loop [a :a b :b n 1] - (if (pos? n) - (recur b a (dec n)) ;; swap bindings - [a b]))))) - (is (= 1 - (runner (loop [x 0 - y (inc x)] - y))))) - - (testing "let expressions" - (is (= 3 - (runner (let [x 1 y 2] - (+ x y)))))) - - (testing "vector destructuring" - (is (= 3 - (runner (let [[x y] [1 2]] - (+ x y)))))) - - (testing "hash-map destructuring" - (is (= 3 - (runner (let [{:keys [x y] x2 :x y2 :y :as foo} {:x 1 :y 2}] - (assert (and foo (pause x) y x2 y2 foo)) - (+ x y)))))) - - (testing "hash-map literals" - (is (= {:1 1 :2 2 :3 3} - (runner {:1 (pause 1) - :2 (pause 2) - :3 (pause 3)})))) - (testing "hash-set literals" - (is (= #{1 2 3} - (runner #{(pause 1) - (pause 2) - (pause 3)})))) - (testing "vector literals" - (is (= [1 2 3] - (runner [(pause 1) - (pause 2) - (pause 3)])))) - - (testing "keywords as functions" - (is (= :bar - (runner (:foo (pause {:foo :bar})))))) - - (testing "vectors as functions" - (is (= 2 - (runner ([1 2] 1))))) - - (testing "dotimes" - (is (= 42 (runner - (dotimes [x 10] - (pause x)) - 42)))) - - (testing "fn closures" - (is (= 42 - (runner - (let [x 42 - _ (pause x) - f (fn [] x)] - (f)))))) - - (testing "lazy-seqs in bodies" - (is (= nil - (runner - (loop [] - (when-let [x (pause 10)] - (pause (vec (for [i (range x)] - i))) - (if-not x - (recur)))))))) - - (testing "specials cannot be shadowed" - (is (= 3 - (let [let* :foo] (runner (let* [x 3] x)))))) - - (testing "case" - (is (= 43 - (runner - (let [value :bar] - (case value - :foo (pause 42) - :bar (pause 43) - :baz (pause 44)))))) - (is (= :default - (runner - (case :baz - :foo 44 - :default)))) - (is (= nil - (runner - (case true - false false - nil)))) - (is (= 42 - (runner - (loop [x 0] - (case (int x) - 0 (recur (inc x)) - 1 42)))))) - - (testing "try" - (is (= 42 - (runner - (try 42 - (catch Throwable ex ex))))) - (is (= 42 - (runner - (try - (assert false) - (catch Throwable ex 42))))) - - (let [a (atom false) - v (runner - (try - true - (catch Throwable _ex false) - (finally (pause (reset! a true)))))] - (is (and @a v))) - - (let [a (atom false) - v (runner - (try - (assert false) - (catch Throwable _ex true) - (finally (reset! a true))))] - (is (and @a v))) - - (let [a (atom false) - v (try (runner - (try - (assert false) - (finally (reset! a true)))) - (catch Throwable ex ex))] - (is (and @a v))) - - - (let [a (atom 0) - v (runner - (try - (try - 42 - (finally (swap! a inc))) - (finally (swap! a inc))))] - (is (= @a 2))) - - (let [a (atom 0) - v (try (runner - (try - (try - (throw (AssertionError. 42)) - (finally (swap! a inc))) - (finally (swap! a inc)))) - (catch AssertionError ex ex))] - (is (= @a 2))) - - (let [a (atom 0) - v (try (runner - (try - (try - (throw (AssertionError. 42)) - (catch Throwable ex (throw ex)) - (finally (swap! a inc))) - (catch Throwable ex (throw ex)) - (finally (swap! a inc)))) - (catch AssertionError ex ex))] - (is (= @a 2))) - - (let [a (atom 0) - v (try (runner - (try - (try - (throw (AssertionError. (pause 42))) - (catch Throwable ex (pause (throw ex))) - (finally (pause (swap! a inc)))) - (catch Throwable ex (pause (throw ex))) - (finally (pause (swap! a inc))))) - (catch AssertionError ex ex))] - (is (= @a 2))))) - - - (defn identity-chan - "Defines a channel that contains the given value" - [x] - (to-chan! [x])) - - (deftest async-test - (testing "values are returned correctly" - (is (= 10 - (! c (! c :foo) 42)] - [(!! c :foo) - (! c :foo) - (>! c :bar) - (>! c :baz) - - (>! c :boz) - (! c (! c :foo) 42)] +;; [(!! c :foo) +;; (! c :foo) +;; (>! c :bar) +;; (>! c :baz) + +;; (>! c :boz) +;; (!! ch v) (close! ch))) -(deftest test-sizes +#_(deftest test-sizes (are [n size] (let [r (range size)] (and @@ -40,7 +40,7 @@ 20 10 5 1000)) -(deftest test-close? +#_(deftest test-close? (doseq [pf [pipeline pipeline-blocking]] (let [cout (chan 1)] (pf 5 cout identity-mapping (to-chan! [1]) true) @@ -57,7 +57,7 @@ (>!! cout :more) (is (= :more (!! ch i)) (close! ch))) -(deftest test-af-multiplier +#_(deftest test-af-multiplier (is (= [0 0 1 0 1 2 0 1 2 3] (pipeline-tester pipeline-async 2 (range 1 5) multiplier-async)))) (def sleep-mapping (mapping #(do (Thread/sleep %) %))) -(deftest test-blocking +#_(deftest test-blocking (let [times [2000 50 1000 100]] (is (= times (pipeline-tester pipeline-blocking 2 times sleep-mapping))))) (defn slow-fib [n] (if (< n 2) n (+ (slow-fib (- n 1)) (slow-fib (- n 2))))) -(deftest test-compute +#_(deftest test-compute (let [input (take 50 (cycle (range 15 38)))] (is (= (slow-fib (last input)) (last (pipeline-tester pipeline 8 input (mapping slow-fib))))))) -(deftest test-async +#_(deftest test-async (is (= (range 1 101) (pipeline-tester pipeline-async 1 (range 100) (fn [v ch] (future (>!! ch (inc v)) (close! ch)))))))