Adjust tests/standalone/io/file_test not to resolve relative to Platform.executable.
Fixes #27748
R=asiva@google.com
Review URL: https://codereview.chromium.org/2477903002 .
diff --git a/tests/standalone/io/empty_file b/tests/standalone/io/empty_file
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/standalone/io/empty_file
diff --git a/tests/standalone/io/file_test.dart b/tests/standalone/io/file_test.dart
index b987698..8a8d681 100644
--- a/tests/standalone/io/file_test.dart
+++ b/tests/standalone/io/file_test.dart
@@ -4,6 +4,8 @@
//
// Dart test program for testing file I/O.
+// OtherResources=empty_file
+// OtherResources=file_test.txt
// OtherResources=fixed_length_file
// OtherResources=read_as_text.dat
// OtherResources=readline_test1.dat
@@ -63,7 +65,7 @@
// Test for file read functionality.
static void testReadStream() {
// Read a file and check part of it's contents.
- String filename = getFilename("bin/file_test.cc");
+ String filename = getFilename("file_test.txt");
File file = new File(filename);
Expect.isTrue('$file'.contains(file.path));
var subscription;
@@ -230,7 +232,7 @@
static void testRead() {
asyncStart();
// Read a file and check part of it's contents.
- String filename = getFilename("bin/file_test.cc");
+ String filename = getFilename("file_test.txt");
File file = new File(filename);
file.open(mode: READ).then((RandomAccessFile file) {
List<int> buffer = new List<int>(10);
@@ -256,7 +258,7 @@
static void testReadSync() {
// Read a file and check part of it's contents.
- String filename = getFilename("bin/file_test.cc");
+ String filename = getFilename("file_test.txt");
RandomAccessFile raf = (new File(filename)).openSync();
List<int> buffer = new List<int>(42);
int bytes_read = 0;
@@ -1071,7 +1073,7 @@
static void testReadAsBytesEmptyFile() {
asyncTestStarted();
- var name = getFilename("tests/vm/data/empty_file");
+ var name = getFilename("empty_file");
var f = new File(name);
f.readAsBytes().then((bytes) {
Expect.equals(0, bytes.length);
@@ -1087,7 +1089,7 @@
}
static void testReadAsBytesSyncEmptyFile() {
- var name = getFilename("tests/vm/data/empty_file");
+ var name = getFilename("empty_file");
var bytes = new File(name).readAsBytesSync();
Expect.equals(bytes.length, 0);
}
@@ -1122,7 +1124,7 @@
static void testReadAsTextEmptyFile() {
asyncTestStarted();
- var name = getFilename("tests/vm/data/empty_file");
+ var name = getFilename("empty_file");
var f = new File(name);
f.readAsString(encoding: UTF8).then((text) {
Expect.equals(0, text.length);
@@ -1159,7 +1161,7 @@
}
static void testReadAsTextSyncEmptyFile() {
- var name = getFilename("tests/vm/data/empty_file");
+ var name = getFilename("empty_file");
var text = new File(name).readAsStringSync();
Expect.equals(0, text.length);
}
@@ -1402,15 +1404,8 @@
}
}
- // Helper method to be able to run the test from the runtime
- // directory, or the top directory.
static String getFilename(String path) {
- var testPath = Platform.script.resolve(path);
- if (new File.fromUri(testPath).existsSync()) {
- return testPath.toFilePath();
- }
- return Uri.parse(Platform.resolvedExecutable)
- .resolve('../../runtime/$path').toFilePath();
+ return Platform.script.resolve(path).toFilePath();
}
// Main test entrypoint.
diff --git a/tests/standalone/io/file_test.txt b/tests/standalone/io/file_test.txt
new file mode 100644
index 0000000..4c2c0d1
--- /dev/null
+++ b/tests/standalone/io/file_test.txt
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, 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.
+
+#include "bin/file.h"
+#include "platform/assert.h"
+#include "platform/globals.h"
+#include "vm/unit_test.h"
+
+namespace dart {
+namespace bin {
+
+// Helper method to be able to run the test from the runtime
+// directory, or the top directory.
+static const char* GetFileName(const char* name) {
+ if (File::Exists(name)) {
+ return name;
+ } else {
+ static const int kRuntimeLength = strlen("runtime/");
+ return name + kRuntimeLength;
+ }
+}
+
+
+TEST_CASE(Read) {
+ const char* kFilename = GetFileName("runtime/bin/file_test.cc");
+ File* file = File::Open(kFilename, File::kRead);
+ EXPECT(file != NULL);
+ char buffer[16];
+ buffer[0] = '\0';
+ EXPECT(file->ReadFully(buffer, 13)); // ReadFully returns true.
+ buffer[13] = '\0';
+ EXPECT_STREQ("// Copyright ", buffer);
+ EXPECT(!file->WriteByte(1)); // Cannot write to a read-only file.
+ file->Release();
+}
+
+
+TEST_CASE(FileLength) {
+ const char* kFilename =
+ GetFileName("runtime/tests/vm/data/fixed_length_file");
+ File* file = File::Open(kFilename, File::kRead);
+ EXPECT(file != NULL);
+ EXPECT_EQ(42, file->Length());
+ file->Release();
+}
+
+
+TEST_CASE(FilePosition) {
+ char buf[42];
+ const char* kFilename =
+ GetFileName("runtime/tests/vm/data/fixed_length_file");
+ File* file = File::Open(kFilename, File::kRead);
+ EXPECT(file != NULL);
+ EXPECT(file->ReadFully(buf, 12));
+ EXPECT_EQ(12, file->Position());
+ EXPECT(file->ReadFully(buf, 6));
+ EXPECT_EQ(18, file->Position());
+ file->Release();
+}
+
+} // namespace bin
+} // namespace dart
diff --git a/tests/standalone/standalone.status b/tests/standalone/standalone.status
index 1d8b9cd..c8a29f7 100644
--- a/tests/standalone/standalone.status
+++ b/tests/standalone/standalone.status
@@ -204,7 +204,6 @@
io/platform_resolved_executable_test/06: RuntimeError # Issue 23641
io/process_sync_test: Pass, Timeout # Issue 24596
io/sleep_test: Pass, Fail # Issue 25757
-io/file_test: RuntimeError # Issue 27748
[ ($runtime == vm || $runtime == dart_precompiled || $runtime == dart_app) && $mode == debug && $builder_tag == asan ]
full_coverage_test: Skip # Timeout.