From a88af8b83ca008c4d5c8c947f1c2c7fea017d3e4 Mon Sep 17 00:00:00 2001 From: Brad Wood Date: Thu, 30 Jan 2020 22:19:21 -0600 Subject: [PATCH 1/5] Updates for base test and debugging captuire --- .gitignore | 3 +++ CodewarsBaseSpec.cfc | 14 ++++++++++++++ CodewarsReporter.cfc | 26 +++++++++++++++++++++++--- TestRunner.cfc | 10 +++++----- box.json | 15 +++++++++++++++ 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 CodewarsBaseSpec.cfc create mode 100644 box.json 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..3b2eccf --- /dev/null +++ b/CodewarsBaseSpec.cfc @@ -0,0 +1,14 @@ +component extends="testbox.system.BaseSpec" { + /** + * @aroundEach + */ + function captureOutput( spec, suite ){ + savecontent variable="local.out" { + arguments.spec.body(); + } + if( len( trim( local.out ) ) ) { + debug( local.out ) + } + } + +} \ No newline at end of file diff --git a/CodewarsReporter.cfc b/CodewarsReporter.cfc index 223c777..95cd04f 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( "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..ac2fadf --- /dev/null +++ b/box.json @@ -0,0 +1,15 @@ +{ + "name":"testbox-codewars", + "version":"1.0.0", + "slug":"testbox-codewars", + "createPackgeDirectory":false, + "shortDescription":"Custom reporter and runner for TestBox", + "type":"projects", + "dependencies":{ + "testbox":"^3.1.0+339" + }, + "installPaths":{ + "testbox":"testbox/" + }, + "scripts":{} +} From dc3b25422ebdfa2e67dbbc94a8652657d110bb0a Mon Sep 17 00:00:00 2001 From: Brad Wood Date: Thu, 30 Jan 2020 22:25:35 -0600 Subject: [PATCH 2/5] typo --- box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box.json b/box.json index ac2fadf..9fcf582 100644 --- a/box.json +++ b/box.json @@ -2,7 +2,7 @@ "name":"testbox-codewars", "version":"1.0.0", "slug":"testbox-codewars", - "createPackgeDirectory":false, + "createPackageDirectory":false, "shortDescription":"Custom reporter and runner for TestBox", "type":"projects", "dependencies":{ From 61f4b592fb1bff4fdb7200d85df9a696ec1b2f21 Mon Sep 17 00:00:00 2001 From: Brad Wood Date: Thu, 30 Jan 2020 22:34:49 -0600 Subject: [PATCH 3/5] Still fail on skip --- CodewarsReporter.cfc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CodewarsReporter.cfc b/CodewarsReporter.cfc index 95cd04f..ae9ec03 100644 --- a/CodewarsReporter.cfc +++ b/CodewarsReporter.cfc @@ -55,7 +55,8 @@ component { } else if ( local.thisSpec.status == "failed" ) { print.line( prependLF( "#escapeLF( local.thisSpec.failMessage )#" ) ); } else if ( local.thisSpec.status == "skipped" ) { - print.line( prependLF( "Skipped" ) ); + print.line( prependLF( "Skipped" ) ); + print.line( prependLF( "Test skipped" ) ); } else if ( local.thisSpec.status == "error" ) { print.line( prependLF( "#escapeLF( local.thisSpec.error.message )#" ) ); From f77f1f29d60f1aa84cd1b951cf0e89daa5466752 Mon Sep 17 00:00:00 2001 From: Brad Wood Date: Thu, 30 Jan 2020 23:50:46 -0600 Subject: [PATCH 4/5] Change skip to show failure --- CodewarsReporter.cfc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CodewarsReporter.cfc b/CodewarsReporter.cfc index ae9ec03..a1d4c02 100644 --- a/CodewarsReporter.cfc +++ b/CodewarsReporter.cfc @@ -55,8 +55,7 @@ component { } else if ( local.thisSpec.status == "failed" ) { print.line( prependLF( "#escapeLF( local.thisSpec.failMessage )#" ) ); } else if ( local.thisSpec.status == "skipped" ) { - print.line( prependLF( "Skipped" ) ); - print.line( prependLF( "Test skipped" ) ); + print.line( prependLF( "Test Skipped" ) ); } else if ( local.thisSpec.status == "error" ) { print.line( prependLF( "#escapeLF( local.thisSpec.error.message )#" ) ); From bae6791c6edd0bd426f81e0bce1f996f9c8129a3 Mon Sep 17 00:00:00 2001 From: Brad Wood Date: Thu, 30 Jan 2020 23:57:19 -0600 Subject: [PATCH 5/5] make sure we debug any output, even on failure --- CodewarsBaseSpec.cfc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/CodewarsBaseSpec.cfc b/CodewarsBaseSpec.cfc index 3b2eccf..9cd7b9e 100644 --- a/CodewarsBaseSpec.cfc +++ b/CodewarsBaseSpec.cfc @@ -3,12 +3,21 @@ component extends="testbox.system.BaseSpec" { * @aroundEach */ function captureOutput( spec, suite ){ - savecontent variable="local.out" { - arguments.spec.body(); - } - if( len( trim( local.out ) ) ) { - debug( local.out ) - } + 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