forked from google/inject.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add train example, travis, easier testing. (google#6)
- Loading branch information
1 parent
ea7fb98
commit 946914f
Showing
19 changed files
with
289 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
language: dart | ||
|
||
# We currently are building against the Dart2 SDK. | ||
dart: | ||
- dev | ||
|
||
# Gives more resources on Travis (8GB Ram, 2CPUs). | ||
# Do not remove without verifying w/ Travis. | ||
sudo: required | ||
|
||
# Only building master means that we don't run two builds for each pull request. | ||
branches: | ||
only: [master] | ||
|
||
# Re-use downloaded pub packages everywhere. | ||
cache: | ||
directories: | ||
- $HOME/.pub-cache | ||
|
||
# Build stages: https://docs.travis-ci.com/user/build-stages/. | ||
stages: | ||
- presubmit | ||
- building | ||
- testing | ||
|
||
jobs: | ||
- stage: presubmit | ||
script: ./tool/travis.sh analyze | ||
env: PKG="example/coffee" | ||
- stage: presubmit | ||
script: ./tool/travis.sh analyze | ||
env: PKG="example/train" | ||
- stage: presubmit | ||
script: ./tool/travis.sh analyze | ||
env: PKG="package/inject" | ||
- stage: presubmit | ||
script: ./tool/travis.sh analyze | ||
env: PKG="package/inject_generator" | ||
|
||
# TODO: Add build, test phases. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# TODO(https://github.com/dart-lang/test/issues/772): Headless chrome timeout. | ||
presets: | ||
travis: | ||
override_platforms: | ||
chrome: | ||
settings: | ||
headless: false | ||
|
||
platforms: | ||
- chrome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Sample app with independently developed sub-libraries | ||
|
||
A common question we receive is how to structure an application that's developed | ||
by multiple independent teams. Typically, in such situation the application is | ||
broken up into several feature tracks, with each team owning one of them. One of | ||
the teams usually owns the infrastructure for the apps, which includes the main | ||
entrypoint that "stitches" the code from multiple feature tracks into the whole | ||
application. | ||
|
||
This example emulates a multi-team situation. It is modeled after a train with | ||
a locomotive and two cars - a bike car and a food car. Each of the pieces - | ||
locomotive, bike and food - are individual feature tracks, with locomotive being | ||
the entrypoint that connects the other features (cars) into an app (the train). | ||
There's a service that's shared by all cars - CarMaintenance. | ||
|
||
## To run the example | ||
|
||
> **NOTE**: Our CLI story is a work-in-progress as work continues on the build | ||
> system and testing package/infrastructure. For now this is a _workaround_. | ||
```bash | ||
$ pub run build_runner build -o build | ||
$ cd build | ||
$ dart bin/brew.dart | ||
``` | ||
|
||
## To run the tests | ||
|
||
> **NOTE**: Our test story is a work-in-progress as work continues on the build | ||
> system and testing package/infrastructure. For now this is a _workaround_. | ||
```bash | ||
$ pub run build_runner test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# TODO(https://github.com/dart-lang/test/issues/772): Headless chrome timeout. | ||
presets: | ||
travis: | ||
override_platforms: | ||
chrome: | ||
settings: | ||
headless: false | ||
|
||
platforms: | ||
- chrome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:inject/inject.dart'; | ||
|
||
import 'common.dart'; | ||
|
||
/// Provides the service locator to the bike car feature code. | ||
BikeServiceLocator bikeServices; | ||
|
||
/// Declares dependencies used by the bike car. | ||
abstract class BikeServiceLocator { | ||
@provide | ||
BikeRack get bikeRack; | ||
} | ||
|
||
/// Declares dependencies needed by the bike car. | ||
@module | ||
class BikeServices { | ||
/// Note the dependency on [CarMaintenance] which this module does not itself | ||
/// provide. This tells `package:inject` to look for it when this module is | ||
/// mixed into an injector. The compiler will _statically_ check that this | ||
/// dependency is satisfied, and issue a warning if it's not. | ||
@provide | ||
BikeRack bikeRack(CarMaintenance cm) => new BikeRack(cm); | ||
} | ||
|
||
class BikeRack { | ||
final CarMaintenance maintenance; | ||
|
||
BikeRack(this.maintenance); | ||
|
||
String pleaseFix() { | ||
return maintenance.pleaseFix(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:inject/inject.dart'; | ||
|
||
/// Provides common dependencies. | ||
@module | ||
class CommonServices { | ||
@provide | ||
CarMaintenance maintenance() => new CarMaintenance(); | ||
} | ||
|
||
/// Fixes train cars of all kinds. | ||
class CarMaintenance { | ||
String pleaseFix() => 'Sure thing!'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:inject/inject.dart'; | ||
|
||
import 'common.dart'; | ||
|
||
/// Provides service locator for food car feature code. | ||
FoodServiceLocator foodServices; | ||
|
||
/// Declares dependencies used by the food car. | ||
abstract class FoodServiceLocator { | ||
@provide | ||
Kitchen get kitchen; | ||
} | ||
|
||
/// Declares dependencies needed by the food car. | ||
@module | ||
class FoodServices { | ||
@provide | ||
Kitchen kitchen(CarMaintenance cm) => new Kitchen(cm); | ||
} | ||
|
||
class Kitchen { | ||
Kitchen(CarMaintenance cm); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:inject/inject.dart'; | ||
|
||
import 'bike.dart'; | ||
import 'common.dart'; | ||
import 'food.dart'; | ||
|
||
import 'locomotive.inject.dart' as g; | ||
|
||
/// The top level injector that stitches together multiple app features into | ||
/// a complete app. | ||
@Injector(const [BikeServices, FoodServices, CommonServices]) | ||
abstract class TrainServices implements BikeServiceLocator, FoodServiceLocator { | ||
static Future<TrainServices> create( | ||
BikeServices bikeModule, | ||
FoodServices foodModule, | ||
CommonServices commonModule, | ||
) async { | ||
var services = await g.TrainServices$Injector.create( | ||
bikeModule, | ||
foodModule, | ||
commonModule, | ||
); | ||
|
||
bikeServices = services; | ||
foodServices = services; | ||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'dart:async'; | ||
|
||
import 'bike.dart'; | ||
import 'common.dart'; | ||
import 'food.dart'; | ||
import 'locomotive.dart'; | ||
|
||
Future<Null> main() async { | ||
final services = await TrainServices.create( | ||
new BikeServices(), | ||
new FoodServices(), | ||
new CommonServices(), | ||
); | ||
print(services.bikeRack.pleaseFix()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: inject.example.train | ||
description: A more complex example of using package:inject | ||
|
||
dependencies: | ||
inject: | ||
path: ../../package/inject | ||
|
||
dev_dependencies: | ||
build_runner: ^0.8.0 | ||
build_test: ^0.10.1+1 | ||
build_web_compilers: ^0.3.4+2 | ||
inject_generator: | ||
path: ../../package/inject_generator | ||
test: ^0.12.32+1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:test/test.dart'; | ||
|
||
import 'package:inject.example.train/bike.dart'; | ||
import 'package:inject.example.train/common.dart'; | ||
import 'package:inject.example.train/food.dart'; | ||
import 'package:inject.example.train/locomotive.dart'; | ||
|
||
void main() { | ||
group('locomotive', () { | ||
test('can instantiate TrainServices', () async { | ||
final services = await TrainServices.create( | ||
new BikeServices(), | ||
new FoodServices(), | ||
new CommonServices(), | ||
); | ||
services.bikeRack; | ||
services.kitchen; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
if [ "$#" == "0" ]; then | ||
echo -e '\033[31mAt least one task argument must be provided!\033[0m' | ||
exit 1 | ||
fi | ||
|
||
EXIT_CODE=0 | ||
|
||
while (( "$#" )); do | ||
TASK=$1 | ||
case $TASK in | ||
dartfmt) echo | ||
echo -e '\033[1mTASK: dartfmt\033[22m' | ||
echo -e 'dartfmt -n --set-exit-if-changed .' | ||
dartfmt -n --set-exit-if-changed . || EXIT_CODE=$? | ||
;; | ||
analyze) echo | ||
echo -e '\033[1mTASK: dartanalyzer\033[22m' | ||
echo -e 'dartanalyzer --fatal-warnings .' | ||
dartanalyzer --fatal-warnings . || EXIT_CODE=$? | ||
;; | ||
dartdevc_build) echo | ||
echo -e '\033[1mTASK: build\033[22m' | ||
echo -e 'pub run build_runner build --fail-on-severe' | ||
pub run build_runner build --fail-on-severe || EXIT_CODE=$? | ||
;; | ||
dartdevc_test) echo | ||
echo -e '\033[1mTASK: dartdevc_test\033[22m' | ||
echo -e 'pub run build_runner test -- -P travis' | ||
pub run build_runner test -- -p chrome || EXIT_CODE=$? | ||
;; | ||
*) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m" | ||
EXIT_CODE=1 | ||
;; | ||
esac | ||
|
||
shift | ||
done | ||
|
||
exit $EXIT_CODE |