2015-10-12 22:13 GMT+01:00 Phillip Lord > ERT is quite nice, but one of the things that I have found lacking is a > nice set of predicates, for use within should. > > So, when I wrote test for my "lentic" package I needed some functions > like, so that I could do things like: > > (should > (test-eq-after-this > "blah-before.txt" > "blah-after.txt" > (insert "hello"))) > > which opens "blah-before.txt" runs (insert "hello") then compares the > result with "blah-after.txt". I think that's a pretty specific use-case. So it's best to let people write their own macros for this. (defmacro should-eq-after-body (file-before file-after &rest body) `(let ((bef (with-temp-buffer (insert-file-contents file-before) ,@body (buffer-string)))) (should (string= bef (with-temp-buffer (insert-file-contents file-after) (buffer-string)))))) > My version of this also does a diff of the > results if the two are not equal. This certainly seems very useful. Maybe ert should do this on *all* multi-line string comparisons instead of doing its default “different-strings” report (which, most of the time, just says “strings are of different length”). > I've noticed that "puppet-mode" has some thing similar. For instance: > ... > > And julia-mode has indentation checking tests like so: > > ... > > My own experience is that these are actually quite hard to right. The > ones in lentic have never worked quite right -- that is, when it all > works they are fine, but restoring state after a crash doesn't always > work. Similarly, checking that, for example, test files are not already > open before a test is run interactively. Yes, there are many packages that use custom-deisgned temp-buffers for testing. In fact, most non-trivial packages do. I'd really like to see ert offer a common interface for this. The difficulty for that is that each package has very different needs when it comes to testing in buffers, so I have no idea what this common interface could be. > So, the point of my question is this; are there any good libraries > providing this kind of fixture logic? Don't know.