blob: 44cda9d7ed552e3eaf4407fda530a4e702d19e15 [file] [log] [blame]
David Symondsc48b90c2014-12-02 14:31:00 +11001// Test of time suffixes.
2
3// Package foo ...
4package foo
5
6import (
7 "flag"
8 "time"
9)
10
11var rpcTimeoutMsec = flag.Duration("rpc_timeout", 100*time.Millisecond, "some flag") // MATCH /Msec.*\*time.Duration/
12
13var timeoutSecs = 5 * time.Second // MATCH /Secs.*time.Duration/
Josh Bleecher Snyderb5505912015-06-16 10:33:53 -070014
15var delay = flag.Duration("delay", 5, "wait impatiently") // MATCH /time.*expression.*"5".*constants/
16
17func f(...time.Duration) {}
18
19var (
20 _ = time.Duration(15) // MATCH /time.*expression.*"15".*constants/
21 _ = time.Duration(15) + time.Duration(30) // Not caught, but rare in real code; see comments in lintDurationUnits
22 _ = []time.Duration{
23 1, // MATCH /time.*expression.*"1".*constants/
24 10, // MATCH /time.*expression.*"10".*constants/
25 1 * time.Nanosecond,
26 10 * 10 * 10 * 10,
27 time.Hour,
28 0, // 0 is OK
29 }
30 abc = f(17) // MATCH /time.*expression.*"17".*constants/
31)
32
33const x = 10
34
35func g() {
36 time.Sleep(
37 12, // MATCH /time.*expression.*"12".*constants/
38 )
39 time.Sleep(x) // Not caught; see comments in lintDurationUnits
40 _ = f(1, // MATCH /time.*expression.*"1".*constants/
41 1e12) // MATCH /time.*expression.*"1e12".*constants/
42}