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

add tests, travis support, some lints #12

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
40 changes: 40 additions & 0 deletions test/test_reflective_loader_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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';

// ignore_for_file: always_declare_return_types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add these return types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the test methods? I normally see them w/o. happy w/ whichever

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


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

@reflectiveTest
class TestReflectiveLoaderTest {
String pathname;

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

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

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

@failingTest
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