Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Interesting testing idea ...

by dragonchild (Archbishop)
on Jan 21, 2009 at 14:20 UTC ( #737829=perlmeditation: print w/replies, xml ) Need Help??

The idea comes from http://stuartsierra.com/2009/01/18/tests-are-code. It's a neat idea, probably best suited for functional programming where one-liners are the norm and not the exception. BUT ... I think we could do it in Perl. Something like:
use Test::With; sub foo : WithTests( 2 ) { my ($x, $y) = @_; return $x + y; } with_test { cmp_ok( foo( 4, 3 ), '==', 7 ); cmp_ok( foo( -6, 2 ), '==', -4 ); };
I'm not even sure if that syntax will work, but it looks appealing. :-)

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re: Interesting testing idea ...
by Corion (Pope) on Jan 21, 2009 at 14:23 UTC

    This is close-yet-different to the idea of Test::Inline, which lets you write your tests in POD directly after the code. I think I prefer Test::Inline's way of allowing a more elaborate test setup, for example setting up a database etc.. The advantage of your idea is that no other tools are required to extract the tests from the POD, but this means that everybody wanting to use your module needs Test::With installed, while the inline tests can be extracted before creating the distribution file.

Re: Interesting testing idea ...
by autarch (Hermit) on Jan 21, 2009 at 21:52 UTC

    I think to do this you'd either need a source filter (gah!) or Devel::Declare.

    As for whether it's a good idea. I don't know. I'm not a big fan of subroutine attributes, and your attribute seems redundant anyway. I think I'd prefer something more like this:

    sub foo { ... } is tested(2) { ... }

    That looks fairly 6-ish.

Re: Interesting testing idea ...
by artist (Parson) on Jan 31, 2009 at 19:13 UTC
    I like the idea. It's like test with the code itself. It eliminates the need of writing 'separate' tests. It also serve purpose of the intended code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://737829]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
[Corion]: Yay. FF now has u2f built-in (behind an about:config setting), so using an USB token to sign in actually works :)
[Corion]: So, it's not all bad with the new FF :)
[holli]: 2factor is a bit too much for me. i just use passwords like jhbn8789q27312laks dmaw98^
[moritz]: isn't there also some about:config setting to enable the old plugin API?
[Discipulus]: indeed, only the logo is nicer
[Corion]: moritz: Hmm, I doubt so, as I think they moved away from XUL and other UI stuff, which was used by most plugins I used
[Corion]: holli: I'm trying it out with Github and so far I don't dislike it. It's basically like an extra key I press to log in, which is an OK flow for Github
[Corion]: I haven't tried out recovery in case of a broken USB key though (even though I have three such U2F tokens lying around here)
[oiskuu]: randomly banging on the keyboard yields pretty poor entropy. much better to just base64 some /dev/random
moritz has a pass entry with recovery codes

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-11-20 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (293 votes). Check out past polls.

    Notices?