Skip to content

Commit

Permalink
Error listings for unit tests
Browse files Browse the repository at this point in the history
This PR adds error listings above the unit test results, which makes it easier to spot failed tests (not only for people with red-green color blindness). Also it looks quite nice.

Depends on PR f3-factory/fatfree-core#64.
  • Loading branch information
Rayne committed May 31, 2015
1 parent 9a8f099 commit 63eaf10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ function beforeroute($f3) {
$f3->set('active',$f3->get('menu["'.$uri.'"]'));
}

function afterroute() {
function afterroute($f3) {
// Collect errors.
if ($results=$f3->get('results')) {
$f3->set('errors', array_reduce($results, function($carry, $item){
if (!$item['status']) $carry[]=$item;
return $carry;
}, array()));
}

echo \Preview::instance()->render('layout.htm');
}

Expand Down
20 changes: 17 additions & 3 deletions ui/layout.htm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,23 @@ <h1>{{ @VERSION }}</h1>
</div>
<div class="main">
<h1>{{ @active }}</h1>
{~ foreach (@results as @i=>@result): ~}
<p>
<span class="status {{ @result.status?'pass':'fail' }}">{{ @i+1 }}</span>

<h2 id="errors">Errors</h2>
{~ if (@errors): ~}
{~ foreach (@errors as @result): ~}
<p>
<span class="status fail"><a href="{{ @PATH }}#test-{{ @result.id }}">{{ @result.id }}</a></span>
<span class="text">{{ @result.text }} {~ if (@result.source) echo '('[email protected].')' ~}</span><br/>
</p>
{~ endforeach ~}
{~ else: ~}
<p>No errors.</p>
{~ endif ~}

<h2 id="tests">Tests</h2>
{~ foreach (@results as @result): ~}
<p id="test-{{ @result.id }}">
<span class="status {{ @result.status?'pass':'fail' }}">{{ @result.id }}</span>
<span class="text">{{ @result.text }} {~ if ([email protected] && @result.source) echo '('[email protected].')' ~}</span><br/>
</p>
{~ endforeach ~}
Expand Down

0 comments on commit 63eaf10

Please sign in to comment.