| 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/io.dart'; | 10 import 'package:test/src/util/io.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 tearDown(() { | 24 tearDown(() { |
| 25 new Directory(_sandbox).deleteSync(recursive: true); | 25 new Directory(_sandbox).deleteSync(recursive: true); |
| 26 }); | 26 }); |
| 27 | 27 |
| 28 group("for suite", () { | 28 group("for suite", () { |
| 29 test("runs a test suite on a matching platform", () { | 29 test("runs a test suite on a matching platform", () { |
| 30 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); | 30 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); |
| 31 | 31 |
| 32 var result = _runUnittest(["vm_test.dart"]); | 32 var result = _runTest(["vm_test.dart"]); |
| 33 expect(result.stdout, contains("All tests passed!")); | 33 expect(result.stdout, contains("All tests passed!")); |
| 34 expect(result.exitCode, equals(0)); | 34 expect(result.exitCode, equals(0)); |
| 35 }); | 35 }); |
| 36 | 36 |
| 37 test("doesn't run a test suite on a non-matching platform", () { | 37 test("doesn't run a test suite on a non-matching platform", () { |
| 38 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); | 38 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); |
| 39 | 39 |
| 40 var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]); | 40 var result = _runTest(["--platform", "chrome", "vm_test.dart"]); |
| 41 expect(result.stdout, contains("No tests ran.")); | 41 expect(result.stdout, contains("No tests ran.")); |
| 42 expect(result.exitCode, equals(0)); | 42 expect(result.exitCode, equals(0)); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 test("runs a test suite on a matching operating system", () { | 45 test("runs a test suite on a matching operating system", () { |
| 46 _writeTestFile("os_test.dart", suiteTestOn: currentOS.name); | 46 _writeTestFile("os_test.dart", suiteTestOn: currentOS.name); |
| 47 | 47 |
| 48 var result = _runUnittest(["os_test.dart"]); | 48 var result = _runTest(["os_test.dart"]); |
| 49 expect(result.stdout, contains("All tests passed!")); | 49 expect(result.stdout, contains("All tests passed!")); |
| 50 expect(result.exitCode, equals(0)); | 50 expect(result.exitCode, equals(0)); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 test("doesn't run a test suite on a non-matching operating system", () { | 53 test("doesn't run a test suite on a non-matching operating system", () { |
| 54 _writeTestFile("os_test.dart", suiteTestOn: _otherOS, | 54 _writeTestFile("os_test.dart", suiteTestOn: _otherOS, |
| 55 loadable: false); | 55 loadable: false); |
| 56 | 56 |
| 57 var result = _runUnittest(["os_test.dart"]); | 57 var result = _runTest(["os_test.dart"]); |
| 58 expect(result.stdout, contains("No tests ran.")); | 58 expect(result.stdout, contains("No tests ran.")); |
| 59 expect(result.exitCode, equals(0)); | 59 expect(result.exitCode, equals(0)); |
| 60 }); | 60 }); |
| 61 | 61 |
| 62 test("only loads matching files when loading as a group", () { | 62 test("only loads matching files when loading as a group", () { |
| 63 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); | 63 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); |
| 64 _writeTestFile("chrome_test.dart", | 64 _writeTestFile("chrome_test.dart", |
| 65 suiteTestOn: "chrome", loadable: false); | 65 suiteTestOn: "chrome", loadable: false); |
| 66 _writeTestFile("this_os_test.dart", suiteTestOn: currentOS.name); | 66 _writeTestFile("this_os_test.dart", suiteTestOn: currentOS.name); |
| 67 _writeTestFile("other_os_test.dart", | 67 _writeTestFile("other_os_test.dart", |
| 68 suiteTestOn: _otherOS, loadable: false); | 68 suiteTestOn: _otherOS, loadable: false); |
| 69 | 69 |
| 70 var result = _runUnittest(["."]); | 70 var result = _runTest(["."]); |
| 71 expect(result.stdout, contains("+2: All tests passed!")); | 71 expect(result.stdout, contains("+2: All tests passed!")); |
| 72 expect(result.exitCode, equals(0)); | 72 expect(result.exitCode, equals(0)); |
| 73 }); | 73 }); |
| 74 }); | 74 }); |
| 75 | 75 |
| 76 group("for group", () { | 76 group("for group", () { |
| 77 test("runs a VM group on the VM", () { | 77 test("runs a VM group on the VM", () { |
| 78 _writeTestFile("vm_test.dart", groupTestOn: "vm"); | 78 _writeTestFile("vm_test.dart", groupTestOn: "vm"); |
| 79 | 79 |
| 80 var result = _runUnittest(["vm_test.dart"]); | 80 var result = _runTest(["vm_test.dart"]); |
| 81 expect(result.stdout, contains("All tests passed!")); | 81 expect(result.stdout, contains("All tests passed!")); |
| 82 expect(result.exitCode, equals(0)); | 82 expect(result.exitCode, equals(0)); |
| 83 }); | 83 }); |
| 84 | 84 |
| 85 test("doesn't run a Chrome group on the VM", () { | 85 test("doesn't run a Chrome group on the VM", () { |
| 86 _writeTestFile("chrome_test.dart", groupTestOn: "chrome"); | 86 _writeTestFile("chrome_test.dart", groupTestOn: "chrome"); |
| 87 | 87 |
| 88 var result = _runUnittest(["chrome_test.dart"]); | 88 var result = _runTest(["chrome_test.dart"]); |
| 89 expect(result.stdout, contains("No tests ran.")); | 89 expect(result.stdout, contains("No tests ran.")); |
| 90 expect(result.exitCode, equals(0)); | 90 expect(result.exitCode, equals(0)); |
| 91 }); | 91 }); |
| 92 | 92 |
| 93 test("runs a Chrome group on Chrome", () { | 93 test("runs a Chrome group on Chrome", () { |
| 94 _writeTestFile("chrome_test.dart", groupTestOn: "chrome"); | 94 _writeTestFile("chrome_test.dart", groupTestOn: "chrome"); |
| 95 | 95 |
| 96 var result = _runUnittest(["--platform", "chrome", "chrome_test.dart"]); | 96 var result = _runTest(["--platform", "chrome", "chrome_test.dart"]); |
| 97 expect(result.stdout, contains("All tests passed!")); | 97 expect(result.stdout, contains("All tests passed!")); |
| 98 expect(result.exitCode, equals(0)); | 98 expect(result.exitCode, equals(0)); |
| 99 }); | 99 }); |
| 100 | 100 |
| 101 test("doesn't run a VM group on Chrome", () { | 101 test("doesn't run a VM group on Chrome", () { |
| 102 _writeTestFile("vm_test.dart", groupTestOn: "vm"); | 102 _writeTestFile("vm_test.dart", groupTestOn: "vm"); |
| 103 | 103 |
| 104 var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]); | 104 var result = _runTest(["--platform", "chrome", "vm_test.dart"]); |
| 105 expect(result.stdout, contains("No tests ran.")); | 105 expect(result.stdout, contains("No tests ran.")); |
| 106 expect(result.exitCode, equals(0)); | 106 expect(result.exitCode, equals(0)); |
| 107 }); | 107 }); |
| 108 }); | 108 }); |
| 109 | 109 |
| 110 group("for test", () { | 110 group("for test", () { |
| 111 test("runs a VM test on the VM", () { | 111 test("runs a VM test on the VM", () { |
| 112 _writeTestFile("vm_test.dart", testTestOn: "vm"); | 112 _writeTestFile("vm_test.dart", testTestOn: "vm"); |
| 113 | 113 |
| 114 var result = _runUnittest(["vm_test.dart"]); | 114 var result = _runTest(["vm_test.dart"]); |
| 115 expect(result.stdout, contains("All tests passed!")); | 115 expect(result.stdout, contains("All tests passed!")); |
| 116 expect(result.exitCode, equals(0)); | 116 expect(result.exitCode, equals(0)); |
| 117 }); | 117 }); |
| 118 | 118 |
| 119 test("doesn't run a Chrome test on the VM", () { | 119 test("doesn't run a Chrome test on the VM", () { |
| 120 _writeTestFile("chrome_test.dart", testTestOn: "chrome"); | 120 _writeTestFile("chrome_test.dart", testTestOn: "chrome"); |
| 121 | 121 |
| 122 var result = _runUnittest(["chrome_test.dart"]); | 122 var result = _runTest(["chrome_test.dart"]); |
| 123 expect(result.stdout, contains("No tests ran.")); | 123 expect(result.stdout, contains("No tests ran.")); |
| 124 expect(result.exitCode, equals(0)); | 124 expect(result.exitCode, equals(0)); |
| 125 }); | 125 }); |
| 126 | 126 |
| 127 test("runs a Chrome test on Chrome", () { | 127 test("runs a Chrome test on Chrome", () { |
| 128 _writeTestFile("chrome_test.dart", testTestOn: "chrome"); | 128 _writeTestFile("chrome_test.dart", testTestOn: "chrome"); |
| 129 | 129 |
| 130 var result = _runUnittest(["--platform", "chrome", "chrome_test.dart"]); | 130 var result = _runTest(["--platform", "chrome", "chrome_test.dart"]); |
| 131 expect(result.stdout, contains("All tests passed!")); | 131 expect(result.stdout, contains("All tests passed!")); |
| 132 expect(result.exitCode, equals(0)); | 132 expect(result.exitCode, equals(0)); |
| 133 }); | 133 }); |
| 134 | 134 |
| 135 test("doesn't run a VM test on Chrome", () { | 135 test("doesn't run a VM test on Chrome", () { |
| 136 _writeTestFile("vm_test.dart", testTestOn: "vm"); | 136 _writeTestFile("vm_test.dart", testTestOn: "vm"); |
| 137 | 137 |
| 138 var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]); | 138 var result = _runTest(["--platform", "chrome", "vm_test.dart"]); |
| 139 expect(result.stdout, contains("No tests ran.")); | 139 expect(result.stdout, contains("No tests ran.")); |
| 140 expect(result.exitCode, equals(0)); | 140 expect(result.exitCode, equals(0)); |
| 141 }); | 141 }); |
| 142 }); | 142 }); |
| 143 | 143 |
| 144 group("with suite, group, and test selectors", () { | 144 group("with suite, group, and test selectors", () { |
| 145 test("runs the test if all selectors match", () { | 145 test("runs the test if all selectors match", () { |
| 146 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", | 146 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", |
| 147 groupTestOn: "!js", testTestOn: "vm"); | 147 groupTestOn: "!js", testTestOn: "vm"); |
| 148 | 148 |
| 149 var result = _runUnittest(["vm_test.dart"]); | 149 var result = _runTest(["vm_test.dart"]); |
| 150 expect(result.stdout, contains("All tests passed!")); | 150 expect(result.stdout, contains("All tests passed!")); |
| 151 expect(result.exitCode, equals(0)); | 151 expect(result.exitCode, equals(0)); |
| 152 }); | 152 }); |
| 153 | 153 |
| 154 test("doesn't runs the test if the suite doesn't match", () { | 154 test("doesn't runs the test if the suite doesn't match", () { |
| 155 _writeTestFile("vm_test.dart", suiteTestOn: "chrome", | 155 _writeTestFile("vm_test.dart", suiteTestOn: "chrome", |
| 156 groupTestOn: "!js", testTestOn: "vm"); | 156 groupTestOn: "!js", testTestOn: "vm"); |
| 157 | 157 |
| 158 var result = _runUnittest(["vm_test.dart"]); | 158 var result = _runTest(["vm_test.dart"]); |
| 159 expect(result.stdout, contains("No tests ran.")); | 159 expect(result.stdout, contains("No tests ran.")); |
| 160 expect(result.exitCode, equals(0)); | 160 expect(result.exitCode, equals(0)); |
| 161 }); | 161 }); |
| 162 | 162 |
| 163 test("doesn't runs the test if the group doesn't match", () { | 163 test("doesn't runs the test if the group doesn't match", () { |
| 164 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", | 164 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", |
| 165 groupTestOn: "chrome", testTestOn: "vm"); | 165 groupTestOn: "chrome", testTestOn: "vm"); |
| 166 | 166 |
| 167 var result = _runUnittest(["vm_test.dart"]); | 167 var result = _runTest(["vm_test.dart"]); |
| 168 expect(result.stdout, contains("No tests ran.")); | 168 expect(result.stdout, contains("No tests ran.")); |
| 169 expect(result.exitCode, equals(0)); | 169 expect(result.exitCode, equals(0)); |
| 170 }); | 170 }); |
| 171 | 171 |
| 172 test("doesn't runs the test if the test doesn't match", () { | 172 test("doesn't runs the test if the test doesn't match", () { |
| 173 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", | 173 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", |
| 174 groupTestOn: "!js", testTestOn: "chrome"); | 174 groupTestOn: "!js", testTestOn: "chrome"); |
| 175 | 175 |
| 176 var result = _runUnittest(["vm_test.dart"]); | 176 var result = _runTest(["vm_test.dart"]); |
| 177 expect(result.stdout, contains("No tests ran.")); | 177 expect(result.stdout, contains("No tests ran.")); |
| 178 expect(result.exitCode, equals(0)); | 178 expect(result.exitCode, equals(0)); |
| 179 }); | 179 }); |
| 180 }); | 180 }); |
| 181 } | 181 } |
| 182 | 182 |
| 183 /// Writes a test file with some platform selectors to [filename]. | 183 /// Writes a test file with some platform selectors to [filename]. |
| 184 /// | 184 /// |
| 185 /// Each of [suiteTestOn], [groupTestOn], and [testTestOn] is a platform | 185 /// Each of [suiteTestOn], [groupTestOn], and [testTestOn] is a platform |
| 186 /// selector that's suite-, group-, and test-level respectively. If [loadable] | 186 /// selector that's suite-, group-, and test-level respectively. If [loadable] |
| (...skipping 19 matching lines...) Expand all Loading... |
| 206 buffer.writeln(" }, testOn: '$groupTestOn');"); | 206 buffer.writeln(" }, testOn: '$groupTestOn');"); |
| 207 } else { | 207 } else { |
| 208 buffer.writeln(" });"); | 208 buffer.writeln(" });"); |
| 209 } | 209 } |
| 210 | 210 |
| 211 buffer.writeln("}"); | 211 buffer.writeln("}"); |
| 212 | 212 |
| 213 new File(p.join(_sandbox, filename)).writeAsStringSync(buffer.toString()); | 213 new File(p.join(_sandbox, filename)).writeAsStringSync(buffer.toString()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 ProcessResult _runUnittest(List<String> args) => | 216 ProcessResult _runTest(List<String> args) => |
| 217 runUnittest(args, workingDirectory: _sandbox); | 217 runTest(args, workingDirectory: _sandbox); |
| OLD | NEW |