File: 1_compile.t

package info (click to toggle)
libastro-fits-header-perl 3.09-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 432 kB
  • sloc: perl: 2,387; makefile: 10
file content (126 lines) | stat: -rw-r--r-- 2,682 bytes parent folder | download | duplicates (5)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!perl

# This test simply loads all the modules
# it does this by scanning the directory for .pm files
# and use'ing each in turn

# It is slow because of the fork required for each separate use
use 5.006;
use strict;
use warnings;

# Test module only used for planning
# Note that we can not use Test::More since Test::More
# will lose count of its tests and complain (through the fork)
use Test::More;

use File::Find;

our @modules;

# If SKIP_COMPILE_TEST environment variable is set we
# just skip this test because it takes a long time
if (exists $ENV{SKIP_COMPILE_TEST}) {
  print "1..0 # Skip compile tests not required\n";
  exit;
}


# Scan the blib/ directory looking for modules


find({ wanted => \&wanted,
       no_chdir => 1,
       }, "blib");

# Start the tests
plan tests => (scalar(@modules));

# Loop through each module and try to run it

$| = 1;
my $counter = 0;

my $tempfile = "results.dat";

for my $module (@modules) {

  # Try forking. Perl test suite runs 
  # we have to fork because each "use" will contaminate the 
  # symbol table and we want to start with a clean slate.
  my $pid;
  if ($pid = fork) {
    # parent

    # wait for the forked process to complete
    waitpid($pid, 0);

    # Control now back with parent.

  } else {
    # Child
    die "cannot fork: $!" unless defined $pid;

    my $isok = 1;
    my $skip = '';
    eval "use $module ();";
    if( $@ ) {
      if ($@ =~ /Can't locate (.*\.pm) in/) {
        my $missing = $1;
        diag( "$module can not locate $missing" );
        $skip = "missing module $missing from $module";
      } else {
        diag( "require failed with '$@'\n" );
        $isok = 0;
      }
    }

    # Open the temp file
    open( my $fh, "> $tempfile") || die "Could not open $tempfile: $!";
    print $fh "$isok $skip\n";
    close($fh);

    exit;
  }

  if (open( my $fh, "< $tempfile")) {
    my $line = <$fh>;
    close($fh);
    if (defined $line) {
      chomp($line);
      my ($status, $skip) = split(/\s+/, $line, 2);
    SKIP: {
        skip( $skip, 1) if $skip;
        ok( $status, "Load $module");
      }
    } else {
      ok( 0, "Could not get results from loading module $module");
    }
  } else {
    # did not get the temp file
    ok(0, "Could not get results from loading module $module");
  }
  unlink($tempfile);

}

# This determines whether we are interested in the module
# and then stores it in the array @modules

sub wanted {
  my $pm = $_;

  # is it a module
  return unless $pm =~ /\.pm$/;

  # Remove the blib/lib (assumes unix!)
  $pm =~ s|^blib/lib/||;

  # Translate / to ::
  $pm =~ s|/|::|g;

  # Remove .pm
  $pm =~ s/\.pm$//;

  push(@modules, $pm);
}