Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Yes - I had started off by checking most of those things. (That was how line 71 became line 76 ;-)
Everything looked fine, except that $cleaned was not defined.
It was actually quite some time before I looked at the test script itself and noticed the $^O override.

File/Spec.pm contains very little code - and it certainly seems to be inviting this override that t/01-basic.t uses.
So I decided to investigate some basic behaviour of File::Spec, without any reference to Path::Class. I used this script:
# fake_os.pl BEGIN { $^O = 'Unix'; } use strict; use warnings; use File::Spec; my $x = File::Spec->catfile('a', 'b', 'c'); print $x;
I find that on both perl-5.32 and 5.34, this script outputs 'a/b/c' as expected.
If I comment out the BEGIN block, then the script outputs 'a\b\c' as expected - on both perl-5.32 and perl-5.34. What is odd is that if I simply load Test::Harness, then on both perl-5.32 and 5.34 I always get 'a\b\c' even when the BEGIN block is included:
C:\_32\pscrpt\file-spec>perl fake_os.pl a/b/c C:\_32\pscrpt\file-spec>perl -MTest::Harness fake_os.pl a\b\c
I think that demonstrates that there might be some fragility around overriding $^O, though it doesn't really explain much about the behaviour of t/01-basic.t.

I think it's a pity that File::Spec invites users to mess with the path formatting by fiddling with $^O.
Surely it would be better if there was a function to call or an environment variable to set ... or something else that doesn't involve fiddling with $^O.

I think I might just file bug reports against both perl (based on the demo of the Test::Harness interference) and Path::Class ... and see where it all ends up.

I've just tried my fake_os.pl on Ubuntu with $^O = 'Win32'; and it just ignores that and gives the Unix style 'a/b/c' (on both perl-5.32 and 5.36).(I think that's intended behaviour.)
I totally buggered that up. I can get Win32 path formatting with fake_os.pl on Ubuntu if I specify $^O = 'MSWin32' .
Again, it doesn't work if the Test::Harness is loaded.
I think I'm just fiddling about with a heap of rubbish ...

Update: Forgot to mention that I did hack File::Spec on Windows perl-5.34 such that 'Unix' was hard coded in, and $^O didn't need to be altered. In that case the t/01-basic.t script ran fine and passed all tests.
To me, that shows that the problem with t/01-basic.t is not that 'Unix' formatting is being selected - it's because $^O is being messed with.
I'll post again with links to relevant bug reports once they have been filed.
Thanks for the interest that has been shown.

Cheers,
Rob

In reply to Re^2: Is it ever legitimate to override $^O ? -- Cwd and File::Spec by syphilis
in thread Is it ever legitimate to override $^O ? by syphilis

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found