Wednesday 18 May 2022

CFML: Filler article with code but no TDD at all

G'day:

I'm still working on the TinyTestFramework though: some things don't change.

My test file for this work, which is the framework and all its tests in one is getting a bit weighty: >1200 LOC, and I'm fiding it difficult to navigate about the place. Especially as I'm using trycf.com as my dev environment :-).

Using the technique I recently documented to execute code on trycf.com remotely ("Running CFML code on trycf.com via a remote HTTP request"), I've split-out the framework and the tests into different gists, and wrote a wee calling-harness to run them all… and for completeness on both ColdFusion 2021 and Lucee 5.

This way I can just have the new tests I am working on in front of me, and have all the rest of the tests running in a different trycf.com window.

It's not doing anything complicated: just some loops and some HTTP requests to get the code from GitHub, and send it to trycf.com; and then outputing the response:

<cfscript>
cfhttp(
    method = "get",
    url = "https://gist.githubusercontent.com/adamcameron/816ce84fd991c2682df612dbaf1cad11/raw/tinyTestFramework.cfm",
    result = "frameworkCodeResponse",
    throwOnError = true
    
);
frameworkCode = frameworkCodeResponse.fileContent;

testSuites = [
    "Tests for misc functions that don't fit another category" = {
        guid = "332e3cda31fa933cfe3a783be07bc59e",
        file = "ttfOtherFunctionsTest.cfm"
    },
    "Tests for matcher functions" = {
        guid = "b006d2c420dd4cbe369b6c809c15ea83",
        file = "ttfMatcherFunctionsTest.cfm"
    },
    "Tests for lifecycle functions" = {
        guid = "f93c3e12885f2913bfc8351ba1ed8911",
        file = "ttfLifeCycleFunctionsTest.cfm"
    }
]

engineUrls = [
    "ColdFusion 2021" = "https://acf14-sbx.trycf.com/getremote.cfm",
    "Lucee 5" = "https://lucee5-sbx.trycf.com/lucee5/getremote.cfm"
]    
    
writeOutput('<div class="tinyTest">');
testSuites.each((label, suite) => {
    writeOutput("<h3>#label#</h3>");
    cfhttp(
        method = "get",
        url = "https://gist.githubusercontent.com/adamcameron/#suite.guid#/raw/#suite.file#",
        result = "testCodeResponse",
        throwOnError = true
    );
    
    testCode = testCodeResponse.fileContent;
    
    engineUrls.each((engine, engineUrl) => {
        cfhttp(method="post", url=engineUrl, result="testRunResponse") {
            cfhttpparam(type="formField", name="setupcode", value=frameworkCode);
            cfhttpparam(type="formField", name="code", value=testCode);
            cfhttpparam(type="formField", name="asserts", value="");
        }
        writeOutput("<h4>#engine#</h4>");
        writeOutput(testRunResponse.fileContent)
        writeOutput("<hr>")
    })
})
writeOutput("</div>")
</cfscript>

(Gist on Github)

And the output's like this:

That'll do for the evening, I think.

Righto.

--
Adam