commit | e9756879683fca133de74258b8bb9607d9bd3f38 | [log] [tgz] |
---|---|---|
author | Nate Bosch <nbosch1@gmail.com> | Tue Nov 03 14:40:29 2020 -0800 |
committer | GitHub <noreply@github.com> | Tue Nov 03 14:40:29 2020 -0800 |
tree | b1a522df8ad4e7fc75b77158b7cf5ac39ea3f9f7 | |
parent | a494269254ba978e7ef8f192c5f7fec3fc05b9d3 [diff] |
Bump SDK constraints for pub (#25) Use a 2.12.0 lower bound since pub does not understand allowed experiments for earlier versions. Use a 3.0.0 upper bound to avoid a warning in pub and to give some flexibility in publishing for stable.
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 Function() 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!')); }); }); }