3 # Some tests for the '--match' flag
6 use Test
::More
'no_plan';
12 # predeclare some subs so we can use them without parens.
21 create_entry
( "1973-02-04 15:08Z" );
23 # parse_date just checks for parsing, while match_date checks for an actual match.
24 # It's better if we can use "match_date", but we have to be able to construct such a date
25 # based on a date dynamically generated by this test script.
27 my $raw_date = get_first_date_from_changes
();
28 my ($mon,$mm,$dd,$year,$hhmmss,$tz) = deconstruct_date
( $raw_date );
31 # warn Dumper ($raw_date, $mon,$mm,$dd,$year,$hhmmss,$tz );
33 # alternately, it might be more useful to build a random date string generator
34 # using QuickCheck... for any n random CalendarTimes, have it generate some
35 # possible variants and roundtrip them to see if they match
37 # this block of dates should all refer to the same thing
38 match_date
"$year-$mm-$dd";
39 match_date
"$year$mm$dd";
40 match_date
"$year-$mm";
41 match_date
"$year$mm";
44 # week dates. note that 2007 was selected as it starts on Monday
46 create_entry
"2007-01-04 15:00";
47 match_date
'2007-W01-4';
48 nomatch_date
'2007-W01-1';
49 match_date
'2007W014';
50 match_date
'2007-W01';
51 nomatch_date
'2007-W02-1';
52 create_entry
"2007-01-08 15:00";
53 match_date
'2007-W02';
54 match_date
'2007-W02-1';
55 create_entry
"2007-05-20 15:00";
56 match_date
'2007-W20';
57 nomatch_date
'2007-W21';
58 nomatch_date
'2007-W19';
59 # ordinal dates. eh... why not?
60 match_date
'2007-004'; # fourth day of 2007
62 nomatch_date
'2007-005';
66 create_entry
"1992-10-15 00:00";
67 match_date
'1992-10-14 24:00';
68 match_date
'1992-10-15 00:00';
70 # all the same date/time
72 create_entry
"1992-02-12T22:32:11";
73 match_date
'1992-02-12T22:32:11';
74 match_date
'1992-02-12 22:32:11';
75 match_date
'1992-02-12T223211.0000';
77 # english dates - the old hard coded from < darcs 1.0.6
80 $raw_date = get_first_date_from_changes
();
81 ($mon,$mm,$dd,$year,$hhmmss,$tz) = deconstruct_date
( $raw_date );
83 create_entry
(($year-1)."$mm-$dd");
85 nomatch_date
'yesterday';
86 nomatch_date
'day before yesterday';
87 nomatch_date
'last week';
88 nomatch_date
'last month';
89 # note: this test might fail if you run it just before midnight
93 nomatch_date
'yesterday';
94 nomatch_date
'day before yesterday';
95 match_date
'last week';
96 match_date
'last month';
99 create_entry
(($year-1)."-$mm-$dd");
100 # english dates - new possibilities
101 nomatch_date
'yesterday at 14:00:00';
102 match_date
'last 3 years';
103 match_date
'last year';
104 nomatch_date
'2 days ago';
105 nomatch_date
'last month 13:00' ;
106 nomatch_date
'3 days before last week';
109 match_date
'day after yesterday';
110 match_date
'week after last week';
111 create_entry
("1992-10-02 00:15");
112 match_date
'15 minutes after 1992-10-02';
114 create_entry
("1992-10-02 00:15+05");
115 # note that earlier dates will always match
116 match_date
'15 minutes after 1992-10-02 00:00+05'; # same time
117 match_date
'15 minutes after 1992-10-01 23:00+04'; # same time
118 nomatch_date
'15 minutes after 1992-10-02 01:00+05'; # 1 hour later
119 nomatch_date
'15 minutes after 1992-10-02 00:00+04'; # 1 hour later
120 nomatch_date
'1 hour, 15 minutes after 1992-10-02 00:00+05'; # 1 hour later
121 match_date
'1 hour, 15 minutes after 1992-10-02 00:00+06'; # same time
122 match_date
'1 hour, 15 minutes after 1992-10-01 23:00+05'; # same time
126 create_entry
("1992-10-02 00:15");
128 nomatch_date
'between last fortnight and day before yesterday';
129 match_date
'between last fortnight and today';
130 match_date
'in the last 45 seconds';
131 match_date
'after 1992';
135 parse_date
'1992-10-02 00:00Z/1992-10-02 00:16Z';
136 match_date
'1992-10-02 00:00/1992-10-02 00:16';
137 match_date
'between 1992-10-02 00:00 and 1992-10-12 00:16';
138 parse_date
'P3YT3M/1992';
139 parse_date
'1992/P3Y3M4DT5H3M2S';
140 parse_date
'1992/P3Y3M';
142 # stuff from the manual
145 nomatch_date
'between 2004-03-12 and last week';
146 match_date
'last week';
147 parse_date
'yesterday';
148 parse_date
'today 14:00';
149 nomatch_date
'3 days before last year at 17:00';
150 # We can't in general parse the raw date output by darcs. If we change the
151 # format to not include timezone information, this would be possible. But
152 # maybe that's not desireable. For now, we just won't test the raw date.
153 #match_date "$raw_date";
154 parse_date
'after 2005';
155 parse_date
'in the last 3 weeks';
156 parse_date
'P3M/2006-03-17';
157 parse_date
'2004-01-02/2006-03-17';
161 parse_date
'2006/01/19 21:14:20 UTC';
162 # We can't handle all timezones in the old style dates
163 # so this test will not work everywhere
164 # match_date "$year/$mm/$dd $hhmmss $tz";
166 # -------------------------------------------------------------------
167 # matching on atomic stuff (other than date)
168 # -------------------------------------------------------------------
174 darcs
qw( record -a -m "first patch" bar -A author1 );
176 darcs
qw( record -a -m "\"second\" \\ patch" bar -A author2 );
178 darcs qw( record -a -m "second" bar -A author3 );
180 # matching on author really matches on that, and not something else
181 unlike
(darcs
(qw(changes --match='author "first patch"')), qr
(.+));
183 { # normal changes shows both authors and both names
184 my $res = darcs
qw( changes );
185 like
($res, qr
(author1
));
186 like
($res, qr
(author2
));
187 like
($res, qr
(author3
));
188 like
($res, qr
(first patch
));
189 like
($res, qr
("second" \\ patch
));
190 like
($res, qr
(second
));
194 my $res = darcs
qw( changes --match='exact second' );
195 unlike
($res, qr
(author1
), 'does not find unrelated patch');
196 unlike
($res, qr
(author2
), 'does not find similar patch');
197 like
($res, qr
(author3
), 'finds the patch');
201 my $res = darcs
qw( changes --match='name second' );
202 unlike
($res, qr
(author1
), 'does not find unrelated patch');
203 like
($res, qr
(author2
), 'finds one of the patches');
204 like
($res, qr
(author3
), 'finds the other patch');
208 my $res = darcs
qw( changes --match='author author1');
209 like
($res, qr
(author1
));
210 unlike
($res, qr
(author2
));
211 unlike
($res, qr
(author3
));
215 my $xml = darcs
(qw(changes --xml-output --match='exact "\"second\" \ patch"'));
216 if ($xml =~ /hash='(.*?)'/) {
217 my $res = darcs "changes --match='hash $1'";
218 unlike($res, qr(author1));
219 like ($res, qr(author2));
220 unlike($res, qr(author3));
226 # -------------------------------------------------------------------
227 # matching on combinations
229 # uses the setup from the atomic patches
230 # -------------------------------------------------------------------
233 my $res = darcs(qw(changes --match='author author1 || author author2'));
234 like
($res, qr
(author1
));
235 like
($res, qr
(author2
));
236 unlike
($res, qr
(author3
));
240 my $res = darcs
(qw(changes --match='name second && author author2'));
241 unlike
($res, qr
(author1
));
242 like
($res, qr
(author2
));
243 unlike
($res, qr
(author3
));
247 my $res = darcs
(qw(changes --match='not name second'));
248 like
($res, qr
(author1
));
249 unlike
($res, qr
(author2
));
250 unlike
($res, qr
(author3
));
254 my $res = darcs
(qw(changes --match='(not name second) || author author3
'));
255 like ($res, qr(author1));
256 unlike($res, qr(author2));
257 like ($res, qr(author3));
264 # just be happy if it doesn't complain about the date being fancy
267 unlike
( darcs
("changes --match='date $d'"), qr
(fancy
), "date format $d is recognized" );
272 like
( darcs
(qq(changes
--match
'date "$d"')), qr/tester/, "date format $d finds a match");
277 my $out = darcs
(qq(changes
--match
'date "$d"'));
278 unlike
($out, qr/tester/, "date format $d shouldn't find a match");
279 unlike
($out, qr/fancy/, "date format $d should be recognized");
282 # Return the date found in the first entry of 'darcs changes';
283 sub get_first_date_from_changes
{
284 my $out = darcs
'changes';
285 my ($date) = split " tester", $out;
286 # $date should now look like: Wed Jan 9 20:02:18 EST 2008
292 =head2 deconstruct_date
294 my ($mon,$mon_num,$day_num,$year,$hhmmss,$tz) = deconstruct_date( $raw_date );
302 Given a date as get_first_date_from_changes() returns, deconstruct it into base components.
304 example input: Wed Jan 9 20:02:18 EST 2008
310 sub deconstruct_date
{
311 my $raw_date = shift;
328 # example input: Wed Jan 9 20:02:18 EST 2008
329 my ($mon,$day_num,$hhmmss,$tz,$year) = ($raw_date =~ m
{
337 (\d\d
:\d\d
:\d\d
) # HH::MM:SS
339 (\w
+) # Time zone abbreviation
344 $day_num = '0'.$day_num if (length $day_num == 1);
345 my $mon_num = $month_to_num{$mon};
347 return ($mon,$mon_num,$day_num,$year,$hhmmss,$tz);
356 sub create_entry_now
{
360 darcs
('record -a -m "" bar');
368 echo_to_darcs
('record -m "" --pipe bar',"$date","tester","a","","");