Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test the prompt command?

my $x = prompt "Are you OK? ";
say $x ~~ 'y' ?? "Great!" !! "Bummer";

use Test;

What tests can a put in a t/ file? How can it respond to the prompt?

like image 354
Jim Bollinger Avatar asked Oct 14 '25 15:10

Jim Bollinger


1 Answers

I don't know how to do it directly(probably by capturing handles), so I leave that to others, but you can put your code in a script file and test it with Test::Run module:

# script.raku

my $x = prompt "Are you OK? ";
say $x ~~ 'y' ?? "Great!" !! "Bummer";
# script.t

use Test::Run:auth<zef:CIAvash>:ver<0.2.*> :runs_ok;

runs_ok :args«$*EXECUTABLE script.raku», :in<y>, :out(*.contains: 'Are you OK? Great!');
runs_ok :args«$*EXECUTABLE script.raku», :in<n>, :out(*.contains: 'Are you OK? Bummer');
like image 157
CIAvash Avatar answered Oct 17 '25 17:10

CIAvash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!