Commit | Line | Data |
7a4e305a |
1 | package MBTest; |
2 | |
3 | use strict; |
eed8b6fa |
4 | use warnings; |
7a4e305a |
5 | |
7a4e305a |
6 | use File::Spec; |
7 | use File::Temp (); |
7a4e305a |
8 | |
9 | # Setup the code to clean out %ENV |
10 | BEGIN { |
11 | # Environment variables which might effect our testing |
12 | my @delete_env_keys = qw( |
13 | HOME |
14 | DEVEL_COVER_OPTIONS |
15 | MODULEBUILDRC |
16 | PERL_MB_OPT |
17 | HARNESS_TIMER |
18 | HARNESS_OPTIONS |
19 | HARNESS_VERBOSE |
20 | PREFIX |
21 | INSTALL_BASE |
22 | INSTALLDIRS |
23 | ); |
24 | |
25 | # Remember the ENV values because on VMS %ENV is global |
26 | # to the user, not the process. |
27 | my %restore_env_keys; |
28 | |
29 | sub clean_env { |
30 | for my $key (@delete_env_keys) { |
31 | if( exists $ENV{$key} ) { |
32 | $restore_env_keys{$key} = delete $ENV{$key}; |
33 | } |
34 | else { |
35 | delete $ENV{$key}; |
36 | } |
37 | } |
38 | } |
39 | |
40 | END { |
41 | while( my($key, $val) = each %restore_env_keys ) { |
42 | $ENV{$key} = $val; |
43 | } |
44 | } |
45 | } |
46 | |
47 | |
48 | BEGIN { |
49 | clean_env(); |
50 | |
51 | # In case the test wants to use our other bundled |
52 | # modules, make sure they can be loaded. |
53 | my $t_lib = File::Spec->catdir('t', 'bundled'); |
54 | push @INC, $t_lib; # Let user's installed version override |
55 | |
56 | if ($ENV{PERL_CORE}) { |
57 | # We change directories, so expand @INC and $^X to absolute paths |
58 | # Also add . |
59 | @INC = (map(File::Spec->rel2abs($_), @INC), "."); |
60 | $^X = File::Spec->rel2abs($^X); |
61 | } |
62 | } |
63 | |
64 | use Exporter; |
65 | use Test::More; |
66 | use Config; |
67 | use Cwd (); |
68 | |
69 | # We pass everything through to Test::More |
70 | use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO); |
71 | $VERSION = 0.01_01; |
72 | @ISA = qw(Test::More); # Test::More isa Exporter |
73 | @EXPORT = @Test::More::EXPORT; |
74 | %EXPORT_TAGS = %Test::More::EXPORT_TAGS; |
75 | |
76 | # We have a few extra exports, but Test::More has a special import() |
77 | # that won't take extra additions. |
78 | my @extra_exports = qw( |
7a4e305a |
79 | ); |
80 | push @EXPORT, @extra_exports; |
81 | __PACKAGE__->export(scalar caller, @extra_exports); |
82 | # XXX ^-- that should really happen in import() |
83 | |
84 | |
85 | ######################################################################## |
86 | |
87 | # always return to the current directory |
88 | { |
89 | my $cwd = File::Spec->rel2abs(Cwd::cwd); |
90 | |
91 | sub original_cwd { return $cwd } |
92 | |
93 | END { |
94 | # Go back to where you came from! |
95 | chdir $cwd or die "Couldn't chdir to $cwd"; |
96 | } |
97 | } |
98 | ######################################################################## |
99 | |
7a4e305a |
100 | # Setup a temp directory |
101 | sub tmpdir { |
102 | my ($self, @args) = @_; |
103 | my $dir = $ENV{PERL_CORE} ? MBTest->original_cwd : File::Spec->tmpdir; |
104 | return File::Temp::tempdir('MB-XXXXXXXX', CLEANUP => 1, DIR => $dir, @args); |
105 | } |
106 | |
107 | BEGIN { |
108 | $ENV{HOME} = tmpdir; # don't want .modulebuildrc or other things interfering |
109 | } |
110 | |
7a4e305a |
111 | 1; |
112 | # vim:ts=2:sw=2:et:sta |