Arc Forumnew | comments | leaders | submitlogin
Re-announcing my unit test library for arc (bitbucket.org)
3 points by zck 4137 days ago | 6 comments


3 points by fallintothis 4136 days ago | link

Note that assert-same requires the expected value before the test-value. This is needed for pretty, pretty messages when the assert fails:

Maybe I'm just tired, but I first took this to mean that it was impossible for assert-same to be defined so that its arguments were (actual expected (o fail-message)). Now I realize that you just mean the positions of your expected/actual values are important.

One design thought: the name assert isn't taken by Arc. You could simplify the interface while generalizing it by just separating assert from the things it's asserting.

So, the basic assert would essentially be assert-t, and the other three could follow. Something like

  (assert-t actual (o fail-message))
  ; becomes
  (assert actual (o fail-message))
  ; or, without the custom message
  (assert actual)

  (assert-nil actual (o fail-message)) 
  ; becomes
  (assert (no actual) (o fail-message))
  ; or, without the custom message
  (assert:no actual)

  (assert-error actual (o expected-error))
  ; becomes
  (assert (error actual (o expected-error)) (o fail-message))
  ; or, without the custom message
  (assert:error actual (o expected-error))

  (assert-same expected actual (o fail-message))
  ; becomes
  (assert (same expected actual) (o fail-message))
  ; or, without the custom message
  (assert:same expected actual)
Then, you define error and same to "do the right things". same would probably need to throw an error when the arguments were mismatched, so that you could generate the nice message---assuming that assert would catch errors and report them as failures. error would be easy to define. Maybe something like

  (mac assert (condition (o fail-message))
    `(on-err (fn (c) ...fail...)
             (fn () (unless ,condition ...fail...))))

  (mac same (expected actual)
    (w/uniq (e a)
      `(with (,e ,expected ,a ,actual)
         (or (iso-that-works-on-hash-tables ,e ,a)
             (err "" ',actual 'returned ,a 'wanted ,e))))) ; modulo prettiness

  (mac error (expr (o expected-error))
    `(on-err (fn (c) ...pass, modulo expected-error...)
             (fn () ,expr ...fail if we get here without an error...)))
Solid work, though!

-----

2 points by zck 4136 days ago | link

Thanks for the feedback, both here and on the bug in the bitbucket tracker.

I'm not sure of my feelings on changing all the asserts to be just one. On one hand, it is simpler to have just the one command. On the other, it seems like a much more complicated interface, as you would never guess how to use it from, for example, the method signature. assert-t, assert-same et. al. seem like a lower conceptual load.

It reminds me of the arguments over CL's loop macro -- who knows all of it? I can never remember how to do much of what I want. Of course, this is much simpler than loop. Maybe I'll implement it and see how it feels.

-----

2 points by zck 4137 days ago | link

I've mentioned my unit test library before (http://arclanguage.org/item?id=17922), but now I think it's pretty much ready for prime time. It reports results nicely (if verbosely), and you can run decent subsets of your tests. It even has a README!

One thing that fell out of this is that there's no built-in way that I know of to check hashes for equality in Arc. Even `iso` doesn't do it (https://bitbucket.org/zck/unit-test.arc/issue/18/make-assert...). So I wrote a way (https://bitbucket.org/zck/unit-test.arc/commits/a007eb6491c3...).

The only big thing that I really want to do for usability right now is to not have a ton of lines of "test X passed!" (https://bitbucket.org/zck/unit-test.arc/issue/20/optionally-...).

I'd love to hear feedback, whether on this forum or by submitting a bug (https://bitbucket.org/zck/unit-test.arc/issues/new). This is a weird thing, but as I'm doing this project for Lisp In Summer Projects (http://lispinsummerprojects.org/), I'm supposed to do pretty much all the work myself. I'd love to take patches after the contest closes.

-----

2 points by zck 4137 days ago | link

Also notable about Lisp In Summer Projects is that 2% of the first 250 entries are in Arc: http://lispinsummerprojects.org/Stats

-----

1 point by akkartik 4137 days ago | link

Wow. Is there a way to see the other 4 projects?

-----

1 point by zck 4136 days ago | link

Well, one other one is brianru's oauth library (http://arclanguage.org/item?id=17925), but I don't think it's publicly released yet. Not to be too stalkeresque, but it's not on his Github (https://github.com/brianru?tab=repositories).

Lisp In Summer Projects hasn't made a list available that I know of. Certainly they will announce the winners; I don't know if they'll announce all the projects. Hopefully.

-----