Skip to content

Try using a staged, fancy travis config. #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 28, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool
.packages
.pub
pubspec.lock
56 changes: 52 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
language: dart
sudo: false
dart:
- dev
script: ./tool/travis.sh

# Gives more resources on Travis (8GB Ram, 2 CPUs).
# Do not remove without verifying w/ Travis.
sudo: required
Copy link
Member

Choose a reason for hiding this comment

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

We should update mono_repo to handle "normal" repos – just to support generating this config.

I chatted w/ @natebosch about this yesterday
CC @alorenzen

addons:
chrome: stable

# Build stages: https://docs.travis-ci.com/user/build-stages/.
stages:
- presubmit
- build
- testing

# 1. Run dartfmt, dartanalyzer, pub run test (VM).
# 2. Then run a build.
# 3. Then run tests compiled via dartdevc and dart2js.
jobs:
include:
- stage: presubmit
script: ./tool/travis.sh dartfmt
dart: dev
- stage: presubmit
script: ./tool/travis.sh dartanalyzer
dart: dev
- stage: presubmit
script: ./tool/travis.sh vm_test
dart: dev
- stage: build
script: ./tool/travis.sh dartdevc_build
dart: dev
- stage: testing
script: ./tool/travis.sh dartdevc_test
dart: dev
- stage: testing
script: ./tool/travis.sh dart2js_test
dart: dev

# Only building master means that we don't run two builds for each pull request.
branches:
only: [master]

# Incremental pub cache and builds.
cache:
directories:
- $HOME/.pub-cache
- .dart_tool

# Necessary for Chrome and Firefox to run
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- "t=0; until (xdpyinfo -display :99 &> /dev/null || test $t -gt 10); do sleep 1; let t=$t+1; done"
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* `thenReturn` now throws an `ArgumentError` if either a `Future` or `Stream`
is provided. `thenReturn` calls with futures and streams should be changed to
`thenAnswer`. See the README for more information.
* Completely remove the mirrors implementation of Mockito (`mirrors.dart`).
* `thenReturn` and `thenAnswer` now support generics and infer the correct
types from the `when` call.

* Completely remove the mirrors implementation of Mockito (`mirrors.dart`).

## 2.2.0

Expand Down
5 changes: 5 additions & 0 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TODO(https://github.com/dart-lang/test/issues/772): Headless chrome timeout.
override_platforms:
chrome:
settings:
headless: false
18 changes: 8 additions & 10 deletions lib/src/mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void clearInteractions(var mock) {
}

class PostExpectation<T> {
T thenReturn(T expected) {
void thenReturn(T expected) {
if (expected is Future) {
throw new ArgumentError(
'`thenReturn` should not be used to return a Future. '
Expand All @@ -311,22 +311,20 @@ class PostExpectation<T> {
return _completeWhen((_) => expected);
}

thenThrow(throwable) {
void thenThrow(throwable) {
return _completeWhen((_) {
throw throwable;
});
}

T thenAnswer(Answering<T> answer) {
void thenAnswer(Answering<T> answer) {
return _completeWhen(answer);
}

_completeWhen(Answering answer) {
void _completeWhen(Answering answer) {
_whenCall._setExpected(answer);
var mock = _whenCall.mock;
_whenCall = null;
_whenInProgress = false;
return mock;
}
}

Expand Down Expand Up @@ -563,18 +561,18 @@ class ArgMatcher {
}

/// An argument matcher that matches any argument passed in "this" position.
get any => new ArgMatcher(anything, false);
/*ArgMatcher*/ get any => new ArgMatcher(anything, false);

/// An argument matcher that matches any argument passed in "this" position, and
/// captures the argument for later access with `captured`.
get captureAny => new ArgMatcher(anything, true);
/*ArgMatcher*/ get captureAny => new ArgMatcher(anything, true);

/// An argument matcher that matches an argument that matches [matcher].
argThat(Matcher matcher) => new ArgMatcher(matcher, false);
/*ArgMatcher*/ argThat(Matcher matcher) => new ArgMatcher(matcher, false);

/// An argument matcher that matches an argument that matches [matcher], and
/// captures the argument for later access with `captured`.
captureThat(Matcher matcher) => new ArgMatcher(matcher, true);
/*ArgMatcher*/ captureThat(Matcher matcher) => new ArgMatcher(matcher, true);

/// A Strong-mode safe argument matcher that wraps other argument matchers.
/// See the README for a full explanation.
Expand Down
6 changes: 6 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ description: A mock framework inspired by Mockito.
homepage: https://github.com/dart-lang/mockito
environment:
sdk: '>=2.0.0-dev.16.0 <2.0.0'

dependencies:
collection: '^1.1.0'
matcher: '^0.12.0'
meta: '^1.0.4'
test: '>=0.12.0 <0.13.0'

dev_dependencies:
build_runner: ^0.7.11
build_test: ^0.10.0
build_web_compilers: ^0.3.1
45 changes: 30 additions & 15 deletions test/invocation_matcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ void main() {

group('$isInvocation', () {
test('positional arguments', () {
var call1 = stub.say('Hello');
var call2 = stub.say('Hello');
var call3 = stub.say('Guten Tag');
stub.say('Hello');
var call1 = Stub.lastInvocation;
stub.say('Hello');
var call2 = Stub.lastInvocation;
stub.say('Guten Tag');
var call3 = Stub.lastInvocation;
shouldPass(call1, isInvocation(call2));
shouldFail(
call1,
Expand All @@ -36,9 +39,12 @@ void main() {
});

test('named arguments', () {
var call1 = stub.eat('Chicken', alsoDrink: true);
var call2 = stub.eat('Chicken', alsoDrink: true);
var call3 = stub.eat('Chicken', alsoDrink: false);
stub.eat('Chicken', alsoDrink: true);
var call1 = Stub.lastInvocation;
stub.eat('Chicken', alsoDrink: true);
var call2 = Stub.lastInvocation;
stub.eat('Chicken', alsoDrink: false);
var call3 = Stub.lastInvocation;
shouldPass(call1, isInvocation(call2));
shouldFail(
call1,
Expand All @@ -50,9 +56,12 @@ void main() {
});

test('optional arguments', () {
var call1 = stub.lie(true);
var call2 = stub.lie(true);
var call3 = stub.lie(false);
stub.lie(true);
var call1 = Stub.lastInvocation;
stub.lie(true);
var call2 = Stub.lastInvocation;
stub.lie(false);
var call3 = Stub.lastInvocation;
shouldPass(call1, isInvocation(call2));
shouldFail(
call1,
Expand All @@ -64,11 +73,13 @@ void main() {
});

test('getter', () {
var call1 = stub.value;
var call2 = stub.value;
stub.value;
var call1 = Stub.lastInvocation;
stub.value;
var call2 = Stub.lastInvocation;
stub.value = true;
var call3 = Stub.lastInvocation;
shouldPass(call1, isInvocation(call2 as Invocation));
shouldPass(call1, isInvocation(call2));
shouldFail(
call1,
isInvocation(call3),
Expand Down Expand Up @@ -98,7 +109,8 @@ void main() {

group('$invokes', () {
test('positional arguments', () {
var call = stub.say('Hello');
stub.say('Hello');
var call = Stub.lastInvocation;
shouldPass(call, invokes(#say, positionalArguments: ['Hello']));
shouldPass(call, invokes(#say, positionalArguments: [anything]));
shouldFail(
Expand All @@ -111,7 +123,8 @@ void main() {
});

test('named arguments', () {
var call = stub.fly(miles: 10);
stub.fly(miles: 10);
var call = Stub.lastInvocation;
shouldPass(call, invokes(#fly, namedArguments: {#miles: 10}));
shouldPass(call, invokes(#fly, namedArguments: {#miles: greaterThan(5)}));
shouldFail(
Expand Down Expand Up @@ -143,7 +156,9 @@ class Stub implements Interface {
const Stub();

@override
noSuchMethod(Invocation invocation) => lastInvocation = invocation;
noSuchMethod(Invocation invocation) {
lastInvocation = invocation;
}
}

// Copied from package:test, which doesn't expose it to users.
Expand Down
Loading