且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Perl 中进行单元测试时提示用户

更新时间:2023-11-16 23:01:10

您在寻找 ExtUtils::MakeMaker::prompt 吗?

其他方便的功能

提示

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

prompt() 函数提供了一种简单的方法来请求用于编写 makefile 的用户输入.它显示 $message 作为输入提示.如果提供了 $default,它将被用作默认值.该函数返回用户选择的 $value.

如果 prompt() 检测到它不是交互式运行并且 STDIN 上没有任何内容,或者如果 PERL_MM_USE_DEFAULT 环境变量设置为 true,则将使用 $default 而不提示.这可以防止自动化进程阻止用户输入.

如果没有提供 $default,将使用空字符串代替.

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

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.