| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use FindBin; |
| 4 |
use lib "$FindBin::Bin/../../"; |
| 5 |
use Test::More; |
| 6 |
use t::Util; |
| 7 |
|
| 8 |
test_cpanfile('no cpanfile', sub { |
| 9 |
my $tmpdir = shift; |
| 10 |
|
| 11 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 12 |
use strict; |
| 13 |
use warnings; |
| 14 |
END |
| 15 |
}, {}, <<'CPANFILE'); |
| 16 |
requires 'strict'; |
| 17 |
requires 'warnings'; |
| 18 |
CPANFILE |
| 19 |
|
| 20 |
test_cpanfile('existing cpanfile', sub { |
| 21 |
my $tmpdir = shift; |
| 22 |
|
| 23 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 24 |
use strict; |
| 25 |
use warnings; |
| 26 |
END |
| 27 |
|
| 28 |
test_file("$tmpdir/cpanfile", <<'END'); |
| 29 |
requires 'strict'; |
| 30 |
requires 'warnings'; |
| 31 |
END |
| 32 |
}, {}, <<'CPANFILE'); |
| 33 |
requires 'strict'; |
| 34 |
requires 'warnings'; |
| 35 |
CPANFILE |
| 36 |
|
| 37 |
test_cpanfile('cpanfile with extra requirements', sub { |
| 38 |
my $tmpdir = shift; |
| 39 |
|
| 40 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
END |
| 44 |
|
| 45 |
test_file("$tmpdir/cpanfile", <<'END'); |
| 46 |
requires 'strict'; |
| 47 |
requires 'warnings'; |
| 48 |
requires 'Something::Else'; |
| 49 |
END |
| 50 |
}, {}, <<'CPANFILE'); |
| 51 |
requires 'Something::Else'; |
| 52 |
requires 'strict'; |
| 53 |
requires 'warnings'; |
| 54 |
CPANFILE |
| 55 |
|
| 56 |
test_cpanfile('cpanfile with features', sub { |
| 57 |
my $tmpdir = shift; |
| 58 |
|
| 59 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 60 |
use strict; |
| 61 |
use warnings; |
| 62 |
END |
| 63 |
|
| 64 |
test_file("$tmpdir/cpanfile", <<'END'); |
| 65 |
requires 'strict'; |
| 66 |
requires 'warnings'; |
| 67 |
|
| 68 |
feature 'foo', 'foo', sub { |
| 69 |
requires 'Something::Else'; |
| 70 |
}; |
| 71 |
END |
| 72 |
}, {}, <<'CPANFILE'); |
| 73 |
requires 'strict'; |
| 74 |
requires 'warnings'; |
| 75 |
feature 'foo', 'foo' => sub { |
| 76 |
requires 'Something::Else'; |
| 77 |
}; |
| 78 |
CPANFILE |
| 79 |
|
| 80 |
test_cpanfile('new feature', sub { |
| 81 |
my $tmpdir = shift; |
| 82 |
|
| 83 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 84 |
use strict; |
| 85 |
use warnings; |
| 86 |
END |
| 87 |
}, {features => 'foo:foo:MyTest.pm'}, <<'CPANFILE'); |
| 88 |
feature 'foo', 'foo' => sub { |
| 89 |
requires 'strict'; |
| 90 |
requires 'warnings'; |
| 91 |
}; |
| 92 |
CPANFILE |
| 93 |
|
| 94 |
test_cpanfile('merge feature', sub { |
| 95 |
my $tmpdir = shift; |
| 96 |
|
| 97 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 98 |
use strict; |
| 99 |
use warnings; |
| 100 |
END |
| 101 |
|
| 102 |
test_file("$tmpdir/cpanfile", <<'END'); |
| 103 |
feature 'foo', 'foo', sub { |
| 104 |
requires 'Something::Else'; |
| 105 |
}; |
| 106 |
END |
| 107 |
}, {features => 'foo:foo:MyTest.pm'}, <<'CPANFILE'); |
| 108 |
feature 'foo', 'foo' => sub { |
| 109 |
requires 'Something::Else'; |
| 110 |
requires 'strict'; |
| 111 |
requires 'warnings'; |
| 112 |
}; |
| 113 |
CPANFILE |
| 114 |
|
| 115 |
test_cpanfile('dedupe feature', sub { |
| 116 |
my $tmpdir = shift; |
| 117 |
|
| 118 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 119 |
use strict; |
| 120 |
use warnings; |
| 121 |
use Foo; |
| 122 |
END |
| 123 |
|
| 124 |
test_file("$tmpdir/MyTest2.pm", <<'END'); |
| 125 |
use strict; |
| 126 |
use warnings; |
| 127 |
use Bar; |
| 128 |
END |
| 129 |
}, {features => 'foo:foo:MyTest2.pm'}, <<'CPANFILE'); |
| 130 |
requires 'Foo'; |
| 131 |
requires 'strict'; |
| 132 |
requires 'warnings'; |
| 133 |
feature 'foo', 'foo' => sub { |
| 134 |
requires 'Bar'; |
| 135 |
}; |
| 136 |
CPANFILE |
| 137 |
|
| 138 |
test_cpanfile('exclude_core and feature', sub { |
| 139 |
my $tmpdir = shift; |
| 140 |
|
| 141 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 142 |
use strict; |
| 143 |
use warnings; |
| 144 |
use Foo; |
| 145 |
END |
| 146 |
|
| 147 |
test_file("$tmpdir/MyTest2.pm", <<'END'); |
| 148 |
use strict; |
| 149 |
use warnings; |
| 150 |
use Test::More; |
| 151 |
use Bar; |
| 152 |
END |
| 153 |
}, {features => 'foo:foo:MyTest2.pm', exclude_core => 1}, <<'CPANFILE'); |
| 154 |
requires 'Foo'; |
| 155 |
feature 'foo', 'foo' => sub { |
| 156 |
requires 'Bar'; |
| 157 |
}; |
| 158 |
CPANFILE |
| 159 |
|
| 160 |
test_cpanfile('empty feature because of exclude_core', sub { |
| 161 |
my $tmpdir = shift; |
| 162 |
|
| 163 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 164 |
use strict; |
| 165 |
use warnings; |
| 166 |
use Foo; |
| 167 |
END |
| 168 |
|
| 169 |
test_file("$tmpdir/MyTest2.pm", <<'END'); |
| 170 |
use strict; |
| 171 |
use warnings; |
| 172 |
use Test::More; |
| 173 |
END |
| 174 |
}, {features => 'foo:foo:MyTest2.pm', exclude_core => 1}, <<'CPANFILE'); |
| 175 |
requires 'Foo'; |
| 176 |
CPANFILE |
| 177 |
|
| 178 |
test_cpanfile('empty feature because of unmatching path', sub { |
| 179 |
my $tmpdir = shift; |
| 180 |
|
| 181 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 182 |
use strict; |
| 183 |
use warnings; |
| 184 |
use Foo; |
| 185 |
END |
| 186 |
}, {features => 'foo:foo:MyTest3.pm', exclude_core => 1}, <<'CPANFILE'); |
| 187 |
requires 'Foo'; |
| 188 |
CPANFILE |
| 189 |
|
| 190 |
test_cpanfile('x_phase', sub { |
| 191 |
my $tmpdir = shift; |
| 192 |
my $tmpfile = "$tmpdir/MyTest.pm"; |
| 193 |
|
| 194 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 195 |
use strict; |
| 196 |
use warnings; |
| 197 |
END |
| 198 |
|
| 199 |
test_file("$tmpdir/cpanfile", <<'END'); |
| 200 |
on "x_phase" => sub { |
| 201 |
requires 'Xtra'; |
| 202 |
}; |
| 203 |
|
| 204 |
feature 'foo', 'foo', sub { |
| 205 |
requires 'Something::Else'; |
| 206 |
}; |
| 207 |
END |
| 208 |
}, {features => 'foo:foo:MyTest.pm'}, <<'CPANFILE'); |
| 209 |
on x_phase => sub { |
| 210 |
requires 'Xtra'; |
| 211 |
}; |
| 212 |
feature 'foo', 'foo' => sub { |
| 213 |
requires 'Something::Else'; |
| 214 |
requires 'strict'; |
| 215 |
requires 'warnings'; |
| 216 |
}; |
| 217 |
CPANFILE |
| 218 |
|
| 219 |
test_cpanfile('keep version', sub { |
| 220 |
my $tmpdir = shift; |
| 221 |
|
| 222 |
test_file("$tmpdir/MyTest.pm", <<'END'); |
| 223 |
use Foo; |
| 224 |
END |
| 225 |
|
| 226 |
test_file("$tmpdir/cpanfile", <<'END'); |
| 227 |
requires 'Foo', '1.05'; |
| 228 |
END |
| 229 |
}, {}, <<'CPANFILE'); |
| 230 |
requires 'Foo', '1.05'; |
| 231 |
CPANFILE |
| 232 |
|
| 233 |
done_testing; |