aboutsummaryrefslogtreecommitdiff
path: root/tests/clock.test
blob: 0ef7bb3816351ab67dacffcfe1bafe3d7d4668de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
source [file dirname [info script]]/testing.tcl

needs cmd clock
constraint cmd {clock scan}

test clock-1.1 {clock usage} -body {
    clock
} -returnCodes error -match glob -result {wrong # args: should be "clock command ..."*}

test clock-1.2 {clock usage} -body {
    clock blah
} -returnCodes error -match glob -result {clock, unknown command "blah": should be clicks, format, microseconds, milliseconds, *seconds}

# clock format
test clock-3.1 {clock format tests} {
    set clockval 657687766
    clock format $clockval -format {%a %b %d %I:%M:%S %p %Y} -gmt true
} {Sun Nov 04 03:02:46 AM 1990}

test clock-3.5 {clock format tests} -body {
    clock format
} -returnCodes error -result {wrong # args: should be "clock format seconds ?-format string? ?-gmt boolean?"}

test clock-3.6 {clock format tests} -body {
    clock format foo
} -returnCodes error -result {expected integer but got "foo"}

test clock-3.7 {clock format tests} -body {
    clock format 10000 -format [string repeat x 1000] -gmt true
} -returnCodes error -result {format string too long or invalid time}

test clock-3.8 {clock format tests} -body {
    clock format a b c d e g
} -returnCodes error -result {wrong # args: should be "clock format seconds ?-format string? ?-gmt boolean?"}

test clock-3.9 {clock format tests} {
    set clockval 0
    clock format $clockval -format "%a %b %d %I:%M:%S %p %Y" -gmt true
} "Thu Jan 01 12:00:00 AM 1970"

test clock-3.10 {clock format tests} -body {
    clock format 123 -bad arg
} -returnCodes error -result {bad option "-bad": must be -format, or -gmt}

test clock-3.11 {clock format tests} {
    clock format 123 -format "x"
} x

test clock-3.12 {clock format tests} -body {
	clock format  123 -gmt blah
} -returnCodes error -result {expected boolean but got "blah"}

test clock-3.13 {clock format tests} -body {
	clock format 123 odd option count
} -returnCodes error -result {wrong # args: should be "clock format seconds ?-format string? ?-gmt boolean?"}

test clock-4.1 {clock scan tests} clock-scan {
    clock scan {Sun Nov 04 03:02:46 AM 1990} -format {%a %b %d %I:%M:%S %p %Y} -gmt true
} 657687766

test clock-4.2 {clock scan tests} -constraints clock-scan -body {
    clock scan odd number arg count
} -returnCodes error -result {wrong # args: should be "clock scan str -format format ?-gmt boolean?"}

test clock-4.3 {clock scan tests} -constraints clock-scan -body {
    clock scan str -bad option
} -returnCodes error -result {bad option "-bad": must be -format, or -gmt}

test clock-4.4 {clock scan tests} -constraints clock-scan -body {
    clock scan str -gmt true
} -returnCodes error -result {wrong # args: should be "clock scan str -format format ?-gmt boolean?"}

test clock-4.5 {clock scan tests} -constraints clock-scan -body {
    clock scan str -format "%H" -gmt true
} -returnCodes error -result {Failed to parse time according to format}

test clock-5.1 {clock seconds} {
	clock format [clock seconds]
	list 1
} {1}

test clock-5.2 {clock millis, micros} {
	set ms [clock millis]
	set us [clock micros]
	set delta [expr {abs($us - $ms * 1000)}]
	if {$delta > 250000} {
		error "clock millis and micros differ by too much"
	}
} {}

testreport