Test::Filename(3pm)

πŸ“¦
version 0.03 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble

πŸ’– Test::Filename πŸ’–

ok so bestie, welcome to Test::Filename β€” the little module that makes filename comparison work the same everywhere instead of exploding the second someone runs your test suite on Win32. it's giving portable filename comparison, and honestly? iconic. πŸ¦‹


✨ VERSION ✨

version 0.03 πŸŽ€


🌸 SYNOPSIS 🌸

use Test::Filename tests => 2;

filename_is  ( "some\path", "some/path", "should pass" );
filename_isnt( "some\path", "some/path", "should fail" );

like. that's it. that's the whole vibe. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

ok so real talk: a ton of cross-platform test failures β€” especially on Win32 β€” happen because somebody hard-coded a file path into a comparison test. like:

my $file = get_file();     # returns "foo\bar.t";
is( $file, "foo/bar.t" );  # fails on Win32

see that? the file is literally the same file. but the slashes are pointing the wrong way and now your whole test run is crying. 😭

so this simple module hands you some handy functions that convert all those path separators automatically, so filename tests just DWIM. (do what i mean, bestie. it's a whole thing. iykyk.) ✨

the alternative is that you write your own utility subroutine and use it everywhere, or you just keep on littering your test code with calls to File::Spec β€” yuck! πŸ’€

is( $file, File::Spec->canonpath("some/path"), "should pass" );

and listen, since this module is so simple, you might be sitting there thinking it's not even worth adding as a dependency. like, "it's not that hard to always remember to use File::Spec, Path::Tiny or some other file utility, 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 everyone what a clever programmer you are. we've all been there. no judgment. 🫢

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. everyone wins. periodt. πŸ‘‘


πŸ’œ 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, except the first two arguments get cleaned up and normalized to Unix-style paths using Path::Tiny. which means .\foo.txt will get normalized to foo.txt and so on. slay. ✨


⭐ SEE ALSO ⭐

  • perlport
  • File::Spec
  • Path::Tiny
  • Test::More

🧚 SUPPORT 🧚

πŸ› Bugs / Feature Requests πŸ›

please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/test-filename/issues>. you will be notified automatically of any progress on your issue. we're on it, bestie. πŸ’Œ

πŸ“¦ Source Code πŸ“¦

this is open source software. the code repository is available for public review and contribution under the terms of the license.

<https://github.com/dagolden/test-filename>

git clone git://github.com/dagolden/test-filename.git

πŸ‘‘ AUTHOR πŸ‘‘

David A. Golden <dagolden@cpan.org>


this software is Copyright (c) 2007 by David A. Golden.

this is free software, licensed under:

The Apache License, Version 2.0, January 2004

and that's the whole page, bestie!! 🫢 generated by perl v5.34.0 on 2022-06-17, from the User Contributed Perl Documentation collection β€” go forth and normalize those paths, you absolute main character. πŸ’…βœ¨πŸŽ€πŸ¦‹
πŸ“¦ where this page comes from