Commit | Line | Data |
---|---|---|
71669a0a MW |
1 | #! /usr/bin/tclsh8.5 |
2 | ### -*-tcl-*- | |
3 | ||
4 | source [file join [file dirname $argv0] "../lib/func.tcl"] | |
5 | ||
6 | set RUN 0 | |
7 | set FAIL 0 | |
8 | ||
9 | proc test {name testargs testbody tests} { | |
10 | global RC RUN FAIL | |
11 | ||
12 | eval proc testproc [list $testargs] [list $testbody] | |
13 | set run 0 | |
14 | set ok true | |
15 | puts -nonewline "$name: " | |
16 | foreach test $tests { | |
17 | puts -nonewline "." | |
18 | flush stdout | |
19 | incr run | |
20 | set rc [catch {eval testproc $test} out] | |
21 | switch -exact $rc { | |
22 | 0 { } | |
23 | 1 { | |
24 | puts "" | |
25 | puts "FAILED: $out" | |
26 | puts -nonewline "$name: [string repeat . $run]" | |
27 | set ok false | |
28 | } | |
29 | default { return -code $code $rc } | |
30 | } | |
31 | } | |
32 | if {$ok} { | |
33 | puts " ok" | |
34 | } else { | |
35 | puts " FAILED" | |
36 | incr FAIL | |
37 | } | |
38 | incr RUN | |
39 | } | |
40 | ||
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>" | |
48 | } | |
49 | } { | |
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"} | |
70 | } | |
71 | ||
72 | ||
73 | set tests [expr {$RUN == 1 ? "test" : "tests"}] | |
74 | if {!$FAIL} { | |
75 | puts "All $RUN $tests PASSED" | |
76 | set rc 0 | |
77 | } else { | |
78 | puts "FAILED $FAIL of $RUN $tests" | |
79 | } | |
80 | exit $RC |