lib/func.tcl, test/unit: Fix spin in `next-matching-date' and test.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 6 Dec 2012 03:17:35 +0000 (03:17 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 6 Dec 2012 03:42:57 +0000 (03:42 +0000)
commit71669a0ab999914152a97ee81edc837f8c1a3277
treed2c02b495df9740fb9c5863d5209ee5f452488f7
parent88f85e06ccb74ae8082af5d592947c3420d76eb5
lib/func.tcl, test/unit: Fix spin in `next-matching-date' and test.

Consider the pattern `*-*-* 10:20:30' applied to the reference date
`2012-12-06 10:21:42'.  The year, month and day are wildcards, so they're
fine.  The hour matches, so we recurse to the minutes.  That match fails,
so the recursive call returns `step'.  At this point, we consider the
hours again: we step `nn' on by one to perturb the matching process and
iterate, attempting to match the literal pattern `10'.  This will compare
the literal with the original unstepped reference value, which is still
`10', and drag `nn' back down.  The result is that we spin, making no
progress and using all available CPU.  Of course, the precise values aren't
important: the significant bit is a literal pattern matching the reference
time, followed by a mismatch which forces a step.

Also include a number of tests for this function, because it's the main
algorithmically fiddly piece of the system.
lib/func.tcl
test/unit [new file with mode: 0755]