|We don't bite newbies here... much|
[Updated] How do you test code that uses Term::UI?by dly (Beadle)
|on Sep 02, 2012 at 05:51 UTC||Need Help??|
dly has asked for the
wisdom of the Perl Monks concerning the following question:
I have some code that uses Term::UI, and now that I've coded it I'm struggling to figure out how to test it.
I've googled and searching perlmonks and stackexchage, but found nothing.
My options seem to be:
Approach 1 seems lame, and hacky. And it doesn't seem to actually test anything, because nothing is printed and enter is never pressed, which might be ok for Term::UI, because it sits on top of Term::Readline, which presumably tests printing output and reading it in.
Approach 2 is not flexible enough, because in my test suite I'm importing functions, and then running them to test them. I'm not creating an actual perl script or binary to test using Expect, which seems to want an actual program to execute, which I don't have.
Approach 3 is just insane, but it might actually be crazy enough to work better than 1 (not really testing anything) or 2 (different paradigm: program to run instead of function to call).
What do you think? 1 or 3? Or any other ideas!Update
I decided to actually implement number 3, but I can't get it to work. I can't figure out how to print an <Enter> key properly. I've tried both print and syswrite and different combinations of "\n", "\r", "\cJ", and "\cM", and none of them work at all. The code is below.
Sorry for no code. I need help figuring out what approach I should take more than help with any code I've already written. And that last crazy idea I came up with while writing this question here on perlmonks, so I haven't had time to actually code anything.