Skip to content

Commit

Permalink
Changed how examples are tested
Browse files Browse the repository at this point in the history
  • Loading branch information
pfreitag committed Feb 26, 2018
1 parent 058cbec commit 5cd748d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
5 changes: 2 additions & 3 deletions tests/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ component {

this.mappings[ "/testbox" ] = ExpandPath( "./testbox" );
this.mappings[ "/tests" ] = ExpandPath( "./tests" );
this.mappings[ "/temp" ] = getTempDirectory();
this.timezone="UTC";

public void function onRequest( required string requestedTemplate ) {
include arguments.requestedTemplate;
}


}
29 changes: 14 additions & 15 deletions tests/tests/TestExamples.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,25 @@ component extends="testbox.system.BaseSpec" {
}
if (!find("<cf", e.code) && !find(";", e.code) && !find("{", e.code)) {
var actualResult = "";
local.examplePath = "/temp/cfdoc-example-#createUUID()#.cfm";
try {
actualResult = evaluate(e.code);

fileWrite(local.examplePath, "<c" & "fscript>writeOutput( " & e.code & ");</c" & "fscript>");

cfsavecontent( variable="actualResult" ) {
include template="#local.examplePath#";
}

actualResult = trim(actualResult);
} catch(any ex) {
if (ex.message == "Syntax Error, invalid Expression [" & e.code & "]") {
if (reFindNoCase("[""'][a-z0-9 ]+[""']\.[a-z]+\(", e.code)) {
//Lucee does not like "String".memberFunction()
//in evaluate but it is valid otherwise
continue;
}
actualResult = "EXCEPTION in example #idx# in #fileName#: #ex.message#";
} finally {
if (fileExists(local.examplePath)) {
fileDelete(local.examplePath);
}
actualResult = "EXCEPTION in example #idx#: #ex.message#";
}

//workaround bug: listRemoveDuplicates adds trailing comma in lucee
//https://luceeserver.atlassian.net/browse/LDEV-387
if (json.name == "listRemoveDuplicates" && server.keyExists("lucee")) {
if (right(actualResult, 1) == ",") {
e.result = e.result & ",";
}
}

if (isBoolean(e.result) && !isNumeric(e.result)) {
expect(isBoolean(actualResult)).toBeTrue("#fileName# example result is:#e.result# but evaluated to:#actualResult#");
if (e.result == true) {
Expand Down

0 comments on commit 5cd748d

Please sign in to comment.