File: 02.create_t.t

package info (click to toggle)
libmodule-starter-smart-perl 0.0.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: perl: 224; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,747 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use Test::More;
use Test::TempDir::Tiny;
use File::Spec::Functions qw(catdir catfile);
use Module::Starter qw(Module::Starter::Smart);

my $content = <<"EOF";
I think that I shall never see,
a test as concise as this in ./t!
EOF

test_old_interface();
test_new_interface();

done_testing();

sub test_old_interface {
    my $tempdir  = tempdir();
    my $tdir     = catdir($tempdir, 't');
    my $testfile = '01.test_old_interface.t';
    my $starter  = Module::Starter::Smart->new();
    $starter->{basedir} = $tempdir;

    Module::Starter::Smart::_create_t($starter, $testfile, $content);

    file_contains_ok(catfile($tdir, $testfile), $content);
}

sub test_new_interface {
    my $tempdir   = tempdir();
    my $tdir      = catdir($tempdir, 't');
    my $xtdir     = catdir($tempdir, 'xt');
    my $testfile1 = '01.test_new_interface.t';
    my $testfile2 = '02.test_new_interface.t';
    my $starter   = Module::Starter::Smart->new();
    $starter->{basedir} = $tempdir;

    Module::Starter::Smart::_create_t($starter, 't',  $testfile1, $content);
    Module::Starter::Smart::_create_t($starter, 'xt', $testfile2, $content);

    file_contains_ok(catfile($tdir,  $testfile1), $content);
    file_contains_ok(catfile($xtdir, $testfile2), $content);
}

sub file_contains_ok {
    my $file = shift;
    my $expected_content = shift;

    SKIP: {
        skip "File '$file' does not exist or is unreadable", 1
            unless ok(-f -r $file, "File '$file' exists and is readable");

        open my $fh, '<', $file or die "Cannot open $file: $!\n";
        my $real_content = do { local $/; <$fh> };
        close $fh;

        ok($expected_content eq $real_content, "File '$file' has correct content");
    }
}