Files
sdk/tests/standalone_2/io/sleep_test.dart
T
Robert Nystrom 01907a6f9b Migrate standalone tests off ancient deprecated unittest package.
We don't intend to migrate unittest to NNBD, so the remaining tests
that use it need to be migrated off. This takes care of the couple of
tests in standalone/ and standalone_2/ that used it.

The tests should behave the same as they did before. I verified by
making the tests fail in various ways after the migration and ensuring
that the tests failed as expected.

Change-Id: I938229cabad1d78a42a030970f2003edd36572f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136060
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
2020-02-24 23:53:33 +00:00

30 lines
738 B
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:expect/expect.dart';
test(int milliseconds) {
var watch = new Stopwatch();
watch.start();
sleep(new Duration(milliseconds: milliseconds));
watch.stop();
Expect.isTrue(watch.elapsedMilliseconds >= milliseconds);
}
main() {
test(0);
test(1);
test(10);
test(100);
bool sawError = false;
try {
sleep(new Duration(milliseconds: -1));
Expect.fail('Should not reach here.');
} on ArgumentError catch (e) {
sawError = true;
}
Expect.isTrue(sawError);
}