| Index: test/runner/test_on_test.dart
|
| diff --git a/test/runner/test_on_test.dart b/test/runner/test_on_test.dart
|
| index 547f758cf5bcd388c67115e22a7bed5920d919fc..f303f909d203f85076312c4d93e6f9c068f73e2b 100644
|
| --- a/test/runner/test_on_test.dart
|
| +++ b/test/runner/test_on_test.dart
|
| @@ -14,105 +14,204 @@ import '../io.dart';
|
|
|
| String _sandbox;
|
|
|
| -final _vm = """
|
| -@TestOn("vm")
|
| -
|
| -import 'package:unittest/unittest.dart';
|
| +final _otherOS = Platform.isWindows ? "mac-os" : "windows";
|
|
|
| void main() {
|
| - test("success", () {});
|
| -}
|
| -""";
|
| + setUp(() {
|
| + _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
|
| + });
|
|
|
| -final _chrome = """
|
| -@TestOn("chrome")
|
| + tearDown(() {
|
| + new Directory(_sandbox).deleteSync(recursive: true);
|
| + });
|
|
|
| -// Make sure that loading this test file on the VM will break.
|
| -import 'dart:html';
|
| + group("for suite", () {
|
| + test("runs a test suite on a matching platform", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "vm");
|
| +
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("doesn't run a test suite on a non-matching platform", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "vm");
|
| +
|
| + var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("runs a test suite on a matching operating system", () {
|
| + _writeTestFile("os_test.dart", suiteTestOn: currentOS.name);
|
| +
|
| + var result = _runUnittest(["os_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("doesn't run a test suite on a non-matching operating system", () {
|
| + _writeTestFile("os_test.dart", suiteTestOn: _otherOS,
|
| + loadable: false);
|
| +
|
| + var result = _runUnittest(["os_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("only loads matching files when loading as a group", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "vm");
|
| + _writeTestFile("chrome_test.dart",
|
| + suiteTestOn: "chrome", loadable: false);
|
| + _writeTestFile("this_os_test.dart", suiteTestOn: currentOS.name);
|
| + _writeTestFile("other_os_test.dart",
|
| + suiteTestOn: _otherOS, loadable: false);
|
| +
|
| + var result = _runUnittest(["."]);
|
| + expect(result.stdout, contains("+2: All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| + });
|
|
|
| -import 'package:unittest/unittest.dart';
|
| + group("for group", () {
|
| + test("runs a VM group on the VM", () {
|
| + _writeTestFile("vm_test.dart", groupTestOn: "vm");
|
|
|
| -void main() {
|
| - test("success", () {});
|
| -}
|
| -""";
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
|
|
| -final _thisOS = """
|
| -@TestOn("$currentOS")
|
| + test("doesn't run a Chrome group on the VM", () {
|
| + _writeTestFile("chrome_test.dart", groupTestOn: "chrome");
|
|
|
| -import 'package:unittest/unittest.dart';
|
| + var result = _runUnittest(["chrome_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
|
|
| -void main() {
|
| - test("success", () {});
|
| -}
|
| -""";
|
| + test("runs a Chrome group on Chrome", () {
|
| + _writeTestFile("chrome_test.dart", groupTestOn: "chrome");
|
|
|
| -final _otherOS = """
|
| -@TestOn("${Platform.isWindows ? "mac-os" : "windows"}")
|
| + var result = _runUnittest(["--platform", "chrome", "chrome_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
|
|
| -// Make sure that loading this test file on the VM will break.
|
| -import 'dart:html';
|
| + test("doesn't run a VM group on Chrome", () {
|
| + _writeTestFile("vm_test.dart", groupTestOn: "vm");
|
|
|
| -import 'package:unittest/unittest.dart';
|
| -
|
| -void main() {
|
| - test("success", () {});
|
| -}
|
| -""";
|
| -
|
| -void main() {
|
| - setUp(() {
|
| - _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
|
| + var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| });
|
|
|
| - tearDown(() {
|
| - new Directory(_sandbox).deleteSync(recursive: true);
|
| - });
|
| -
|
| - test("runs a test suite on a matching platform", () {
|
| - new File(p.join(_sandbox, "vm_test.dart")).writeAsStringSync(_vm);
|
| + group("for test", () {
|
| + test("runs a VM test on the VM", () {
|
| + _writeTestFile("vm_test.dart", testTestOn: "vm");
|
|
|
| - var result = _runUnittest(["vm_test.dart"]);
|
| - expect(result.stdout, contains("All tests passed!"));
|
| - expect(result.exitCode, equals(0));
|
| - });
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
|
|
| - test("doesn't run a test suite on a non-matching platform", () {
|
| - new File(p.join(_sandbox, "vm_test.dart")).writeAsStringSync(_vm);
|
| + test("doesn't run a Chrome test on the VM", () {
|
| + _writeTestFile("chrome_test.dart", testTestOn: "chrome");
|
|
|
| - var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]);
|
| - expect(result.stdout, contains("No tests ran."));
|
| - expect(result.exitCode, equals(0));
|
| - });
|
| + var result = _runUnittest(["chrome_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
|
|
| - test("runs a test suite on a matching operating system", () {
|
| - new File(p.join(_sandbox, "os_test.dart")).writeAsStringSync(_thisOS);
|
| + test("runs a Chrome test on Chrome", () {
|
| + _writeTestFile("chrome_test.dart", testTestOn: "chrome");
|
|
|
| - var result = _runUnittest(["os_test.dart"]);
|
| - expect(result.stdout, contains("All tests passed!"));
|
| - expect(result.exitCode, equals(0));
|
| - });
|
| + var result = _runUnittest(["--platform", "chrome", "chrome_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
|
|
| - test("doesn't run a test suite on a non-matching operating system", () {
|
| - new File(p.join(_sandbox, "os_test.dart")).writeAsStringSync(_otherOS);
|
| + test("doesn't run a VM test on Chrome", () {
|
| + _writeTestFile("vm_test.dart", testTestOn: "vm");
|
|
|
| - var result = _runUnittest(["os_test.dart"]);
|
| - expect(result.stdout, contains("No tests ran."));
|
| - expect(result.exitCode, equals(0));
|
| + var result = _runUnittest(["--platform", "chrome", "vm_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| });
|
|
|
| - test("only loads matching files when loading as a group", () {
|
| - new File(p.join(_sandbox, "vm_test.dart")).writeAsStringSync(_vm);
|
| - new File(p.join(_sandbox, "chrome_test.dart")).writeAsStringSync(_chrome);
|
| - new File(p.join(_sandbox, "this_os_test.dart")).writeAsStringSync(_thisOS);
|
| - new File(p.join(_sandbox, "other_os_test.dart"))
|
| - .writeAsStringSync(_otherOS);
|
| -
|
| - var result = _runUnittest(["."]);
|
| - expect(result.stdout, contains("+2: All tests passed!"));
|
| - expect(result.exitCode, equals(0));
|
| + group("with suite, group, and test selectors", () {
|
| + test("runs the test if all selectors match", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "!browser",
|
| + groupTestOn: "!js", testTestOn: "vm");
|
| +
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("All tests passed!"));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("doesn't runs the test if the suite doesn't match", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "chrome",
|
| + groupTestOn: "!js", testTestOn: "vm");
|
| +
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("doesn't runs the test if the group doesn't match", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "!browser",
|
| + groupTestOn: "chrome", testTestOn: "vm");
|
| +
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| +
|
| + test("doesn't runs the test if the test doesn't match", () {
|
| + _writeTestFile("vm_test.dart", suiteTestOn: "!browser",
|
| + groupTestOn: "!js", testTestOn: "chrome");
|
| +
|
| + var result = _runUnittest(["vm_test.dart"]);
|
| + expect(result.stdout, contains("No tests ran."));
|
| + expect(result.exitCode, equals(0));
|
| + });
|
| });
|
| }
|
|
|
| +/// Writes a test file with some platform selectors to [filename].
|
| +///
|
| +/// Each of [suiteTestOn], [groupTestOn], and [testTestOn] is a platform
|
| +/// selector that's suite-, group-, and test-level respectively. If [loadable]
|
| +/// is `false`, the test file will be made unloadable on the Dart VM.
|
| +void _writeTestFile(String filename, {String suiteTestOn, String groupTestOn,
|
| + String testTestOn, bool loadable: true}) {
|
| + var buffer = new StringBuffer();
|
| + if (suiteTestOn != null) buffer.writeln("@TestOn('$suiteTestOn')");
|
| + if (!loadable) buffer.writeln("import 'dart:html';");
|
| +
|
| + buffer
|
| + ..writeln("import 'package:unittest/unittest.dart';")
|
| + ..writeln("void main() {")
|
| + ..writeln(" group('group', () {");
|
| +
|
| + if (testTestOn != null) {
|
| + buffer.writeln(" test('test', () {}, testOn: '$testTestOn');");
|
| + } else {
|
| + buffer.writeln(" test('test', () {});");
|
| + }
|
| +
|
| + if (groupTestOn != null) {
|
| + buffer.writeln(" }, testOn: '$groupTestOn');");
|
| + } else {
|
| + buffer.writeln(" });");
|
| + }
|
| +
|
| + buffer.writeln("}");
|
| +
|
| + new File(p.join(_sandbox, filename)).writeAsStringSync(buffer.toString());
|
| +}
|
| +
|
| ProcessResult _runUnittest(List<String> args) =>
|
| runUnittest(args, workingDirectory: _sandbox);
|
|
|