How to get REPL to recognize tests within a map?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a map defined as follows:



"Arcane Golem"
{:name "Arcane Golem"
:attack 4
:health 4
:mana-cost 3
:type :minion
:set :classic
:rarity :rare
:description "Battlecry: Give your opponent a Mana
Crystal."
:battlecry (fn battlecry [state minion]
{:test (fn
(as-> (create-game [{:minions [(create-minion "Arcane Golem" :id "ag")]}]) $
(battlecry $ (get-minion $ "ag"))
(contains? (get-in $[:players "p1" :hand]) "Mana Crystal")))}
(-> (get-opponent state (:id minion))
(:id)
(add-card-to-hand state (create-card "Mana Crystal"))))}


This map is itself a key-value pair in a larger map of maps called card-definitions. As you can see, I've written a test for battlecry function below; however, when I start REPL and run all tests in this maps' namespace, it says Ran 0 tests with 0 assertions. How can I get REPL to recognize this test?










share|improve this question





























    0















    I have a map defined as follows:



    "Arcane Golem"
    {:name "Arcane Golem"
    :attack 4
    :health 4
    :mana-cost 3
    :type :minion
    :set :classic
    :rarity :rare
    :description "Battlecry: Give your opponent a Mana
    Crystal."
    :battlecry (fn battlecry [state minion]
    {:test (fn
    (as-> (create-game [{:minions [(create-minion "Arcane Golem" :id "ag")]}]) $
    (battlecry $ (get-minion $ "ag"))
    (contains? (get-in $[:players "p1" :hand]) "Mana Crystal")))}
    (-> (get-opponent state (:id minion))
    (:id)
    (add-card-to-hand state (create-card "Mana Crystal"))))}


    This map is itself a key-value pair in a larger map of maps called card-definitions. As you can see, I've written a test for battlecry function below; however, when I start REPL and run all tests in this maps' namespace, it says Ran 0 tests with 0 assertions. How can I get REPL to recognize this test?










    share|improve this question

























      0












      0








      0








      I have a map defined as follows:



      "Arcane Golem"
      {:name "Arcane Golem"
      :attack 4
      :health 4
      :mana-cost 3
      :type :minion
      :set :classic
      :rarity :rare
      :description "Battlecry: Give your opponent a Mana
      Crystal."
      :battlecry (fn battlecry [state minion]
      {:test (fn
      (as-> (create-game [{:minions [(create-minion "Arcane Golem" :id "ag")]}]) $
      (battlecry $ (get-minion $ "ag"))
      (contains? (get-in $[:players "p1" :hand]) "Mana Crystal")))}
      (-> (get-opponent state (:id minion))
      (:id)
      (add-card-to-hand state (create-card "Mana Crystal"))))}


      This map is itself a key-value pair in a larger map of maps called card-definitions. As you can see, I've written a test for battlecry function below; however, when I start REPL and run all tests in this maps' namespace, it says Ran 0 tests with 0 assertions. How can I get REPL to recognize this test?










      share|improve this question














      I have a map defined as follows:



      "Arcane Golem"
      {:name "Arcane Golem"
      :attack 4
      :health 4
      :mana-cost 3
      :type :minion
      :set :classic
      :rarity :rare
      :description "Battlecry: Give your opponent a Mana
      Crystal."
      :battlecry (fn battlecry [state minion]
      {:test (fn
      (as-> (create-game [{:minions [(create-minion "Arcane Golem" :id "ag")]}]) $
      (battlecry $ (get-minion $ "ag"))
      (contains? (get-in $[:players "p1" :hand]) "Mana Crystal")))}
      (-> (get-opponent state (:id minion))
      (:id)
      (add-card-to-hand state (create-card "Mana Crystal"))))}


      This map is itself a key-value pair in a larger map of maps called card-definitions. As you can see, I've written a test for battlecry function below; however, when I start REPL and run all tests in this maps' namespace, it says Ran 0 tests with 0 assertions. How can I get REPL to recognize this test?







      clojure read-eval-print-loop






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 23:06









      lmotl3lmotl3

      15212




      15212
























          1 Answer
          1






          active

          oldest

          votes


















          2














          You can use with-test to define a function and a unit test at the same time



          ; with-test is the same as using {:test #((is...)(is...))} in the meta data of the function.

          (:use 'clojure.test)

          (with-test
          (defn my-function [x y]
          (+ x y))
          (is (= 4 (my-function 2 2)))
          (is (= 7 (my-function 3 4))))

          (test #'my-function) ;(test (var my-function))
          => :ok


          NOTE: When using with-test, the function must still be defined as a global var using defn (see example). An anonymous fn as the value of a map key will not be found by the testing machinery.



          What should work is to define the function as standalone var, and then include a reference to it in the map:



          {:battlecry my-function}    ; for example


          Having said that, most people (myself included) prefer to have a separate testing namespace to keep the tests from cluttering the source code. I like to organize them as:



          flintstones.core           ; main namespace
          tst.flintstones.core ; the unit test namespace


          These are then placed in ./src and ./test subdirs of the project dir:



          src/flintstones/core.clj            ; main namespace
          test/tst/flintstones/core.clj ; the unit tests


          But there are other possiblities. See also the Clojure Cookbook discussion on testing.






          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421697%2fhow-to-get-repl-to-recognize-tests-within-a-map%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You can use with-test to define a function and a unit test at the same time



            ; with-test is the same as using {:test #((is...)(is...))} in the meta data of the function.

            (:use 'clojure.test)

            (with-test
            (defn my-function [x y]
            (+ x y))
            (is (= 4 (my-function 2 2)))
            (is (= 7 (my-function 3 4))))

            (test #'my-function) ;(test (var my-function))
            => :ok


            NOTE: When using with-test, the function must still be defined as a global var using defn (see example). An anonymous fn as the value of a map key will not be found by the testing machinery.



            What should work is to define the function as standalone var, and then include a reference to it in the map:



            {:battlecry my-function}    ; for example


            Having said that, most people (myself included) prefer to have a separate testing namespace to keep the tests from cluttering the source code. I like to organize them as:



            flintstones.core           ; main namespace
            tst.flintstones.core ; the unit test namespace


            These are then placed in ./src and ./test subdirs of the project dir:



            src/flintstones/core.clj            ; main namespace
            test/tst/flintstones/core.clj ; the unit tests


            But there are other possiblities. See also the Clojure Cookbook discussion on testing.






            share|improve this answer






























              2














              You can use with-test to define a function and a unit test at the same time



              ; with-test is the same as using {:test #((is...)(is...))} in the meta data of the function.

              (:use 'clojure.test)

              (with-test
              (defn my-function [x y]
              (+ x y))
              (is (= 4 (my-function 2 2)))
              (is (= 7 (my-function 3 4))))

              (test #'my-function) ;(test (var my-function))
              => :ok


              NOTE: When using with-test, the function must still be defined as a global var using defn (see example). An anonymous fn as the value of a map key will not be found by the testing machinery.



              What should work is to define the function as standalone var, and then include a reference to it in the map:



              {:battlecry my-function}    ; for example


              Having said that, most people (myself included) prefer to have a separate testing namespace to keep the tests from cluttering the source code. I like to organize them as:



              flintstones.core           ; main namespace
              tst.flintstones.core ; the unit test namespace


              These are then placed in ./src and ./test subdirs of the project dir:



              src/flintstones/core.clj            ; main namespace
              test/tst/flintstones/core.clj ; the unit tests


              But there are other possiblities. See also the Clojure Cookbook discussion on testing.






              share|improve this answer




























                2












                2








                2







                You can use with-test to define a function and a unit test at the same time



                ; with-test is the same as using {:test #((is...)(is...))} in the meta data of the function.

                (:use 'clojure.test)

                (with-test
                (defn my-function [x y]
                (+ x y))
                (is (= 4 (my-function 2 2)))
                (is (= 7 (my-function 3 4))))

                (test #'my-function) ;(test (var my-function))
                => :ok


                NOTE: When using with-test, the function must still be defined as a global var using defn (see example). An anonymous fn as the value of a map key will not be found by the testing machinery.



                What should work is to define the function as standalone var, and then include a reference to it in the map:



                {:battlecry my-function}    ; for example


                Having said that, most people (myself included) prefer to have a separate testing namespace to keep the tests from cluttering the source code. I like to organize them as:



                flintstones.core           ; main namespace
                tst.flintstones.core ; the unit test namespace


                These are then placed in ./src and ./test subdirs of the project dir:



                src/flintstones/core.clj            ; main namespace
                test/tst/flintstones/core.clj ; the unit tests


                But there are other possiblities. See also the Clojure Cookbook discussion on testing.






                share|improve this answer















                You can use with-test to define a function and a unit test at the same time



                ; with-test is the same as using {:test #((is...)(is...))} in the meta data of the function.

                (:use 'clojure.test)

                (with-test
                (defn my-function [x y]
                (+ x y))
                (is (= 4 (my-function 2 2)))
                (is (= 7 (my-function 3 4))))

                (test #'my-function) ;(test (var my-function))
                => :ok


                NOTE: When using with-test, the function must still be defined as a global var using defn (see example). An anonymous fn as the value of a map key will not be found by the testing machinery.



                What should work is to define the function as standalone var, and then include a reference to it in the map:



                {:battlecry my-function}    ; for example


                Having said that, most people (myself included) prefer to have a separate testing namespace to keep the tests from cluttering the source code. I like to organize them as:



                flintstones.core           ; main namespace
                tst.flintstones.core ; the unit test namespace


                These are then placed in ./src and ./test subdirs of the project dir:



                src/flintstones/core.clj            ; main namespace
                test/tst/flintstones/core.clj ; the unit tests


                But there are other possiblities. See also the Clojure Cookbook discussion on testing.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '18 at 19:56

























                answered Nov 22 '18 at 1:10









                Alan ThompsonAlan Thompson

                14.4k22534




                14.4k22534
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421697%2fhow-to-get-repl-to-recognize-tests-within-a-map%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Guess what letter conforming each word

                    Port of Spain

                    Run scheduled task as local user group (not BUILTIN)