Skip to content

Commit 1d6f3a4

Browse files
authored
Merge pull request flutter#12 from dart-lang/tests
add tests, travis support, some lints
2 parents adf5ed4 + f1c4e97 commit 1d6f3a4

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: dart
2+
script: ./tool/travis.sh

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ analyzer:
22
strong-mode: true
33
linter:
44
rules:
5+
- always_declare_return_types
56
- directives_ordering
7+
- public_member_api_docs

lib/test_reflective_loader.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const _FailingTest failingTest = const _FailingTest();
2727
* A marker annotation used to instruct dart2js to keep reflection information
2828
* for the annotated classes.
2929
*/
30-
const ReflectiveTest reflectiveTest = const ReflectiveTest();
30+
const _ReflectiveTest reflectiveTest = const _ReflectiveTest();
3131

3232
/**
3333
* A marker annotation used to annotate "solo" groups and tests.
@@ -92,7 +92,7 @@ void defineReflectiveSuite(void define(), {String name}) {
9292
void defineReflectiveTests(Type type) {
9393
ClassMirror classMirror = reflectClass(type);
9494
if (!classMirror.metadata.any((InstanceMirror annotation) =>
95-
annotation.type.reflectedType == ReflectiveTest)) {
95+
annotation.type.reflectedType == _ReflectiveTest)) {
9696
String name = MirrorSystem.getName(classMirror.qualifiedName);
9797
throw new Exception('Class $name must have annotation "@reflectiveTest" '
9898
'in order to be run by runReflectiveTests.');
@@ -247,21 +247,21 @@ Future _runFailingTest(ClassMirror classMirror, Symbol symbol) {
247247
});
248248
}
249249

250-
_runTest(ClassMirror classMirror, Symbol symbol) {
250+
Future _runTest(ClassMirror classMirror, Symbol symbol) {
251251
InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []);
252252
return _invokeSymbolIfExists(instanceMirror, #setUp)
253253
.then((_) => instanceMirror.invoke(symbol, []).reflectee)
254254
.whenComplete(() => _invokeSymbolIfExists(instanceMirror, #tearDown));
255255
}
256256

257-
typedef _TestFunction();
257+
typedef dynamic _TestFunction();
258258

259259
/**
260260
* A marker annotation used to instruct dart2js to keep reflection information
261261
* for the annotated classes.
262262
*/
263-
class ReflectiveTest {
264-
const ReflectiveTest();
263+
class _ReflectiveTest {
264+
const _ReflectiveTest();
265265
}
266266

267267
/**

test/test_reflective_loader_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2017, 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+
import 'dart:async';
6+
7+
import 'package:test/test.dart';
8+
import 'package:test_reflective_loader/test_reflective_loader.dart';
9+
10+
void main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(TestReflectiveLoaderTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class TestReflectiveLoaderTest {
18+
String pathname;
19+
20+
void test_passes() {
21+
expect(true, true);
22+
}
23+
24+
@failingTest
25+
void test_fails() {
26+
expect(false, true);
27+
}
28+
29+
@failingTest
30+
void test_fails_throws_sync() {
31+
throw 'foo';
32+
}
33+
34+
@failingTest
35+
Future test_fails_throws_async() {
36+
return new Future.error('foo');
37+
}
38+
}

tool/travis.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
4+
# for details. All rights reserved. Use of this source code is governed by a
5+
# BSD-style license that can be found in the LICENSE file.
6+
7+
# Fast fail the script on failures.
8+
set -e
9+
10+
# Verify that the libraries are error free.
11+
dartanalyzer --fatal-warnings \
12+
lib/test_reflective_loader.dart \
13+
test/test_reflective_loader_test.dart
14+
15+
# Run the tests.
16+
dart test/test_reflective_loader_test.dart

0 commit comments

Comments
 (0)