Fix compatibility tests
[gitmo/Mouse.git] / tool / create-moose-compatibility-tests.pl
1 #!perl
2 use strict;
3 use warnings;
4
5 use File::Path ();
6 use File::Spec ();
7 use File::Basename ();
8
9 print "Creating compatibility tests in xt/compatibility/* ...\n";
10
11 File::Path::rmtree(File::Spec->catfile('xt', 'compatibility'));
12
13 # some test does not pass... currently skip it.
14 my %SKIP_TEST = (
15     '016-trigger.t'    => "trigger's argument is incompatble :(",
16     '810-isa-or.t'     => "Mouse has a bug",
17
18     '052-undefined-type-in-union.t' => "Mouse accepts undefined type as a member of union types",
19     '054-anon-leak.t'     => 'Moose has memory leaks',
20
21     '059-weak-with-default.t' => 'Moose has a bug',
22
23     '600-tiny-tiny.t'     => "Moose doesn't support ::Tiny",
24     '601-tiny-mouse.t'    => "Moose doesn't support ::Tiny",
25     '602-mouse-tiny.t'    => "Moose doesn't support ::Tiny",
26     '603-mouse-pureperl.t'=> "Moose doesn't have ::PurePerl",
27
28     '031_roles_applied_in_create.t' => 't/lib/* classes are not Moose classes/roles',
29 );
30
31 my @compat_tests;
32
33 File::Find::find(
34     {
35         wanted => sub {
36             return unless -f $_;
37
38             return if /failing/; # skip tests in failing/ directories which  are Moose specific
39
40             return if /with_moose/; # tests with Moose
41             return if /100_bugs/;   # some tests require Mouse specific files
42             return if /deprecated/;
43
44             my $basename = File::Basename::basename($_);
45             return if $basename =~ /^\./;
46
47             if(exists $SKIP_TEST{$basename}){
48                 print "# skip $basename because: $SKIP_TEST{$basename}\n";
49                 return;
50             }
51
52             my $dirname = File::Basename::dirname($_);
53
54             my $tmpdir = File::Spec->catfile('xt', 'compatibility', $dirname);
55             File::Path::mkpath($tmpdir);
56
57             my $tmpfile = File::Spec->catfile($tmpdir, $basename);
58             open my $wfh, '>', $tmpfile or die $!;
59             print $wfh do {
60                 my $src = do {
61                     open my $rfh, '<', $_ or die $!;
62                     my $s = do { local $/; <$rfh> };
63                     close $rfh;
64                     $s;
65                 };
66                 $src =~ s/Mouse::(?:Util::)?is_class_loaded/Class::MOP::is_class_loaded/g;
67                 $src =~ s/Mouse::(?:Util::)?load_class/Class::MOP::load_class/g;
68                 $src =~ s/Mouse/Moose/g;
69                 $src;
70             };
71             close $wfh;
72             push @compat_tests, $tmpfile;
73         },
74         no_chdir => 1
75     },
76     't',
77 );
78 print "Compatibility tests created.\n";
79
80 clean_files("@compat_tests"); # defined in main
81
82