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:convert'; |
| 8 |
| 9 import 'package:scheduled_test/descriptor.dart' as d; |
| 10 import 'package:scheduled_test/scheduled_test.dart'; |
| 11 |
| 12 import 'package:test/src/util/exit_codes.dart' as exit_codes; |
| 13 import 'package:test/src/util/io.dart'; |
| 14 |
| 15 import '../../io.dart'; |
| 16 |
| 17 void main() { |
| 18 useSandbox(); |
| 19 |
| 20 group("on_platform", () { |
| 21 test("applies platform-specific configuration to matching tests", () { |
| 22 d.file("dart_test.yaml", JSON.encode({ |
| 23 "on_platform": { |
| 24 "content-shell": {"timeout": "0s"} |
| 25 } |
| 26 })).create(); |
| 27 |
| 28 d.file("test.dart", """ |
| 29 import 'dart:async'; |
| 30 |
| 31 import 'package:test/test.dart'; |
| 32 |
| 33 void main() { |
| 34 test("test", () => new Future.delayed(Duration.ZERO)); |
| 35 } |
| 36 """).create(); |
| 37 |
| 38 var test = runTest(["-p", "content-shell,vm", "test.dart"]); |
| 39 test.stdout.expect(containsInOrder([ |
| 40 "-1: [Dartium Content Shell] test", |
| 41 "+1 -1: Some tests failed." |
| 42 ])); |
| 43 test.shouldExit(1); |
| 44 }, tags: ['content-shell']); |
| 45 |
| 46 test("supports platform selectors", () { |
| 47 d.file("dart_test.yaml", JSON.encode({ |
| 48 "on_platform": { |
| 49 "content-shell || vm": {"timeout": "0s"} |
| 50 } |
| 51 })).create(); |
| 52 |
| 53 d.file("test.dart", """ |
| 54 import 'dart:async'; |
| 55 |
| 56 import 'package:test/test.dart'; |
| 57 |
| 58 void main() { |
| 59 test("test", () => new Future.delayed(Duration.ZERO)); |
| 60 } |
| 61 """).create(); |
| 62 |
| 63 var test = runTest(["-p", "content-shell,vm", "test.dart"]); |
| 64 test.stdout.expect(containsInOrder([ |
| 65 "-1: [VM] test", |
| 66 "-2: [Dartium Content Shell] test", |
| 67 "-2: Some tests failed." |
| 68 ])); |
| 69 test.shouldExit(1); |
| 70 }, tags: ['content-shell']); |
| 71 |
| 72 group("errors", () { |
| 73 test("rejects an invalid selector type", () { |
| 74 d.file("dart_test.yaml", '{"on_platform": {12: null}}').create(); |
| 75 |
| 76 var test = runTest([]); |
| 77 test.stderr.expect(containsInOrder([ |
| 78 "on_platform key must be a string", |
| 79 "^^" |
| 80 ])); |
| 81 test.shouldExit(exit_codes.data); |
| 82 }); |
| 83 |
| 84 test("rejects an invalid selector", () { |
| 85 d.file("dart_test.yaml", JSON.encode({ |
| 86 "on_platform": {"foo bar": null} |
| 87 })).create(); |
| 88 |
| 89 var test = runTest([]); |
| 90 test.stderr.expect(containsInOrder([ |
| 91 "Invalid on_platform key: Expected end of input.", |
| 92 "^^^^^^^^^" |
| 93 ])); |
| 94 test.shouldExit(exit_codes.data); |
| 95 }); |
| 96 |
| 97 test("rejects a selector with an undefined variable", () { |
| 98 d.file("dart_test.yaml", JSON.encode({ |
| 99 "on_platform": {"foo": null} |
| 100 })).create(); |
| 101 |
| 102 var test = runTest([]); |
| 103 test.stderr.expect(containsInOrder([ |
| 104 "Invalid on_platform key: Undefined variable.", |
| 105 "^^^^^" |
| 106 ])); |
| 107 test.shouldExit(exit_codes.data); |
| 108 }); |
| 109 |
| 110 test("rejects an invalid map", () { |
| 111 d.file("dart_test.yaml", JSON.encode({ |
| 112 "on_platform": {"linux": 12} |
| 113 })).create(); |
| 114 |
| 115 var test = runTest([]); |
| 116 test.stderr.expect(containsInOrder([ |
| 117 "on_platform value must be a map.", |
| 118 "^^" |
| 119 ])); |
| 120 test.shouldExit(exit_codes.data); |
| 121 }); |
| 122 |
| 123 test("rejects an invalid configuration", () { |
| 124 d.file("dart_test.yaml", JSON.encode({ |
| 125 "on_platform": {"linux": {"timeout": "12p"}} |
| 126 })).create(); |
| 127 |
| 128 var test = runTest([]); |
| 129 test.stderr.expect(containsInOrder([ |
| 130 "Invalid timeout: expected unit.", |
| 131 "^^^^^" |
| 132 ])); |
| 133 test.shouldExit(exit_codes.data); |
| 134 }); |
| 135 |
| 136 test("rejects runner configuration", () { |
| 137 d.file("dart_test.yaml", JSON.encode({ |
| 138 "on_platform": {"linux": {"filename": "*_blorp"}} |
| 139 })).create(); |
| 140 |
| 141 var test = runTest([]); |
| 142 test.stderr.expect(containsInOrder([ |
| 143 "filename isn't supported here.", |
| 144 "^^^^^^^^^" |
| 145 ])); |
| 146 test.shouldExit(exit_codes.data); |
| 147 }); |
| 148 }); |
| 149 }); |
| 150 |
| 151 group("on_os", () { |
| 152 test("applies OS-specific configuration on a matching OS", () { |
| 153 d.file("dart_test.yaml", JSON.encode({ |
| 154 "on_os": { |
| 155 currentOS.identifier: {"filename": "test_*.dart"} |
| 156 } |
| 157 })).create(); |
| 158 |
| 159 d.file("foo_test.dart", """ |
| 160 import 'package:test/test.dart'; |
| 161 |
| 162 void main() { |
| 163 test("foo_test", () {}); |
| 164 } |
| 165 """).create(); |
| 166 |
| 167 d.file("test_foo.dart", """ |
| 168 import 'package:test/test.dart'; |
| 169 |
| 170 void main() { |
| 171 test("test_foo", () {}); |
| 172 } |
| 173 """).create(); |
| 174 |
| 175 var test = runTest(["."]); |
| 176 test.stdout.expect(containsInOrder([ |
| 177 "+0: ./test_foo.dart: test_foo", |
| 178 "+1: All tests passed!" |
| 179 ])); |
| 180 test.shouldExit(0); |
| 181 }); |
| 182 |
| 183 test("doesn't OS-specific configuration on a non-matching OS", () { |
| 184 d.file("dart_test.yaml", JSON.encode({ |
| 185 "on_os": { |
| 186 otherOS: {"filename": "test_*.dart"} |
| 187 } |
| 188 })).create(); |
| 189 |
| 190 d.file("foo_test.dart", """ |
| 191 import 'package:test/test.dart'; |
| 192 |
| 193 void main() { |
| 194 test("foo_test", () {}); |
| 195 } |
| 196 """).create(); |
| 197 |
| 198 d.file("test_foo.dart", """ |
| 199 import 'package:test/test.dart'; |
| 200 |
| 201 void main() { |
| 202 test("test_foo", () {}); |
| 203 } |
| 204 """).create(); |
| 205 |
| 206 var test = runTest(["."]); |
| 207 test.stdout.expect(containsInOrder([ |
| 208 "+0: ./foo_test.dart: foo_test", |
| 209 "+1: All tests passed!" |
| 210 ])); |
| 211 test.shouldExit(0); |
| 212 }); |
| 213 |
| 214 group("errors", () { |
| 215 test("rejects an invalid OS type", () { |
| 216 d.file("dart_test.yaml", '{"on_os": {12: null}}').create(); |
| 217 |
| 218 var test = runTest([]); |
| 219 test.stderr.expect(containsInOrder([ |
| 220 "on_os key must be a string", |
| 221 "^^" |
| 222 ])); |
| 223 test.shouldExit(exit_codes.data); |
| 224 }); |
| 225 |
| 226 test("rejects an unknown OS name", () { |
| 227 d.file("dart_test.yaml", JSON.encode({ |
| 228 "on_os": {"foo": null} |
| 229 })).create(); |
| 230 |
| 231 var test = runTest([]); |
| 232 test.stderr.expect(containsInOrder([ |
| 233 "Invalid on_os key: No such operating system.", |
| 234 "^^^^^" |
| 235 ])); |
| 236 test.shouldExit(exit_codes.data); |
| 237 }); |
| 238 |
| 239 test("rejects an invalid map", () { |
| 240 d.file("dart_test.yaml", JSON.encode({ |
| 241 "on_os": {"linux": 12} |
| 242 })).create(); |
| 243 |
| 244 var test = runTest([]); |
| 245 test.stderr.expect(containsInOrder([ |
| 246 "on_os value must be a map.", |
| 247 "^^" |
| 248 ])); |
| 249 test.shouldExit(exit_codes.data); |
| 250 }); |
| 251 |
| 252 test("rejects an invalid configuration", () { |
| 253 d.file("dart_test.yaml", JSON.encode({ |
| 254 "on_os": {"linux": {"timeout": "12p"}} |
| 255 })).create(); |
| 256 |
| 257 var test = runTest([]); |
| 258 test.stderr.expect(containsInOrder([ |
| 259 "Invalid timeout: expected unit.", |
| 260 "^^^^^" |
| 261 ])); |
| 262 test.shouldExit(exit_codes.data); |
| 263 }); |
| 264 }); |
| 265 }); |
| 266 } |
OLD | NEW |