Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / tool / create-moose-compatibility-tests.pl
CommitLineData
32cf1353 1#!perl
2use strict;
3use warnings;
4
5use File::Path ();
6use File::Spec ();
7use File::Basename ();
8
2af88019 9print "Creating compatibility tests in xt/compat/* ...\n";
32cf1353 10
2af88019 11File::Path::rmtree(File::Spec->catfile('xt', 'compat'));
32cf1353 12
13# some test does not pass... currently skip it.
14my %SKIP_TEST = (
98e392b9 15 '810-isa-or.t' => "Mouse has a bug",
32cf1353 16
17 '052-undefined-type-in-union.t' => "Mouse accepts undefined type as a member of union types",
18 '054-anon-leak.t' => 'Moose has memory leaks',
19
98e392b9 20 '059-weak-with-default.t' => 'Moose has a bug',
21
32cf1353 22 '600-tiny-tiny.t' => "Moose doesn't support ::Tiny",
23 '601-tiny-mouse.t' => "Moose doesn't support ::Tiny",
24 '602-mouse-tiny.t' => "Moose doesn't support ::Tiny",
ed2f9d78 25 '603-mouse-pureperl.t'=> "Moose doesn't have ::PurePerl",
32cf1353 26
4f21a0b3 27 '031_roles_applied_in_create.t' => 't/lib/*.pm are not for Moose',
28 '013_metaclass_traits.t' => 't/lib/*.pm are not for Moose',
32cf1353 29);
30
31my @compat_tests;
32
33File::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
2af88019 54 my $tmpdir = File::Spec->catfile('xt', 'compat', $dirname);
32cf1353 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;
b3d7fe46 68 $src =~ s/Mouse::Util::class_of/Class::MOP::class_of/g;
32cf1353 69 $src =~ s/Mouse/Moose/g;
70 $src;
71 };
72 close $wfh;
73 push @compat_tests, $tmpfile;
74 },
75 no_chdir => 1
76 },
77 't',
78);
79print "Compatibility tests created.\n";
80
81clean_files("@compat_tests"); # defined in main
82
83