Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Testing CLI commands on Windows machines

by nysus (Priest)
on Sep 12, 2018 at 01:51 UTC ( #1222173=perlquestion: print w/replies, xml ) Need Help??
nysus has asked for the wisdom of the Perl Monks concerning the following question:

I have a cpan module with the following tests that has failed smoke testing on a Windows machine. It is choking on these tests:

stderr_like { `bin/anki_import` } qr/usage: anki_import FILE/, 'dies w +ithout file'; stderr_like { `bin/anki_import blasdfah` } qr/[FATAL].*does not exist/ +, 'dies with bad file'; lives_ok { `bin/anki_import t/data/source.anki` } 'can process good fi +le';

Looks like Windows is getting confused by the forward slash. Here is the reported error:

# Failed test 'dies without file' # at t/02-cli.t line 22. # STDERR: # 'bin' is not recognized as an internal or external command, # operable program or batch file.

Do I need to detect the OS and write a special command for Windows? Maybe I can just cd into the bin and execute from there? What's the best fix for this?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Testing CLI commands on Windows machines
by beech (Vicar) on Sep 12, 2018 at 06:51 UTC
Re: Testing CLI commands on Windows machines
by marto (Archbishop) on Sep 12, 2018 at 07:57 UTC

    As a side note, you would benefit from using CI testing. You can use Travis_CI for OSX and Linux testing and AppVeyor for Windows. Automatic testing of various OS & perl versions before you release your module to cpan.

      Thanks, always wondered what those were. Will look into using them. Continuously uploading to cpan to try to address problems with other platforms is getting old.</>

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Since no one has mentioned it yet, stevieb has an excellent meditation on setting up Travis-CI for Perl development with multiple versions of perl. I've used his writeup as the starting point for all my CI.

        It's pretty straightforward to setup, and really convenient in terms of getting emailed about failures and so on.

      Whut ?

        Which part of the post do you have problems understanding?

Re: Testing CLI commands on Windows machines
by syphilis (Chancellor) on Sep 12, 2018 at 10:32 UTC
    Do I need to detect the OS and write a special command for Windows?

    Yes - one solution for windows would be to execute the command as `bin\\anki_import`.

    Maybe I can just cd into the bin and execute from there?

    That would also work.

    Update: Just realised that, as regards running system commands in perl (as opposed to running the command from the command line prompt), `bin/anki_import` should be fine on Windows so long as "anki_import" is recognized as an executable. If windows doesn't recognize "anki_import" as an executable, then you get the message you reported.
    So ... maybe that's your problem. Does "anki_import" have an extension that windows recognizes as executable ?

    Cheers,
    Rob
      anki_import is just an executable perl script.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Unfortunately, MS Windows doesn't know what to do with a file that has no extension. Maybe a MS Windows expert could make it work, but I'm pretty sure that would not be a good idea on Windows.

        Assuming the .pl extension is properly registered and associated with perl.exe, MS Windows will "open" the program using perl.exe, which will then run it.

        However, the most common way to run Perl (or other compile-on-execute (or interpreted) languages) is to create a .bat file to run the program.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1222173]
Approved by beech
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-09-24 03:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (191 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!