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

Side by Side Diff: tests/standalone/io/file_test.dart

Issue 899243002: Make standalone tests not dependent on current working directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove stray blank line Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // Dart test program for testing file I/O. 5 // Dart test program for testing file I/O.
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:collection'; 9 import 'dart:collection';
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 Expect.equals(bytes.length, 0); 962 Expect.equals(bytes.length, 0);
963 } 963 }
964 964
965 static void testReadAsText() { 965 static void testReadAsText() {
966 asyncTestStarted(); 966 asyncTestStarted();
967 var name = getFilename("tests/vm/data/fixed_length_file"); 967 var name = getFilename("tests/vm/data/fixed_length_file");
968 var f = new File(name); 968 var f = new File(name);
969 f.readAsString(encoding: UTF8).then((text) { 969 f.readAsString(encoding: UTF8).then((text) {
970 Expect.isTrue(text.endsWith("42 bytes.")); 970 Expect.isTrue(text.endsWith("42 bytes."));
971 Expect.equals(42, text.length); 971 Expect.equals(42, text.length);
972 var name = getDataFilename("tests/standalone/io/read_as_text.dat"); 972 var name = getFilename("tests/standalone/io/read_as_text.dat");
973 var f = new File(name); 973 var f = new File(name);
974 f.readAsString(encoding: UTF8).then((text) { 974 f.readAsString(encoding: UTF8).then((text) {
975 Expect.equals(6, text.length); 975 Expect.equals(6, text.length);
976 var expected = [955, 120, 46, 32, 120, 10]; 976 var expected = [955, 120, 46, 32, 120, 10];
977 Expect.listEquals(expected, text.codeUnits); 977 Expect.listEquals(expected, text.codeUnits);
978 f.readAsString(encoding: LATIN1).then((text) { 978 f.readAsString(encoding: LATIN1).then((text) {
979 Expect.equals(7, text.length); 979 Expect.equals(7, text.length);
980 var expected = [206, 187, 120, 46, 32, 120, 10]; 980 var expected = [206, 187, 120, 46, 32, 120, 10];
981 Expect.listEquals(expected, text.codeUnits); 981 Expect.listEquals(expected, text.codeUnits);
982 var readAsStringFuture = f.readAsString(encoding: ASCII); 982 var readAsStringFuture = f.readAsString(encoding: ASCII);
(...skipping 16 matching lines...) Expand all
999 asyncTestDone("testReadAsTextEmptyFile"); 999 asyncTestDone("testReadAsTextEmptyFile");
1000 return true; 1000 return true;
1001 }); 1001 });
1002 } 1002 }
1003 1003
1004 static void testReadAsTextSync() { 1004 static void testReadAsTextSync() {
1005 var name = getFilename("tests/vm/data/fixed_length_file"); 1005 var name = getFilename("tests/vm/data/fixed_length_file");
1006 var text = new File(name).readAsStringSync(); 1006 var text = new File(name).readAsStringSync();
1007 Expect.isTrue(text.endsWith("42 bytes.")); 1007 Expect.isTrue(text.endsWith("42 bytes."));
1008 Expect.equals(42, text.length); 1008 Expect.equals(42, text.length);
1009 name = getDataFilename("tests/standalone/io/read_as_text.dat"); 1009 name = getFilename("tests/standalone/io/read_as_text.dat");
1010 text = new File(name).readAsStringSync(); 1010 text = new File(name).readAsStringSync();
1011 Expect.equals(6, text.length); 1011 Expect.equals(6, text.length);
1012 var expected = [955, 120, 46, 32, 120, 10]; 1012 var expected = [955, 120, 46, 32, 120, 10];
1013 Expect.listEquals(expected, text.codeUnits); 1013 Expect.listEquals(expected, text.codeUnits);
1014 // First character is not ASCII. The default ASCII decoder will throw. 1014 // First character is not ASCII. The default ASCII decoder will throw.
1015 Expect.throws(() => new File(name).readAsStringSync(encoding: ASCII), 1015 Expect.throws(() => new File(name).readAsStringSync(encoding: ASCII),
1016 (e) => e is FileSystemException); 1016 (e) => e is FileSystemException);
1017 // We can use an ASCII decoder that inserts the replacement character. 1017 // We can use an ASCII decoder that inserts the replacement character.
1018 var lenientAscii = const AsciiCodec(allowInvalid: true); 1018 var lenientAscii = const AsciiCodec(allowInvalid: true);
1019 text = new File(name).readAsStringSync(encoding: lenientAscii); 1019 text = new File(name).readAsStringSync(encoding: lenientAscii);
(...skipping 27 matching lines...) Expand all
1047 }); 1047 });
1048 } 1048 }
1049 1049
1050 static void testReadAsLinesSync() { 1050 static void testReadAsLinesSync() {
1051 var name = getFilename("tests/vm/data/fixed_length_file"); 1051 var name = getFilename("tests/vm/data/fixed_length_file");
1052 var lines = new File(name).readAsLinesSync(); 1052 var lines = new File(name).readAsLinesSync();
1053 Expect.equals(1, lines.length); 1053 Expect.equals(1, lines.length);
1054 var line = lines[0]; 1054 var line = lines[0];
1055 Expect.isTrue(line.endsWith("42 bytes.")); 1055 Expect.isTrue(line.endsWith("42 bytes."));
1056 Expect.equals(42, line.length); 1056 Expect.equals(42, line.length);
1057 name = getDataFilename("tests/standalone/io/readline_test1.dat"); 1057 name = getFilename("tests/standalone/io/readline_test1.dat");
1058 lines = new File(name).readAsLinesSync(); 1058 lines = new File(name).readAsLinesSync();
1059 Expect.equals(10, lines.length); 1059 Expect.equals(10, lines.length);
1060 } 1060 }
1061 1061
1062 1062
1063 static void testReadAsErrors() { 1063 static void testReadAsErrors() {
1064 asyncTestStarted(); 1064 asyncTestStarted();
1065 var f = new File('.'); 1065 var f = new File('.');
1066 Expect.throws(f.readAsBytesSync, (e) => e is FileSystemException); 1066 Expect.throws(f.readAsBytesSync, (e) => e is FileSystemException);
1067 Expect.throws(f.readAsStringSync, (e) => e is FileSystemException); 1067 Expect.throws(f.readAsStringSync, (e) => e is FileSystemException);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 if (Platform.operatingSystem != "windows") { 1267 if (Platform.operatingSystem != "windows") {
1268 var brokenLink = new Link(source); 1268 var brokenLink = new Link(source);
1269 brokenLink.createSync(dest); 1269 brokenLink.createSync(dest);
1270 Expect.throws(() => file.renameSync('xxx')); 1270 Expect.throws(() => file.renameSync('xxx'));
1271 brokenLink.deleteSync(); 1271 brokenLink.deleteSync();
1272 } 1272 }
1273 } 1273 }
1274 1274
1275 // Helper method to be able to run the test from the runtime 1275 // Helper method to be able to run the test from the runtime
1276 // directory, or the top directory. 1276 // directory, or the top directory.
1277 static String getFilename(String path) => 1277 static String getFilename(String path) {
1278 new File(path).existsSync() ? path : 'runtime/$path'; 1278 var testPath = Platform.script.resolve('../../../$path');
1279 1279 return new File.fromUri(testPath).existsSync()
1280 static String getDataFilename(String path) => 1280 ? testPath.toFilePath()
1281 new File(path).existsSync() ? path : '../$path'; 1281 : Platform.script.resolve('../../../runtime/$path').toFilePath();
1282 }
1282 1283
1283 // Main test entrypoint. 1284 // Main test entrypoint.
1284 static testMain() { 1285 static testMain() {
1285 asyncStart(); 1286 asyncStart();
1286 1287
1287 testRead(); 1288 testRead();
1288 testReadSync(); 1289 testReadSync();
1289 testReadStream(); 1290 testReadStream();
1290 testLengthSync(); 1291 testLengthSync();
1291 testPositionSync(); 1292 testPositionSync();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 testLastModified(); 1337 testLastModified();
1337 testDoubleAsyncOperation(); 1338 testDoubleAsyncOperation();
1338 asyncEnd(); 1339 asyncEnd();
1339 }); 1340 });
1340 } 1341 }
1341 } 1342 }
1342 1343
1343 main() { 1344 main() {
1344 FileTest.testMain(); 1345 FileTest.testMain();
1345 } 1346 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_invalid_arguments_test.dart ('k') | tests/standalone/io/platform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698