ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
935 stars 33 forks source link

Control TerminalInfo for testing #170

Closed mikaelstaldal closed 2 months ago

mikaelstaldal commented 2 months ago

I am working with an application which behaves differently depending on values in TerminalInfo, and it would be nice to be able to control those for automated integration tests which are run in a separate process started with java.lang.ProcessBuilderon JVM. In particular, I need to control inputInteractive and outputInteractive, but everthing in TerminalInfo would be nice to be able to control.

Now inputInteractive and outputInteractive are false when using a subprocess.

I fetch TerminalInfo through CliKi's CliktCommand.terminal.info. (Perhaps this should be an issue on CliKt, but would be nice to do the same if you use Mordant without CliKi I guess.)

ajalt commented 2 months ago

You can control interactivity and other info values by passing them to the terminal constructor. There are a couple of examples of setting the terminal in the clikt docs.

mikaelstaldal commented 2 months ago

OK. However, would be nice to be able to control interactivity directly, creating an CliKt issue for that: https://github.com/ajalt/clikt/issues/517

mikaelstaldal commented 2 months ago

Seems like you cannot combine setting Terminal with context and test, since test overrides the Terminal :shrug:

MyCommand().context {
            terminal = Terminal(interactive = true)
        }.test("foo bar")
ajalt commented 2 months ago

You're right, that needs to be customizable with test. That's a clikt issue, though, so I'm closing this one.