commit | 4b36dfbbf1860fa4e94d80239ef9889dff01867f | [log] [tgz] |
---|---|---|
author | Keerti Parthasarathy <keertip@users.noreply.github.com> | Wed Oct 09 10:07:00 2019 -0700 |
committer | GitHub <noreply@github.com> | Wed Oct 09 10:07:00 2019 -0700 |
tree | c617f4d1c1930f1c6d5e275b19eddd87aafac989 | |
parent | 22c2eb6acde52d153bf71795dc4c5ede0afe5943 [diff] |
Update package to pedantic 1.8.0 (#12) * Update package to pedantic 1.8.0 * Update travis to use stable, update SDK constraints * format files * Travis: test with 2.1.1
This package provides a Clock
class which encapsulates the notion of the “current time” and provides easy access to points relative to the current time. Different Clock
s can have a different notion of the current time, and the default top-level clock
's notion can be swapped out to reliably test timing-dependent code.
For example, you can use clock
in your libraries like this:
// run_with_timing.dart import 'package:clock/clock.dart'; /// Runs [callback] and prints how long it took. T runWithTiming<T>(T callback()) { var stopwatch = clock.stopwatch()..start(); var result = callback(); print('It took ${stopwatch.elapsed}!'); return result; }
...and then test your code using the fake_async
package, which automatically overrides the current clock:
// run_with_timing_test.dart import 'run_with_timing.dart'; import 'package:fake_async/fake_async.dart'; import 'package:test/test.dart'; void main() { test('runWithTiming() prints the elapsed time', () { FakeAsync().run((async) { expect(() { runWithTiming(() { async.elapse(Duration(seconds: 10)); }); }, prints('It took 0:00:10.000000!')); }); }); }