Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with-redefs + wrap-with macros #123

Merged
merged 6 commits into from
May 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enabled
  • Loading branch information
caioaao committed May 18, 2020
commit 8e0aab2dfaba288e7173d4c02793d0ba561e7218
20 changes: 11 additions & 9 deletions test/state_flow/labs/state_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
[state-flow.labs.state :as labs.state]))

(defn- set-redefs-macro-feature-flag [v f]
(let [old-v labs.state/*with-redefs-macro-enabled*]
(alter-var-root #'labs.state/*with-redefs-macro-enabled* (constantly v))
(f)
(alter-var-root #'labs.state/*with-redefs-macro-enabled* old-v)))
(let [old-v labs.state/*with-redefs-macro-enabled*
_ (alter-var-root #'labs.state/*with-redefs-macro-enabled* (constantly v))
result (f)]
result))

(def with-redefs-macro-enabled (partial set-redefs-macro-feature-flag true))
(def with-redefs-macro-disabled (partial set-redefs-macro-feature-flag false))

(def flow-form `(labs.state/with-redefs [a 1, b 2] some-flow))

(deftest with-redefs-macro-test
(testing "if disabled, throws assertion warning user and giving instructions"
(deftest with-redefs-feature-flag-test
(testing "if disabled, macroexpansion throws assertion warning user and giving instructions"
(is (thrown? clojure.lang.Compiler$CompilerException
(with-redefs-macro-disabled (macroexpand flow-form))))
(is (try (with-redefs-macro-disabled (macroexpand flow-form))
(with-redefs-macro-disabled #(macroexpand flow-form))))
(is (try (with-redefs-macro-disabled #(macroexpand flow-form))
(catch clojure.lang.Compiler$CompilerException ex
(is (instance? java.lang.AssertionError (ex-cause ex)))
(is (-> ex ex-cause ex-message
(str/includes? "`with-redefs` usage is not recommended. If you know what you're doing and really want to continue, set `*with-redefs-macro-enabled*` to true"))))))))
(str/includes? "`with-redefs` usage is not recommended. If you know what you're doing and really want to continue, set `*with-redefs-macro-enabled*` to true")))))))
(testing "if enabled, macroexpansion works as expected"
(is (seq? (with-redefs-macro-enabled #(macroexpand flow-form))))))