Skip to content

@kentfredric /gist:529083
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
07:33:44< Mithaldu> is it just me or does Test::Class fight subclassing nail and tooth?
07:33:58< rjbs> just you, I think
07:34:05< Mithaldu> alright
07:34:20< Mithaldu> how do i subclass _run_method? :/
07:34:32< rjbs> presumably you don't.
07:34:45< rjbs> the _ means it's private, and subclassing that stuff is usually a bad idea, because it isn't meant for anybody else to think about
07:34:54< rjbs> probably the interface needs to be clarified, documented.
07:35:04< Mithaldu> i'm trying to make it wrap any "Tests"-marked sub in subtests from Test::More
07:35:43< Mithaldu> and that's basically the only point where i can see that happening :/
07:36:29< Mithaldu> hmm, or i just rewrite the namespace of my test class
07:36:32< Mithaldu> nasty, but welp
07:38:47< kentnl> Mithaldu: even the author of T/C just calls "subtest" in a method =(
07:39:16< Mithaldu> woo :/
07:39:38< kentnl> and attribute decorated methods suck imo
07:40:10< Mithaldu> i don't have an opinion there really
07:40:15< Mithaldu> i just need to get a job done
07:58:15< Mithaldu> ok, subtests working
07:58:18< stephan48> and tbh i never finished the campaigns without cheats ;)
07:58:21< Mithaldu> let's see how we can sprice this up
07:58:24< Mithaldu> *spruce
08:06:47< Mithaldu> http://gist.github.com/527670
08:06:48< dipsy> [ gist: 527670 - GitHub ]
08:06:52< Mithaldu> thoughts?
08:21:10< kentnl> mmmm. Tits.
08:21:18< kentnl> Oh, you mean thoughts on your *link*
08:21:28< Mithaldu> :p
08:21:51 * rafl sees attrs and runs
08:22:49< kentnl> My head hurts =(
08:22:57< kentnl> How does one use this?
08:23:15< Mithaldu> use parent 'Test::Class::Subtest';
08:23:20< kentnl> things are easier to understand when coupled with API usage examples. =)
08:23:22< Mithaldu> sub overrides_basic : Subtest {
08:23:25< Mithaldu> alternatively
08:23:30< Mithaldu> sub overrides_no_profile : Subtest(configuration overrides work if all no profile is given) {
08:24:07< Mithaldu> i guess i'm just too used to munging the symbol table at this point
08:24:41< kentnl> how does it know what its a subtest *of* ?
08:24:43< Mithaldu> either ways, the api is really simple, it works just like
08:24:59< Mithaldu> sub subname : Tests {
08:25:03< Mithaldu> in Test::Class
08:25:14< Mithaldu> only it wraps the sub in Test::More's subtest
08:25:23< Mithaldu> it's not a subtest of something :)
08:25:26< Mithaldu> sec
08:25:41< Mithaldu> http://search.cpan.org/~mschwern/Test-Simple-0.96/lib/Test/More.pm
08:25:42< dipsy> [ Test::More - search.cpan.org ]
08:25:44< Mithaldu> ctrl+f subtest there
08:27:29< Mithaldu> ugh, i dumb
08:27:44< kentnl> the thing is, test-more's 'subtest' *is* a subtest of something
08:28:05 * kentnl wrote something that used subtest so I get it =)
08:28:13< Mithaldu> i read it more as grouping something else
08:28:21< kentnl> you can do subtest inside a subtest, and it indents further
08:28:21< Mithaldu> either ways, i don't understand your question then
08:28:39< kentnl> and each subtest is a single test to its parent context
08:29:02< Mithaldu> uh
08:29:07< Mithaldu> let me put it like this:
08:29:16< Mithaldu> http://stackoverflow.com/questions/3496544/is-there-a-way-to-have-testclasss-tests-subs-always-act-like-testmores-su
08:29:19< dipsy> urgh. long url. Try http://tinyurl.com/27v3fxx
08:29:19< dipsy> [ Is there a way to have Test::Class's "Tests" subs always act like Test::More's subtests? - Stack Overflow ]
08:30:18< kentnl> ok 1 - overrides_basic # one test in the parent context =)
08:30:35< Mithaldu> yeah
08:30:48< Mithaldu> with all tests inside the sub being subtests of it
08:31:21< kentnl> if you're just wanting to say "this one test method contains multiple tests" then something other than "subtests" should be used imo, becuase its confusing
08:31:52< Mithaldu> um
08:32:05< kentnl> because I had thought you'd be doing lots of sub foo : Subtest { ok( ) } and expecting them to be magically grouped under a parent somehow
08:32:06< Mithaldu> my api is exactly like the api for subtest in Test::More
08:32:19< Mithaldu> no
08:32:26< Mithaldu> i just want it to work exactly the same
08:32:37< Mithaldu> just by ATTR instead of directly
08:33:56< Mithaldu> i'm sorry, i'm really trying to understand, but i don't get your line of thinking
08:36:47< kentnl> to my line of thought, sub foo :Test { } should contain only 1 test.
08:37:07< Mithaldu> that is still as it is
08:37:07< kentnl> and likewise, sub foo :SubTest { } one test also
08:37:23< Mithaldu> why?
08:37:24< dipsy> because
08:37:36< kentnl> becuase thats how its parent acts =)
08:37:38< Mithaldu> Test::More::subtest contains multiple tests too?
08:37:42< kentnl> 1 test vs 1 subtest
08:37:49< kentnl> they're the same concept
08:37:56< kentnl> 1 test can have many subtests
08:38:07< kentnl> 1 subtest can have many subtests
08:38:12< Mithaldu> so you're saying it should be subtests?
08:38:33< kentnl> possibly. :TestGroup would probably be more obvious.
08:39:01< kentnl> Its explicit in what it does.
08:39:13< Mithaldu> hmmm
08:39:21< Mithaldu> you got a point there
08:39:32< Mithaldu> oh well, why not
08:40:20< kentnl> its just "subtests" suggests "we are under something" and that "something" is not obvious =)
08:40:43< Mithaldu> you're saying the original subtest api is badly named, right? :)
08:41:26< kentnl> in the context of Test::More its fine, because one file contains many tests, and thus a "subtest" makes sence in that context
08:41:34< Mithaldu> um
08:41:38< Mithaldu> test class works the same
08:41:47< Mithaldu> you have many tests in each class
08:41:54< kentnl> yes, but its different =)
08:42:03< Mithaldu> aaaaaaaaaaaaaaaaaaaaaaaaa
08:42:10< kentnl> the scope of each sub is your 'scope' now
08:42:22< kentnl> previously your scope was the whole .t file
08:42:32< Mithaldu> well
08:42:38< Mithaldu> there's the problem
08:42:55< Mithaldu> if you look at the output of a Test::Class test, they aren't scoped to subs
08:43:01< Mithaldu> they're scoped to the class itself
08:43:31< Mithaldu> it doesn't even reset the number counts between subs
08:44:05< kentnl> :(
08:44:29< Mithaldu> that's why i was all :< and went and wrote a terrible module that uses symbol table munging :p
08:44:44< Mithaldu> ps: want to see real horror?
08:45:01< kentnl> not sure >_>
08:47:01< Mithaldu> uploading it, just because i did not yet
08:49:24< Mithaldu> http://gist.github.com/527740
08:49:25< dipsy> [ gist: 527740 - GitHub ]
08:49:33< Mithaldu> the very short of it
08:50:45< Mithaldu> this lets you load ExporterModule in such a way that it copies all subs from $var::ExporterModule
08:51:03< Mithaldu> and $var can be changed at runtime and ExporterModule reloaded at runtime to get different subs
08:51:21< kentnl> O_o.
08:51:28< Mithaldu> i wrote this because someone wrote very very very dumb code and my solution was marginally less dumb
08:51:35< Mithaldu> (it did not break the perl debugger)
08:52:05 * kentnl wrote some insane Test::StructuredObject thing which pretty much makes your code into a lazy-executed AST. But its very nasty and I need a better way of doing it that doesn't kill me with parentheses
08:52:18< Mithaldu> what's an AST?
08:52:24< kentnl> AbstractSyntaxTree
08:52:26< Mithaldu> aside from a wooden stick
08:53:27 * kentnl has the criteria of "one line of code per test sub" which results in the cool property I can parse and reformat the test-code into a form thats serial in the event I have to run it on a Test::More without the subtests feature
08:53:31< Mithaldu> that structured thing looks interesting
08:54:03< kentnl> it does require you to do some weird things though.
08:54:47< kentnl> like for instance, because you can only have one loc per sub, you have to predeclare all the variables in advance and use them like registers >_>]
08:54:50< Mithaldu> i *think* i get the basic idea
08:55:01< Mithaldu> that sounds terrible :o
08:55:30< kentnl> it is interesting in what it makes you get out though. Sort of like using a template language encourages you to seperate concerns
08:55:40< kentnl> but I'm not entirely sure my approch is good yet =P
08:55:57< Mithaldu> i couldn't tell
08:56:03< Mithaldu> i'm not grokking it enough :)
08:56:10< kentnl> Yeah, Its poorly documented.
08:57:05< kentnl> It also has the advantage of doing it that way is you get a guaranteed expected test count.
08:57:26< kentnl> ie: without "Done testing" , and without counting them all yourself.
08:57:36< Mithaldu> not sure i care about that much
08:57:40< Mithaldu> i like done testing :)
08:57:59< Mithaldu> oh wait
08:58:03< Mithaldu> Test::StructuredObject IS from you
08:58:09< Mithaldu> i did not make that connection :D
08:58:10< kentnl> done testing is only nasty if you accidentally somehow run less tests than you expected youd run, you'll never see =)
08:58:13< kentnl> =)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.