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") |
| 6 |
5 import 'dart:io'; | 7 import 'dart:io'; |
6 | 8 |
7 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
8 import 'package:unittest/src/util/exit_codes.dart' as exit_codes; | 10 import 'package:unittest/src/util/exit_codes.dart' as exit_codes; |
9 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
10 | 12 |
11 import '../io.dart'; | 13 import '../io.dart'; |
12 | 14 |
13 String _sandbox; | 15 String _sandbox; |
14 | 16 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 var result = _runUnittest(["test.dart"]); | 93 var result = _runUnittest(["test.dart"]); |
92 | 94 |
93 expect(result.stderr, equals( | 95 expect(result.stderr, equals( |
94 'Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 96 'Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
95 "line 1 pos 1: unexpected token 'invalid'\n" | 97 "line 1 pos 1: unexpected token 'invalid'\n" |
96 "invalid Dart file\n" | 98 "invalid Dart file\n" |
97 "^\n")); | 99 "^\n")); |
98 expect(result.exitCode, equals(exit_codes.data)); | 100 expect(result.exitCode, equals(exit_codes.data)); |
99 }); | 101 }); |
100 | 102 |
| 103 // This is slightly different from the above test because it's an error |
| 104 // that's caught first by the analyzer when it's used to parse the file. |
| 105 test("a test file fails to parse", () { |
| 106 var testPath = p.join(_sandbox, "test.dart"); |
| 107 new File(testPath).writeAsStringSync("@TestOn)"); |
| 108 var result = _runUnittest(["test.dart"]); |
| 109 |
| 110 expect(result.stderr, equals( |
| 111 'Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
| 112 "line 1 pos 8: unexpected token ')'\n" |
| 113 "@TestOn)\n" |
| 114 " ^\n")); |
| 115 expect(result.exitCode, equals(exit_codes.data)); |
| 116 }); |
| 117 |
| 118 test("an annotation's structure is invalid", () { |
| 119 var testPath = p.join(_sandbox, "test.dart"); |
| 120 new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;"); |
| 121 var result = _runUnittest(["test.dart"]); |
| 122 |
| 123 expect(result.stderr, equals( |
| 124 'Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
| 125 "Error on line 1, column 8: TestOn takes one argument.\n" |
| 126 "@TestOn()\n" |
| 127 " ^^\n")); |
| 128 expect(result.exitCode, equals(exit_codes.data)); |
| 129 }); |
| 130 |
101 test("a test file throws", () { | 131 test("a test file throws", () { |
102 var testPath = p.join(_sandbox, "test.dart"); | 132 var testPath = p.join(_sandbox, "test.dart"); |
103 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); | 133 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); |
104 | 134 |
105 var result = _runUnittest(["test.dart"]); | 135 var result = _runUnittest(["test.dart"]); |
106 expect(result.stderr, startsWith( | 136 expect(result.stderr, startsWith( |
107 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no\n')); | 137 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no\n')); |
108 expect(result.exitCode, equals(exit_codes.data)); | 138 expect(result.exitCode, equals(exit_codes.data)); |
109 }); | 139 }); |
110 | 140 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 expect(result.stdout, contains("\u001b[31m")); | 259 expect(result.stdout, contains("\u001b[31m")); |
230 }); | 260 }); |
231 }); | 261 }); |
232 } | 262 } |
233 | 263 |
234 ProcessResult _runUnittest(List<String> args) => | 264 ProcessResult _runUnittest(List<String> args) => |
235 runUnittest(args, workingDirectory: _sandbox); | 265 runUnittest(args, workingDirectory: _sandbox); |
236 | 266 |
237 ProcessResult _runDart(List<String> args) => | 267 ProcessResult _runDart(List<String> args) => |
238 runDart(args, workingDirectory: _sandbox); | 268 runDart(args, workingDirectory: _sandbox); |
OLD | NEW |