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

against-background around :contents forms are evaluated even when filtered out #417

Open
sbgreene1307 opened this issue Nov 11, 2017 · 2 comments

Comments

@sbgreene1307
Copy link

The functions in against-background around :contents are evaluated even when you filter out the tests when autotesting.

(fact-group :integration
                    (against-background
                         [(around :contents 
                              (let [] (println "Loading content wrapping functions.") ?form))]))

(midje.repl/autotest :filter (complement :integration))

The println will evaluate.

@philomates
Copy link
Collaborator

philomates commented Nov 13, 2017

I just took a dive into how against-background and the other background-changers work. They are pretty complicated and their syntax is a bit loose, in the sense that you have a few options as to how to use them, like you can do:

(fact
  (against-background [(f 1) => 2])
  (f 1) => 2)

or

(against-background [(f 1) => 2]
  (fact (f 1) => 2))

to similar effect.

Strangely, the second form doesn't run into the bug you've described, so I would recommend using that form for now.

You can also toy around using :facts or :checks instead of :contents as the first argument for around. They have different behavior, but also don't seem to encounter the bug.

Sorry that this is confusing, there are a few things surrounding background-changers that could be clearer, but making them so isn't easy given their current expressive power/complexity.

Fun note if anyone knows the answer, the following causes a stack overflow:

(macroexpand
  `(fact (against-background [(around :contents (do ?form (println "__")))]) 
     1 => 2))

while this works fine:

(macroexpand
  `(fact (against-background [(around :facts (do ?form (println "__")))]) 
     1 => 2))

@marick
Copy link
Owner

marick commented Nov 14, 2017

I want to apologize for the against-background form. I didn't spend enough "hammock time" on it, and the implementation suffered from being written by a novice Clojure person. Someone should think of a better abstraction.

That said, around :contents is particularly horrible. The other forms essentially attach before-and-after functions to whatever is within their lexical scope. (So you can do setup for many facts within the around form.) :contents just behaves differently, because it's not applied to recognizable sub-forms (fact...) but rather takes effect at the moment the Clojure interpreter sees it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants