My first attempt to use the module:
[prompt]perl -MTest::Harness -e"runtests 'test1.perl'" test1.per...........'C:\Program' is not recognized as an internal or e +xternal command, operable program or batch file. test1.per...........dubious Test returned status 1 (wstat 256, 0x100) FAILED--1 test script could be run, alas--no output ever seen
According to the docs, "Test::Harness uses $^X to determine the perl binary to run the tests with." Meanwhile, it appears to simply concatenate it with the arguments and system() that string (or otherwise split on whitespace itself), because it things that the path up to the first space is the whole interpreter name!

Why do Perl tools have such problems with spaces? Haven't spaces (as well as control chars, and really anything except a slash) been legal on UNIX systems since the dawn of time?

In my own script, I reciently used $^X to launch another perl script and used the list form of system() with no problems. Perl knew that the first one was the program name, and how to quote or escape the argument strings properly on this platform.

So what's Test::Harness' problem? A quick search of the code shows:

my $cmd = ($ENV{'HARNESS_COMPILE_TEST'}) ? "./perl -I../lib ../utils/perlcc $test " . "-r 2>> ./compilelog |" : "$^X $s $test|"; $cmd = "MCR $cmd" if $^O eq 'VMS'; $fh->open($cmd) or print "can't run $test. $!\n";
or, to condense that, it turns into
open FH, "$^X $scriptname|"
The pipe-out form of open takes a single string, as on a command prompt shell, rather than multiple arguments. Perhaps the new list form of open in Perl 5.8 is to provide exactly this? Anyway, the script has to take charge of knowing how to quote/escape whatever all the contents of the command to run.

That is fraught with system-specific details, so there should be something like File::Spec to hide that. Is there (yet)?

Second, this program makes no attempt to even try! Not only does it fall flat if the Perl path has spaces in it (on any platform), but the scriptname has the same problem. And it's not just spaces—any special characters used by the shell will mess it up, since they are not escaped.

I find it amusing that Test::Harness is not itself tested too see how it likes a standard Windows installation (typically C:\Program Files\... and ...\My Documents\...).

A quick edit to Test::Harness.pm involving

my $interp_name= $^O eq 'MSWin32' ? Win32::GetShortPathName($^X) : $^X +;
and it gets past that problem. Not as robust as it could be, though, since it doesn't handle Unicode names.

—John


In reply to Test::Harness not working on my machine by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.