Skip to content

Commit

Permalink
dart-lang#2303. Add more File.create() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Oct 24, 2023
1 parent 5d40729 commit ff1bcae
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 41 deletions.
23 changes: 16 additions & 7 deletions LibTest/io/File/create_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
// 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.

/// @assertion Future<File> create({bool recursive: false})
/// Create the file. Returns a Future<File> that completes with the file when it
/// has been created.
/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in the path exist. If recursive is true, all non-existing path
/// components are created.
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// Existing files are left untouched by create. Calling create on an existing
/// file might fail if there are restrictive permissions on the file.
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
///
/// @description Checks that this method creates the file
/// @author sgrekhov@unipro.ru
Expand Down
27 changes: 18 additions & 9 deletions LibTest/io/File/create_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@
// 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.

/// @assertion Future<File> create({bool recursive: false})
/// Create the file. Returns a Future<File> that completes with the file when it
/// has been created.
/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in the path exist. If recursive is true, all non-existing path
/// components are created.
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// Existing files are left untouched by create. Calling create on an existing
/// file might fail if there are restrictive permissions on the file.
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
/// @description Checks that if recursive is false and there are non-existing
/// path components, then operation fails
///
/// @description Checks that if `recursive` is `false` and there are
/// non-existing path components, then operation fails
/// @author sgrekhov@unipro.ru
import "dart:io";
Expand Down
25 changes: 17 additions & 8 deletions LibTest/io/File/create_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
// 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.

/// @assertion Future<File> create({bool recursive: false})
/// Create the file. Returns a Future<File> that completes with the file when it
/// has been created.
/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in the path exist. If recursive is true, all non-existing path
/// components are created.
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// Existing files are left untouched by create. Calling create on an existing
/// file might fail if there are restrictive permissions on the file.
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
/// @description Checks that if recursive is true, all non-existing path
///
/// @description Checks that if `recursive` is `true`, all non-existing path
/// components are created
/// @author sgrekhov@unipro.ru
Expand Down
26 changes: 18 additions & 8 deletions LibTest/io/File/create_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
// 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.

/// @assertion Future<File> create({bool recursive: false})
/// Create the file. Returns a Future<File> that completes with the file when it
/// has been created.
/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in the path exist. If recursive is true, all non-existing path
/// components are created.
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// Existing files are left untouched by create. Calling create on an existing
/// file might fail if there are restrictive permissions on the file.
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
/// @description Checks that existing files are left untouched by create
///
/// @description Checks that if `exclusive` is `false`, existing files are left
/// untouched by create. Test the case when `recursive` is `false`
/// @author sgrekhov@unipro.ru
import "dart:io";
Expand Down
49 changes: 49 additions & 0 deletions LibTest/io/File/create_A03_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2023, 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.

/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
///
/// @description Checks that if `exclusive` is `false`, existing files are left
/// untouched by create. Test the case when `recursive` is `true`
/// @author sgrekhov22@gmail.com
import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() async {
await inSandbox(_main);
}

_main(Directory sandbox) async {
File tmp = getTempFileSync(parent: sandbox);
tmp.writeAsStringSync("Existing file content");
File file = new File(tmp.path);
asyncStart();
await file.create(recursive: true).then((File created) {
Expect.isTrue(created.existsSync());
Expect.equals(tmp.path, created.path);
Expect.equals("Existing file content", created.readAsStringSync());
asyncEnd();
});
}
50 changes: 50 additions & 0 deletions LibTest/io/File/create_A03_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2023, 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.

/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
///
/// @description Checks that if `exclusive` is `true` and to-be-created file
/// already exists, this operation completes the future with a
/// [PathExistsException]. Test the case when `recursive` is `false`
/// @author sgrekhov22@gmail.com
import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() async {
await inSandbox(_main);
}

_main(Directory sandbox) async {
File tmp = getTempFileSync(parent: sandbox);
tmp.writeAsStringSync("Existing file content");
File file = new File(tmp.path);
asyncStart();
await file.create(exclusive: true).then((File created) {
Expect.fail("PathExistsException is expected");
}, onError: (e) {
Expect.isTrue(e is PathExistsException);
asyncEnd();
});
}
50 changes: 50 additions & 0 deletions LibTest/io/File/create_A03_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2023, 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.

/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
///
/// @description Checks that if `exclusive` is `true` and to-be-created file
/// already exists, this operation completes the future with a
/// [PathExistsException]. Test the case when `recursive` is `true`
/// @author sgrekhov22@gmail.com
import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() async {
await inSandbox(_main);
}

_main(Directory sandbox) async {
File tmp = getTempFileSync(parent: sandbox);
tmp.writeAsStringSync("Existing file content");
File file = new File(tmp.path);
asyncStart();
await file.create(exclusive: true, recursive: true).then((File created) {
Expect.fail("PathExistsException is expected");
}, onError: (e) {
Expect.isTrue(e is PathExistsException);
asyncEnd();
});
}
28 changes: 19 additions & 9 deletions LibTest/io/File/create_A04_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
// 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.

/// @assertion Future<File> create({bool recursive: false})
/// Create the file. Returns a Future<File> that completes with the file when it
/// has been created.
/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in the path exist. If recursive is true, all non-existing path
/// components are created.
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// Existing files are left untouched by create. Calling create on an existing
/// file might fail if there are restrictive permissions on the file.
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
/// @description Checks that future is completed with a FileSystemException if
/// the operation fails
///
/// @description Checks that future is completed with a `FileSystemException` if
/// the operation fails. Test the case when there is an existing directory with
/// the same path, `recursive` is `false` and `exclusive` is `false`
/// @author sgrekhov@unipro.ru
import "dart:io";
Expand Down
49 changes: 49 additions & 0 deletions LibTest/io/File/create_A04_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2023, 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.

/// @assertion Future<File> create(
/// {bool recursive = false,
/// bool exclusive = false}
/// )
/// Creates the file.
///
/// Returns a Future<File> that completes with the file when it has been created
///
/// If recursive is false, the default, the file is created only if all
/// directories in its path already exist. If recursive is true, any
/// non-existing parent paths are created first.
///
/// If exclusive is true and to-be-created file already exists, this operation
/// completes the future with a PathExistsException.
///
/// If exclusive is false, existing files are left untouched by create. Calling
/// create on an existing file still might fail if there are restrictive
/// permissions on the file.
///
/// Completes the future with a FileSystemException if the operation fails.
///
/// @description Checks that future is completed with a `FileSystemException` if
/// the operation fails. Test the case when there is an existing directory with
/// the same path, `recursive` is `true` and `exclusive` is `false`
/// @author sgrekhov22@gmail.com
import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() async {
await inSandbox(_main);
}

_main(Directory sandbox) async {
Directory dir = getTempDirectorySync(parent: sandbox);
File file = new File(dir.path);
asyncStart();
await file.create(recursive: true).then((File created) {
Expect.fail("FileSystemException is expected");
}, onError: (e) {
Expect.isTrue(e is FileSystemException);
asyncEnd();
});
}

0 comments on commit ff1bcae

Please sign in to comment.