1use strict;
2use Test::More;
3use xt::CLI;
4
5subtest 'snapshot file has canonical representation' => sub {
6    my $app = cli();
7    $app->write_cpanfile(<<EOF);
8requires 'Try::Tiny', '== 0.11';
9requires 'Getopt::Long', '2.41';
10EOF
11
12    $app->run("install");
13
14    my $content = $app->dir->child('cpanfile.snapshot')->slurp;
15    for (1..3) {
16        $app->dir->child('cpanfile.snapshot')->remove;
17        $app->run("install");
18        is $content, $app->dir->child('cpanfile.snapshot')->slurp;
19    }
20};
21
22subtest 'Bad snapshot version' => sub {
23    my $app = cli();
24    $app->write_cpanfile('');
25    $app->write_file('cpanfile.snapshot', <<EOF);
26# carton snapshot format: version 111
27EOF
28
29    $app->run("install");
30    like $app->stderr, qr/Could not parse/;
31};
32
33subtest 'Bad snapshot file' => sub {
34    my $app = cli();
35    $app->write_cpanfile('');
36    $app->write_file('cpanfile.snapshot', <<EOF);
37# carton snapshot format: version 1.0
38DISTRIBUTIONS
39  Foo-Bar-1
40    unknown: foo
41EOF
42
43    $app->run("install");
44    like $app->stderr, qr/Could not parse/;
45};
46
47subtest 'snapshot file support separate CRLF' => sub {
48    my $app = cli();
49    $app->write_cpanfile(<<EOF);
50requires 'Try::Tiny', '== 0.11';
51requires 'Getopt::Long', '2.41';
52EOF
53
54    $app->run("install");
55
56    my $content = $app->dir->child('cpanfile.snapshot')->slurp;
57    $content =~ s/\n/\r\n/g;
58    $app->write_file('cpanfile.snapshot', $content);
59
60    $app->run("install");
61    ok !$app->stderr;
62};
63
64done_testing;
65
66