Skip to content

Commit 68a8d51

Browse files
authored
Updates for base test and debugging capture (#2)
Updates for base test and debugging capture
2 parents a830ef7 + bae6791 commit 68a8d51

File tree

5 files changed

+69
-8
lines changed

5 files changed

+69
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/testbox
2+
Solution.cfc
3+
SolutionTest.cfc

CodewarsBaseSpec.cfc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
component extends="testbox.system.BaseSpec" {
2+
/**
3+
* @aroundEach
4+
*/
5+
function captureOutput( spec, suite ){
6+
var out = '';
7+
savecontent variable="local.out" {
8+
try{
9+
arguments.spec.body();
10+
} catch( any e ) {
11+
var thisFailure = e;
12+
}
13+
}
14+
// make sure we debug any output, even on failure
15+
if( len( trim( local.out ) ) ) {
16+
debug( local.out )
17+
}
18+
if( !isNull( thisFailure ) ) {
19+
throw( thisFailure );
20+
}
21+
}
22+
23+
}

CodewarsReporter.cfc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ component {
2323
}
2424
}
2525

26+
var debugMap = prepareDebugBuffer( thisBundle.debugBuffer );
27+
2628
// Generate reports for each suite
2729
for ( var suiteStats in thisBundle.suiteStats ) {
28-
genSuiteReport( suiteStats = suiteStats, bundleStats = thisBundle, print = print );
30+
genSuiteReport( suiteStats = suiteStats, bundleStats = thisBundle, print = print, debugMap = debugMap );
2931
}
3032
}
3133
}
@@ -36,16 +38,24 @@ component {
3638
* @bundleStats Bundle stats
3739
* @print The print Buffer
3840
*/
39-
function genSuiteReport( required suiteStats, required bundleStats, required print ){
41+
function genSuiteReport( required suiteStats, required bundleStats, required print, debugMap={}, labelPrefix='' ){
42+
labelPrefix &= '/' & arguments.suiteStats.name;
4043
print.line( prependLF( "<DESCRIBE::>#arguments.suiteStats.name#" ) );
4144

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

49+
if( debugMap.keyExists( thisSpecLabel ) ) {
50+
print.line( debugMap[ thisSpecLabel ] )
51+
}
52+
4553
if ( local.thisSpec.status == "passed" ) {
4654
print.line( prependLF( "<PASSED::>Test Passed" ) );
4755
} else if ( local.thisSpec.status == "failed" ) {
4856
print.line( prependLF( "<FAILED::>#escapeLF( local.thisSpec.failMessage )#" ) );
57+
} else if ( local.thisSpec.status == "skipped" ) {
58+
print.line( prependLF( "<FAILED::>Test Skipped" ) );
4959
} else if ( local.thisSpec.status == "error" ) {
5060
print.line( prependLF( "<ERROR::>#escapeLF( local.thisSpec.error.message )#" ) );
5161

@@ -80,7 +90,7 @@ component {
8090
// Handle nested Suites
8191
if ( arguments.suiteStats.suiteStats.len() ) {
8292
for ( local.nestedSuite in arguments.suiteStats.suiteStats ) {
83-
genSuiteReport( local.nestedSuite, arguments.bundleStats, print )
93+
genSuiteReport( local.nestedSuite, arguments.bundleStats, print, debugMap, labelPrefix )
8494
}
8595
}
8696

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

108+
// Transofrm array of messages to struct keyed on message label containing an array of
109+
private function prepareDebugBuffer( array debugBuffer ) {
110+
return debugBuffer.reduce( ( debugMap={}, d )=> {
111+
debugMap[ d.label ] = debugMap[ d.label ] ?: '';
112+
debugMap[ d.label ] &= prependLF( isSimpleValue( d.data ) ? d.data : serialize( d.data ) );
113+
return debugMap;
114+
} ) ?: {};
115+
116+
}
117+
98118
}

TestRunner.cfc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ component {
77

88
function run(){
99
// Bootstrap TestBox framework
10-
filesystemUtil.createMapping( "/testbox", getCWD() & "/testbox" );
10+
filesystemUtil.createMapping( "/testbox", resolvepath( "testbox" ) );
1111

1212
// Create TestBox and run the tests
13-
testData = new testbox.system.TestBox()
13+
testData = new testbox.system.TestBox( options={ coverage : { enabled : false } } )
1414
.runRaw(
1515
directory = {
1616
// Find all CFCs in this directory that ends with Test.
1717
mapping : filesystemUtil.makePathRelative( getCWD() ),
1818
recurse : false,
1919
filter = function( path ){
20-
return path.reFindNoCase( "Test.cfc$" );
20+
return path.reFindNoCase( "Test\.cfc$" );
2121
}
2222
}
2323
)
24-
.getMemento();
24+
.getMemento( includeDebugBuffer=true );
2525

26-
createObject( "CodewarsReporter" ).render( print, testData );
26+
new CodewarsReporter().render( print, testData );
2727

2828
// Flush the buffer
2929
print.toConsole();

box.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name":"testbox-codewars",
3+
"version":"1.0.0",
4+
"slug":"testbox-codewars",
5+
"createPackageDirectory":false,
6+
"shortDescription":"Custom reporter and runner for TestBox",
7+
"type":"projects",
8+
"dependencies":{
9+
"testbox":"^3.1.0+339"
10+
},
11+
"installPaths":{
12+
"testbox":"testbox/"
13+
},
14+
"scripts":{}
15+
}

0 commit comments

Comments
 (0)