| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 @TestOn("vm") | 5 @TestOn("vm") |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:test/src/util/exit_codes.dart' as exit_codes; | 10 import 'package:test/src/util/exit_codes.dart' as exit_codes; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 'Failed to load "${p.relative(testPath, from: _sandbox)}": Top-level ' | 89 'Failed to load "${p.relative(testPath, from: _sandbox)}": Top-level ' |
| 90 'main() function takes arguments.\n')); | 90 'main() function takes arguments.\n')); |
| 91 expect(result.exitCode, equals(exit_codes.data)); | 91 expect(result.exitCode, equals(exit_codes.data)); |
| 92 }); | 92 }); |
| 93 | 93 |
| 94 // TODO(nweiz): test what happens when a test file is unreadable once issue | 94 // TODO(nweiz): test what happens when a test file is unreadable once issue |
| 95 // 15078 is fixed. | 95 // 15078 is fixed. |
| 96 }); | 96 }); |
| 97 | 97 |
| 98 group("runs successful tests", () { | 98 group("runs successful tests", () { |
| 99 test("on the browser only", () { | 99 test("on Chrome", () { |
| 100 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 100 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 101 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 101 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
| 102 expect(result.exitCode, equals(0)); | 102 expect(result.exitCode, equals(0)); |
| 103 }); | 103 }); |
| 104 | 104 |
| 105 test("on Firefox", () { |
| 106 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 107 var result = _runUnittest(["-p", "firefox", "test.dart"]); |
| 108 expect(result.exitCode, equals(0)); |
| 109 }); |
| 110 |
| 111 test("on multiple browsers", () { |
| 112 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 113 var result = _runUnittest(["-p", "firefox", "-p", "chrome", "test.dart"]); |
| 114 expect("Compiling".allMatches(result.stdout), hasLength(1)); |
| 115 expect(result.exitCode, equals(0)); |
| 116 }); |
| 117 |
| 105 test("on the browser and the VM", () { | 118 test("on the browser and the VM", () { |
| 106 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 119 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 107 var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]); | 120 var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]); |
| 108 expect(result.exitCode, equals(0)); | 121 expect(result.exitCode, equals(0)); |
| 109 }); | 122 }); |
| 110 }); | 123 }); |
| 111 | 124 |
| 112 group("runs failing tests", () { | 125 group("runs failing tests", () { |
| 113 test("on the browser only", () { | 126 test("on Chrome", () { |
| 114 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 127 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 115 import 'dart:async'; | 128 import 'dart:async'; |
| 116 | 129 |
| 117 import 'package:test/test.dart'; | 130 import 'package:test/test.dart'; |
| 118 | 131 |
| 119 void main() { | 132 void main() { |
| 120 test("failure", () => throw new TestFailure("oh no")); | 133 test("failure", () => throw new TestFailure("oh no")); |
| 121 } | 134 } |
| 122 """); | 135 """); |
| 123 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 136 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
| 124 expect(result.exitCode, equals(1)); | 137 expect(result.exitCode, equals(1)); |
| 125 }); | 138 }); |
| 126 | 139 |
| 140 test("on Firefox", () { |
| 141 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 142 import 'dart:async'; |
| 143 |
| 144 import 'package:test/test.dart'; |
| 145 |
| 146 void main() { |
| 147 test("failure", () => throw new TestFailure("oh no")); |
| 148 } |
| 149 """); |
| 150 var result = _runUnittest(["-p", "firefox", "test.dart"]); |
| 151 expect(result.exitCode, equals(1)); |
| 152 }); |
| 153 |
| 127 test("that fail only on the browser", () { | 154 test("that fail only on the browser", () { |
| 128 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 155 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 129 import 'dart:async'; | 156 import 'dart:async'; |
| 130 | 157 |
| 131 import 'package:path/path.dart' as p; | 158 import 'package:path/path.dart' as p; |
| 132 import 'package:test/test.dart'; | 159 import 'package:test/test.dart'; |
| 133 | 160 |
| 134 void main() { | 161 void main() { |
| 135 test("test", () { | 162 test("test", () { |
| 136 if (p.style == p.Style.url) throw new TestFailure("oh no"); | 163 if (p.style == p.Style.url) throw new TestFailure("oh no"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 """); | 201 """); |
| 175 | 202 |
| 176 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 203 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
| 177 expect(result.stdout, contains("Hello,\nworld!\n")); | 204 expect(result.stdout, contains("Hello,\nworld!\n")); |
| 178 expect(result.exitCode, equals(0)); | 205 expect(result.exitCode, equals(0)); |
| 179 }); | 206 }); |
| 180 } | 207 } |
| 181 | 208 |
| 182 ProcessResult _runUnittest(List<String> args) => | 209 ProcessResult _runUnittest(List<String> args) => |
| 183 runUnittest(args, workingDirectory: _sandbox); | 210 runUnittest(args, workingDirectory: _sandbox); |
| OLD | NEW |