Skip to content

Updates for base test and debugging capture #2

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

Merged
merged 5 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/testbox
Solution.cfc
SolutionTest.cfc
23 changes: 23 additions & 0 deletions CodewarsBaseSpec.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
component extends="testbox.system.BaseSpec" {
/**
* @aroundEach
*/
function captureOutput( spec, suite ){
var out = '';
savecontent variable="local.out" {
try{
arguments.spec.body();
} catch( any e ) {
var thisFailure = e;
}
}
// make sure we debug any output, even on failure
if( len( trim( local.out ) ) ) {
debug( local.out )
}
if( !isNull( thisFailure ) ) {
throw( thisFailure );
}
}

}
26 changes: 23 additions & 3 deletions CodewarsReporter.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ component {
}
}

var debugMap = prepareDebugBuffer( thisBundle.debugBuffer );

// Generate reports for each suite
for ( var suiteStats in thisBundle.suiteStats ) {
genSuiteReport( suiteStats = suiteStats, bundleStats = thisBundle, print = print );
genSuiteReport( suiteStats = suiteStats, bundleStats = thisBundle, print = print, debugMap = debugMap );
}
}
}
Expand All @@ -36,16 +38,24 @@ component {
* @bundleStats Bundle stats
* @print The print Buffer
*/
function genSuiteReport( required suiteStats, required bundleStats, required print ){
function genSuiteReport( required suiteStats, required bundleStats, required print, debugMap={}, labelPrefix='' ){
labelPrefix &= '/' & arguments.suiteStats.name;
print.line( prependLF( "<DESCRIBE::>#arguments.suiteStats.name#" ) );

for ( local.thisSpec in arguments.suiteStats.specStats ) {
var thisSpecLabel = labelPrefix & '/' & local.thisSpec.name;
print.line( prependLF( "<IT::>#local.thisSpec.name#" ) );

if( debugMap.keyExists( thisSpecLabel ) ) {
print.line( debugMap[ thisSpecLabel ] )
}

if ( local.thisSpec.status == "passed" ) {
print.line( prependLF( "<PASSED::>Test Passed" ) );
} else if ( local.thisSpec.status == "failed" ) {
print.line( prependLF( "<FAILED::>#escapeLF( local.thisSpec.failMessage )#" ) );
} else if ( local.thisSpec.status == "skipped" ) {
print.line( prependLF( "<FAILED::>Test Skipped" ) );
} else if ( local.thisSpec.status == "error" ) {
print.line( prependLF( "<ERROR::>#escapeLF( local.thisSpec.error.message )#" ) );

Expand Down Expand Up @@ -80,7 +90,7 @@ component {
// Handle nested Suites
if ( arguments.suiteStats.suiteStats.len() ) {
for ( local.nestedSuite in arguments.suiteStats.suiteStats ) {
genSuiteReport( local.nestedSuite, arguments.bundleStats, print )
genSuiteReport( local.nestedSuite, arguments.bundleStats, print, debugMap, labelPrefix )
}
}

Expand All @@ -95,4 +105,14 @@ component {
return "#chr( 10 )##text#";
}

// Transofrm array of messages to struct keyed on message label containing an array of
private function prepareDebugBuffer( array debugBuffer ) {
return debugBuffer.reduce( ( debugMap={}, d )=> {
debugMap[ d.label ] = debugMap[ d.label ] ?: '';
debugMap[ d.label ] &= prependLF( isSimpleValue( d.data ) ? d.data : serialize( d.data ) );
return debugMap;
} ) ?: {};

}

}
10 changes: 5 additions & 5 deletions TestRunner.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ component {

function run(){
// Bootstrap TestBox framework
filesystemUtil.createMapping( "/testbox", getCWD() & "/testbox" );
filesystemUtil.createMapping( "/testbox", resolvepath( "testbox" ) );

// Create TestBox and run the tests
testData = new testbox.system.TestBox()
testData = new testbox.system.TestBox( options={ coverage : { enabled : false } } )
.runRaw(
directory = {
// Find all CFCs in this directory that ends with Test.
mapping : filesystemUtil.makePathRelative( getCWD() ),
recurse : false,
filter = function( path ){
return path.reFindNoCase( "Test.cfc$" );
return path.reFindNoCase( "Test\.cfc$" );
}
}
)
.getMemento();
.getMemento( includeDebugBuffer=true );

createObject( "CodewarsReporter" ).render( print, testData );
new CodewarsReporter().render( print, testData );

// Flush the buffer
print.toConsole();
Expand Down
15 changes: 15 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name":"testbox-codewars",
"version":"1.0.0",
"slug":"testbox-codewars",
"createPackageDirectory":false,
"shortDescription":"Custom reporter and runner for TestBox",
"type":"projects",
"dependencies":{
"testbox":"^3.1.0+339"
},
"installPaths":{
"testbox":"testbox/"
},
"scripts":{}
}