Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- ready for 0.01 release?

git-svn-id: https://dagolden.googlecode.com/svn/Test-Filename/trunk@1324 dfce27d5-b31c-0410-bb09-030b4413eeba
  • Loading branch information...
commit 874592e7225dbcd19e6bff5dd337b78fb32ca736 1 parent a941654
@dagolden authored
View
4 Build.PL
@@ -10,12 +10,10 @@ $class->new(
create_readme => 1,
create_makefile_pl => 'traditional',
requires => {
- # module requirements here
- 'File::Basename' => 0,
- 'File::Spec' => 3.19,
'Test::More' => 0.62, # various features/fixes
},
build_requires => {
+ 'File::Spec' => 0,
'Test::Tester' => 0.08,
},
meta_add => {
View
6 Changes
@@ -1,4 +1,6 @@
-Revision history for Perl module Test::Filenames
+Revision history for Perl module Test::Filename
-0.01
+0.01 Sat Oct 6 11:00:40 EDT 2007
+
+ - initial release with filename_is() and filename_isnt()
View
7 MANIFEST
@@ -5,14 +5,15 @@ INSTALL
lib/Test/Filename.pm
lib/Test/Filename.pod
LICENSE
+Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
+META.yml
+README
t/00_load.t
+t/filename_is.t
Todo
xt/criticrc
xt/perl-critic.t
xt/pod-coverage.t
xt/pod.t
-Makefile.PL
-README
-META.yml
View
5 META.yml
@@ -3,15 +3,14 @@ name: Test-Filename
version: 0.01
author:
- 'David A. Golden <dagolden@cpan.org>'
-abstract: Portable tests for filenames
+abstract: Portable filename comparison
license: apache
resources:
license: http://apache.org/licenses/LICENSE-2.0
requires:
- File::Basename: 0
- File::Spec: 3.19
Test::More: 0.62
build_requires:
+ File::Spec: 0
Test::Tester: 0.08
provides:
Test::Filename:
View
5 Makefile.PL
@@ -9,9 +9,8 @@ WriteMakefile
'VERSION_FROM' => 'lib/Test/Filename.pm',
'PREREQ_PM' => {
'Test::More' => '0.62',
- 'File::Spec' => '3.19',
- 'Test::Tester' => '0.08',
- 'File::Basename' => 0
+ 'File::Spec' => 0,
+ 'Test::Tester' => '0.08'
}
)
;
View
51 README
@@ -1,12 +1,55 @@
NAME
- Test::Filename - Portable tests for filenames
+ Test::Filename - Portable filename comparison
VERSION
This documentation describes version 0.01.
SYNOPSIS
+ use Test::Filename tests => 2;
+
+ filename_is ( "some\path", "some/path", "should pass" );
+ filename_isnt( "some\path", "some/path", "should fail" );
+
DESCRIPTION
+ Many cross-platform test failures -- particularly on Win32 -- are due to
+ hard-coded file paths being used in comparison tests.
+
+ my $file = get_file(); # returns "foo\bar.t";
+ is( $file, "foo/bar.t" ); # fails on Win32
+
+ This simple module provides some handy functions to convert all those
+ path separators automatically so filename tests will just DWIM.
+
+ The alternative is to write your own utility subroutine and use it
+ everywhere or just keep on littering your test code with calls to
+ File::Spec -- yuck!
+
+ is( $file, File::Spec->canonpath("some/path"), "should pass" );
+
+ Since this module is so simple, you might not think it worth including
+ as a "build_requires" dependency. After all, it's not *that* hard to
+ always remember to use File::Spec, right? But odds are that, at some
+ point, you'll be so busy writing tests that you'll forget and hard-code
+ a path in your haste to show what a clever programmer you are.
+
+ So just use this module and stop worrying about it. You'll be happier
+ and so will anyone trying to install your modules on Win32.
+
USAGE
+ Just like Test::More, you have the option of providing a test plan as
+ arguments when you "use" this module. The following functions are
+ imported by default.
+
+ filename_is
+ filename_isnt
+ filename_is ( $got, $expected, $label );
+ filename_isnt( $got, $expected, $label );
+
+ These functions work just like "is()" and "isnt()" from Test::More, but
+ the first argument will have native path separators converted to forward
+ slashes before comparison. The $expected argument must use unix-style
+ forward slashes as path separators.
+
BUGS
Please report any bugs or feature using the CPAN Request Tracker. Bugs
can be submitted through the web interface at
@@ -16,6 +59,12 @@ BUGS
to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
+ * perlport
+
+ * File::Spec
+
+ * Test::More
+
AUTHOR
David A. Golden (DAGOLDEN)
View
7 Todo
@@ -0,0 +1,7 @@
+TODO for Test::Filename
+
+- add filename_like() and filename_unlike()
+
+- consider basename_is, etc.
+
+- consider abs_path_is, etc.
View
6 examples/simple.t
@@ -0,0 +1,6 @@
+use Test::Filename tests => 1;
+
+my @files = glob "examples/*";
+
+filename_is( $files[0], 'examples/simple.t', "first file is simple.t" );
+
View
113 lib/Test/Filename.pm
@@ -1,63 +1,47 @@
package Test::Filename;
+use 5.004;
use strict;
-
-$Test::Filename::VERSION = '0.01';
-
-use Test::Builder;
-use File::Basename qw/basename/;
-use File::Spec::Functions qw/canonpath/;
-
-use vars qw/@ISA @EXPORT/;
-use Exporter ();
-BEGIN { @ISA = qw/Exporter/ }
-@EXPORT = qw(
- filename_is
- filename_isnt
- filename_like
- filename_unlike
-);
-
-my $TB = Test::Builder->new();
-
-#--------------------------------------------------------------------------#
-# import -- cribbed from Test::Builder
-#--------------------------------------------------------------------------#
-
-sub import {
- my ($self, @args) = @_;
- my $pack = caller;
-
- $TB->exported_to($pack);
- $TB->plan(@args) if @args;
-
- $self->export_to_level(1, $self, $_) for @EXPORT;
+use vars qw/$VERSION @ISA @EXPORT/;
+use Config;
+use Test::Builder::Module;
+
+BEGIN {
+ $VERSION = '0.01';
+ @ISA = qw/Test::Builder::Module/;
+ @EXPORT = qw(
+ filename_is
+ filename_isnt
+ );
}
+my $CLASS = __PACKAGE__;
+
#--------------------------------------------------------------------------#
# public API
#--------------------------------------------------------------------------#
sub filename_is {
my($got, $expected, $label) = @_;
- $TB->is_eq(canonpath($got), canonpath($expected), $label);
+ return $CLASS->builder->is_eq(_path($got), _path($expected), $label);
}
sub filename_isnt {
-
-}
-
-sub filename_like {
-
-}
-
-sub filename_unlike {
-
+ my($got, $expected, $label) = @_;
+ return $CLASS->builder->isnt_eq(_path($got), _path($expected), $label);
}
#--------------------------------------------------------------------------#
# private functions
#--------------------------------------------------------------------------#
+my $path_sep = quotemeta($Config{path_sep});
+
+sub _path {
+ my ($path) = @_;
+ $path =~ s{$path_sep}{/}g;
+ return $path;
+}
+
1; #modules must return true
@@ -71,7 +55,7 @@ __END__
= NAME
-Test::Filename - Portable tests for filenames
+Test::Filename - Portable filename comparison
= VERSION
@@ -79,11 +63,53 @@ This documentation describes version %%VERSION%%.
= SYNOPSIS
+ use Test::Filename tests => 2;
+
+ filename_is ( "some\path", "some/path", "should pass" );
+ filename_isnt( "some\path", "some/path", "should fail" );
= DESCRIPTION
+Many cross-platform test failures -- particularly on Win32 -- are due to
+hard-coded file paths being used in comparison tests.
+
+ my $file = get_file(); # returns "foo\bar.t";
+ is( $file, "foo/bar.t" ); # fails on Win32
+
+This simple module provides some handy functions to convert all those
+path separators automatically so filename tests will just DWIM.
+
+The alternative is to write your own utility subroutine and use it everywhere
+or just keep on littering your test code with calls to File::Spec -- yuck!
+
+ is( $file, File::Spec->canonpath("some/path"), "should pass" );
+
+Since this module is so simple, you might not think it worth including
+as a {build_requires} dependency. After all, it's not ~that~ hard to
+always remember to use [File::Spec], right? But odds are that, at some point,
+you'll be so busy writing tests that you'll forget and hard-code a path in
+your haste to show what a clever programmer you are.
+
+So just use this module and stop worrying about it. You'll be happier
+and so will anyone trying to install your modules on Win32.
+
= USAGE
+Just like Test::More, you have the option of providing a test plan
+as arguments when you {use} this module. The following functions are
+imported by default.
+
+== filename_is
+== filename_isnt
+
+ filename_is ( $got, $expected, $label );
+ filename_isnt( $got, $expected, $label );
+
+These functions work just like {is()} and {isnt()} from Test::More, but
+the first argument will have native path separators converted to forward
+slashes before comparison. The {$expected} argument must use unix-style
+forward slashes as path separators.
+
= BUGS
Please report any bugs or feature using the CPAN Request Tracker.
@@ -95,6 +121,9 @@ existing test-file that illustrates the bug or desired feature.
= SEE ALSO
+* [perlport]
+* [File::Spec]
+* [Test::More]
= AUTHOR
View
62 lib/Test/Filename.pod
@@ -4,7 +4,7 @@
=head1 NAME
-Test::Filename - Portable tests for filenames
+Test::Filename - Portable filename comparison
=head1 VERSION
@@ -12,10 +12,54 @@ This documentation describes version 0.01.
=head1 SYNOPSIS
+ use Test::Filename tests => 2;
+
+ filename_is ( "some\path", "some/path", "should pass" );
+ filename_isnt( "some\path", "some/path", "should fail" );
+
=head1 DESCRIPTION
+Many cross-platform test failures -- particularly on Win32 -- are due to
+hard-coded file paths being used in comparison tests.
+
+ my $file = get_file(); # returns "foo\bar.t";
+ is( $file, "foo/bar.t" ); # fails on Win32
+
+This simple module provides some handy functions to convert all those
+path separators automatically so filename tests will just DWIM.
+
+The alternative is to write your own utility subroutine and use it everywhere
+or just keep on littering your test code with calls to File::Spec -- yuck!
+
+ is( $file, File::Spec->canonpath("some/path"), "should pass" );
+
+Since this module is so simple, you might not think it worth including
+as a C<<< build_requires >>> dependency. After all, it's not I<that> hard to
+always remember to use L<File::Spec>, right? But odds are that, at some point,
+you'll be so busy writing tests that you'll forget and hard-code a path in
+your haste to show what a clever programmer you are.
+
+So just use this module and stop worrying about it. You'll be happier
+and so will anyone trying to install your modules on Win32.
+
=head1 USAGE
+Just like Test::More, you have the option of providing a test plan
+as arguments when you C<<< use >>> this module. The following functions are
+imported by default.
+
+=head2 filename_is
+
+=head2 filename_isnt
+
+ filename_is ( $got, $expected, $label );
+ filename_isnt( $got, $expected, $label );
+
+These functions work just like C<<< is() >>> and C<<< isnt() >>> from Test::More, but
+the first argument will have native path separators converted to forward
+slashes before comparison. The C<<< $expected >>> argument must use unix-style
+forward slashes as path separators.
+
=head1 BUGS
Please report any bugs or feature using the CPAN Request Tracker.
@@ -27,6 +71,22 @@ existing test-file that illustrates the bug or desired feature.
=head1 SEE ALSO
+=over
+
+=item *
+
+L<perlport>
+
+=item *
+
+L<File::Spec>
+
+=item *
+
+L<Test::More>
+
+=back
+
=head1 AUTHOR
David A. Golden (DAGOLDEN)
View
2  t/00_load.t
@@ -9,8 +9,6 @@ use Test::More;
my @api = qw(
filename_is
filename_isnt
- filename_like
- filename_unlike
);
plan tests => 1 + 2 * @api;
View
53 t/filename_is.t
@@ -7,15 +7,20 @@ select(STDOUT); $|=1;
use File::Spec::Functions qw/canonpath/;
#--------------------------------------------------------------------------#
-
-my $expected_file = "t/00-load.t";
-my $got_file = canonpath( $expected_file );
-
+# setup
#--------------------------------------------------------------------------#
use Test::Tester 'no_plan';
use Test::Filename;
+my $expected_file = 't/00_load.t';
+my $got_file = canonpath( $expected_file );
+my $wrong_file = canonpath('t/wrongfile.t');
+
+#--------------------------------------------------------------------------#
+# filename_is
+#--------------------------------------------------------------------------#
+
check_test(
sub {
filename_is( $got_file, $expected_file, "foo" );
@@ -25,6 +30,44 @@ check_test(
name => "foo",
diag => q{},
},
- "filename_is"
+ "filename_is - ok"
+);
+
+check_test(
+ sub {
+ filename_is( $wrong_file, $expected_file, "foo" );
+ },
+ {
+ ok => 0,
+ name => "foo",
+ },
+ "filename_is - nok"
+);
+
+#--------------------------------------------------------------------------#
+# filename_isnt
+#--------------------------------------------------------------------------#
+
+check_test(
+ sub {
+ filename_isnt( $wrong_file, $expected_file, "foo" );
+ },
+ {
+ ok => 1,
+ name => "foo",
+ diag => q{},
+ },
+ "filename_isnt - ok"
+);
+
+check_test(
+ sub {
+ filename_isnt( $got_file, $expected_file, "foo" );
+ },
+ {
+ ok => 0,
+ name => "foo",
+ },
+ "filename_isnt - nok"
);
View
11 xt/pod-coverage.t
@@ -10,4 +10,13 @@ eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;
-all_pod_coverage_ok();
+my @modules = all_modules('lib');
+
+plan tests => scalar @modules;
+
+for my $mod ( @modules ) {
+ my $doc = "lib/$mod\.pod";
+ $doc =~ s{::}{/}g;
+ pod_coverage_ok( $mod, { pod_from => $doc } );
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.