| 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 19 matching lines...) Expand all Loading... |
| 30 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); | 30 _writeTestFile("vm_test.dart", suiteTestOn: "vm"); |
| 31 | 31 |
| 32 var result = _runTest(["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 = _runTest(["--platform", "chrome", "vm_test.dart"]); | 40 var result = _runTest(["--platform", "content-shell", "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 = _runTest(["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 = _runTest(["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("browser_test.dart", |
| 65 suiteTestOn: "chrome", loadable: false); | 65 suiteTestOn: "browser", 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 = _runTest(["."]); | 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 = _runTest(["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 Browser group on the VM", () { |
| 86 _writeTestFile("chrome_test.dart", groupTestOn: "chrome"); | 86 _writeTestFile("browser_test.dart", groupTestOn: "browser"); |
| 87 | 87 |
| 88 var result = _runTest(["chrome_test.dart"]); | 88 var result = _runTest(["browser_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 browser group on a browser", () { |
| 94 _writeTestFile("chrome_test.dart", groupTestOn: "chrome"); | 94 _writeTestFile("browser_test.dart", groupTestOn: "browser"); |
| 95 | 95 |
| 96 var result = _runTest(["--platform", "chrome", "chrome_test.dart"]); | 96 var result = _runTest( |
| 97 ["--platform", "content-shell", "browser_test.dart"]); |
| 97 expect(result.stdout, contains("All tests passed!")); | 98 expect(result.stdout, contains("All tests passed!")); |
| 98 expect(result.exitCode, equals(0)); | 99 expect(result.exitCode, equals(0)); |
| 99 }); | 100 }); |
| 100 | 101 |
| 101 test("doesn't run a VM group on Chrome", () { | 102 test("doesn't run a VM group on a browser", () { |
| 102 _writeTestFile("vm_test.dart", groupTestOn: "vm"); | 103 _writeTestFile("vm_test.dart", groupTestOn: "vm"); |
| 103 | 104 |
| 104 var result = _runTest(["--platform", "chrome", "vm_test.dart"]); | 105 var result = _runTest(["--platform", "content-shell", "vm_test.dart"]); |
| 105 expect(result.stdout, contains("No tests ran.")); | 106 expect(result.stdout, contains("No tests ran.")); |
| 106 expect(result.exitCode, equals(0)); | 107 expect(result.exitCode, equals(0)); |
| 107 }); | 108 }); |
| 108 }); | 109 }); |
| 109 | 110 |
| 110 group("for test", () { | 111 group("for test", () { |
| 111 test("runs a VM test on the VM", () { | 112 test("runs a VM test on the VM", () { |
| 112 _writeTestFile("vm_test.dart", testTestOn: "vm"); | 113 _writeTestFile("vm_test.dart", testTestOn: "vm"); |
| 113 | 114 |
| 114 var result = _runTest(["vm_test.dart"]); | 115 var result = _runTest(["vm_test.dart"]); |
| 115 expect(result.stdout, contains("All tests passed!")); | 116 expect(result.stdout, contains("All tests passed!")); |
| 116 expect(result.exitCode, equals(0)); | 117 expect(result.exitCode, equals(0)); |
| 117 }); | 118 }); |
| 118 | 119 |
| 119 test("doesn't run a Chrome test on the VM", () { | 120 test("doesn't run a browser test on the VM", () { |
| 120 _writeTestFile("chrome_test.dart", testTestOn: "chrome"); | 121 _writeTestFile("browser_test.dart", testTestOn: "browser"); |
| 121 | 122 |
| 122 var result = _runTest(["chrome_test.dart"]); | 123 var result = _runTest(["browser_test.dart"]); |
| 123 expect(result.stdout, contains("No tests ran.")); | 124 expect(result.stdout, contains("No tests ran.")); |
| 124 expect(result.exitCode, equals(0)); | 125 expect(result.exitCode, equals(0)); |
| 125 }); | 126 }); |
| 126 | 127 |
| 127 test("runs a Chrome test on Chrome", () { | 128 test("runs a browser test on a browser", () { |
| 128 _writeTestFile("chrome_test.dart", testTestOn: "chrome"); | 129 _writeTestFile("browser_test.dart", testTestOn: "browser"); |
| 129 | 130 |
| 130 var result = _runTest(["--platform", "chrome", "chrome_test.dart"]); | 131 var result = _runTest( |
| 132 ["--platform", "content-shell", "browser_test.dart"]); |
| 131 expect(result.stdout, contains("All tests passed!")); | 133 expect(result.stdout, contains("All tests passed!")); |
| 132 expect(result.exitCode, equals(0)); | 134 expect(result.exitCode, equals(0)); |
| 133 }); | 135 }); |
| 134 | 136 |
| 135 test("doesn't run a VM test on Chrome", () { | 137 test("doesn't run a VM test on a browser", () { |
| 136 _writeTestFile("vm_test.dart", testTestOn: "vm"); | 138 _writeTestFile("vm_test.dart", testTestOn: "vm"); |
| 137 | 139 |
| 138 var result = _runTest(["--platform", "chrome", "vm_test.dart"]); | 140 var result = _runTest(["--platform", "content-shell", "vm_test.dart"]); |
| 139 expect(result.stdout, contains("No tests ran.")); | 141 expect(result.stdout, contains("No tests ran.")); |
| 140 expect(result.exitCode, equals(0)); | 142 expect(result.exitCode, equals(0)); |
| 141 }); | 143 }); |
| 142 }); | 144 }); |
| 143 | 145 |
| 144 group("with suite, group, and test selectors", () { | 146 group("with suite, group, and test selectors", () { |
| 145 test("runs the test if all selectors match", () { | 147 test("runs the test if all selectors match", () { |
| 146 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", | 148 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", |
| 147 groupTestOn: "!js", testTestOn: "vm"); | 149 groupTestOn: "!js", testTestOn: "vm"); |
| 148 | 150 |
| 149 var result = _runTest(["vm_test.dart"]); | 151 var result = _runTest(["vm_test.dart"]); |
| 150 expect(result.stdout, contains("All tests passed!")); | 152 expect(result.stdout, contains("All tests passed!")); |
| 151 expect(result.exitCode, equals(0)); | 153 expect(result.exitCode, equals(0)); |
| 152 }); | 154 }); |
| 153 | 155 |
| 154 test("doesn't runs the test if the suite doesn't match", () { | 156 test("doesn't runs the test if the suite doesn't match", () { |
| 155 _writeTestFile("vm_test.dart", suiteTestOn: "chrome", | 157 _writeTestFile("vm_test.dart", suiteTestOn: "browser", |
| 156 groupTestOn: "!js", testTestOn: "vm"); | 158 groupTestOn: "!js", testTestOn: "vm"); |
| 157 | 159 |
| 158 var result = _runTest(["vm_test.dart"]); | 160 var result = _runTest(["vm_test.dart"]); |
| 159 expect(result.stdout, contains("No tests ran.")); | 161 expect(result.stdout, contains("No tests ran.")); |
| 160 expect(result.exitCode, equals(0)); | 162 expect(result.exitCode, equals(0)); |
| 161 }); | 163 }); |
| 162 | 164 |
| 163 test("doesn't runs the test if the group doesn't match", () { | 165 test("doesn't runs the test if the group doesn't match", () { |
| 164 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", | 166 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", |
| 165 groupTestOn: "chrome", testTestOn: "vm"); | 167 groupTestOn: "browser", testTestOn: "vm"); |
| 166 | 168 |
| 167 var result = _runTest(["vm_test.dart"]); | 169 var result = _runTest(["vm_test.dart"]); |
| 168 expect(result.stdout, contains("No tests ran.")); | 170 expect(result.stdout, contains("No tests ran.")); |
| 169 expect(result.exitCode, equals(0)); | 171 expect(result.exitCode, equals(0)); |
| 170 }); | 172 }); |
| 171 | 173 |
| 172 test("doesn't runs the test if the test doesn't match", () { | 174 test("doesn't runs the test if the test doesn't match", () { |
| 173 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", | 175 _writeTestFile("vm_test.dart", suiteTestOn: "!browser", |
| 174 groupTestOn: "!js", testTestOn: "chrome"); | 176 groupTestOn: "!js", testTestOn: "browser"); |
| 175 | 177 |
| 176 var result = _runTest(["vm_test.dart"]); | 178 var result = _runTest(["vm_test.dart"]); |
| 177 expect(result.stdout, contains("No tests ran.")); | 179 expect(result.stdout, contains("No tests ran.")); |
| 178 expect(result.exitCode, equals(0)); | 180 expect(result.exitCode, equals(0)); |
| 179 }); | 181 }); |
| 180 }); | 182 }); |
| 181 } | 183 } |
| 182 | 184 |
| 183 /// Writes a test file with some platform selectors to [filename]. | 185 /// Writes a test file with some platform selectors to [filename]. |
| 184 /// | 186 /// |
| (...skipping 23 matching lines...) Expand all Loading... |
| 208 buffer.writeln(" });"); | 210 buffer.writeln(" });"); |
| 209 } | 211 } |
| 210 | 212 |
| 211 buffer.writeln("}"); | 213 buffer.writeln("}"); |
| 212 | 214 |
| 213 new File(p.join(_sandbox, filename)).writeAsStringSync(buffer.toString()); | 215 new File(p.join(_sandbox, filename)).writeAsStringSync(buffer.toString()); |
| 214 } | 216 } |
| 215 | 217 |
| 216 ProcessResult _runTest(List<String> args) => | 218 ProcessResult _runTest(List<String> args) => |
| 217 runTest(args, workingDirectory: _sandbox); | 219 runTest(args, workingDirectory: _sandbox); |
| OLD | NEW |