File: test.pl

package info (click to toggle)
libhtml-calendarmonth-perl 1.09-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 152 kB
  • ctags: 68
  • sloc: perl: 755; makefile: 38
file content (83 lines) | stat: -rw-r--r-- 2,041 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
73
74
75
76
77
78
79
80
81
82
83
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

######################### We start with some black magic to print on failure.

# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)

# Establish number of tests (ugh)
BEGIN {
  # Required test dates
  open(D, "test.dat");
  $rds = <D>;
  foreach (split(' ', $rds)) {
    ++$dates{$_};
  }

  # Today's date
  ($month, $year) = (localtime(time))[4,5];
  ++$month;
  $year += 1900;

  # Flag tests for a year
  foreach $y ($year .. $year + 1) {
    foreach $m (1 .. 12) {
      ++$dates{sprintf("%d/%02d", $y, $m)};
    }
  }

  # Yank test cases
  while (<D>) {
    chomp;
    ($d, $wb) = split(' ', $_);
    ($y, $m) = split('/', $d);
    $cal = <D>;
    push(@cals, [$y, $m, $cal, $wb]) if $dates{"$y/$m"};
  }

  close(D);
  $tcount = @cals;

  # Figure out calendar generation options
  @modules  = qw(Time::Local Date::Calc Date::Manip);
  @tmethods = ();

  foreach $module (@modules) {
    if (eval "require $module") {
      print "Found $module, adding to tests.\n";
      push(@tmethods, $module);
    }
  }

  if ($CAL = `which cal`) {
    chomp $CAL;
    print "Found cal command at '$CAL', adding to tests.\n";
    push(@tmethods, 'cal');
  }

  $tcount = $tcount * @tmethods;

}

# Carry on
BEGIN { $| = 1; print "1..$tcount\n"; }
END {print "not ok   1\n" unless $loaded;}
use HTML::CalendarMonth;
$loaded = 1;
print "ok   1\n";

######################### End of black magic.

# Compare each case using each method
@days = qw( Sun Mon Tue Wed Thr Fri Sat );
$tc = 2;
foreach $tmethod (@tmethods) {
  foreach $cal (@cals) {
    $c = HTML::CalendarMonth->new( year => $cal->[0], month => $cal->[1], week_begin => $cal->[3] );
    print $c->as_HTML eq $cal->[2] ? "ok " : "not ok ";
    $day1 = $days[$cal->[3] - 1];
    printf("%3d (%d/%-02d %s 1st day) using $tmethod\n", $tc, $cal->[0], $cal->[1], $day1);
    ++$tc;
  }
}