Skip to content

Commit

Permalink
TESTBOX-401 #resolve
Browse files Browse the repository at this point in the history
BoxLang CLI mode and Runner
  • Loading branch information
lmajano committed Sep 11, 2024
1 parent 2d72033 commit 603c0b1
Show file tree
Hide file tree
Showing 27 changed files with 55 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ WEB-INF
build/build.number
.artifacts
.tmp

# Harness Testers
bx/testbox
bx/grapher
cfml/testbox
20 changes: 20 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env boxlang

/**
* TestBox Runner for BoxLang
*/

executionPath = server.java.executionPath
testsDirectory = "tests.specs"
executionArgs = jsonDeserialize( server.java.executionArgs )

// No Arguments, execute the entire suite
testArgs = {}
if( executionArgs.isEmpty() ){
testArgs = {
"directory" : testsDirectory,
"recurse" : true
}
}

println( new testbox.system.TestBox( argumentCollection = testArgs ).run() )
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion bx/test-harness/Application.bx → bx/tests/Application.bx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class {
this.mappings[ "/tests" ] = getDirectoryFromPath( getCurrentTemplatePath() );
// The mapping to easily access the root application usually the parent folder
this.mappings[ "/root" ] = expandPath( "/../" );
//this.mappings[ "/testbox" ] = expandPath( "/../" );

// Any application settings go here

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file added bx/tests/specs/unit/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions bx/tests/test.bxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Run all the specs in the tests.specs directory and subdirectories
r = new testbox.system.TestBox( directory="tests.specs" )
println( r.run() )
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added cfml/tests/integration/.gitkeep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added cfml/tests/unit/.gitkeep
Empty file.
25 changes: 14 additions & 11 deletions system/TestBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ component accessors="true" {
// A list of globbing patterns to match bundles to test ONLY! Ex: *Spec|*Test
property name="bundlesPattern";

// Constants
// Static Variables
variables.TESTBOX_PATH = expandPath( "/testbox" );
variables.IS_BOXLANG = server.keyExists( "boxlang" );
variables.IS_CLI = !getFunctionList().keyExists( "getPageContext" );
variables.DEFAULT_REPORTER = variables.IS_CLI ? "text" : "simple";
variables.DEFAULT_BUNDLES_PATTERN = "*.bx|*.cfc";
// TestBox Info : Modified by the build process.
variables.VERSION = "@build.version@[email protected]@";
variables.CODENAME = "";

/**
* Constructor
Expand All @@ -51,18 +57,15 @@ component accessors="true" {
any bundles = [],
any directory = {},
any directories = {},
any reporter = "simple",
any reporter = variables.DEFAULT_REPORTER,
any labels = [],
any excludes = [],
struct options = {},
string bundlesPattern = "*.bx|*.cfc"
string bundlesPattern = variables.DEFAULT_BUNDLES_PATTERN
){
// TestBox version
variables.version = "@build.version@[email protected]@";
variables.codename = "";
// Bundles pattern
if ( !len( arguments.bundlesPattern ) ) {
arguments.bundlesPattern = "*.bx|*.cfc";
arguments.bundlesPattern = variables.DEFAULT_BUNDLES_PATTERN;
}
variables.bundlesPattern = arguments.bundlesPattern;
// Utility and mappings
Expand Down Expand Up @@ -203,10 +206,10 @@ component accessors="true" {
moduleRecord.moduleConfig.onLoad();
} catch ( any e ) {
moduleRecord.activationFailure = e;
writeDump(
var = "**** Error activating (#arguments.name#) TestBox Module: #e.message & e.detail#",
output = "console"
);
// writeDump(
// var = "**** Error activating (#arguments.name#) TestBox Module: #e.message & e.detail#",
// output = "console"
// );
}

return this;
Expand Down
13 changes: 13 additions & 0 deletions system/reports/BaseReporter.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ component {
* Helper method to deal with ACF2016's overload of the page context response, come on Adobe, get your act together!
*/
function getPageContextResponse(){
// If running in CLI mode, we don't have a page context
if( !getFunctionList().keyExists( "pageContext" ) ){
return {
"setContentType" : function(){
// do nothing
}
};
}

if ( server.keyExists( "coldfusion" ) && server.coldfusion.productName.findNoCase( "ColdFusion" ) ) {
return getPageContext().getResponse().getResponse();
} else {
Expand All @@ -28,6 +37,10 @@ component {
* Reset the HTML response
*/
function resetHTMLResponse(){
// If running in CLI mode, we don't have a page context
if( !getFunctionList().keyExists( "pageContext" ) ){
return;
}
// reset cfhtmlhead from integration tests
if ( structKeyExists( server, "lucee" ) ) {
try {
Expand Down

0 comments on commit 603c0b1

Please sign in to comment.