"Fossies" - the Fresh Open Source Software Archive

Member "Module-Build-0.4224/t/mymeta.t" (30 May 2017, 5661 Bytes) of package /linux/privat/Module-Build-0.4224.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl -w
    2 
    3 use strict;
    4 use lib 't/lib';
    5 use MBTest;
    6 
    7 if (eval { require CPAN::Meta; CPAN::Meta->VERSION(2.142060) }) {
    8     plan(tests => 41);
    9     require CPAN::Meta::YAML;
   10     require Parse::CPAN::Meta;
   11 }
   12 else {
   13     plan(skip_all => 'No or old CPAN::Meta');
   14 }
   15 
   16 blib_load('Module::Build');
   17 
   18 my $tmp = MBTest->tmpdir;
   19 
   20 use DistGen;
   21 my $dist = DistGen->new( dir => $tmp );
   22 $dist->change_file('Build.PL', <<"---");
   23 use strict;
   24 use Module::Build;
   25 
   26 my \$builder = Module::Build->new(
   27   module_name         => '$dist->{name}',
   28   license             => 'perl',
   29   requires            => {
   30     'File::Spec' => ( \$ENV{BUMP_PREREQ} ? 0.86 : 0 ),
   31   },
   32   configure_requires  => {
   33     'Module::Build' => '0.42',
   34   }
   35 );
   36 
   37 \$builder->create_build_script();
   38 ---
   39 $dist->regen;
   40 $dist->chdir_in;
   41 
   42 #########################
   43 
   44 # Test MYMETA generation
   45 {
   46   ok( ! -e "META.yml", "META.yml doesn't exist before Build.PL runs" );
   47   ok( ! -e "MYMETA.yml", "MYMETA.yml doesn't exist before Build.PL runs" );
   48   ok( ! -e "META.json", "META.json doesn't exist before Build.PL runs" );
   49   ok( ! -e "MYMETA.json", "MYMETA.json doesn't exist before Build.PL runs" );
   50   my $output;
   51   $output = stdout_of sub { $dist->run_build_pl };
   52   like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
   53     "Ran Build.PL and saw MYMETA.yml creation message"
   54   );
   55   ok( -e "MYMETA.yml", "MYMETA.yml exists" );
   56   ok( -e "MYMETA.json", "MYMETA.json exists" );
   57 }
   58 
   59 #########################
   60 
   61 # Test interactions between META/MYMETA
   62 {
   63   my $output = stdout_stderr_of sub { $dist->run_build('distmeta') };
   64   like($output, qr/Created META\.yml and META\.json/,
   65     "Ran Build distmeta to create META.yml");
   66   # regenerate MYMETA to pick up from META instead of creating from scratch
   67   $output = stdout_of sub { $dist->run_build_pl };
   68   like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
   69     "Re-ran Build.PL and regenerated MYMETA.yml based on META.yml"
   70   );
   71 
   72   for my $suffix ( qw/.yml .json/ ) {
   73     my $meta = Parse::CPAN::Meta->load_file("META$suffix");
   74     my $mymeta = Parse::CPAN::Meta->load_file("MYMETA$suffix");
   75     is( delete $meta->{dynamic_config}, 1,
   76       "META$suffix 'dynamic_config' is 1"
   77     );
   78     is( delete $mymeta->{dynamic_config}, 0,
   79       "MYMETA$suffix 'dynamic_config' is 0"
   80     );
   81 
   82     my $have_url = delete $mymeta->{'meta-spec'}->{url};
   83     my $want_url = delete $meta->{'meta-spec'}->{url};
   84 
   85     is_deeply( $mymeta, $meta, "Other generated MYMETA$suffix matches generated META$suffix" )
   86       or do {
   87         require Data::Dumper;
   88         diag "MYMETA:\n" . Data::Dumper::Dumper($mymeta)
   89           .  "META:\n" . Data::Dumper::Dumper($meta);
   90       };
   91 
   92     like $have_url, qr{Meta(::|-)Spec}i, "CPAN meta spec mentioned in meta-spec URL";
   93   }
   94 
   95   $output = stdout_stderr_of sub { $dist->run_build('realclean') };
   96   like( $output, qr/Cleaning up/, "Ran realclean");
   97   ok( ! -e 'Build', "Build file removed" );
   98   ok( ! -e 'MYMETA.yml', "MYMETA.yml file removed" );
   99   ok( ! -e 'MYMETA.json', "MYMETA.json file removed" );
  100 
  101   # test that dynamic prereq is picked up
  102   my $meta = Parse::CPAN::Meta->load_file("META.yml");
  103   my $meta2 = Parse::CPAN::Meta->load_file("META.json");
  104   local $ENV{BUMP_PREREQ} = 1;
  105   $output = stdout_of sub { $dist->run_build_pl };
  106   like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
  107     "Ran Build.PL with dynamic config"
  108   );
  109   ok( -e "MYMETA.yml", "MYMETA.yml exists" );
  110   ok( -e "MYMETA.json", "MYMETA.json exists" );
  111   my $mymeta = Parse::CPAN::Meta->load_file('MYMETA.yml');
  112   my $mymeta2 = Parse::CPAN::Meta->load_file('MYMETA.json');
  113   isnt(   $meta->{requires}{'File::Spec'},
  114         $mymeta->{requires}{'File::Spec'},
  115         "MYMETA.yml requires differs from META.yml"
  116   );
  117   isnt(   $meta2->{prereqs}{runtime}{requires}{'File::Spec'},
  118         $mymeta2->{prereqs}{runtime}{requires}{'File::Spec'},
  119         "MYMETA.json requires differs from META.json"
  120   );
  121   $output = stdout_stderr_of sub { $dist->run_build('realclean') };
  122   like( $output, qr/Cleaning up/, "Ran realclean");
  123   ok( ! -e 'Build', "Build file removed" );
  124   ok( ! -e 'MYMETA.yml', "MYMETA file removed" );
  125   ok( ! -e 'MYMETA.json', "MYMETA file removed" );
  126 
  127   # manually change META and check that changes are preserved
  128   $meta->{author} = ['John Gault'];
  129   $meta2->{author} = ['John Gault'];
  130   ok( CPAN::Meta::YAML->new($meta)->write('META.yml'),
  131     "Wrote manually modified META.yml" );
  132   ok( CPAN::Meta->new( $meta2 )->save('META.json'),
  133     "Wrote manually modified META.json" );
  134 
  135   $output = stdout_of sub { $dist->run_build_pl };
  136   like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
  137     "Ran Build.PL"
  138   );
  139   $mymeta = Parse::CPAN::Meta->load_file('MYMETA.yml');
  140   $mymeta2 = Parse::CPAN::Meta->load_file('MYMETA.json');
  141   is_deeply( $mymeta->{author}, [ 'John Gault' ],
  142     "MYMETA.yml preserved META.yml modifications"
  143   );
  144   is_deeply( $mymeta2->{author}, [ 'John Gault' ],
  145     "MYMETA.json preserved META.json modifications"
  146   );
  147 
  148 }
  149 
  150 #########################
  151 
  152 # Test cleanup
  153 {
  154   my $output = stdout_stderr_of sub { $dist->run_build('distcheck') };
  155   like($output, qr/Creating a temporary 'MANIFEST.SKIP'/,
  156     "MANIFEST.SKIP created for distcheck"
  157   );
  158   unlike($output, qr/MYMETA/,
  159     "MYMETA not flagged by distcheck"
  160   );
  161 }
  162 
  163 
  164 {
  165   my $output = stdout_of sub { $dist->run_build_pl };
  166   like($output, qr/Created MYMETA\.yml and MYMETA\.json/,
  167     "Ran Build.PL and saw MYMETA.yml creation message"
  168   );
  169   $output = stdout_stderr_of sub { $dist->run_build('distclean') };
  170   ok( ! -f 'MYMETA.yml', "No MYMETA.yml after distclean" );
  171   ok( ! -f 'MYMETA.json', "No MYMETA.json after distclean" );
  172   ok( ! -f 'MANIFEST.SKIP', "No MANIFEST.SKIP after distclean" );
  173 }
  174 
  175