File: ancient-sv-date.t

package info (click to toggle)
lintian 2.5.10.4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 12,608 kB
  • sloc: perl: 12,430; sh: 5,787; makefile: 2,834; xml: 1,125; ansic: 347; python: 28; java: 9; tcl: 4; sed: 3
file content (72 lines) | stat: -rwxr-xr-x 1,896 bytes parent folder | download
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
#!/usr/bin/perl
#
# Test for keeping "ancient standards version" date
# recent.
#

use strict;
use warnings;

use Test::More;

# How much out of date the check may be; measured in seconds
# 1 month
use constant ERROR_MARGIN => 3600 * 24 * 31;
# How long before a SV is considered "Ancient" in seconds.
# 2 years.
use constant ANCIENT_AGE  => 3600 * 24 * 365 * 2;
use Date::Parse qw(str2time);

# STOP! Before you even consider to make this run always
# remember that this test will fail (causing FTBFS) every
# "ERROR_MARGIN" seconds!
#   This check is here to remind us to update ANCIENT_DATE
# in checks/standards-version every now and then during
# development cycles!
plan skip_all => 'Only checked for UNRELEASED versions'
    if should_skip();

plan tests => 2;

my $check = "$ENV{'LINTIAN_ROOT'}/checks/standards-version";
my $found = 0;
open my $fd, '<', $check or die "opening $check: $!";
while ( my $line = <$fd> ) {
    # We are looking for:
    #   my $ANCIENT_DATE = str2time('20 Aug 2009')
    $line =~ s,\#.*+,,o;
    if ($line =~ m/ANCIENT_DATE \s* = \s* str2time\s*\(\s*
                  [\'\"]([^\'\"]+)[\'\"]/ox){
        my $date = $1;
        my $and = str2time($date) or die "Cannot parse date ($date, line $.): $!";
        my $time = time - ANCIENT_AGE;
        $found = 1;
        cmp_ok($time, '<', $and + ERROR_MARGIN, "ANCIENT_DATE is up to date");
        cmp_ok($time, '>', $and - ERROR_MARGIN, "ANCIENT_DATE is not too far ahead");
        last;
    }
}
close $fd;

die "Cannot find ANCIENT_DATE.\n" unless $found;


sub should_skip {
    my $skip = 1;
    my $pid;

    $pid = open (DPKG, '-|', 'dpkg-parsechangelog', '-c0');

    die("failed to execute dpkg-parsechangelog: $!")
	unless defined ($pid);

    while (<DPKG>) {
	$skip = 0 if m/^Distribution: UNRELEASED$/;
    }

    close(DPKG)
	or die ("dpkg-parsechangelog returned: $?");

    return $skip;
}