Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Merge pull request #12 from dart-lang/tests
Browse files Browse the repository at this point in the history
add tests, travis support, some lints
  • Loading branch information
devoncarew authored Dec 8, 2017
2 parents adf5ed4 + f1c4e97 commit 1d6f3a4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: dart
script: ./tool/travis.sh
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ analyzer:
strong-mode: true
linter:
rules:
- always_declare_return_types
- directives_ordering
- public_member_api_docs
12 changes: 6 additions & 6 deletions lib/test_reflective_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const _FailingTest failingTest = const _FailingTest();
* A marker annotation used to instruct dart2js to keep reflection information
* for the annotated classes.
*/
const ReflectiveTest reflectiveTest = const ReflectiveTest();
const _ReflectiveTest reflectiveTest = const _ReflectiveTest();

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

_runTest(ClassMirror classMirror, Symbol symbol) {
Future _runTest(ClassMirror classMirror, Symbol symbol) {
InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []);
return _invokeSymbolIfExists(instanceMirror, #setUp)
.then((_) => instanceMirror.invoke(symbol, []).reflectee)
.whenComplete(() => _invokeSymbolIfExists(instanceMirror, #tearDown));
}

typedef _TestFunction();
typedef dynamic _TestFunction();

/**
* A marker annotation used to instruct dart2js to keep reflection information
* for the annotated classes.
*/
class ReflectiveTest {
const ReflectiveTest();
class _ReflectiveTest {
const _ReflectiveTest();
}

/**
Expand Down
38 changes: 38 additions & 0 deletions test/test_reflective_loader_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(TestReflectiveLoaderTest);
});
}

@reflectiveTest
class TestReflectiveLoaderTest {
String pathname;

void test_passes() {
expect(true, true);
}

@failingTest
void test_fails() {
expect(false, true);
}

@failingTest
void test_fails_throws_sync() {
throw 'foo';
}

@failingTest
Future test_fails_throws_async() {
return new Future.error('foo');
}
}
16 changes: 16 additions & 0 deletions tool/travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# Fast fail the script on failures.
set -e

# Verify that the libraries are error free.
dartanalyzer --fatal-warnings \
lib/test_reflective_loader.dart \
test/test_reflective_loader_test.dart

# Run the tests.
dart test/test_reflective_loader_test.dart

0 comments on commit 1d6f3a4

Please sign in to comment.