File: 10-basics.t

package info (click to toggle)
libfile-slurper-perl 0.009-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 172 kB
  • sloc: perl: 356; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 935 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
#! perl

use strict;
use warnings;

use File::Spec::Functions qw/catfile/;
use File::Slurper qw/read_text read_binary read_lines write_text read_dir/;
use File::Temp 'tempfile';

use Test::More;

my $content = do { local $/; open my $fh, '<:raw', $0; <$fh> };
is(read_text($0), $content, 'read_file() works');
is(read_binary($0), $content, 'read_binary() works');

my @content = split /(?<=\n)/, $content;

is_deeply([ read_lines($0, 'utf-8', 0, 1) ], \@content, 'read_lines returns the right thing (no chomp)');
chomp @content;

is_deeply([ read_lines($0) ], \@content, 'read_lines returns the right thing (chomp)');

is_deeply([ read_dir('lib') ], [ 'File' ], 'read_dir appears to work') unless $ENV{ADTTMP};

my ($fh, $filename) = tempfile(UNLINK => 1);

ok(eval { write_text($filename, $content); 1 }, 'File has been written') or diag "Error: $@";
is(read_text($filename), $content, 'New file has correct content');

done_testing;