File: StaticSource.pm

package info (click to toggle)
libmason-perl 2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 748 kB
  • sloc: perl: 4,882; makefile: 7
file content (101 lines) | stat: -rw-r--r-- 3,015 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package Mason::t::StaticSource;
$Mason::t::StaticSource::VERSION = '2.24';
use Test::Class::Most parent => 'Mason::Test::Class';
use Mason::Util qw(write_file touch_file);

sub setup : Test(setup) {
    my ($self) = @_;

    $self->setup_dirs();
    $self->add_comp(
        path => "/ss/remove_component.mc",
        src  => "I will be removed.\n",
    );
    $self->add_comp(
        path => "/ss/change_component.mc",
        src  => "I will be changed.\n",
    );
}

sub write_comp {
    my ( $self, $path, $contents ) = @_;
    my $source_file = $self->interp->load($path)->cmeta->source_file;
    write_file( $source_file, $contents );
}

sub remove_comp {
    my ( $self, $path ) = @_;
    my $source_file = $self->interp->load($path)->cmeta->source_file;
    unlink($source_file);
}

sub test_change_no_ss : Tests {
    my $self = shift;
    $self->test_comp(
        src    => '<& /ss/change_component.mc &>',
        expect => 'I will be changed.',
    );
    sleep(1);    # Make sure timestamp changes
    $self->write_comp( "/ss/change_component.mc", "I have changed!\n" );
    $self->test_comp(
        src    => '<& /ss/change_component.mc &>',
        expect => 'I have changed!',
    );
}

sub test_change_and_touch_ss : Tests {
    my $self       = shift;
    my $touch_file = $self->temp_dir . "/purge.dat";
    $self->setup_interp( static_source => 1, static_source_touch_file => $touch_file );
    $self->test_comp(
        src    => '<& /ss/change_component.mc &>',
        expect => 'I will be changed.',
    );
    sleep(1);    # Make sure timestamp changes
    $self->interp->load('/ss/change_component.mc');
    $self->write_comp( "/ss/change_component.mc", "I have changed!\n" );
    $self->test_comp(
        src    => '<& /ss/change_component.mc &>',
        expect => 'I will be changed.',
    );
    touch_file($touch_file);
    $self->test_comp(
        src    => '<& /ss/change_component.mc &>',
        expect => 'I have changed!',
    );
}

sub test_remove_no_ss : Tests {
    my $self = shift;
    $self->test_comp(
        src    => '<& /ss/remove_component.mc &>',
        expect => 'I will be removed.',
    );
    $self->remove_comp("/ss/remove_component.mc");
    $self->test_comp(
        src          => '<& /ss/remove_component.mc &>',
        expect_error => qr/could not find component/
    );
}

sub test_remove_and_touch_ss : Tests {
    my $self       = shift;
    my $touch_file = $self->temp_dir . "/purge.dat";
    $self->setup_interp( static_source => 1, static_source_touch_file => $touch_file );
    $self->test_comp(
        src    => '<& /ss/remove_component.mc &>',
        expect => 'I will be removed.',
    );
    $self->remove_comp("/ss/remove_component.mc");
    $self->test_comp(
        src    => '<& /ss/remove_component.mc &>',
        expect => 'I will be removed.',
    );
    touch_file($touch_file);
    $self->test_comp(
        src          => '<& /ss/remove_component.mc &>',
        expect_error => qr/could not find component/
    );
}

1;