Index: pkg/unittest/test/with_test_environment_test.dart |
diff --git a/pkg/unittest/test/with_test_environment_test.dart b/pkg/unittest/test/with_test_environment_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..57459136ec6d33f73a20a4a53f51633329f6c54d |
--- /dev/null |
+++ b/pkg/unittest/test/with_test_environment_test.dart |
@@ -0,0 +1,50 @@ |
+// Copyright (c) 2014, 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. |
+ |
+library unittest.with_test_environment_test; |
+ |
+import 'package:unittest/unittest.dart'; |
+ |
+void runUnittests(Function callback) { |
+ unittestConfiguration = new SimpleConfiguration(); |
+ callback(); |
+} |
+ |
+void runTests() { |
+ test('test', () => expect(2 + 3, equals(5))); |
+} |
+ |
+void runTests1() { |
+ test('test1', () => expect(4 + 3, equals(7))); |
+} |
+ |
+// Test that we can run two different sets of tests in the same run using the |
+// withTestEnvironment method. |
+void main() { |
nweiz
2014/11/13 19:34:28
Why doesn't this use metatest to isolate its test
wibling
2014/11/14 10:09:49
I am not sure what the benefit of metatests would
nweiz
2014/11/17 23:02:54
metatest allows you to create isolated test run wi
wibling
2014/11/18 10:16:49
I did look at the other tests and also at the meta
nweiz
2014/11/19 21:40:39
Oh, I see, that's a good point. It's probably poss
|
+ // First check that we cannot call runUnittests twice in a row without it |
+ // throwing a StateError due to the unittestConfiguration being set globally |
+ // in the first call. |
+ try { |
+ runUnittests(runTests); |
+ runUnittests(runTests1); |
+ throw 'Expected this to be unreachable since 2nd run above should throw'; |
+ } catch(error) { |
nweiz
2014/11/13 19:34:28
Add a space after "catch".
Also, if you write "on
wibling
2014/11/14 10:09:49
Done.
|
+ if (error is! StateError) |
+ throw error; |
nweiz
2014/11/13 19:34:28
If you're using a bracketless if, you must put the
wibling
2014/11/14 10:09:49
Done.
|
+ // expected, silently ignore. |
+ } |
+ |
+ // Second test that we can run both when encapsulating in their own private |
+ // test environment. |
+ withTestEnvironment(() => runUnittests(runTests)); |
+ withTestEnvironment(() => runUnittests(runTests1)); |
+ |
+ // Third test that we can run with two nested test environments. |
+ withTestEnvironment(() { |
+ runUnittests(runTests); |
+ withTestEnvironment(() { |
+ runUnittests(runTests1); |
+ }); |
+ }); |
+} |