Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prompt user during unit test in Perl

I'm writing a module which has unit tests that require a certain external server program to be running, and, if it is, the hostname and port need to be known.

I would like to prompt for this information when running the test suite, and skip those tests if the user declines to provide it.

What's the best way to handle this?

Thanks

like image 406
friedo Avatar asked Oct 02 '11 21:10

friedo


1 Answers

Are you looking for ExtUtils::MakeMaker::prompt?

Other Handy Functions

prompt

my $value = prompt($message);
my $value = prompt($message, $default);

The prompt() function provides an easy way to request user input used to write a makefile. It displays the $message as a prompt for input. If a $default is provided it will be used as a default. The function returns the $value selected by the user.

If prompt() detects that it is not running interactively and there is nothing on STDIN or if the PERL_MM_USE_DEFAULT environment variable is set to true, the $default will be used without prompting. This prevents automated processes from blocking on user input.

If no $default is provided an empty string will be used instead.

like image 93
socket puppet Avatar answered Oct 14 '22 00:10

socket puppet