4 source [file join [file dirname $argv0] "../lib/func.tcl"]
9 proc test {name testargs testbody tests} {
12 eval proc testproc [list $testargs] [list $testbody]
15 puts -nonewline "$name: "
20 set rc [catch {eval testproc $test} out]
26 puts -nonewline "$name: [string repeat . $run]"
29 default { return -code $code $rc }
41 test next-matching-date {pat ref want} {
42 set t_ref [clock scan $ref -format "%Y-%m-%d %H:%M:%S"]
43 set t_want [clock scan $want -format "%Y-%m-%d %H:%M:%S"]
44 set t_found [next-matching-date $pat $t_ref]
45 if {$t_found != $t_want} {
46 set found [clock format $t_found -format "%Y-%m-%d %H:%M:%S"]
47 error "mismatch: <$pat> <$ref> -> <$found> /= <$want>"
50 {"*-*-* 03:00:00" "2011-09-03 02:32:45" "2011-09-03 03:00:00"}
51 {"*-*-* 03:00:00" "2011-09-03 18:32:45" "2011-09-04 03:00:00"}
52 {"*-*-* 03:00:00" "2011-02-28 18:32:45" "2011-03-01 03:00:00"}
53 {"*-*-* 03:00:00" "2012-02-28 18:32:45" "2012-02-29 03:00:00"}
54 {"*-*-* 03:00:00" "2011-03-30 18:32:45" "2011-03-31 03:00:00"}
55 {"*-*-* 03:00:00" "2012-04-30 18:32:45" "2012-05-01 03:00:00"}
56 {"*-*-* 03:00:00" "2012-12-31 18:32:45" "2013-01-01 03:00:00"}
57 {"*-*-* 00:00:00" "2012-12-04 00:25:01" "2012-12-05 00:00:00"}
58 {"*-*-* 10:20:30" "2012-12-06 10:21:30" "2012-12-07 10:20:30"}
59 {"*-*-* *:*:05" "2012-12-04 00:00:00" "2012-12-04 00:00:05"}
60 {"*-*-* *:*:05" "2012-12-04 00:00:04" "2012-12-04 00:00:05"}
61 {"*-*-* *:*:05" "2012-12-04 00:00:05" "2012-12-04 00:00:05"}
62 {"*-*-* *:*:05" "2012-12-04 00:00:06" "2012-12-04 00:01:05"}
63 {"*-*-* *:*:05" "2012-12-04 23:59:06" "2012-12-05 00:00:05"}
64 {"*-*-* *:19:05" "2012-12-04 00:00:00" "2012-12-04 00:19:05"}
65 {"*-*-* *:19:05" "2012-12-04 00:20:04" "2012-12-04 01:19:05"}
66 {"*-*-* *:19:05" "2012-12-04 00:18:06" "2012-12-04 00:19:05"}
67 {"*-*-* *:19:05" "2012-12-04 00:19:06" "2012-12-04 01:19:05"}
68 {"*-*-31 01:02:03" "2012-11-03 04:05:06" "2012-12-31 01:02:03"}
69 {"*/2-*/3-*/5 */7:*/11:*/13" "2011-12-04 00:00:04" "2012-03-05 00:00:00"}
73 set tests [expr {$RUN == 1 ? "test" : "tests"}]
75 puts "All $RUN $tests PASSED"
78 puts "FAILED $FAIL of $RUN $tests"