Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created March 23, 2022 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/8b0913963c768b089b48434f43d5eaac to your computer and use it in GitHub Desktop.
Save adamcameron/8b0913963c768b089b48434f43d5eaac to your computer and use it in GitHub Desktop.
Example tests for Brad
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