Skip to content

Find a way to group debugging output with relevant test case #1

Closed
@bdw429s

Description

@bdw429s

In CFML, you can output directly to the console like so:

systemOutput( 'my debug message', true )

This is crude but effective, however if you have a test suite with a lot of tests, all the debugging messages show up at the top. I noticed in the JS katas, calls to console.log() are grouped within each spec's output. CFML provides no way to capture the output from this function as it is fed directly to the System.out stream in the JVM.

I have a few ideas, but I'd need to think about how we're calling the tests to see what's available. TestBox itself has a debug() method and it tracks a debug stream for each spec which is available in the test results. However, the debug method is only available inside the actual test cases, not in the solution CFC. One option is we "inject" a debug method by default into the solution component at runtime for users to call which would be "spec aware".

Another option may be to look into the echo() function in CFML. It writes content to a print buffer that exists in each thread. (In a web context, this print buffer is what becomes the output to the browser). It's possible to call a UDF in CFML and wrap it in a manner that captures all output from that method:

function myMethodThatOutputsStuff() {
  echo( 'I like spam' )
}

savecontent variable='local.out' {
  myMethodThatOutputsStuff()
}
// Variable local.out contains text "I like spam"

This seems promising as echo() is a CF built-in wouldn't require any special injections into the Solution cfc, however since the actual spec closures are executed inside of the TestBox framework, I'm not sure Codewar's runner would have the opportunity to wrap each one. Actually-- come to think of it-- we may be able to do this with a base test case all our test cases extend that uses an aroundEach() advice to wrap the execution of each spec, feeding any output into the debug stream for that test. 🤔

https://testbox.ortusbooks.com/primers/testbox-bdd-primer/life-cycle-methods#around-specs

component extends="testbox.system.BaseSpec" {
     /**
     * @aroundEach
     */
	 function captureOutput( spec, suite ){
		savecontent variable="local.out" {
    		arguments.spec.body();
		}
		if( len( trim( local.out ) ) ) {
			debug( local.out )
		}
 	 }
}

We could put that ☝️ in a base spec and then change the codewars specs to all extend that class so they inherit the aroundeach behavior.


Let me know your thoughts and how I can help experiment with this. I'm sure there's a better solution we can find, but I'm not positive about all the plumbing in place nor how to play around and test with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions