Created
March 23, 2022 21:07
-
-
Save adamcameron/8b0913963c768b089b48434f43d5eaac to your computer and use it in GitHub Desktop.
Example tests for Brad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test.BaseSpec | |
component extends=BaseSpec { | |
function run() { | |
describe("Trying to capture stdout", () => { | |
var fixtures = {} | |
aroundEach((spec) => { | |
try { | |
fixtures.outFilePath = getTempDirectory() & createUuid() & ".out" | |
fixtures.system = createObject("java", "java.lang.System") | |
var originalOut = fixtures.system.out | |
var fos = createObject("java", "java.io.FileOutputStream").init(fixtures.outFilePath) | |
var ps = createObject("java", "java.io.PrintStream").init(fos, true) | |
fixtures.system.setOut(ps) | |
spec.body() | |
} finally { | |
fixtures.system.setOut(originalOut) | |
} | |
}) | |
it("captures stuff Java puts there", () => { | |
var testString = "find this (Java)" | |
fixtures.system.out.println(testString) | |
var contents = fileRead(fixtures.outFilePath) | |
expect(contents).toBe(testString & chr(10)) | |
}) | |
it("doesn't capture stuff Lucee puts there", () => { | |
systemOutput("find this (Lucee)") | |
var contents = fileRead(fixtures.outFilePath) | |
expect(contents).toBeEmpty() // except I wish this *wasn't* the case | |
}) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment