diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e336f52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/testbox +Solution.cfc +SolutionTest.cfc \ No newline at end of file diff --git a/CodewarsBaseSpec.cfc b/CodewarsBaseSpec.cfc new file mode 100644 index 0000000..9cd7b9e --- /dev/null +++ b/CodewarsBaseSpec.cfc @@ -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 ); + } + } + +} \ No newline at end of file diff --git a/CodewarsReporter.cfc b/CodewarsReporter.cfc index 223c777..a1d4c02 100644 --- a/CodewarsReporter.cfc +++ b/CodewarsReporter.cfc @@ -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 ); } } } @@ -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( "#arguments.suiteStats.name#" ) ); for ( local.thisSpec in arguments.suiteStats.specStats ) { + var thisSpecLabel = labelPrefix & '/' & local.thisSpec.name; print.line( prependLF( "#local.thisSpec.name#" ) ); + if( debugMap.keyExists( thisSpecLabel ) ) { + print.line( debugMap[ thisSpecLabel ] ) + } + if ( local.thisSpec.status == "passed" ) { print.line( prependLF( "Test Passed" ) ); } else if ( local.thisSpec.status == "failed" ) { print.line( prependLF( "#escapeLF( local.thisSpec.failMessage )#" ) ); + } else if ( local.thisSpec.status == "skipped" ) { + print.line( prependLF( "Test Skipped" ) ); } else if ( local.thisSpec.status == "error" ) { print.line( prependLF( "#escapeLF( local.thisSpec.error.message )#" ) ); @@ -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 ) } } @@ -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; + } ) ?: {}; + + } + } diff --git a/TestRunner.cfc b/TestRunner.cfc index 7616102..65c2246 100644 --- a/TestRunner.cfc +++ b/TestRunner.cfc @@ -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(); diff --git a/box.json b/box.json new file mode 100644 index 0000000..9fcf582 --- /dev/null +++ b/box.json @@ -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":{} +}