Perl user request perl

I am writing a module that has unit tests that require running some kind of external server program, and if so, you need to know the host name and port.

I would like to request this information when running the test suite and skip these tests if the user refuses to provide it.

What is the best way to handle this?

thanks

+7
source share
2 answers

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

Other useful features

hints

 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 $ message as a prompt for input. If set to $ default, it will be used by default. The function returns the value of $ selected by the user.

If prompt () detects that it is not running interactively and there is nothing in STDIN, or if the environment variable PERL_MM_USE_DEFAULT is set to true, the value $ default will be used without a request. This prevents blocking of automatic processes during user input.

If $ default is not set, an empty string will be used instead.

+7
source

I will take a different approach to this. Why exactly do you need a user as an intermediary for this - especially for automated tests? A significantly better approach (in my own experience) is to do one of the following:

  • Make the server (hostname / port) somehow detected during testing. This can be either genuine openness, or the server registration itself, or, maybe, some kind of configuration. Given that server clients in the real world should be able to connect to the server, such a discovery logic (again, the worst case scenario, which is some configuration file) should already exist.

  • For a really difficult case, let the test harness run the test instance of the server on the test port if it is not running.

Keep in mind that if your server for some reason cannot be adapted to allow any of the above approaches, then the smallest approach to the socket doll.

+3
source

All Articles