David Symonds | c48b90c | 2014-12-02 14:31:00 +1100 | [diff] [blame] | 1 | // Test of time suffixes. |
| 2 | |
| 3 | // Package foo ... |
| 4 | package foo |
| 5 | |
| 6 | import ( |
| 7 | "flag" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | var rpcTimeoutMsec = flag.Duration("rpc_timeout", 100*time.Millisecond, "some flag") // MATCH /Msec.*\*time.Duration/ |
| 12 | |
| 13 | var timeoutSecs = 5 * time.Second // MATCH /Secs.*time.Duration/ |
Josh Bleecher Snyder | b550591 | 2015-06-16 10:33:53 -0700 | [diff] [blame^] | 14 | |
| 15 | var delay = flag.Duration("delay", 5, "wait impatiently") // MATCH /time.*expression.*"5".*constants/ |
| 16 | |
| 17 | func f(...time.Duration) {} |
| 18 | |
| 19 | var ( |
| 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 | |
| 33 | const x = 10 |
| 34 | |
| 35 | func 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 | } |