From 6e4313700f95b24913cebf9a63c0ba2a02f7b6f7 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 20 Mar 2021 13:22:33 +0100 Subject: [PATCH] Test macro [skip ci] --- test/babashka/bb_edn_test.clj | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index aa193920..01e47f47 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -12,15 +12,19 @@ :eof nil} (apply test-utils/bb nil (map str args)))) +(defmacro with-config [cfg & body] + `(let [temp-dir# (fs/create-temp-dir) + bb-edn-file# (fs/file temp-dir# "bb.edn")] + (spit bb-edn-file# ~cfg) + (binding [test-utils/*bb-edn-path* (str bb-edn-file#)] + ~@body))) + (deftest foobar-test (let [temp-dir (fs/create-temp-dir) - temp-file (fs/create-file (fs/path temp-dir "temp-file.txt")) - bb-edn-file (fs/file temp-dir "bb.edn") - bb-edn `{:tasks {:clean {:task/type :shell - :args ["rm" ~(str temp-file)]}}}] - (spit bb-edn-file bb-edn) - (is (fs/exists? temp-file)) - (binding [test-utils/*bb-edn-path* (str bb-edn-file)] - (bb :clean)) - (is (not (fs/exists? temp-file))))) + temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))] + (with-config {:tasks {:clean {:task/type :shell + :args ["rm" (str temp-file)]}}} + (is (fs/exists? temp-file)) + (bb :clean) + (is (not (fs/exists? temp-file))))))