FastGlob

 view release on metacpan or  search on metacpan

t/glob-comparison.t  view on Meta::CPAN

#!/usr/bin/env perl

# Comprehensive comparison test: FastGlob::glob() vs CORE::glob()
#
# Creates a controlled directory structure and verifies that FastGlob
# produces the same results as CORE::glob for a wide variety of patterns.
# Divergences are documented as TODO tests so they serve as a roadmap
# for fixes without blocking CI.

use strict;
use warnings;

use Test::More;
use File::Temp qw(tempdir);
use File::Path qw(make_path);
use File::Spec;
use File::Basename qw(basename);
use Cwd qw(getcwd abs_path);

use FastGlob ();

# --- Build a controlled directory tree ---

# Use DIR => '.' to avoid 8.3 short path issues on Windows
my $root = tempdir( DIR => '.', CLEANUP => 1 );
$root = abs_path($root);

# Helper: create a file (and parent dirs if needed)
sub touch {
    my ($relpath) = @_;
    my $full = File::Spec->catfile( $root, split m{/}, $relpath );
    my $dir  = File::Basename::dirname($full);
    make_path($dir) unless -d $dir;
    open my $fh, '>', $full or die "Cannot create $full: $!";
    close $fh;
}

# Helper: create a directory
sub mkd {
    my ($relpath) = @_;
    my $full = File::Spec->catdir( $root, split m{/}, $relpath );
    make_path($full) unless -d $full;
}

# Build the tree:
#   root/
#     alpha.c
#     beta.c
#     gamma.h
#     delta.txt
#     README
#     .hidden
#     .dotdir/
#       secret.txt
#     src/
#       main.c
#       util.c
#       helper.h
#       lib/
#         core.c
#         extra.c
#     docs/
#       guide.txt
#       notes.txt
#     empty/

touch('alpha.c');
touch('beta.c');
touch('gamma.h');
touch('delta.txt');
touch('README');
touch('.hidden');
mkd('.dotdir');
touch('.dotdir/secret.txt');
mkd('src');
touch('src/main.c');
touch('src/util.c');
touch('src/helper.h');
mkd('src/lib');
touch('src/lib/core.c');
touch('src/lib/extra.c');
mkd('docs');
touch('docs/guide.txt');
touch('docs/notes.txt');
mkd('empty');

# --- Helpers ---

# Compare FastGlob and CORE::glob, using basenames on Windows
# to avoid separator/drive-prefix mismatches.
sub compare_glob {
    my ($pattern, $description, %opts) = @_;

    my @fast = FastGlob::glob($pattern);
    my @core = do { my @r = CORE::glob($pattern); sort @r };

    if ( $^O eq 'MSWin32' ) {
        # On Windows, compare basenames only — FastGlob uses \, CORE::glob uses /
        @fast = sort map { basename($_) } @fast;
        @core = sort map { basename($_) } @core;
    } else {



( run in 0.480 second using v1.01-cache-2.11-cpan-71847e10f99 )