Skip to content

Commit

Permalink
Make bisectable DWIM
Browse files Browse the repository at this point in the history
Resolves #282. The user is expected to use `old=…, new=…` syntax, but
sometimes people forget. This commit makes bisectable understand
committable-like syntax. Note that bisectable can only detect this by
checking the existence of suspected revisions, meaning that it won't be
able to produce helpful β€œDid you mean …” messages if you misspell one
of the commits.

Also, feel free to throw tomatoes at me for writing this (I find it
readable πŸ˜‹):

    if ($<maybe-rev> without $<old> // $<new>) { }
  • Loading branch information
AlexDaniel committed Mar 19, 2018
1 parent 132adeb commit 5eb618d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
21 changes: 17 additions & 4 deletions bin/Bisectable.p6
Expand Up @@ -135,14 +135,27 @@ my regex bisect-cmd { :i
[ [new|bad] <&spaceeq> $<new>=<-[\s,]>+ <&delim> ]?
[ [old|good] <&spaceeq> $<old>=\S+ \s* ]?
]
$<code>=.*
$<code>=[
[ [ $<maybe-rev>=<-[\s,]>+
<?{so to-full-commit $<maybe-rev>.tail}> ]**1..2 % <&delim>
\s+
]?
$<maybe-code>=.*
]
$
}

multi method irc-to-me($msg where .text ~~ &bisect-cmd) {
self.process: $msg, ~$<code>,
~($<old> // β€˜2015.12’),
~($<new> // β€˜HEAD’)
my $old = $<old> // β€˜2015.12’;
my $new = $<new> // β€˜HEAD’;
my $code = $<code>;
if ($<maybe-rev> without $<old> // $<new>) {
$old = $<maybe-rev>[0];
$new = $_ with $<maybe-rev>[1];
$code = $<maybe-code>;
$msg.reply: β€œUsing old=$old new=$new in an attempt to DWIM”
}
self.process: $msg, ~$code, ~$old, ~$new
}

method process($msg, $code is copy, $old, $new) {
Expand Down
52 changes: 52 additions & 0 deletions t/bisectable.t
Expand Up @@ -111,6 +111,58 @@ $t.test(:30timeout, β€˜mixed term styles’,
β€œ{$t.our-nick}, bisect log: https://whatever.able/fakeupload”,
β€œ{$t.our-nick}, (2016-03-18) https://github.com/rakudo/rakudo/commit/6d120cab6d0bf55a3c96fd3bd9c2e841e7eb99b0”);

# DWIM

$t.test(β€˜forgot the right syntax (comma)’,
β€˜bisect: 2016.02,2016.03 say 42’,
β€œ{$t.our-nick}, Using old=2016.02 new=2016.03 in an attempt to DWIM”,
β€œ{$t.our-nick}, On both starting points (old=2016.02 new=2016.03) the exit code is 0 and the output is identical as well”,
β€œ{$t.our-nick}, Output on both points: Β«42␀»”);

$t.test(β€˜forgot the right syntax (space)’,
β€˜bisect: 2016.02 2016.03 say 42’,
β€œ{$t.our-nick}, Using old=2016.02 new=2016.03 in an attempt to DWIM”,
β€œ{$t.our-nick}, On both starting points (old=2016.02 new=2016.03) the exit code is 0 and the output is identical as well”,
β€œ{$t.our-nick}, Output on both points: Β«42␀»”);

$t.test(β€˜forgot the right syntax (comma+space)’,
β€˜bisect: 2016.02 , 2016.03 say 42’,
β€œ{$t.our-nick}, Using old=2016.02 new=2016.03 in an attempt to DWIM”,
β€œ{$t.our-nick}, On both starting points (old=2016.02 new=2016.03) the exit code is 0 and the output is identical as well”,
β€œ{$t.our-nick}, Output on both points: Β«42␀»”);

$t.test(β€˜forgot the right syntax (one revision only)’,
β€˜bisect: 2016.02 say 42’,
β€œ{$t.our-nick}, Using old=2016.02 new=HEAD in an attempt to DWIM”,
/^ <me($t)>β€˜, On both starting points (old=2016.02 new=’<sha>β€˜) the exit code is 0 and the output is identical as well’ $/,
β€œ{$t.our-nick}, Output on both points: Β«42␀»”);

$t.test(β€˜did not forget the right syntax (one suspicious)’,
β€˜bisect: old=2014.01,new=2014.02 2014.03 say 42’,
β€œ{$t.our-nick}, On both starting points (old=2014.01 new=2014.02) the exit code is 1 and the output is identical as well”,
β€œ{$t.our-nick}, https://whatever.able/fakeupload”);

$t.test(β€˜did not forget the right syntax (two suspicious)’,
β€˜bisect: old=2014.01,new=2014.02 2014.03,2014.04 say 42’,
β€œ{$t.our-nick}, On both starting points (old=2014.01 new=2014.02) the exit code is 1 and the output is identical as well”,
β€œ{$t.our-nick}, https://whatever.able/fakeupload”);

$t.test(β€˜non-revisions are ignored (one revision)’,
β€˜bisect: 2015.13 .say # heh’,
/^ <me($t)>β€˜, On both starting points (old=2015.12 new=’<sha>β€˜) the exit code is 0 and the output is identical as well’ $/,
β€œ{$t.our-nick}, Output on both points: Β«2015.13␀»”);

$t.test(β€˜non-revisions are ignored (two revisions)’,
β€˜bisect: 2016.12,2016.13 … BEGIN { say 42; exit 0 }’,
/^ <me($t)>β€˜, On both starting points (old=2015.12 new=’<sha>β€˜) the exit code is 0 and the output is identical as well’ $/,
β€œ{$t.our-nick}, Output on both points: Β«42␀»”);

$t.test(β€˜some non-revisions are ignored (one is correct)’,
β€˜bisect: 2016.05 2017.13 .say # heh’,
β€œ{$t.our-nick}, Using old=2016.05 new=HEAD in an attempt to DWIM”,
/^ <me($t)>β€˜, On both starting points (old=2016.05 new=’<sha>β€˜) the exit code is 0 and the output is identical as well’ $/,
β€œ{$t.our-nick}, Output on both points: Β«2017.13␀»”);

# Special characters
#`{ What should we do with colors?
$t.test(β€˜special characters’,
Expand Down

0 comments on commit 5eb618d

Please sign in to comment.