From a8623976d4cdbdb2ccb3fa8fee166132d689bf74 Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Sat, 7 Sep 2024 14:05:05 +0200 Subject: [PATCH] TESTBOX-394 new `test(), xtest(), ftest()` alias for more natuarl testing --- system/runners/BaseRunner.cfc | 6 ++ system/runners/UnitRunner.cfc | 40 ++++--- tests/index.cfm | 196 ++++++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+), 16 deletions(-) create mode 100644 tests/index.cfm diff --git a/system/runners/BaseRunner.cfc b/system/runners/BaseRunner.cfc index 224aa29..865a97e 100644 --- a/system/runners/BaseRunner.cfc +++ b/system/runners/BaseRunner.cfc @@ -223,6 +223,12 @@ component { if ( structKeyExists( getMetadata( arguments.target[ arguments.methodName ] ), "test" ) ) { return true; } + + // Skip: test, ftest, xtest which are internal methods + if ( reFindNoCase( "^(f|x)?test$", arguments.methodName ) ) { + return false; + } + // All xUnit test methods must start or end with the term, "test". return ( !!reFindNoCase( "(^test|test$)", arguments.methodName ) ); } diff --git a/system/runners/UnitRunner.cfc b/system/runners/UnitRunner.cfc index ac29efe..f97cbfc 100644 --- a/system/runners/UnitRunner.cfc +++ b/system/runners/UnitRunner.cfc @@ -386,26 +386,28 @@ component required testResults ){ var suite = { + // ID + "id" : hash( arguments.targetMD.name ), // suite name - name : ( + "name" : ( structKeyExists( arguments.targetMD, "displayName" ) ? arguments.targetMD.displayname : arguments.targetMD.name ), // async flag - asyncAll : ( structKeyExists( arguments.targetMD, "asyncAll" ) ? arguments.targetMD.asyncAll : false ), + "asyncAll" : ( structKeyExists( arguments.targetMD, "asyncAll" ) ? arguments.targetMD.asyncAll : false ), // skip suite testing flag - skip : ( + "skip" : ( structKeyExists( arguments.targetMD, "skip" ) ? ( len( arguments.targetMD.skip ) ? arguments.targetMD.skip : true ) : false ), // labels attached to the suite for execution - labels : ( + "labels" : ( structKeyExists( arguments.targetMD, "labels" ) ? listToArray( arguments.targetMD.labels ) : [] ), // the specs attached to this suite. - specs : getTestMethods( arguments.target, arguments.testResults ), - // the recursive suites - suites : [] + "specs" : getTestMethods( arguments.target, arguments.testResults ), + // nested suites + "suites" : [] }; // skip constraint for suite? @@ -423,7 +425,10 @@ component /** * Retrieve the testing methods/specs from a given target. * - * @target.hint The target to get the methods from + * @target The target to get the methods from + * @testResults The test results object + * + * @return An array of method specs */ private array function getTestMethods( required any target, required any testResults ){ var mResults = []; @@ -433,25 +438,28 @@ component for ( var thisMethod in methodArray ) { // only valid functions and test functions allowed if ( - isCustomFunction( arguments.target[ thisMethod ] ) && + ( isCustomFunction( arguments.target[ thisMethod ] ) || isClosure( arguments.target[ thisMethod ] ) ) + && isValidTestMethod( thisMethod, arguments.target ) ) { // Build the spec data packet var specMD = getMetadata( arguments.target[ thisMethod ] ); var spec = { - name : specMD.name, - hint : ( structKeyExists( specMD, "hint" ) ? specMD.hint : "" ), - skip : ( structKeyExists( specMD, "skip" ) ? ( len( specMD.skip ) ? specMD.skip : true ) : false ), - labels : ( structKeyExists( specMD, "labels" ) ? listToArray( specMD.labels ) : [] ), - order : ( structKeyExists( specMD, "order" ) ? listToArray( specMD.order ) : index++ ), - expectedException : ( + "id" : hash( specMD.name ), + "name" : specMD.name, + "hint" : ( structKeyExists( specMD, "hint" ) ? specMD.hint : "" ), + "skip" : ( structKeyExists( specMD, "skip" ) ? ( len( specMD.skip ) ? specMD.skip : true ) : false ), + "focused" : ( structKeyExists( specMD, "focused" ) ? ( len( specMD.focused ) ? specMD.focused : true ) : false ), + "labels" : ( structKeyExists( specMD, "labels" ) ? listToArray( specMD.labels ) : [] ), + "order" : ( structKeyExists( specMD, "order" ) ? listToArray( specMD.order ) : index++ ), + "expectedException" : ( structKeyExists( specMD, "expectedException" ) ? specMD.expectedException : "" ) }; // skip constraint? if ( !isBoolean( spec.skip ) && isCustomFunction( arguments.target[ spec.skip ] ) ) { - spec.skip = invoke( arguments.target, "#spec.skip#" ); + spec.skip = invoke( arguments.target, spec.skip ); } // do we have labels applied? diff --git a/tests/index.cfm b/tests/index.cfm new file mode 100644 index 0000000..f06be9b --- /dev/null +++ b/tests/index.cfm @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + // create reporters + reporters = [ "ANTJunit", "Console", "Codexwiki", "Doc", "Dot", "JSON", "JUnit", "Min", "Raw", "Simple", "Tap", "Text", "XML" ]; + ASSETS_DIR = expandPath( "/testbox/system/reports/assets" ); + + if( url.opt_run ){ + // Include the TestBox HTML Runner + include "/testbox/system/runners/HTMLRunner.cfm"; + abort; + } + + + + + + + + + TestBox Runner + + + + + + + + + + + + + + + +
+
+
+ +
+
+
+
+
+ + + +

TestBox Global Runner

+

Please use the form below to run test bundle(s), directories and more.

+
+ + +
+
+ + +
+
+ checked="true" /> + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ checked="true" /> + +
+
+
+ + +
+
+
+ checked="true" /> + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+
+
+
+ + +
+ + + + +