Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Unified Diff: test/runner/runner_test.dart

Issue 1243293002: Convert a bunch of tests to use scheduled_test's infrastructure. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/runner/pub_serve_test.dart ('k') | test/runner/signal_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/runner/runner_test.dart
diff --git a/test/runner/runner_test.dart b/test/runner/runner_test.dart
index 7b578d12dc05482904b53e9745089eecbd0bdb35..389c97180ab3257d3669e41e54c4340733107481 100644
--- a/test/runner/runner_test.dart
+++ b/test/runner/runner_test.dart
@@ -8,14 +8,13 @@ import 'dart:io';
import 'dart:math' as math;
import 'package:path/path.dart' as p;
+import 'package:scheduled_test/descriptor.dart' as d;
+import 'package:scheduled_test/scheduled_stream.dart';
+import 'package:scheduled_test/scheduled_test.dart';
import 'package:test/src/util/exit_codes.dart' as exit_codes;
-import 'package:test/src/util/io.dart';
-import 'package:test/test.dart';
import '../io.dart';
-String _sandbox;
-
final _success = """
import 'dart:async';
@@ -71,205 +70,177 @@ Usage: pub run test:test [files or directories...]
""";
void main() {
- setUp(() {
- _sandbox = createTempDir();
- });
-
- tearDown(() {
- new Directory(_sandbox).deleteSync(recursive: true);
- });
+ useSandbox();
test("prints help information", () {
- var result = _runTest(["--help"]);
- expect(result.stdout, equals("""
+ var test = runTest(["--help"]);
+ expectStdoutEquals(test, """
Runs tests in this package.
-$_usage"""));
- expect(result.exitCode, equals(exit_codes.success));
+$_usage""");
+ test.shouldExit(0);
});
group("fails gracefully if", () {
test("an invalid option is passed", () {
- var result = _runTest(["--asdf"]);
- expect(result.stderr, equals("""
+ var test = runTest(["--asdf"]);
+ expectStderrEquals(test, """
Could not find an option named "asdf".
-$_usage"""));
- expect(result.exitCode, equals(exit_codes.usage));
+$_usage""");
+ test.shouldExit(exit_codes.usage);
});
test("a non-existent file is passed", () {
- var result = _runTest(["file"]);
- expect(result.stdout, allOf([
- contains('-1: loading file'),
- contains('Failed to load "file": Does not exist.')
+ var test = runTest(["file"]);
+ test.stdout.expect(containsInOrder([
+ '-1: loading file',
+ 'Failed to load "file": Does not exist.'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("the default directory doesn't exist", () {
- var result = _runTest([]);
- expect(result.stderr, equals("""
+ var test = runTest([]);
+ expectStderrEquals(test, """
No test files were passed and the default "test/" directory doesn't exist.
-$_usage"""));
- expect(result.exitCode, equals(exit_codes.data));
+$_usage""");
+ test.shouldExit(exit_codes.data);
});
test("a test file fails to load", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("invalid Dart file");
- var result = _runTest(["test.dart"]);
-
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n'
- " line 1 pos 1: unexpected token 'invalid'\n"
- " invalid Dart file\n"
- " ^\n")
+ d.file("test.dart", "invalid Dart file").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart":',
+ "line 1 pos 1: unexpected token 'invalid'",
+ "invalid Dart file",
+ "^"
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
// This syntax error is detected lazily, and so requires some extra
// machinery to support.
test("a test file fails to parse due to a missing semicolon", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("void main() {foo}");
- var result = _runTest(["test.dart"]);
-
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n'
- " line 1 pos 17: semicolon expected\n"
- " void main() {foo}\n"
- " ^\n")
+ d.file("test.dart", "void main() {foo}").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart":',
+ 'line 1 pos 17: semicolon expected',
+ 'void main() {foo}',
+ ' ^'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
// This is slightly different from the above test because it's an error
// that's caught first by the analyzer when it's used to parse the file.
test("a test file fails to parse", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("@TestOn)");
- var result = _runTest(["test.dart"]);
-
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n'
- " line 1 pos 8: unexpected token ')'\n"
- " @TestOn)\n"
- " ^\n")
+ d.file("test.dart", "@TestOn)").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart":',
+ "line 1 pos 8: unexpected token ')'",
+ "@TestOn)",
+ " ^"
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("an annotation's structure is invalid", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;");
- var result = _runTest(["test.dart"]);
-
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n'
- " Error on line 1, column 8: TestOn takes 1 argument.\n"
- " @TestOn()\n"
- " ^^\n")
+ d.file("test.dart", "@TestOn()\nlibrary foo;").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart":',
+ "Error on line 1, column 8: TestOn takes 1 argument.",
+ "@TestOn()",
+ " ^^"
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("an annotation's contents are invalid", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("@TestOn('zim')\nlibrary foo;");
- var result = _runTest(["test.dart"]);
-
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n'
- " Error on line 1, column 10: Undefined variable.\n"
- " @TestOn('zim')\n"
- " ^^^\n")
+ d.file("test.dart", "@TestOn('zim')\nlibrary foo;").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart":',
+ "Error on line 1, column 10: Undefined variable.",
+ "@TestOn('zim')",
+ " ^^^"
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("a test file throws", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("void main() => throw 'oh no';");
-
- var result = _runTest(["test.dart"]);
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no')
+ d.file("test.dart", "void main() => throw 'oh no';").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart": oh no'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("a test file doesn't have a main defined", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("void foo() {}");
-
- var result = _runTest(["test.dart"]);
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- 'Failed to load "${p.relative(testPath, from: _sandbox)}": No '
- 'top-level main() function defined.')
+ d.file("test.dart", "void foo() {}").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart": No top-level main() function defined.'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("a test file has a non-function main", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("int main;");
-
- var result = _runTest(["test.dart"]);
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
- 'Top-level main getter is not a function.')
+ d.file("test.dart", "int main;").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart": Top-level main getter is not a function.'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("a test file has a main with arguments", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("void main(arg) {}");
-
- var result = _runTest(["test.dart"]);
- expect(result.stdout, allOf([
- contains('-1: loading test.dart'),
- contains(
- 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
- 'Top-level main() function takes arguments.')
+ d.file("test.dart", "void main(arg) {}").create();
+ var test = runTest(["test.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ '-1: loading test.dart',
+ 'Failed to load "test.dart": Top-level main() function takes arguments.'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
test("multiple load errors occur", () {
- var testPath = p.join(_sandbox, "test.dart");
- new File(testPath).writeAsStringSync("invalid Dart file");
- var result = _runTest(["test.dart", "nonexistent.dart"]);
-
- expect(result.stdout, allOf([
- contains('loading test.dart'),
- contains(
- ' Failed to load "test.dart":\n'
- " line 1 pos 1: unexpected token 'invalid'\n"
- " invalid Dart file\n"
- " ^\n"),
- contains('loading nonexistent.dart'),
- contains('Failed to load "nonexistent.dart": Does not exist.')
+ d.file("test.dart", "invalid Dart file").create();
+ var test = runTest(["test.dart", "nonexistent.dart"]);
+
+ test.stdout.expect(containsInOrder([
+ 'loading nonexistent.dart',
+ 'Failed to load "nonexistent.dart": Does not exist.',
+ 'loading test.dart',
+ 'Failed to load "test.dart":',
+ "line 1 pos 1: unexpected token 'invalid'",
+ "invalid Dart file",
+ "^"
]));
+ test.shouldExit(1);
});
// TODO(nweiz): test what happens when a test file is unreadable once issue
@@ -278,100 +249,103 @@ $_usage"""));
group("runs successful tests", () {
test("defined in a single file", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
- var result = _runTest(["test.dart"]);
- expect(result.exitCode, equals(0));
+ d.file("test.dart", _success).create();
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
test("defined in a directory", () {
for (var i = 0; i < 3; i++) {
- new File(p.join(_sandbox, "${i}_test.dart"))
- .writeAsStringSync(_success);
+ d.file("${i}_test.dart", _success).create();
}
- var result = _runTest(["."]);
- expect(result.exitCode, equals(0));
+ var test = runTest(["."]);
+ test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
+ test.shouldExit(0);
});
test("defaulting to the test directory", () {
- new Directory(p.join(_sandbox, "test")).createSync();
- for (var i = 0; i < 3; i++) {
- new File(p.join(_sandbox, "test", "${i}_test.dart"))
- .writeAsStringSync(_success);
- }
+ d.dir("test", new Iterable.generate(3, (i) {
+ return d.file("${i}_test.dart", _success);
+ })).create();
- var result = _runTest([]);
- expect(result.exitCode, equals(0));
+ var test = runTest([]);
+ test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
+ test.shouldExit(0);
});
test("directly", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
- var result = _runDart([
+ d.file("test.dart", _success).create();
+ var test = runDart([
"--package-root=${p.join(packageDir, 'packages')}",
"test.dart"
]);
- expect(result.stdout, contains("All tests passed!"));
- expect(result.exitCode, equals(0));
+
+ test.stdout.expect(consumeThrough(contains("All tests passed!")));
+ test.shouldExit(0);
});
// Regression test; this broke in 0.12.0-beta.9.
test("on a file in a subdirectory", () {
- new Directory(p.join(_sandbox, "dir")).createSync();
- new File(p.join(_sandbox, "dir", "test.dart"))
- .writeAsStringSync(_success);
- var result = _runTest(["dir/test.dart"]);
- expect(result.exitCode, equals(0));
+ d.dir("dir", [d.file("test.dart", _success)]).create();
+
+ var test = runTest(["dir/test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
});
group("runs failing tests", () {
test("defined in a single file", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
- var result = _runTest(["test.dart"]);
- expect(result.exitCode, equals(1));
+ d.file("test.dart", _failure).create();
+
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("-1: Some tests failed.")));
+ test.shouldExit(1);
});
test("defined in a directory", () {
for (var i = 0; i < 3; i++) {
- new File(p.join(_sandbox, "${i}_test.dart"))
- .writeAsStringSync(_failure);
+ d.file("${i}_test.dart", _failure).create();
}
- var result = _runTest(["."]);
- expect(result.exitCode, equals(1));
+ var test = runTest(["."]);
+ test.stdout.expect(consumeThrough(contains("-3: Some tests failed.")));
+ test.shouldExit(1);
});
test("defaulting to the test directory", () {
- new Directory(p.join(_sandbox, "test")).createSync();
- for (var i = 0; i < 3; i++) {
- new File(p.join(_sandbox, "test", "${i}_test.dart"))
- .writeAsStringSync(_failure);
- }
+ d.dir("test", new Iterable.generate(3, (i) {
+ return d.file("${i}_test.dart", _failure);
+ })).create();
- var result = _runTest([]);
- expect(result.exitCode, equals(1));
+ var test = runTest([]);
+ test.stdout.expect(consumeThrough(contains("-3: Some tests failed.")));
+ test.shouldExit(1);
});
test("directly", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
- var result = _runDart([
+ d.file("test.dart", _failure).create();
+ var test = runDart([
"--package-root=${p.join(packageDir, 'packages')}",
"test.dart"
]);
- expect(result.stdout, contains("Some tests failed."));
- expect(result.exitCode, isNot(equals(0)));
+ test.stdout.expect(consumeThrough(contains("Some tests failed.")));
+ test.shouldExit(255);
});
});
test("runs tests even when a file fails to load", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
- var result = _runTest(["test.dart", "nonexistent.dart"]);
- expect(result.stdout, contains("+1 -1: Some tests failed."));
- expect(result.exitCode, equals(1));
+ d.file("test.dart", _success).create();
+
+ var test = runTest(["test.dart", "nonexistent.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1 -1: Some tests failed.")));
+ test.shouldExit(1);
});
test("respects top-level @Timeout declarations", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
@Timeout(const Duration(seconds: 0))
import 'dart:async';
@@ -381,15 +355,18 @@ import 'package:test/test.dart';
void main() {
test("timeout", () {});
}
-''');
-
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("Test timed out after 0 seconds."));
- expect(result.stdout, contains("-1: Some tests failed."));
+''').create();
+
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(containsInOrder([
+ "Test timed out after 0 seconds.",
+ "-1: Some tests failed."
+ ]));
+ test.shouldExit(1);
});
test("respects top-level @Skip declarations", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
@Skip()
import 'dart:async';
@@ -399,15 +376,16 @@ import 'package:test/test.dart';
void main() {
test("fail", () => throw 'oh no');
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+0 ~1: All tests skipped."));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
+ test.shouldExit(0);
});
group("with onPlatform", () {
test("respects matching Skips", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
import 'dart:async';
import 'package:test/test.dart';
@@ -415,14 +393,15 @@ import 'package:test/test.dart';
void main() {
test("fail", () => throw 'oh no', onPlatform: {"vm": new Skip()});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+0 ~1: All tests skipped."));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
+ test.shouldExit(0);
});
test("ignores non-matching Skips", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
import 'dart:async';
import 'package:test/test.dart';
@@ -430,14 +409,15 @@ import 'package:test/test.dart';
void main() {
test("success", () {}, onPlatform: {"chrome": new Skip()});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+1: All tests passed!"));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
test("respects matching Timeouts", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
import 'dart:async';
import 'package:test/test.dart';
@@ -447,15 +427,18 @@ void main() {
"vm": new Timeout(new Duration(seconds: 0))
});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("Test timed out after 0 seconds."));
- expect(result.stdout, contains("-1: Some tests failed."));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(containsInOrder([
+ "Test timed out after 0 seconds.",
+ "-1: Some tests failed."
+ ]));
+ test.shouldExit(1);
});
test("ignores non-matching Timeouts", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
import 'dart:async';
import 'package:test/test.dart';
@@ -465,14 +448,15 @@ void main() {
"chrome": new Timeout(new Duration(seconds: 0))
});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+1: All tests passed!"));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
test("applies matching platforms in order", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
import 'dart:async';
import 'package:test/test.dart';
@@ -486,22 +470,21 @@ void main() {
"vm || android": new Skip("fifth")
});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("Skip: fifth"));
- expect(result.stdout, isNot(anyOf([
- contains("Skip: first"),
- contains("Skip: second"),
- contains("Skip: third"),
- contains("Skip: fourth")
- ])));
+ var test = runTest(["test.dart"]);
+ test.stdout.fork().expect(never(contains("Skip: first")));
+ test.stdout.fork().expect(never(contains("Skip: second")));
+ test.stdout.fork().expect(never(contains("Skip: third")));
+ test.stdout.fork().expect(never(contains("Skip: fourth")));
+ test.stdout.expect(consumeThrough(contains("Skip: fifth")));
+ test.shouldExit(0);
});
});
group("with an @OnPlatform annotation", () {
test("respects matching Skips", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
@OnPlatform(const {"vm": const Skip()})
import 'dart:async';
@@ -511,14 +494,15 @@ import 'package:test/test.dart';
void main() {
test("fail", () => throw 'oh no');
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+0 ~1: All tests skipped."));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
+ test.shouldExit(0);
});
test("ignores non-matching Skips", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
@OnPlatform(const {"chrome": const Skip()})
import 'dart:async';
@@ -528,14 +512,15 @@ import 'package:test/test.dart';
void main() {
test("success", () {});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+1: All tests passed!"));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
test("respects matching Timeouts", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
@OnPlatform(const {
"vm": const Timeout(const Duration(seconds: 0))
})
@@ -547,15 +532,18 @@ import 'package:test/test.dart';
void main() {
test("fail", () => throw 'oh no');
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("Test timed out after 0 seconds."));
- expect(result.stdout, contains("-1: Some tests failed."));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(containsInOrder([
+ "Test timed out after 0 seconds.",
+ "-1: Some tests failed."
+ ]));
+ test.shouldExit(1);
});
test("ignores non-matching Timeouts", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync('''
+ d.file("test.dart", '''
@OnPlatform(const {
"chrome": const Timeout(const Duration(seconds: 0))
})
@@ -567,24 +555,26 @@ import 'package:test/test.dart';
void main() {
test("success", () {});
}
-''');
+''').create();
- var result = _runTest(["test.dart"]);
- expect(result.stdout, contains("+1: All tests passed!"));
+ var test = runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
});
group("flags:", () {
test("with the --color flag, uses colors", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
- var result = _runTest(["--color", "test.dart"]);
+ d.file("test.dart", _failure).create();
+ var test = runTest(["--color", "test.dart"]);
// This is the color code for red.
- expect(result.stdout, contains("\u001b[31m"));
+ test.stdout.expect(consumeThrough(contains("\u001b[31m")));
+ test.shouldExit();
});
group("with the --name flag,", () {
test("selects tests with matching names", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+ d.file("test.dart", """
import 'dart:async';
import 'package:test/test.dart';
@@ -594,15 +584,15 @@ void main() {
test("nope", () => throw new TestFailure("oh no"));
test("selected 2", () {});
}
-""");
+""").create();
- var result = _runTest(["--name", "selected", "test.dart"]);
- expect(result.stdout, contains("+2: All tests passed!"));
- expect(result.exitCode, equals(0));
+ var test = runTest(["--name", "selected", "test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
+ test.shouldExit(0);
});
test("supports RegExp syntax", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+ d.file("test.dart", """
import 'dart:async';
import 'package:test/test.dart';
@@ -612,35 +602,35 @@ void main() {
test("test 2", () => throw new TestFailure("oh no"));
test("test 3", () {});
}
-""");
+""").create();
- var result = _runTest(["--name", "test [13]", "test.dart"]);
- expect(result.stdout, contains("+2: All tests passed!"));
- expect(result.exitCode, equals(0));
+ var test = runTest(["--name", "test [13]", "test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
+ test.shouldExit(0);
});
test("produces an error when no tests match", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
+ d.file("test.dart", _success).create();
- var result = _runTest(["--name", "no match", "test.dart"]);
- expect(result.stderr,
- contains('No tests match regular expression "no match".'));
- expect(result.exitCode, equals(exit_codes.data));
+ var test = runTest(["--name", "no match", "test.dart"]);
+ test.stderr.expect(consumeThrough(
+ contains('No tests match regular expression "no match".')));
+ test.shouldExit(exit_codes.data);
});
test("doesn't filter out load exceptions", () {
- var result = _runTest(["--name", "name", "file"]);
- expect(result.stdout, allOf([
- contains('-1: loading file'),
- contains('Failed to load "file": Does not exist.')
+ var test = runTest(["--name", "name", "file"]);
+ test.stdout.expect(containsInOrder([
+ '-1: loading file',
+ ' Failed to load "file": Does not exist.'
]));
- expect(result.exitCode, equals(1));
+ test.shouldExit(1);
});
});
group("with the --plain-name flag,", () {
test("selects tests with matching names", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+ d.file("test.dart", """
import 'dart:async';
import 'package:test/test.dart';
@@ -650,15 +640,15 @@ void main() {
test("nope", () => throw new TestFailure("oh no"));
test("selected 2", () {});
}
-""");
+""").create();
- var result = _runTest(["--plain-name", "selected", "test.dart"]);
- expect(result.stdout, contains("+2: All tests passed!"));
- expect(result.exitCode, equals(0));
+ var test = runTest(["--plain-name", "selected", "test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
+ test.shouldExit(0);
});
test("doesn't support RegExp syntax", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+ d.file("test.dart", """
import 'dart:async';
import 'package:test/test.dart';
@@ -668,27 +658,21 @@ void main() {
test("test 2", () => throw new TestFailure("oh no"));
test("test [12]", () {});
}
-""");
+""").create();
- var result = _runTest(["--plain-name", "test [12]", "test.dart"]);
- expect(result.stdout, contains("+1: All tests passed!"));
- expect(result.exitCode, equals(0));
+ var test = runTest(["--plain-name", "test [12]", "test.dart"]);
+ test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
+ test.shouldExit(0);
});
test("produces an error when no tests match", () {
- new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
+ d.file("test.dart", _success).create();
- var result = _runTest(["--plain-name", "no match", "test.dart"]);
- expect(result.stderr,
- contains('No tests match "no match".'));
- expect(result.exitCode, equals(exit_codes.data));
+ var test = runTest(["--plain-name", "no match", "test.dart"]);
+ test.stderr.expect(
+ consumeThrough(contains('No tests match "no match".')));
+ test.shouldExit(exit_codes.data);
});
});
});
}
-
-ProcessResult _runTest(List<String> args) =>
- runTest(args, workingDirectory: _sandbox);
-
-ProcessResult _runDart(List<String> args) =>
- runDart(args, workingDirectory: _sandbox);
« no previous file with comments | « test/runner/pub_serve_test.dart ('k') | test/runner/signal_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698