Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail on Windows due to hard coded directory separators #26

Closed
nanis opened this issue Dec 9, 2014 · 17 comments
Closed

Tests fail on Windows due to hard coded directory separators #26

nanis opened this issue Dec 9, 2014 · 17 comments

Comments

@nanis
Copy link

nanis commented Dec 9, 2014

In inc/TestML/Runtime.pm line 18, you should use File::Basename::dirname instead of a regex match.

use File::Basename qw( dirname );
sub BUILD {
    my ($self) = @_;
    $TestML::Runtime::Singleton = $self;
    $self->{base} ||= dirname($0);
}

Joining path components using '/' instead of using File::Spec->catfile is also unnecessarily unportable, but it does work on Windows.

@ingydotnet
Copy link
Collaborator

Hi @nanis. Can you gist a test failure. I'm not seeing any conclusive failures here: http://cpantesters.org/distro/P/Pegex.html

@nanis
Copy link
Author

nanis commented Dec 9, 2014

You would not see them on CPANTesters, because most Windows results are from Strawberry Perl which uses dmake. In that set up, EUMM invokes test scripts with Unix style paths. However, I am using Visual Studio 2013 with nmake in which case EUMM invokes test scripts with Windows style directory separators.

See, for example,

http://blog.nu42.com/2014/11/how-can-invalid-assumptions-remain.html

http://blog.nu42.com/2014/12/what-is-really-broken.html

I am on a different machine right now, so posting test output will have to wait.

But, regardless, trying to replace File::Basename::dirname with a regex pattern, and hard-coding directory separators are not the right things to do for portability.

@nanis
Copy link
Author

nanis commented Dec 9, 2014

Here is the output:

t\testml-compiler-checks.t ....... Can't open './testml/compiler-checks.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-compiler-checks.t ....... Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\testml-compiler-equivalence.t .. Can't open './testml/compiler-equivalence.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-compiler-equivalence.t .. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\testml-compiler.t .............. Can't open './testml/compiler.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-compiler.t .............. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\testml-error.t ................. Can't open './testml/error.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-error.t ................. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\testml-optimize.t .............. Can't open './testml/optimize.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-optimize.t .............. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\testml-tree-pegex.t ............ Can't open './testml/tree-pegex.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-tree-pegex.t ............ Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\testml-tree.t .................. Can't open './testml/tree.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-tree.t .................. Dubious, test returned 2 (wstat 512, 0x200)

This happens because when $0 is, for example, t\testml-tree-pegex.t, the statement on line 19 in inc/TestML/Runtime.pm:

    $self->{base} ||= $0 =~ m!(.*)/! ? $1 : ".";

assigns "." to $self->{base}. Then, on line 284 in inc/TestML/Runtime.pm

my $path = $self->base . '/' . $file;

results in the subsequent open looking for ./testml/tree.tml rather than t/testml/tree.ml.

@nanis
Copy link
Author

nanis commented Dec 9, 2014

Also, I cannot figure out how to submit a pull request because I cannot find the inc/TestML/Runtime.pm file in the repo.

See also ingydotnet/testml-pm#10

@nanis nanis changed the title Test fail on Windows due to hard coded directory separators Tests fail on Windows due to hard coded directory separators Dec 9, 2014
@ingydotnet
Copy link
Collaborator

OK. I have a Win7 vm and looks like I can get compiler tools without cost here: http://www.visualstudio.com/en-US/products/visual-studio-express-vs

I'll try to get to this soon.

@ingydotnet
Copy link
Collaborator

@nanis are you using ActivePerl?

@nanis
Copy link
Author

nanis commented Dec 10, 2014

No, I am using perl 5.20.1 I built using Visual Studio 2013 community edition, and therefore, nmake. Due to a recent change in EUMM, nmake builds get Windows style paths.

With ActivePerl, one would probably use their MinGW package, and get the dmake tool. In that case, EUMM uses Unix style paths.

HTH.

@vikasnkumar
Copy link
Contributor

@nanis i have submitted a pull request for this issue.

ingydotnet added a commit that referenced this issue Dec 12, 2014
- Fix test for windows (issue #26) vicash++
- Share Pegex grammar for Pegex
@ingydotnet
Copy link
Collaborator

@nanis, I applied PR/27 and released new version.

Please test, and close this if fixed.

@ingydotnet
Copy link
Collaborator

@nanis, Can you test this now that TestML is fixed. I guess you can test installing Inline::C since that requires Pegex.

@nanis
Copy link
Author

nanis commented Dec 28, 2014

Did you release a new Pegex? Because 0.58 from CPAN fails:

C:\...> cpanm Pegex
--> Working on Pegex
Fetching http://www.cpan.org/authors/id/I/IN/INGY/Pegex-0.58.tar.gz ... OK
Configuring Pegex-0.58 ... OK
Building and testing Pegex-0.58 ... FAIL
! Installing Pegex failed. See C:\...\build.log for details. Retry with --force to force install it.
t\sample.t ....................... ok
Can't open './testml\compiler-checks.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-compiler-checks.t ....... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't open './testml\compiler-equivalence.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-compiler-equivalence.t .. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't open './testml\compiler.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-compiler.t .............. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't open './testml\error.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-error.t ................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't open './testml\optimize.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-optimize.t .............. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't open './testml\tree-pegex.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-tree-pegex.t ............ 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't open './testml\tree.tml' for input: No such file or directory at inc/TestML/Runtime.pm line 285.
t\testml-tree.t .................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Test Summary Report
-------------------
t\testml-compiler-checks.t     (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t\testml-compiler-equivalence.t (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t\testml-compiler.t            (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t\testml-error.t               (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t\testml-optimize.t            (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t\testml-tree-pegex.t          (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t\testml-tree.t                (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
Files=18, Tests=40,  8 wallclock secs ( 0.17 usr +  0.01 sys =  0.19 CPU)
Result: FAIL
Failed 7/18 test programs. 0/40 subtests failed.
NMAKE : fatal error U1077: 'C:\opt\perl-5.20.1\bin\perl.exe' : return code '0x2'
Stop

@vikasnkumar
Copy link
Contributor

Hi @nanis

Please give the output of the following command in your Perl. Seems like
an issue with File::Spec that you have installed and the output it is
producing: "./testml\compiler-checks.tml" instead of
".\testml\compiler-checks.tml" or "testml\compiler-checks.tml" which is
what it should be producing.

Here is a one-liner that you can run and show us your output on your Perl.

$ perl -MFile::Spec -e 'print File::Spec->catfile(qw{testml
testfile.tml}), "\n";'

This is the exact code we are using in Pegex test so something is off
with your Perl.

--Vikas

@nanis
Copy link
Author

nanis commented Dec 28, 2014

Hi Vikas:

Nothing is off with my perl. Instead, what is off is the fact that TestML::Runtime now finally uses dirname $0 to get the base directory, whereas the inc\TestML\Runtime.pm that I get when I download Pegex-0.58 from CPAN still is using the same regex match I mention at the top of this thread.

You are failing to notice that the t subdirectory missing from "./testml\compiler-checks.tml" is the real problem.

The failed regex match is setting the base directory to be . when it should be t. Then, in TestML::Runtime::read_testml_file you actually do:

my $path = $self->base . '/' . $file;

which is where the / comes from.

The fix for this nonsense of using a regex match to extract the directory portion from a file path has finally made it to TestML. Now, someone has to make sure the TestML included with Pegex is also fixed.

That's all.

@vikasnkumar
Copy link
Contributor

@nanis, I disagree. We have fixed that issue and Pegex 0.58 has been
released with using File::Spec instead of the concatenation with the
dots that you had mentioned.

I just checked by installing Pegex 0.58 explicitly using cpanminus. The
code in t/testml-compiler.t has File::Spec and so do all the other
testml test files.

So the problem lies in your custom built Perl. Please run the one-liner
with File::Spec I had asked for before ranting. Here it is again:

$ perl -MFile::Spec -e 'print File::Spec->catfile(qw{testml
testfile.tml}), "\n";'

--vikas

@nanis
Copy link
Author

nanis commented Dec 28, 2014

Vikas, you can disagree all you want, except that you are not reading what I am writing, and you are missing the point. The hard-coded directory separator is in the regex pattern used to match the directory portion of a file path in inc/TestML/Runtime.pm

$ wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/Pegex-0.58.tar.gz
$ tar -xvf Pegex-0.58.tar.gz
...
$ head -n 30 Pegex-0.58/inc/TestML/Runtime.pm
package TestML::Runtime;
use TestML::Base;
has testml => ();
has bridge => ();
has library => ();
has compiler => ();
has skip => ();
has function => ();
has error => ();
has global => ();
has base => ();
sub BUILD {
    my ($self) = @_;
    $TestML::Runtime::Singleton = $self;
    $self->{base} ||= $0 =~ m!(.*)/! ? $1 : ".";
}

That last line shown above is the root cause of the problem. This is fixed in the TestML distribution, but Pegex from CPAN still includes this stupid thing. You are probably testing with Strawberry Perl.

Please read what I am saying before responding. Better yet, please stop responding and fix this if you care at all.

@ingydotnet
Copy link
Collaborator

@nanis, please test Pegex-0.59 and report back.

@nanis
Copy link
Author

nanis commented Dec 29, 2014

Fixed. Thank you very much.

C:\> cpanm Pegex
--> Working on Pegex
Fetching http://www.cpan.org/authors/id/I/IN/INGY/Pegex-0.59.tar.gz ... OK
Configuring Pegex-0.59 ... OK
Building and testing Pegex-0.59 ... OK
Successfully installed Pegex-0.59 (upgraded from 0.58)
1 distribution installed
C:\> cpanm-reporter
sending: (http://www.cpan.org/authors/id/I/IN/INGY/Pegex-0.59.tar.gz, INGY, Pegex-0.59, PASS)

@nanis nanis closed this as completed Dec 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants