Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: examples/dart/hello_world/hello/test/hello_test.dart

Issue 1571823002: Dart: Adds tests of a couple Dart examples. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Restore analyze-dart Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/dart/hello_world/hello/pubspec.yaml ('k') | examples/dart/wget/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:io';
8
9 import "package:args/args.dart";
10 import "package:path/path.dart" as path;
11 import "package:test/test.dart";
12
13 void main(List<String> args) {
14 final ArgParser parser = new ArgParser();
15 parser.addOption('mojo-shell',
16 help: 'Path to the Mojo shell.');
17 final ArgResults results = parser.parse(args);
18 final String shellPath = results['mojo-shell'];
19 final List<String> devtoolsFlags = results.rest;
20
21 test("Hello, .mojo!", () async {
22 final String mojoUrl = 'http://core.mojoapps.io/dart_hello.mojo';
23 final List<String> args = new List.from(devtoolsFlags)..add(mojoUrl);
24 final ProcessResult result = await Process.run(shellPath, args);
25 expect(result.exitCode, equals(0));
26 expect(result.stdout.contains('Hello'), isTrue);
27 expect(result.stdout.contains('World'), isTrue);
28 });
29
30 test("Hello, .dart!", () async {
31 final HttpServer server = await HttpServer.bind('127.0.0.1', 0);
32 final String scriptOrigin = path.normalize(
33 path.join(path.dirname(Platform.script.path), '..', '..'));
34 final String packageOrigin = path.normalize(
35 path.join(path.fromUri(Platform.packageRoot), '..'));
36
37 server.listen((HttpRequest request) async {
38 final String requestPath = request.uri.toFilePath();
39
40 String origin;
41 if (requestPath.startsWith('/packages')) {
42 origin = packageOrigin;
43 } else {
44 origin = scriptOrigin;
45 }
46
47 final String filePath =
48 path.join(origin, path.relative(requestPath, from: '/'));;
49 final File file = new File(filePath);
50 if (await file.exists()) {
51 try {
52 await file.openRead().pipe(request.response);
53 } catch (e) {
54 print(e);
55 }
56 } else {
57 request.response.statusCode = HttpStatus.NOT_FOUND;
58 request.response.close();
59 }
60 });
61
62 final String dartUrl =
63 'http://127.0.0.1:${server.port}/hello/lib/main.dart';
64
65 final List<String> args = new List.from(devtoolsFlags)..add(dartUrl);
66 final ProcessResult result = await Process.run(shellPath, args);
67 expect(result.exitCode, equals(0));
68 expect(result.stdout.contains('Hello'), isTrue);
69 expect(result.stdout.contains('World'), isTrue);
70 server.close();
71 });
72 }
OLDNEW
« no previous file with comments | « examples/dart/hello_world/hello/pubspec.yaml ('k') | examples/dart/wget/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698