在 Perl 中进行单元测试时提示用户 [英] Prompt user during unit test in Perl

查看:47
本文介绍了在 Perl 中进行单元测试时提示用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个模块,其中包含需要运行某个外部服务器程序的单元测试,如果是,则需要知道主机名和端口.

我想在运行测试套件时提示输入此信息,如果用户拒绝提供,则跳过这些测试.

处理这个问题的最佳方法是什么?

谢谢

解决方案

您在寻找 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.

这篇关于在 Perl 中进行单元测试时提示用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆