1#!/usr/bin/env perl
2# vim: ts=8 sts=4 et sw=4 sr sta
3use Test::More;
4use Path::Class;
5use Catalyst::Plugin::ErrorCatcher::Email;
6
7can_ok('Catalyst::Plugin::ErrorCatcher::Email', qw/_munge_path/)
8    or die "_munge_path() method not implemented";
9
10my @tests = (
11    { # unix-y path
12        for         => 'linux',
13        input       => '/X/.build/Y/t/lib/TestApp/Controller/Foo.pm',
14        expected    => Path::Class::dir(qw/TestApp Controller Foo.pm/)->stringify,
15    },
16    { # unix-y path - somehow has no lib or script
17      # - test we DTRT if things go wrong
18        for         => 'linux',
19        input       => '/X/.build/Y/t/blibble/TestApp/Controller/Foo.pm',
20        expected    => Path::Class::dir(qw[/ X .build Y t blibble TestApp Controller Foo.pm])->stringify,
21    },
22    { # windows-y path; from http://www.cpantesters.org/cpan/report/6c4e926e-77db-1014-9ca9-8abd9bd6a865
23        for         => 'MSWin32',
24        input       => 'C:\Perl\cpan\build\Catalyst-Plugin-ErrorCatcher-0.0.8.4-R4oSOi\t\lib\TestApp\Controller\Foo.pm',
25        expected    => Path::Class::dir('TestApp', 'Controller', 'Foo.pm')->stringify,
26    },
27    { # windows-y path; from http://www.cpantesters.org/cpan/report/6c4e926e-77db-1014-9ca9-8abd9bd6a865
28        for         => 'MSWin32',
29        input       => 'C:\Perl\XXX\t\lib\TestApp\Controller\Foo.pm',
30        expected    => Path::Class::dir('TestApp', 'Controller', 'Foo.pm')->stringify,
31    },
32);
33
34# run the appropriate tests for the current OS
35foreach my $test (@tests) {
36    SKIP: {
37        skip "not testing $test->{for} path on $^O system", 1
38            if ($test->{for} ne $^O);
39        my $result = Catalyst::Plugin::ErrorCatcher::Email::_munge_path(
40            $test->{input}
41        );
42        is(
43            $result,
44            $test->{expected},
45            'munged ' . $test->{for} . ' path to ' .  $test->{expected}
46        );
47    }
48}
49
50done_testing;
51