-
Notifications
You must be signed in to change notification settings - Fork 34
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
Automate code snippet tests #8
Comments
|
I think the main problem is most of the examples will be partial code, not fully complete (as otherwise it would bloat the faq too much), so there would need to be some other way of wrapping the code snippet with whatever was needed to make it into a test. So this may be a non-starter. |
Right - the code examples aren't themselves tests. What Test::Inline would let you do is: =pod
Here's how you get rid of newlines when reading a file:
while(<>) { # puts each line in $_
chomp; # $_ is implicit
# Now $_ lacks the newline at the end
}
=begin testing
open my $in, '<', __FILE__ or die "Couldn't open myself: $!";
while (<$in>) {
chomp;
unlike $_, qr/\n$/;
}
done_testing($.);
=done testing
=cut
So, you get to write your tests beside the FAQ they relate to. You still have to write stuff as a test. That block between begin testing and end testing gets extracted, put in a test script template so it has use strict, use Test::More etc, and then dumped in t/ (which could easily be automated with Dist::Zilla). I'm not sure how much better that is than putting the tests in t/ directly from the start. I guess with it in the POD, you're more likely to be reminded to update the test if you change the FAQs' answer? |
Ahh, this sounds good, we should try that going forward, Inline is much better than t/ as so many people may edit the file over time and it is easier to track. Would be good to check DZIL doesn't add any modules used in the tests as dependencies. We'd only want these tests to run before release, rather than during normal test/install. |
Run tests against the code snippets.
Moose::Manual apparently has some useful examples of doing this
The text was updated successfully, but these errors were encountered: