OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 @TestOn("vm") |
| 6 |
| 7 import 'dart:io'; |
| 8 |
| 9 import 'package:path/path.dart' as p; |
| 10 import 'package:unittest/src/util/io.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 |
| 13 import '../io.dart'; |
| 14 |
| 15 String _sandbox; |
| 16 |
| 17 final _vm = """ |
| 18 @TestOn("vm") |
| 19 |
| 20 import 'package:unittest/unittest.dart'; |
| 21 |
| 22 void main() { |
| 23 test("success", () {}); |
| 24 } |
| 25 """; |
| 26 |
| 27 final _chrome = """ |
| 28 @TestOn("chrome") |
| 29 |
| 30 // Make sure that loading this test file on the VM will break. |
| 31 import 'dart:html'; |
| 32 |
| 33 import 'package:unittest/unittest.dart'; |
| 34 |
| 35 void main() { |
| 36 test("success", () {}); |
| 37 } |
| 38 """; |
| 39 |
| 40 final _thisOS = """ |
| 41 @TestOn("$currentOS") |
| 42 |
| 43 import 'package:unittest/unittest.dart'; |
| 44 |
| 45 void main() { |
| 46 test("success", () {}); |
| 47 } |
| 48 """; |
| 49 |
| 50 final _otherOS = """ |
| 51 @TestOn("${Platform.isWindows ? "mac-os" : "windows"}") |
| 52 |
| 53 // Make sure that loading this test file on the VM will break. |
| 54 import 'dart:html'; |
| 55 |
| 56 import 'package:unittest/unittest.dart'; |
| 57 |
| 58 void main() { |
| 59 test("success", () {}); |
| 60 } |
| 61 """; |
| 62 |
| 63 void main() { |
| 64 setUp(() { |
| 65 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; |
| 66 }); |
| 67 |
| 68 tearDown(() { |
| 69 new Directory(_sandbox).deleteSync(recursive: true); |
| 70 }); |
| 71 |
| 72 test("runs a test suite on a matching platform", () { |
| 73 new File(p.join(_sandbox, "vm_test.dart")).writeAsStringSync(_vm); |
| 74 |
| 75 var result = _runUnittest(["vm_test.dart"]); |
| 76 expect(result.stdout, contains("All tests passed!")); |
| 77 expect(result.exitCode, equals(0)); |
| 78 }); |
| 79 |
| 80 test("doesn't run a test suite on a non-matching platform", () { |
| 81 new File(p.join(_sandbox, "vm_test.dart")).writeAsStringSync(_vm); |
| 82 |
| 83 var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]); |
| 84 expect(result.stdout, contains("No tests ran.")); |
| 85 expect(result.exitCode, equals(0)); |
| 86 }); |
| 87 |
| 88 test("runs a test suite on a matching operating system", () { |
| 89 new File(p.join(_sandbox, "os_test.dart")).writeAsStringSync(_thisOS); |
| 90 |
| 91 var result = _runUnittest(["os_test.dart"]); |
| 92 expect(result.stdout, contains("All tests passed!")); |
| 93 expect(result.exitCode, equals(0)); |
| 94 }); |
| 95 |
| 96 test("doesn't run a test suite on a non-matching operating system", () { |
| 97 new File(p.join(_sandbox, "os_test.dart")).writeAsStringSync(_otherOS); |
| 98 |
| 99 var result = _runUnittest(["os_test.dart"]); |
| 100 expect(result.stdout, contains("No tests ran.")); |
| 101 expect(result.exitCode, equals(0)); |
| 102 }); |
| 103 |
| 104 test("only loads matching files when loading as a group", () { |
| 105 new File(p.join(_sandbox, "vm_test.dart")).writeAsStringSync(_vm); |
| 106 new File(p.join(_sandbox, "chrome_test.dart")).writeAsStringSync(_chrome); |
| 107 new File(p.join(_sandbox, "this_os_test.dart")).writeAsStringSync(_thisOS); |
| 108 new File(p.join(_sandbox, "other_os_test.dart")) |
| 109 .writeAsStringSync(_otherOS); |
| 110 |
| 111 var result = _runUnittest(["."]); |
| 112 expect(result.stdout, contains("+2: All tests passed!")); |
| 113 expect(result.exitCode, equals(0)); |
| 114 }); |
| 115 } |
| 116 |
| 117 ProcessResult _runUnittest(List<String> args) => |
| 118 runUnittest(args, workingDirectory: _sandbox); |
OLD | NEW |