File: IO_All_Test.pm

package info (click to toggle)
libio-all-perl 0.38-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 508 kB
  • ctags: 312
  • sloc: perl: 2,647; makefile: 14
file content (61 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download | duplicates (3)
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
package IO_All_Test;
use File::Path;
@EXPORT = qw(
    test_file_contents 
    test_file_contents2 
    test_matching_files
    read_file_lines
    flip_slash f
);
use strict;
use base 'Exporter';
use Test::More ();

sub test_file_contents {
    my ($data, $file) = @_;
    Test::More::is($data, read_file($file));
}

sub test_file_contents2 {
    my ($file, $data) = @_;
    Test::More::is(read_file($file), $data);
}

sub test_matching_files {
    my ($file1, $file2) = @_;
    Test::More::is(read_file($file1), read_file($file2));
}

sub read_file {
    my ($file) = @_;
    local(*FILE, $/);
    open FILE, $file 
      or die "Can't open $file for input:\n$!";
    <FILE>;
}

sub read_file_lines {
    my ($file) = @_;
    local(*FILE);
    open FILE, $file or die $!;
    (<FILE>);
}

sub flip_slash {
    my $string = shift;
    if ($^O =~ /^mswin32$/i) {
        $string =~ s/\//\\/g;
    }
    return $string;
}
{
    no warnings;
    *f = \&flip_slash;
}

BEGIN {
    File::Path::rmtree('t/output');
    File::Path::mkpath('t/output');
}

1;