File: 10-repo.t

package info (click to toggle)
libdist-zilla-plugin-repository-perl 0.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: perl: 559; makefile: 2
file content (489 lines) | stat: -rw-r--r-- 13,784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#! /usr/bin/perl
#---------------------------------------------------------------------

use strict;
use warnings;
use Test::More;

use Dist::Zilla::Tester;

#---------------------------------------------------------------------
# Fake execution of VCS commands:

use Dist::Zilla::Plugin::Repository;    # make sure it's already loaded
use File::Temp qw/tempdir/;
local $ENV{HOME} = tempdir(CLEANUP => 1);

my %result;

{

    package Dist::Zilla::Plugin::Repository;
    no warnings 'redefine';

    sub _execute {
        my $cmd = shift;
        $result{$cmd} || die "Unexpected command <$cmd>";
    }
}

$result{'git remote show -n origin'} = <<'END GIT';
* remote origin
  Fetch URL: git@github.com:fayland/dist-zilla-plugin-repository.git
  Push  URL: git@github.com:fayland/dist-zilla-plugin-repository.git
  HEAD branch: (not queried)
  Remote branch: (status not queried)
    master
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push' (status not queried):
    (matching) pushes to (matching)
END GIT

$result{'git remote show -n dzil'} = <<'END GIT DZIL';
* remote dzil
  Fetch URL: git://github.com/rjbs/dist-zilla.git
  Push  URL: git://github.com/rjbs/dist-zilla.git
  HEAD branch: (not queried)
  Remote branches: (status not queried)
    config-mvp-reader
    cpan-meta-prereqs
    master
    new-classic
    prereq-overhaul
  Local ref configured for 'git push' (status not queried):
    (matching) pushes to (matching)
END GIT DZIL

$result{'svn info'} = <<'END SVN';
Path: .
URL: http://example.com/svn/trunk/my-project
Repository Root: http://example.com/svn
Repository UUID: 12345678-9012-3456-7890-123456789012
Revision: 1234
Node Kind: directory
Schedule: normal
Last Changed Author: example
Last Changed Rev: 1234
Last Changed Date: 2008-09-27 15:42:32 -0500 (Sat, 27 Sep 2008)
END SVN

$result{'darcs query repo'} = <<'END DARCS';
          Type: darcs
        Format: darcs-1.0
          Root: /home/user/foobar
      Pristine: PlainPristine "_darcs/pristine"
         Cache: thisrepo:/home/user/foobar
Default Remote: http://example.com/darcs
   Num Patches: 2
END DARCS

$result{'hg paths'} = <<'END HG';
default = https://foobar.googlecode.com/hg/
END HG

$result{'git remote show -n gitlab'} = <<'END GITLAB';
* remote origin
  Fetch URL: git@gitlab.com:foo/bar
  Push  URL: git@gitlab.com:foo/bar
  HEAD branch: (not queried)
  Remote branch: (status not queried)
    master
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push' (status not queried):
    (matching) pushes to (matching)
END GITLAB

$result{'git remote show -n bitbucket'} = <<'END BITBUCKET';
* remote origin
  Fetch URL: git@bitbucket.org:foo/bar
  Push  URL: git@bitbucket.org:foo/bar
  HEAD branch: (not queried)
  Remote branch: (status not queried)
    master
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push' (status not queried):
    (matching) pushes to (matching)
END BITBUCKET

#---------------------------------------------------------------------
sub make_ini {
    my $ini = <<'END START';
name     = DZT-Sample
author   = E. Xavier Ample <example@example.org>
license  = Perl_5
copyright_holder = E. Xavier Ample
version  = 0.01

[GatherDir]
[Repository]
END START

    $ini . join('', map { "$_\n" } @_);
}    # end make_ini

#---------------------------------------------------------------------
sub build_tzil {
    my $repo = shift || [];

    my @extra_files;
    while (@_) {
        push @extra_files, "source/" . shift;
        push @extra_files, @_ ? shift : '';
    }

    my $tzil = Builder->from_config(
        {dist_root => 't/corpus/DZT'},
        {
            add_files => {
                'source/dist.ini' => make_ini(@$repo),
                @extra_files,
            },
        },
    );

    $tzil->build;

    return $tzil;
}    # end build_tzil

#---------------------------------------------------------------------
sub github_deprecated {
    scalar grep { /github_http is deprecated/ } @{shift->log_messages};
}    # end github_deprecated
#---------------------------------------------------------------------
sub remote_not_found {
    scalar grep { /Skipping invalid git remote/ } @{shift->log_messages};
}    # end remote_not_found

#=====================================================================
{
    my $tzil = build_tzil();

    is($tzil->distmeta->{resources}{repository}, undef, "No repository");
    ok(!github_deprecated($tzil), "No repository log message");
}

#---------------------------------------------------------------------
{
    my $url = 'http://example.com';

    my $tzil = build_tzil(["repository = $url"]);

    is_deeply($tzil->distmeta->{resources}{repository}, {url => $url}, "Just a URL");
    ok(!github_deprecated($tzil), "Just a URL log message");
}

#---------------------------------------------------------------------
{
    my $url = 'http://example.com/svn/repo';

    my $tzil = build_tzil(["repository = $url", 'type = svn']);

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            url  => $url,
            type => 'svn'
        },
        "SVN with type"
    );
    ok(!github_deprecated($tzil), "SVN with type log message");
}

#---------------------------------------------------------------------
{
    my $url = 'http://example.com/svn/repo';
    my $web = 'http://example.com';

    my $tzil = build_tzil(["repository = $url", "web = $web", 'type = svn']);

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            web  => $web,
            url  => $url,
            type => 'svn'
        },
        "SVN with type and web"
    );
    ok(!github_deprecated($tzil), "SVN with type and web log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil([], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => 'git://github.com/fayland/dist-zilla-plugin-repository.git',
            web  => 'https://github.com/fayland/dist-zilla-plugin-repository'
        },
        "Auto github"
    );
    ok(!github_deprecated($tzil), "Auto github log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['github_http = 1'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            web  => 'https://github.com/fayland/dist-zilla-plugin-repository'
        },
        "Auto github with http"
    );
    ok(github_deprecated($tzil), "Auto github with http log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['github_http = 0'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => 'git://github.com/fayland/dist-zilla-plugin-repository.git',
            web  => 'https://github.com/fayland/dist-zilla-plugin-repository'
        },
        "Auto github no http"
    );
    ok(!github_deprecated($tzil), "Auto github no http log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['git_remote = dzil', 'github_http = 1'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            web  => 'https://github.com/rjbs/dist-zilla'
        },
        "Auto github remote dzil with github_http"
    );
    ok(github_deprecated($tzil), "Auto github remote dzil with github_http log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['git_remote = dzil'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => 'git://github.com/rjbs/dist-zilla.git',
            web  => 'https://github.com/rjbs/dist-zilla'
        },
        "Auto github remote dzil no http"
    );
    ok(!github_deprecated($tzil), "Auto github remote dzil no http log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['git_remote = gitlab'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => 'git://gitlab.com/foo/bar',
            web  => 'https://gitlab.com/foo/bar'
        },
        "Auto gitlab"
    );
    ok(!github_deprecated($tzil), "Auto gitlab log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['git_remote = bitbucket'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => 'git://bitbucket.org/foo/bar',
            web  => 'https://bitbucket.org/foo/bar'
        },
        "Auto bitbucket"
    );
    ok(!github_deprecated($tzil), "Auto bitbucket log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil([], '.svn');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'svn',
            url  => 'http://example.com/svn/trunk/my-project'
        },
        "Auto svn"
    );
    ok(!github_deprecated($tzil), "Auto svn log message");
}

#---------------------------------------------------------------------
{
    my $web = 'http://example.com';

    my $tzil = build_tzil(["web = $web"], '.svn');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'svn',
            web  => $web,
            url  => 'http://example.com/svn/trunk/my-project'
        },
        "Auto svn with web"
    );
    ok(!github_deprecated($tzil), "Auto svn with web log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil([], '_darcs');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'darcs',
            url  => 'http://example.com/darcs'
        },
        "Auto darcs from default remote"
    );
    ok(!github_deprecated($tzil), "Auto darcs from default remote log message");
}

#---------------------------------------------------------------------
{
    my $url = 'http://example.com/darcs/fromprefs';

    # Munge the Default Remote so it's not http:
    local $result{'darcs query repo'} = $result{'darcs query repo'};
    $result{'darcs query repo'} =~ s!Remote: http!Remote: ssh!;

    my $tzil = build_tzil([], '_darcs/prefs/repos' => "ssh:foo\n$url\n");

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'darcs',
            url  => $url
        },
        "Auto darcs from prefs/repos"
    );
    ok(!github_deprecated($tzil), "Auto darcs from prefs/repos log message");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil([], '.hg');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'hg',
            url  => 'https://foobar.googlecode.com/hg/'
        },
        "Auto hg"
    );
    ok(!github_deprecated($tzil), "Auto hg log message");
}

#---------------------------------------------------------------------
{
    my $web = 'http://code.google.com/p/foobar/';
    my $tzil = build_tzil(["web = $web"], '.hg');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'hg',
            web  => $web,
            url  => 'https://foobar.googlecode.com/hg/'
        },
        "Auto hg with web"
    );
    ok(!github_deprecated($tzil), "Auto hg with web log message");
}

#---------------------------------------------------------------------
$result{'git remote show -n nourl'} = <<'END GIT NOURL';
* remote nourl
  Fetch URL: origin
  Push  URL: origin
  HEAD branch: (not queried)
  Remote branches: (status not queried)
END GIT NOURL

{
    my $tzil = build_tzil(['git_remote = nourl'], '.git');

    is($tzil->distmeta->{resources}{repository}, undef, "Auto git remote nourl");
    ok(!github_deprecated($tzil), "Auto git remote nourl log message");
}

{
    my $url = 'git://example.com/example.git';
    my $tzil = build_tzil(['git_remote = nourl', "repository = $url"], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => $url
        },
        "Auto git remote nourl with repository"
    );
    ok(!github_deprecated($tzil), "Auto git remote nourl with repository log message");
}

#---------------------------------------------------------------------
$result{'git remote show -n github'} = <<'END GITHUB REMOTE NOT FOUND';
* remote github
  Fetch URL: github
  Push  URL: github
  HEAD branch: (not queried)
  Remote branches: (status not queried)
END GITHUB REMOTE NOT FOUND

{
    my $tzil = build_tzil(['git_remote = github'], '.git');

    is($tzil->distmeta->{resources}{repository}, undef, "Auto git remote github not found");
    ok(remote_not_found($tzil), "Auto git remote github not found");
}

#---------------------------------------------------------------------
{
    my $tzil = build_tzil(['repository = git@gitlab.com:foo/bar.git'], '.git');

    is_deeply(
        $tzil->distmeta->{resources}{repository},
        {
            type => 'git',
            url  => 'git://gitlab.com/foo/bar.git',
            web  => 'https://gitlab.com/foo/bar'
        },
        "Auto gitlab"
    );
    ok(!github_deprecated($tzil), "Auto gitlab log message");
}

done_testing;