OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 @TestOn("vm") |
| 6 |
| 7 import 'dart:io'; |
| 8 import 'dart:math' as math; |
| 9 |
| 10 import 'package:scheduled_test/descriptor.dart' as d; |
| 11 import 'package:scheduled_test/scheduled_stream.dart'; |
| 12 import 'package:scheduled_test/scheduled_test.dart'; |
| 13 import 'package:test/src/util/exit_codes.dart' as exit_codes; |
| 14 |
| 15 import '../io.dart'; |
| 16 |
| 17 void main() { |
| 18 useSandbox(); |
| 19 |
| 20 group("a skipped expect", () { |
| 21 test("marks the test as skipped", () { |
| 22 d.file("test.dart", """ |
| 23 import 'package:test/test.dart'; |
| 24 |
| 25 void main() { |
| 26 test("skipped", () => expect(1, equals(2), skip: true)); |
| 27 } |
| 28 """).create(); |
| 29 |
| 30 var test = runTest(["test.dart"]); |
| 31 test.stdout.expect(consumeThrough(contains("~1: All tests skipped."))); |
| 32 test.shouldExit(0); |
| 33 }); |
| 34 |
| 35 test("prints the skip reason if there is one", () { |
| 36 d.file("test.dart", """ |
| 37 import 'package:test/test.dart'; |
| 38 |
| 39 void main() { |
| 40 test("skipped", () => expect(1, equals(2), |
| 41 reason: "1 is 2", skip: "is failing")); |
| 42 } |
| 43 """).create(); |
| 44 |
| 45 var test = runTest(["test.dart"]); |
| 46 test.stdout.expect(containsInOrder([ |
| 47 "+0: skipped", |
| 48 " Skip expect: is failing", |
| 49 "~1: All tests skipped." |
| 50 ])); |
| 51 test.shouldExit(0); |
| 52 }); |
| 53 |
| 54 test("prints the expect reason if there's no skip reason", () { |
| 55 d.file("test.dart", """ |
| 56 import 'package:test/test.dart'; |
| 57 |
| 58 void main() { |
| 59 test("skipped", () => expect(1, equals(2), |
| 60 reason: "1 is 2", skip: true)); |
| 61 } |
| 62 """).create(); |
| 63 |
| 64 var test = runTest(["test.dart"]); |
| 65 test.stdout.expect(containsInOrder([ |
| 66 "+0: skipped", |
| 67 " Skip expect (1 is 2).", |
| 68 "~1: All tests skipped." |
| 69 ])); |
| 70 test.shouldExit(0); |
| 71 }); |
| 72 |
| 73 test("prints the matcher description if there are no reasons", () { |
| 74 d.file("test.dart", """ |
| 75 import 'package:test/test.dart'; |
| 76 |
| 77 void main() { |
| 78 test("skipped", () => expect(1, equals(2), skip: true)); |
| 79 } |
| 80 """).create(); |
| 81 |
| 82 var test = runTest(["test.dart"]); |
| 83 test.stdout.expect(containsInOrder([ |
| 84 "+0: skipped", |
| 85 " Skip expect (<2>).", |
| 86 "~1: All tests skipped." |
| 87 ])); |
| 88 test.shouldExit(0); |
| 89 }); |
| 90 |
| 91 test("still allows the test to fail", () { |
| 92 d.file("test.dart", """ |
| 93 import 'package:test/test.dart'; |
| 94 |
| 95 void main() { |
| 96 test("failing", () { |
| 97 expect(1, equals(2), skip: true); |
| 98 expect(1, equals(2)); |
| 99 }); |
| 100 } |
| 101 """).create(); |
| 102 |
| 103 var test = runTest(["test.dart"]); |
| 104 test.stdout.expect(containsInOrder([ |
| 105 "+0: failing", |
| 106 " Skip expect (<2>).", |
| 107 "+0 -1: failing", |
| 108 " Expected: <2>", |
| 109 " Actual: <1>", |
| 110 "+0 -1: Some tests failed." |
| 111 ])); |
| 112 test.shouldExit(1); |
| 113 }); |
| 114 }); |
| 115 |
| 116 group("errors", () { |
| 117 test("when called after the test succeeded", () { |
| 118 d.file("test.dart", """ |
| 119 import 'dart:async'; |
| 120 |
| 121 import 'package:test/test.dart'; |
| 122 |
| 123 void main() { |
| 124 var skipCompleter = new Completer(); |
| 125 var waitCompleter = new Completer(); |
| 126 test("skip", () { |
| 127 skipCompleter.future.then((_) { |
| 128 waitCompleter.complete(); |
| 129 expect(1, equals(2), skip: true); |
| 130 }); |
| 131 }); |
| 132 |
| 133 // Trigger the skip completer in a following test to ensure that it |
| 134 // only fires after skip has completed successfully. |
| 135 test("wait", () async { |
| 136 skipCompleter.complete(); |
| 137 await waitCompleter.future; |
| 138 }); |
| 139 } |
| 140 """).create(); |
| 141 |
| 142 var test = runTest(["test.dart"]); |
| 143 test.stdout.expect(containsInOrder([ |
| 144 "+0: skip", |
| 145 "+1: wait", |
| 146 "+0 -1: skip", |
| 147 "This test was marked as skipped after it had already completed. " |
| 148 "Make sure to use", |
| 149 "[expectAsync] or the [completes] matcher when testing async code.", |
| 150 "+1 -1: Some tests failed." |
| 151 ])); |
| 152 test.shouldExit(1); |
| 153 }); |
| 154 |
| 155 test("when an invalid type is used for skip", () { |
| 156 d.file("test.dart", """ |
| 157 import 'package:test/test.dart'; |
| 158 |
| 159 void main() { |
| 160 test("failing", () { |
| 161 expect(1, equals(2), skip: 10); |
| 162 }); |
| 163 } |
| 164 """).create(); |
| 165 |
| 166 var test = runTest(["test.dart"]); |
| 167 test.stdout.expect(containsInOrder([ |
| 168 "Invalid argument (skip)", |
| 169 "+0 -1: Some tests failed." |
| 170 ])); |
| 171 test.shouldExit(1); |
| 172 }); |
| 173 }); |
| 174 } |
OLD | NEW |