Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / afterAllBasicTest.cfm
Created May 14, 2022 20:48
First test for afterAll functionality of TinyTestFramework
<cfscript>
function run() {
afterAll(() => {
writeOutput("afterAll ran OK")
})
describe("Tests of afterAll", () => {
it("is a simple test", () => {
expect(true).toBeTrue()
})
@adamcameron
adamcameron / passingTestForTinyTestFramework.cfm
Created May 14, 2022 20:17
A test to load into the saved gist that has the framework loaded as setupcode in trycf.com
<cfscript>
function run() {
describe("some tests", () => {
it("a passing test", () => {
expect(true).toBe(true)
})
})
}
tinyTest.runTests()
<style>.tt{background-color:black;color:white;font-family:monospace}.tt div {margin-left:1em}.tt .p{color:green}.tt .f{color:red}.tt .e{background-color:red;color:black}</style><cfscript>_={r={p=0,f=0,e=0},runTests=()=>{writeOutput('<div class="tt">');run();_.u();writeOutput('</div>')},u=()=>{savecontent variable="local.r"{writeOutput("<div>Results: [Pass: #_.r.p#] [Fail: #_.r.f#] [Error: #_.r.e#] [Total: #_.r.p + _.r.f + _.r.e#]</div>")}writeOutput(r)},c=[],d=(l,g)=>{_.i(()=>{try{writeOutput("#l#<br>");_.c.push({});g()}catch(any e){writeOutput("Error: #e.message#<br>")}finally{_.c.pop()}})},s=(c)=>{return _.c.last().x=c},t=(c)=>{return _.c.last().y=c},w=(c)=>{return _.c.last().z=c},it=(l,t)=>{_.i(()=>{try{writeOutput("It #l#: ");_.c.filter((c)=>c.keyExists("x")).each((c)=>c.x());d=_.c.filter((c)=>c.keyExists("z")).reduce((r,c)=>r.prepend(c),[]).reduce((d,c)=>()=>c.z(d),t);d();_.c.filter((c)=>c.keyExists("y")).reduce((j,c)=>j.prepend(c),[]).each((c)=>c.y());_.l()}catch(TT e){_.k()}catch(any e){_.b(e)}})},e=(a
@adamcameron
adamcameron / testContext.cfm
Last active May 9, 2022 13:24
testing how to deal with beforeEach / afterEach
<style>
.tinytest {background-color: black; color:white; font-family:monospace}
.tinytest div {margin-left: 1em}
.tinyTest .pass {color:green;}
.tinyTest .fail {color:red;}
.tinyTest .error {background-color:red; color:black}
</style>
<cfscript>
baseContext = []
<style>
.tinytest {background-color: black; color:white; font-family:monospace}
.tinytest div {margin-left: 1em}
.tinyTest .pass {color:green;}
.tinyTest .fail {color:red;}
.tinyTest .error {background-color:red; color:black}
</style>
<cfscript>
tinyTest = {
@adamcameron
adamcameron / test.cfm
Created May 1, 2022 17:58
CF playing silly buggers with doubles
<cfscript>
i = 0
f = 0.0
d = createObject("java", "java.lang.Double").init(0)
writeDump([
i = [
i = i,
"i === i" = i === i,
"i.equals(i)" = i.equals(i),
<cfscript>
s1 = "ABCDEF".mid(1,3)
s2 = "DEFABC".mid(4,6)
writeOutput(s1 & "<br>") // ABC
writeOutput(s2 & "<br>") // ABC
writeOutput("<br>")
writeOutput((s1 == s2) & "<br>") // true
writeOutput((s1 === s2) & "<br>") // true (FALSE ON LUCEE)
@adamcameron
adamcameron / AssertionsTest.cfc
Last active April 18, 2022 14:13
Tests for probable bug with notToThrow assertion.
import test.BaseSpec
component extends=BaseSpec {
function run() {
describe("Tests TestBox assertions", () => {
describe("Tests toThrow", () => {
it("should pass because it DOES throw an exception with the matching message", () => {
expect(() => throwExceptionWithMatchingMessage()).toThrow(regex="^.*MATCH_THIS.*$")
})
@adamcameron
adamcameron / luceeCfftpScopingBug.cfm
Created April 8, 2022 18:06
Demonstrates what seems to be a bug in how Lucee scopes the cfftp variable when in modern mode: it still goes in the variables scope.
<cfscript>
serverDetails = {
server="ftp.dlptest.com",
username="dlpuser",
password="rNrKYTX9g7z3RgJRmxWuGHbeu"
}
function usingClassicMode() localmode="classic" {
cfftp(connection="c1", action="open", attributeCollection=serverDetails)
cfftp(connection="c2", action="open", attributeCollection=serverDetails, result="c2ConnectionResult")
@adamcameron
adamcameron / CaptureStdOutTest.cfc
Created March 23, 2022 21:07
Example tests for Brad
import test.BaseSpec
component extends=BaseSpec {
function run() {
describe("Trying to capture stdout", () => {
var fixtures = {}
aroundEach((spec) => {