File: log_watch.t

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,912 kB
  • ctags: 4,588
  • sloc: perl: 95,064; ansic: 14,527; makefile: 49; sh: 18
file content (76 lines) | stat: -rw-r--r-- 2,035 bytes parent folder | download | duplicates (13)
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
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil qw/t_start_file_watch
                        t_read_file_watch
                        t_finish_file_watch
                        t_write_file
                        t_append_file
                        t_catfile
                        t_cmp/;

plan tests => 11;

my $fn=t_catfile(Apache::Test::vars->{t_logs}, 'watch');
unlink $fn;

t_start_file_watch 'watch';

t_write_file $fn, "1\n2\n";

ok t_cmp [t_read_file_watch 'watch'], ["1\n", "2\n"],
    "t_read_file_watch on previously non-existing file";

t_append_file $fn, "3\n4\n";

ok t_cmp [t_read_file_watch 'watch'], ["3\n", "4\n"],
    "subsequent t_read_file_watch";

t_append_file $fn, "5\n6\n";

ok t_cmp [t_finish_file_watch 'watch'], ["5\n", "6\n"],
    "subsequent t_finish_file_watch";

ok t_cmp [t_finish_file_watch 'watch'], ["1\n","2\n","3\n","4\n","5\n","6\n"],
    "t_finish_file_watch w/o start";

ok t_cmp [t_read_file_watch 'watch'], ["1\n","2\n","3\n","4\n","5\n","6\n"],
    "t_read_file_watch w/o start";

ok t_cmp [t_read_file_watch 'watch'], [],
    "subsequent t_read_file_watch";

t_append_file $fn, "7\n8\n";
unlink $fn;

ok t_cmp [t_read_file_watch 'watch'], ["7\n","8\n"],
    "subsequent t_read_file_watch file unlinked";

t_write_file $fn, "1\n2\n3\n4\n5\n6\n7\n8\n";

ok t_cmp [t_finish_file_watch 'watch'], [],
    "subsequent t_finish_file_watch - new file exists but fh is cached";

t_start_file_watch 'watch';

ok t_cmp [t_read_file_watch 'watch'], [],
    "t_read_file_watch at EOF";

# Make sure the file is closed before deleting it on Windows.
t_finish_file_watch 'watch' if $^O eq 'MSWin32';

unlink $fn;
t_start_file_watch 'watch';

t_write_file $fn, "1\n2\n3\n4\n5\n6\n7\n8\n";

{
    local $/=\4;

    ok t_cmp [scalar t_read_file_watch 'watch'], ["1\n2\n"],
        "t_read_file_watch fixed record length / scalar context";

    ok t_cmp [t_finish_file_watch 'watch'], ["3\n4\n","5\n6\n","7\n8\n"],
        "t_finish_file_watch fixed record length";
}