From 5db5e300dc557b59d9e5318b4aff613d51f869c8 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 2 Jan 2017 22:03:37 -0500 Subject: [PATCH 1/2] Cleanup for v2.0.0 --- .analysis_options | 35 +++++++++++++++++++++++++++ lib/mockito.dart | 48 ++++++++++++++++++------------------- lib/mockito_no_mirrors.dart | 18 -------------- lib/src/mock.dart | 6 ++--- lib/src/spy.dart | 5 ++-- test/mockito_test.dart | 3 ++- tool/travis.sh | 36 +++++++++++++++++++--------- 7 files changed, 92 insertions(+), 59 deletions(-) create mode 100644 .analysis_options delete mode 100644 lib/mockito_no_mirrors.dart diff --git a/.analysis_options b/.analysis_options new file mode 100644 index 00000000..a8908b09 --- /dev/null +++ b/.analysis_options @@ -0,0 +1,35 @@ +analyzer: + strong-mode: true +linter: + rules: + # Errors + - avoid_empty_else + - comment_references + - control_flow_in_finally + - empty_statements + - hash_and_equals + - iterable_contains_unrelated_type + - list_remove_unrelated_type + - test_types_in_equals + - throw_in_finally + - unrelated_type_equality_checks + - valid_regexps + + # Style + - annotate_overrides + - avoid_init_to_null + - avoid_return_types_on_setters + - await_only_futures + - camel_case_types + - constant_identifier_names + - empty_catches + - empty_constructor_bodies + - library_names + - library_prefixes + - non_constant_identifier_names + - overridden_fields + - package_prefixed_library_names + - prefer_is_not_empty + - slash_for_doc_comments + - type_init_formals + - package_names diff --git a/lib/mockito.dart b/lib/mockito.dart index 4518c48a..4ece809f 100644 --- a/lib/mockito.dart +++ b/lib/mockito.dart @@ -14,30 +14,30 @@ export 'src/mock.dart' show - Mock, - named, + Mock, + named, - // -- setting behaviour - when, - any, - argThat, - captureAny, - captureThat, - typed, - Answering, - Expectation, - PostExpectation, + // -- setting behaviour + when, + any, + argThat, + captureAny, + captureThat, + typed, + Answering, + Expectation, + PostExpectation, - // -- verification - verify, - verifyInOrder, - verifyNever, - verifyNoMoreInteractions, - verifyZeroInteractions, - VerificationResult, - Verification, + // -- verification + verify, + verifyInOrder, + verifyNever, + verifyNoMoreInteractions, + verifyZeroInteractions, + VerificationResult, + Verification, - // -- misc - clearInteractions, - reset, - logInvocations; + // -- misc + clearInteractions, + reset, + logInvocations; diff --git a/lib/mockito_no_mirrors.dart b/lib/mockito_no_mirrors.dart deleted file mode 100644 index 7c356655..00000000 --- a/lib/mockito_no_mirrors.dart +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 Dart Mockito authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@Deprecated('Import "package:mockito/mockito.dart" instead.') -library mockito.mockito_no_mirrors; - -export 'mockito.dart'; diff --git a/lib/src/mock.dart b/lib/src/mock.dart index 3da51c4d..d717813e 100644 --- a/lib/src/mock.dart +++ b/lib/src/mock.dart @@ -20,7 +20,7 @@ import 'package:test/test.dart'; bool _whenInProgress = false; bool _verificationInProgress = false; -_WhenCall _whenCall = null; +_WhenCall _whenCall; final List<_VerifyCall> _verifyCalls = <_VerifyCall>[]; final _TimeStampProvider _timer = new _TimeStampProvider(); final List _capturedArgs = []; @@ -70,8 +70,8 @@ class Mock { final List _realCalls = []; final List _responses = []; - String _givenName = null; - int _givenHashCode = null; + String _givenName; + int _givenHashCode; _ReturnsCannedResponse _defaultResponse = _nullResponse; diff --git a/lib/src/spy.dart b/lib/src/spy.dart index 78548310..f584d658 100644 --- a/lib/src/spy.dart +++ b/lib/src/spy.dart @@ -24,11 +24,12 @@ import 'mock.dart' show CannedResponse, Mock, setDefaultResponse; /// var mockAnimal = new MockAnimal(); /// var realAnimal = new RealAnimal(); /// spy(mockAnimal, realAnimal); -/*=E*/ spy/**/(Mock mock, Object /*=E*/ spyOn) { +/*=E*/ spy/**/(Mock mock, Object/*=E*/ spyOn) { var mirror = reflect(spyOn); setDefaultResponse( mock, () => new CannedResponse(null, (Invocation realInvocation) => mirror.delegate(realInvocation))); - return mock; + // No reified types for generic methods yet, so silence the warning below. + return mock; // ignore: return_of_invalid_type } diff --git a/test/mockito_test.dart b/test/mockito_test.dart index 7b95a4bf..2f709586 100644 --- a/test/mockito_test.dart +++ b/test/mockito_test.dart @@ -35,7 +35,7 @@ class RealClass { {List y, List z}) => "Real"; String get getter => "Real"; - void set setter(String arg) { + set setter(String arg) { throw new StateError("I must be mocked"); } } @@ -45,6 +45,7 @@ abstract class Foo { } abstract class AbstractFoo implements Foo { + @override String bar() => baz(); String baz(); diff --git a/tool/travis.sh b/tool/travis.sh index 4ca80327..4d2387ab 100755 --- a/tool/travis.sh +++ b/tool/travis.sh @@ -14,16 +14,30 @@ #!/bin/bash -# Fast fail the script on failures. -set -e +# Make sure dartfmt is run on everything +# This assumes you have dart_style as a dev_dependency +echo "Checking dartfmt..." +NEEDS_DARTFMT="$(find lib test -name "*.dart" | xargs dartfmt -n)" +if [[ ${NEEDS_DARTFMT} != "" ]] +then + echo "FAILED" + echo "${NEEDS_DARTFMT}" + exit 1 +fi +echo "PASSED" + +# Make sure we pass the analyzer +echo "Checking dartanalyzer..." +FAILS_ANALYZER="$(find lib test -name "*.dart" | xargs dartanalyzer --options .analysis_options)" +if [[ $FAILS_ANALYZER == *"[error]"* ]] +then + echo "FAILED" + echo "${FAILS_ANALYZER}" + exit 1 +fi +echo "PASSED" -# Verify that the libraries are error free. -dartanalyzer --fatal-warnings \ - lib/mockito.dart \ - lib/mockito_no_mirrors.dart \ - lib/src/invocation_matcher.dart \ - test/mockito_test.dart +# Fail on anything that fails going forward. +set -e -# Run the tests. -dart -c test/invocation_matcher_test.dart -dart -c test/mockito_test.dart +pub run test From c90c58c0e6d0ab97cbbfbb83e197b0a66808fc0c Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 2 Jan 2017 22:04:21 -0500 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89117a59..2f9f2fa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.0 + +* Removed `mockito_no_mirrors.dart` + ## 2.0.0-dev * Remove export of `spy` and any `dart:mirrors` based API from