mordant icon indicating copy to clipboard operation
mordant copied to clipboard

Testing interactive input

Open mikaelstaldal opened this issue 3 months ago • 3 comments

There seems to be no way to automatically test a program using Termial.prompt(), Terminal.interactiveSelectList() or Terminal.interactiveMultiSelectList().

Would be nice if there was possible to somehow mock them when testing.

mikaelstaldal avatar Nov 12 '25 17:11 mikaelstaldal

You can! Create a TerminalRecorder with the input you want to simulate, and set it as the terminalInterface on your Terminal in tests. Take a look at how mordant tests the InteractiveSelectList

ajalt avatar Nov 12 '25 17:11 ajalt

Interesting. Would be nice if this was supported by https://github.com/ajalt/clikt/blob/master/clikt-mordant/src/commonMain/kotlin/com/github/ajalt/clikt/testing/CliktTesting.kt

created Clikt issue about that: https://github.com/ajalt/clikt/issues/625

mikaelstaldal avatar Nov 13 '25 08:11 mikaelstaldal

Might be useful to be able to mock those input widgets on a higher lever (e.g. "user selected this element" rather than "user pressed this and that key").

mikaelstaldal avatar Nov 13 '25 09:11 mikaelstaldal