Updates (#27)
* Add analysis options, fix some lints
* Update travis to tasks
* requires at least SDK 1.20.x
* dartfmt
* remove unneeded import
diff --git a/.travis.yml b/.travis.yml
index b35c9f6..dfee504 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,26 @@
language: dart
-
-script: ./tool/travis.sh
-
-# Speed up builds by using containerization. Disable this if you need to use
-# sudo in your scripts.
sudo: false
+dart:
+ - stable
+ - dev
+ - 1.20.1
+dart_task:
+ - test: -p vm
+ xvfb: false
+ - test: -p firefox
+ - test: -p dartium
+ install_dartium: true
+ - dartanalyzer
+matrix:
+ include:
+ - dart: stable
+ dart_task: dartfmt
+
+# Only building master means that we don't run two builds for each pull request.
branches:
- only:
- - master
+ only: [master]
cache:
directories:
- - $HOME/.pub-cache
+ - $HOME/.pub-cache
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..a10d4c5
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,2 @@
+analyzer:
+ strong-mode: true
diff --git a/lib/src/package_loader.dart b/lib/src/package_loader.dart
index e8c153e..2e39d8c 100644
--- a/lib/src/package_loader.dart
+++ b/lib/src/package_loader.dart
@@ -5,8 +5,8 @@
import "dart:async" show Future, Stream;
import "dart:convert" show Encoding;
-import "resource_loader.dart";
import "resolve.dart";
+import "resource_loader.dart";
/// Implementation of [ResourceLoader] that accepts relative and package: URIs.
///
@@ -26,6 +26,6 @@
Future<List<int>> readAsBytes(Uri uri) async =>
_loader.readAsBytes(await resolveUri(uri));
- Future<String> readAsString(Uri uri, { Encoding encoding }) async =>
+ Future<String> readAsString(Uri uri, {Encoding encoding}) async =>
_loader.readAsString(await resolveUri(uri), encoding: encoding);
}
diff --git a/lib/src/resource.dart b/lib/src/resource.dart
index c13c2ea..d5c4208 100644
--- a/lib/src/resource.dart
+++ b/lib/src/resource.dart
@@ -5,8 +5,8 @@
import "dart:async" show Future, Stream;
import "dart:convert" show Encoding;
-import "resource_loader.dart";
import "resolve.dart";
+import "resource_loader.dart";
/// Base resource implementation.
class Resource {
@@ -43,7 +43,8 @@
/// as many of `http`, `https`, `file` and `data` as are available on the
/// current platform.
const Resource(uri, {ResourceLoader loader})
- : _uri = uri, _loader = loader ?? const DefaultLoader();
+ : _uri = uri,
+ _loader = loader ?? const DefaultLoader();
/// The location URI of this resource.
///
diff --git a/lib/src/resource_loader.dart b/lib/src/resource_loader.dart
index cdc8e77..3f282e8 100644
--- a/lib/src/resource_loader.dart
+++ b/lib/src/resource_loader.dart
@@ -4,11 +4,11 @@
import "dart:async" show Future, Stream;
import "dart:convert" show Encoding;
-import "package_loader.dart";
+
import "io_none.dart"
if (dart.library.html) "io_html.dart"
- if (dart.library.io) "io_io.dart"
- as io;
+ if (dart.library.io) "io_io.dart" as io;
+import "package_loader.dart";
/// Resource loading strategy.
///
@@ -68,4 +68,3 @@
Future<String> readAsString(Uri uri, {Encoding encoding}) =>
io.readAsString(uri, encoding);
}
-
diff --git a/test/loader_data_test.dart b/test/loader_data_test.dart
index e73efb7..fe767e7 100644
--- a/test/loader_data_test.dart
+++ b/test/loader_data_test.dart
@@ -16,9 +16,8 @@
group("${encoding.name}${base64 ? " base64" : ""}", () {
var uri;
setUp(() {
- var dataUri = new UriData.fromString(content,
- encoding: encoding,
- base64: base64);
+ var dataUri =
+ new UriData.fromString(content, encoding: encoding, base64: base64);
uri = dataUri.uri;
});
@@ -43,6 +42,7 @@
});
});
}
+
testFile(LATIN1, true);
testFile(LATIN1, false);
testFile(UTF8, true);
diff --git a/test/loader_file_test.dart b/test/loader_file_test.dart
index e13c1c1..54a42d7 100644
--- a/test/loader_file_test.dart
+++ b/test/loader_file_test.dart
@@ -54,6 +54,7 @@
});
});
}
+
testFile(LATIN1);
testFile(UTF8);
diff --git a/test/resource_test.dart b/test/resource_test.dart
index 608943a..d1102a1 100644
--- a/test/resource_test.dart
+++ b/test/resource_test.dart
@@ -4,10 +4,9 @@
@TestOn("vm")
-import 'dart:core' hide Resource;
import "dart:async" show Future, Stream;
-import "dart:isolate" show Isolate;
import "dart:convert" show Encoding, ASCII;
+import "dart:isolate" show Isolate;
import "package:resource/resource.dart";
import "package:test/test.dart";
@@ -27,15 +26,19 @@
var resource = new Resource(uri, loader: loader);
var res = await resource.openRead().toList();
var resolved = await resolve(uri);
- expect(res, [[0, 0, 0]]);
- res = await resource.readAsBytes();
- expect(res, [0, 0, 0]);
- res = await resource.readAsString(encoding: ASCII);
- expect(res, "\x00\x00\x00");
+ expect(res, [
+ [0, 0, 0]
+ ]);
+ var res1 = await resource.readAsBytes();
+ expect(res1, [0, 0, 0]);
+ var res2 = await resource.readAsString(encoding: ASCII);
+ expect(res2, "\x00\x00\x00");
- expect(loader.requests, [["Stream", resolved],
- ["Bytes", resolved],
- ["String", resolved, ASCII]]);
+ expect(loader.requests, [
+ ["Stream", resolved],
+ ["Bytes", resolved],
+ ["String", resolved, ASCII]
+ ]);
}
test("load package: URIs", () async {
@@ -52,18 +55,22 @@
});
}
-
class LogLoader implements ResourceLoader {
final List requests = [];
- void reset() { requests.clear(); }
+ void reset() {
+ requests.clear();
+ }
+
Stream<List<int>> openRead(Uri uri) async* {
requests.add(["Stream", uri]);
yield [0x00, 0x00, 0x00];
}
+
Future<List<int>> readAsBytes(Uri uri) async {
requests.add(["Bytes", uri]);
return [0x00, 0x00, 0x00];
}
+
Future<String> readAsString(Uri uri, {Encoding encoding}) async {
requests.add(["String", uri, encoding]);
return "\x00\x00\x00";
diff --git a/tool/travis.sh b/tool/travis.sh
deleted file mode 100755
index 5afae3c..0000000
--- a/tool/travis.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-# for details. All rights reserved. Use of this source code is governed by a
-# BSD-style license that can be found in the LICENSE file.
-
-# Fast fail the script on failures.
-set -e
-
-# Verify that the libraries are error free.
-dartanalyzer --fatal-warnings \
- lib/sample.dart \
- test/all_test.dart
-
-# Run the tests.
-pub run test