File: gen.pl

package info (click to toggle)
libalien-build-perl 2.84-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,116 kB
  • sloc: perl: 10,350; ansic: 134; sh: 66; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 1,607 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
use strict;
use warnings;

my @list = sort map { chomp; s/\.pm$//; s/^lib\///; s/\//::/g; $_ } `find lib -name \*.pm`;

open my $fh, '>', 't/01_use.t';

print $fh <<'EOM';
use Test2::V0 -no_srand => 1;

sub require_ok ($);

EOM

foreach my $module (@list)
{
  print $fh "require_ok '$module';\n";
}

foreach my $module (@list)
{
  my $test = lc $module;
  $test =~ s/::/_/g;
  $test = "t/$test.t";
  printf $fh "ok -f %-55s %s\n", "'$test',", "'test for $module';";
}

print $fh <<'EOM';
done_testing;

sub require_ok ($)
{
  # special case of when I really do want require_ok.
  # I just want a test that checks that the modules
  # will compile okay.  I won't be trying to use them.
  my($mod) = @_;
  my $ctx = context();
  {
    my $pm = "$mod.pm";
    $pm =~ s/::/\//g;
    eval { require $pm };
  }
  my $error = $@;
  my $ok = !$error;
  $ctx->ok($ok, "require $mod");
  $ctx->diag("error: $error") if $error ne '';
  $ctx->release;
}
EOM

close $fh;

#system 'perltidy -b -i=2 -l=900 t/01_use.t';
#unlink 't/01_use.t.bak';


{
  sub run
  {
    my(@cmd) = @_;
    print "% @cmd\n";
    system @cmd;
    die 'command failed' if $?;
  }
  use autodie;
  mkdir 'corpus/dist2' unless -d 'corpus/dist2';
  chdir 'corpus/dist2';
  run 'rm', '-rf', 'foo', 'foo.tar';
  mkdir 'foo';
  run 'git', -C => 'foo', 'init';
  open my $fh, '>', 'foo/foo.txt';
  print $fh "xx\n";
  close $fh;
  run 'git', -C => 'foo', 'add', '.';
  run 'git', -C => 'foo', 'commit', -m => 'yy';
  run 'git', -C => 'foo', 'archive', '--prefix=foo-1.00/', -o => '../foo.tar', 'master';
  run 'rm', '-rf', 'foo';
  chdir '../..';
}