Debian Codegraph @

t/unit/App/Yath/Plugin/Git.t

raw
1 use Test2::V0 -target => 'App::Yath::Plugin::Git';
2 use Test2::Util qw/CAN_THREAD CAN_REALLY_FORK CAN_FORK CAN_SIGSYS/;
3 # HARNESS-DURATION-SHORT
4
5 use Test2::Harness::Settings;
6
7 subtest NOTHING => sub {
8 my $control = mock $CLASS => (
9 override => [
10 can_run => sub { undef },
11 git_cmd => sub { return },
12 ],
13 );
14
15 local $ENV{GIT_COMMAND};
16 local $ENV{GIT_LONG_SHA};
17 local $ENV{GIT_SHORT_SHA};
18 local $ENV{GIT_STATUS};
19 local $ENV{GIT_BRANCH};
20
21 my $meta = {};
22 my $fields = [];
23 $CLASS->inject_run_data(meta => $meta, fields => $fields);
24
25 ok(!$meta->{git}, "no git added to meta");
26 is(@$fields, 0, "No fields added");
27 };
28
29 subtest ENV => sub {
30 my $script = __FILE__;
31 $script =~ s/\.t$/\.script/;
32 local $ENV{GIT_COMMAND} = $script;
33 local $ENV{GIT_LONG_SHA} = "1230988f2c2bd26a1691a82766d5bf5c7524b123";
34 local $ENV{GIT_SHORT_SHA} = "1230988";
35 local $ENV{GIT_STATUS} = " M lib/App/Yath/Command.pm";
36 local $ENV{GIT_BRANCH} = "my.super-long-branch-name-needs-to-be-trimmed";
37
38 my $meta = {};
39 my $fields = [];
40 $CLASS->inject_run_data(meta => $meta, fields => $fields);
41
42 is(
43 $meta,
44 {
45 git => {
46 branch => 'my.super-long-branch-name-needs-to-be-trimmed',
47 sha => '1230988f2c2bd26a1691a82766d5bf5c7524b123',
48 status => ' M lib/App/Yath/Command.pm',
49 },
50 },
51 "Added git info to meta-data"
52 );
53
54 is(
55 $fields,
56 [
57 {
58 data => $meta->{git},
59 details => 'my.super-long-branch',
60 name => 'git',
61 raw => 'my.super-long-branch-name-needs-to-be-trimmed',
62 }
63 ],
64 "Added git field",
65 );
66 };
67
68 subtest CMD => sub {
69 my $script = __FILE__;
70 $script =~ s/\.t$/\.script/;
71 local $ENV{GIT_COMMAND} = $script;
72 local $ENV{GIT_LONG_SHA};
73 local $ENV{GIT_SHORT_SHA};
74 local $ENV{GIT_STATUS};
75 local $ENV{GIT_BRANCH};
76
77 my $meta = {};
78 my $fields = [];
79 $CLASS->inject_run_data(meta => $meta, fields => $fields);
80
81 is(
82 $meta,
83 {
84 git => {
85 branch => 'my.branch.foo',
86 sha => '4570988f2c2bd26a1691a82766d5bf5c7524bcea',
87 status => ' M lib/App/Yath/Plugin/Git.pm',
88 },
89 },
90 "Added git info to meta-data"
91 );
92
93 is(
94 $fields,
95 [
96 {
97 data => $meta->{git},
98 details => 'my.branch.foo',
99 name => 'git',
100 raw => 'my.branch.foo',
101 }
102 ],
103 "Added git field",
104 );
105 };
106
107 subtest MIX => sub {
108 my $script = __FILE__;
109 $script =~ s/\.t$/\.script/;
110 local $ENV{GIT_COMMAND} = $script;
111 local $ENV{GIT_LONG_SHA} = "1230988f2c2bd26a1691a82766d5bf5c7524b123";
112 local $ENV{GIT_SHORT_SHA};
113 local $ENV{GIT_STATUS};
114 local $ENV{GIT_BRANCH};
115
116 my $meta = {};
117 my $fields = [];
118 $CLASS->inject_run_data(meta => $meta, fields => $fields);
119
120 is(
121 $meta,
122 {
123 git => {
124 branch => 'my.branch.foo',
125 sha => '1230988f2c2bd26a1691a82766d5bf5c7524b123',
126 status => ' M lib/App/Yath/Plugin/Git.pm',
127 },
128 },
129 "Added git info to meta-data"
130 );
131
132 is(
133 $fields,
134 [
135 {
136 data => $meta->{git},
137 details => 'my.branch.foo',
138 name => 'git',
139 raw => 'my.branch.foo',
140 }
141 ],
142 "Added git field",
143 );
144 };
145
146 #subtest changed_files => sub {
147 # my $settings = Test2::Harness::Settings->new();
148 # $settings->define_prefix('git');
149 # $settings->git->vivify_field('change_base');
150 #
151 # my $script = __FILE__;
152 # $script =~ s/\.t$/\.script/;
153 # local $ENV{GIT_COMMAND} = $script;
154 #
155 # is(
156 # [$CLASS->changed_files($settings)],
157 # [['a.file', '*', 'sub1', 'sub3']],
158 # "Got changed file"
159 # );
160 #
161 # $settings->git->field(change_base => 'master');
162 # is(
163 # [$CLASS->changed_files($settings)],
164 # [
165 # ['a.file', '*', 'sub1', 'sub3'],
166 # ['b.file', '*', 'sub1'],
167 # ['c.file', 'sub1'],
168 # ],
169 # "Got changed files from change_base"
170 # );
171 #};
172
173 done_testing;