1Test::Filename(3) User Contributed Perl Documentation Test::Filename(3)
2
3
4
6 Test::Filename - Portable filename comparison
7
9 version 0.03
10
12 use Test::Filename tests => 2;
13
14 filename_is ( "some\path", "some/path", "should pass" );
15 filename_isnt( "some\path", "some/path", "should fail" );
16
18 Many cross-platform test failures -- particularly on Win32 -- are due
19 to hard-coded file paths being used in comparison tests.
20
21 my $file = get_file(); # returns "foo\bar.t";
22 is( $file, "foo/bar.t" ); # fails on Win32
23
24 This simple module provides some handy functions to convert all those
25 path separators automatically so filename tests will just DWIM.
26
27 The alternative is to write your own utility subroutine and use it
28 everywhere or just keep on littering your test code with calls to
29 File::Spec -- yuck!
30
31 is( $file, File::Spec->canonpath("some/path"), "should pass" );
32
33 Since this module is so simple, you might not think it worth including
34 as a dependency. After all, it's not that hard to always remember to
35 use File::Spec, Path::Tiny or some other file utility, right? But odds
36 are that, at some point, you'll be so busy writing tests that you'll
37 forget and hard-code a path in your haste to show what a clever
38 programmer you are.
39
40 So just use this module and stop worrying about it. You'll be happier
41 and so will anyone trying to install your modules on Win32.
42
44 Just like Test::More, you have the option of providing a test plan as
45 arguments when you use this module. The following functions are
46 imported by default.
47
48 filename_is =head2 filename_isnt
49 filename_is ( $got, $expected, $label );
50 filename_isnt( $got, $expected, $label );
51
52 These functions work just like is() and isnt() from Test::More, but the
53 first two argument will be cleaned up and normalized to Unix-style
54 paths using Path::Tiny. This means that ".\foo.txt" will get
55 normalized to "foo.txt" and so on.
56
58 • perlport
59
60 • File::Spec
61
62 • Path::Tiny
63
64 • Test::More
65
67 Bugs / Feature Requests
68 Please report any bugs or feature requests through the issue tracker at
69 <https://github.com/dagolden/test-filename/issues>. You will be
70 notified automatically of any progress on your issue.
71
72 Source Code
73 This is open source software. The code repository is available for
74 public review and contribution under the terms of the license.
75
76 <https://github.com/dagolden/test-filename>
77
78 git clone git://github.com/dagolden/test-filename.git
79
81 David A. Golden <dagolden@cpan.org>
82
84 This software is Copyright (c) 2007 by David A. Golden.
85
86 This is free software, licensed under:
87
88 The Apache License, Version 2.0, January 2004
89
90
91
92perl v5.38.0 2023-07-21 Test::Filename(3)