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
Get coverage from Mojolicious templates #31
Comments
To get proper line coverage of those templates, So the task is not for Devel::Cover, but instead a patch for Cc: @kraih |
There's a good chance the next version of Mojolicious will be using line directives. mojolicious/mojo@99b1521 |
Excellent. Then I'll leave this until the next version is out. |
After some nice coding by @kraih, the line numbers are placed correctly (the filename is something still being discussed). The problem now is that once D::C reads that template and has no idea what to do with it. In Mojolicious the template is read in, preprocessed into a Perl form (which we could hand off, this is also where the line numbers come in if I understand correctly) then evaled into a sub. Care is taken so that if there was lacking coverage in the sub, it would relate to the line in the original template. The question is, how can we tell D::C that the pre-evaled string form is related to the template file? If there is such a mechanism, then we are nearly there. If not, there might be no hope. |
There is no other trick than |
Are the line annotations still problematic in Mojolicious? As far as I can see, they are generated correctly for the templates I have tried. For instance, the template
generates the code #line 1 "tmpl/mojo/foo.html.ep"
package Mojo::Template::SandBox; use Mojo::Base -strict; sub { my $_O = ''; ; { $_O .= "\<ul\>\n";
for my $l ($lines) {
$_O .= "\ \ \ \ \<li\>";$_O .= scalar $l ;$_O .= "\<\/li\>\n";
}
$_O .= "\<\/ul\>\n";
#line 5 "tmpl/mojo/foo.html.ep"
; } $_O }; As far as I can tell, this matches the lines up correctly with the corresponding source file. |
The basic problem here is that Devel::Cover isn't seeing the code at all. A normal anonymous sub exists in the optree, so it will be found. And if you install your generated sub into the symbol table, it will be found. But an anonymous sub that doesn't exist at process end in any form will not be found. |
Add support for Devel::Cover in Mojo::Template, by monkey patching the compiled template into its own namespace. This way the previously-anonymous sub exists in the symbol table, and therefore Devel::Cover can see it. As suggested by @haarg in pjcj/Devel--Cover#31 A path attribute is also added, to provide the path to the template instead of using the name, which doesn't identify the template file.
mojolicious/mojo#956 has been closed to move the discussion elsewhere, but is there any progress here? I'm happy to keep this open until we get a solution or until it comes back to a Devel::Cover problem. I'm also happy to close it if the problem has been fixed, or if it can be fixed entirely within Mojolicious. |
As threatened :-) I am formally requesting the ability to test Mojolicious templates. I have learned more about them and might even be able to get either text of the parsed template or the compiled form (as a sub ref) when needed. I am opening this ticket to be a point of communication along this task.
The text was updated successfully, but these errors were encountered: