File: 10_noglob.t

package info (click to toggle)
libfile-remove-perl 1.60-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 240 kB
  • sloc: perl: 836; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl

use strict;
use warnings;

use 5.006;

use File::Spec ();
use Cwd        (qw/getcwd/);

use File::Path qw/rmtree/;

use Test::More tests => 3;

use File::Remove qw/remove/;

{
    my $dir = File::Spec->rel2abs(
        File::Spec->catdir( File::Spec->curdir(), "t", "10_noglob_dir", ) );

    mkdir($dir);

    my $file_path = sub {
        my ($bn) = @_;
        return File::Spec->catfile( $dir, $bn );
    };

    my $create_file = sub {
        my ( $bn, $contents ) = @_;

        open my $fh, '>', $file_path->($bn)
            or die "Cannot create basename '$bn'";
        print {$fh} $contents;
        close($fh);

        return;
    };

    $create_file->( "a", "a contents\n" );
    $create_file->( "b", "b contents\n" );
    $create_file->( "c", "c contents\n" );

    my $cur_dir = getcwd();

    chdir($dir);

    remove( \0, +{ glob => 0 }, '*' );

    my $is_file = sub {
        my ($bn) = @_;

        local $Test::Builder::Level = $Test::Builder::Level + 1;

        return ok( scalar( -e $file_path->($bn) ), "$bn was not deleted." );
    };

    # TEST
    $is_file->('a');

    # TEST
    $is_file->('b');

    # TEST
    $is_file->('c');

    chdir($cur_dir);

    rmtree($dir);
}