Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions .status

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.2.1-dev
## 0.2.1

- Use package:lints for analysis.
- Populate the pubspec `repository` field.
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# test_reflective_loader

[![Build Status](https://github.com/dart-lang/test_reflective_loader/workflows/Dart/badge.svg)](https://github.com/dart-lang/test_reflective_loader/actions)
[![pub package](https://img.shields.io/pub/v/test_reflective_loader.svg)](https://pub.dev/packages/test_reflective_loader)

Support for discovering tests and test suites using reflection.

Expand Down
6 changes: 5 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include: package:lints/core.yaml
include: package:lints/recommended.yaml

analyzer:
errors:
slash_for_doc_comments: ignore

linter:
rules:
Expand Down
33 changes: 18 additions & 15 deletions lib/test_reflective_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ import 'package:test/test.dart' as test_package;
* A marker annotation used to annotate test methods which are expected to fail
* when asserts are enabled.
*/
const _AssertFailingTest assertFailingTest = const _AssertFailingTest();
const _AssertFailingTest assertFailingTest = _AssertFailingTest();

/**
* A marker annotation used to annotate test methods which are expected to fail.
*/
const FailingTest failingTest = const FailingTest();
const FailingTest failingTest = FailingTest();

/**
* A marker annotation used to instruct dart2js to keep reflection information
* for the annotated classes.
*/
const _ReflectiveTest reflectiveTest = const _ReflectiveTest();
const _ReflectiveTest reflectiveTest = _ReflectiveTest();

/**
* A marker annotation used to annotate test methods that should be skipped.
*/
const SkippedTest skippedTest = const SkippedTest();
const SkippedTest skippedTest = SkippedTest();

/**
* A marker annotation used to annotate "solo" groups and tests.
*/
const _SoloTest soloTest = const _SoloTest();
const _SoloTest soloTest = _SoloTest();

final List<_Group> _currentGroups = <_Group>[];
int _currentSuiteLevel = 0;
Expand All @@ -58,7 +58,7 @@ final bool _isCheckedMode = () {
* create embedded suites. If the current suite is the top-level one, perform
* check for "solo" groups and tests, and run all or only "solo" items.
*/
void defineReflectiveSuite(void define(), {String name = ''}) {
void defineReflectiveSuite(void Function() define, {String name = ''}) {
String groupName = _currentSuiteName;
_currentSuiteLevel++;
try {
Expand Down Expand Up @@ -96,15 +96,15 @@ void defineReflectiveTests(Type type) {
if (!classMirror.metadata.any((InstanceMirror annotation) =>
annotation.type.reflectedType == _ReflectiveTest)) {
String name = MirrorSystem.getName(classMirror.qualifiedName);
throw new Exception('Class $name must have annotation "@reflectiveTest" '
throw Exception('Class $name must have annotation "@reflectiveTest" '
'in order to be run by runReflectiveTests.');
}

_Group group;
{
bool isSolo = _hasAnnotationInstance(classMirror, soloTest);
String className = MirrorSystem.getName(classMirror.simpleName);
group = new _Group(isSolo, _combineNames(_currentSuiteName, className));
group = _Group(isSolo, _combineNames(_currentSuiteName, className));
_currentGroups.add(group);
}

Expand Down Expand Up @@ -229,16 +229,18 @@ bool _hasSkippedTestAnnotation(MethodMirror method) =>

Future<Object?> _invokeSymbolIfExists(
InstanceMirror instanceMirror, Symbol symbol) {
Object? invocationResult = null;
Object? invocationResult;
InstanceMirror? closure;
try {
closure = instanceMirror.getField(symbol);
} on NoSuchMethodError {}
} on NoSuchMethodError {
// ignore
}

if (closure is ClosureMirror) {
invocationResult = closure.apply([]).reflectee;
}
return new Future.value(invocationResult);
return Future.value(invocationResult);
}

/**
Expand All @@ -252,7 +254,8 @@ Future<Object?> _invokeSymbolIfExists(
Future<Object?>? _runFailingTest(ClassMirror classMirror, Symbol symbol) {
bool passed = false;
return runZonedGuarded(() {
return new Future.sync(() => _runTest(classMirror, symbol)).then<void>((_) {
// ignore: void_checks
return Future.sync(() => _runTest(classMirror, symbol)).then<void>((_) {
passed = true;
test_package.fail('Test passed - expected to fail.');
}).catchError((e) {
Expand All @@ -272,7 +275,7 @@ Future<Object?>? _runFailingTest(ClassMirror classMirror, Symbol symbol) {
}

Future<Object?> _runTest(ClassMirror classMirror, Symbol symbol) {
InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []);
InstanceMirror instanceMirror = classMirror.newInstance(Symbol(''), []);
return _invokeSymbolIfExists(instanceMirror, #setUp)
.then((_) => instanceMirror.invoke(symbol, []).reflectee)
.whenComplete(() => _invokeSymbolIfExists(instanceMirror, #tearDown));
Expand Down Expand Up @@ -341,15 +344,15 @@ class _Group {

void addSkippedTest(String name) {
var fullName = _combineNames(this.name, name);
tests.add(new _Test.skipped(isSolo, fullName));
tests.add(_Test.skipped(isSolo, fullName));
}

void addTest(bool isSolo, String name, MethodMirror memberMirror,
_TestFunction function) {
var fullName = _combineNames(this.name, name);
var timeout =
_getAnnotationInstance(memberMirror, TestTimeout) as TestTimeout?;
tests.add(new _Test(isSolo, fullName, function, timeout?._timeout));
tests.add(_Test(isSolo, fullName, function, timeout?._timeout));
}
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test_reflective_loader
version: 0.2.1-dev
version: 0.2.1
description: Support for discovering tests and test suites using reflection.
repository: https://github.com/dart-lang/test_reflective_loader

Expand All @@ -8,4 +8,4 @@ environment:

dependencies:
lints: ^1.0.0
test: '>=1.16.0 <2.0.0'
test: ^1.16.0
2 changes: 1 addition & 1 deletion test/test_reflective_loader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestReflectiveLoaderTest {

@failingTest
Future test_fails_throws_async() {
return new Future.error('foo');
return Future.error('foo');
}

@skippedTest
Expand Down