-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more File.create() tests, check all possible parameters, add tests checking file behavior on links, add check if the link is deleted.
- Loading branch information
Showing
18 changed files
with
710 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,37 @@ | |
// 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 void createSync({bool recursive: false}) | ||
/// Synchronously create the file. Existing files are left untouched by | ||
/// createSync. Calling createSync on an existing file might fail if there are | ||
/// restrictive permissions on the file. | ||
/// @assertion void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// 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, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws a FileSystemException if the operation fails. | ||
/// | ||
/// @description Checks that this method creates the file | ||
/// @author [email protected] | ||
import "dart:io"; | ||
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() async { | ||
await inSandbox(_main); | ||
main() { | ||
inSandbox(_main); | ||
} | ||
|
||
_main(Directory sandbox) async { | ||
_main(Directory sandbox) { | ||
File file = new File(getTempFilePath(parent: sandbox)); | ||
file.createSync(); | ||
Expect.isTrue(file.existsSync()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,33 +2,47 @@ | |
// 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 void createSync({bool recursive: false}) | ||
/// Synchronously create the file. Existing files are left untouched by | ||
/// createSync. Calling createSync on an existing file might fail if there are | ||
/// restrictive permissions on the file. | ||
/// @assertion void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// 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, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws 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 [email protected] | ||
import "dart:io"; | ||
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() async { | ||
await inSandbox(_main); | ||
main() { | ||
inSandbox(_main); | ||
} | ||
|
||
_main(Directory sandbox) async { | ||
_test(Directory sandbox, {bool exclusive = false}) { | ||
String dirPath = getTempDirectoryPath(parent: sandbox); | ||
String filePath = dirPath + Platform.pathSeparator + getTempFileName(); | ||
File file = new File(filePath); | ||
Expect.throws(() { | ||
file.createSync(recursive: false); | ||
file.createSync(recursive: false, exclusive: exclusive); | ||
}, (e) => e is FileSystemException); | ||
} | ||
|
||
_main(Directory sandbox) { | ||
_test(sandbox, exclusive: false); | ||
_test(sandbox, exclusive: true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,25 @@ | |
// 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 void createSync({bool recursive: false}) | ||
/// Synchronously create the file. Existing files are left untouched by | ||
/// createSync. Calling createSync on an existing file might fail if there are | ||
/// restrictive permissions on the file. | ||
/// @assertion void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// 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, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws a FileSystemException if the operation fails. | ||
/// | ||
/// @description Checks that if recursive is true, all non-existing path | ||
/// components are created | ||
/// @author [email protected] | ||
|
@@ -20,15 +29,20 @@ import "dart:io"; | |
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() async { | ||
await inSandbox(_main); | ||
main() { | ||
inSandbox(_main); | ||
} | ||
|
||
_main(Directory sandbox) async { | ||
_test(Directory sandbox, {bool exclusive = false}) { | ||
String dirPath = getTempDirectoryPath(parent: sandbox); | ||
String filePath = dirPath + Platform.pathSeparator + getTempFileName(); | ||
File file = new File(filePath); | ||
file.createSync(recursive: true); | ||
file.createSync(recursive: true, exclusive: exclusive); | ||
Expect.isTrue(file.existsSync()); | ||
Expect.equals(filePath, file.path); | ||
} | ||
|
||
_main(Directory sandbox) { | ||
_test(sandbox, exclusive: false); | ||
_test(sandbox, exclusive: true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,34 +2,49 @@ | |
// 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 void createSync({bool recursive: false}) | ||
/// Synchronously create the file. Existing files are left untouched by | ||
/// createSync. Calling createSync on an existing file might fail if there are | ||
/// restrictive permissions on the file. | ||
/// @assertion void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// 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, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws a FileSystemException if the operation fails. | ||
/// @description Checks that existing files are left untouched by create | ||
/// | ||
/// @description Checks that if `exclusive` is `false` then existing files are | ||
/// left untouched by createSync | ||
/// @author [email protected] | ||
import "dart:io"; | ||
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() async { | ||
await inSandbox(_main); | ||
main() { | ||
inSandbox(_main); | ||
} | ||
|
||
_main(Directory sandbox) async { | ||
_test(Directory sandbox, {bool recursive = false}) async { | ||
File tmp = getTempFileSync(parent: sandbox); | ||
tmp.writeAsStringSync("Existing file content"); | ||
File file = new File(tmp.path); | ||
|
||
file.createSync(); | ||
file.createSync(recursive: recursive); | ||
Expect.isTrue(file.existsSync()); | ||
Expect.equals(tmp.path, file.path); | ||
Expect.equals("Existing file content", file.readAsStringSync()); | ||
} | ||
|
||
_main(Directory sandbox) { | ||
_test(sandbox, recursive: false); | ||
_test(sandbox, recursive: true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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 void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// If recursive is false, the default, the file is created only if all | ||
/// directories in its path already exist. If recursive is true, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws a FileSystemException if the operation fails. | ||
/// | ||
/// @description Checks that if `exclusive` is `true` and to-be-created file | ||
/// already exists, then a [PathExistsException] is thrown. | ||
/// @author [email protected] | ||
import "dart:io"; | ||
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() { | ||
inSandbox(_main); | ||
} | ||
|
||
_test(Directory sandbox, {bool recursive = false}) async { | ||
File tmp = getTempFileSync(parent: sandbox); | ||
File file = new File(tmp.path); | ||
Expect.throws(() { | ||
file.createSync(exclusive: true, recursive: recursive); | ||
}, (e) => e is PathExistsException); | ||
} | ||
|
||
_main(Directory sandbox) { | ||
_test(sandbox, recursive: false); | ||
_test(sandbox, recursive: true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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 void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// If recursive is false, the default, the file is created only if all | ||
/// directories in its path already exist. If recursive is true, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws a FileSystemException if the operation fails. | ||
/// | ||
/// @description Checks that if `exclusive` is `false`, existing files are left | ||
/// untouched by create. Test [Link] pointing to a file | ||
/// @author [email protected] | ||
import "dart:io"; | ||
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() async { | ||
await inSandbox(_main); | ||
} | ||
|
||
_test(Directory sandbox, {bool recursive = false}) { | ||
File target = getTempFileSync(parent: sandbox); | ||
target.writeAsStringSync("Target content"); | ||
Link link = getTempLinkSync(parent: sandbox, target: target.path); | ||
File file = File(link.path); | ||
file.createSync(recursive: recursive); | ||
Expect.isTrue(file.existsSync()); | ||
Expect.isTrue(target.existsSync()); | ||
Expect.equals(file.path, link.path); | ||
// Now check that all read/write operations are performed on link's target | ||
Expect.equals("Target content", file.readAsStringSync()); | ||
file.writeAsStringSync("Lily was here"); | ||
Expect.equals("Lily was here", target.readAsStringSync()); | ||
// Delete doesn't delete the target of the link but the link itself | ||
file.deleteSync(); | ||
Expect.isFalse(file.existsSync()); | ||
Expect.isTrue(target.existsSync()); | ||
Expect.isFalse(link.existsSync()); | ||
} | ||
|
||
_main(Directory sandbox) { | ||
_test(sandbox, recursive: false); | ||
_test(sandbox, recursive: true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 void createSync( | ||
/// {bool recursive = false, | ||
/// bool exclusive = false} | ||
/// ) | ||
/// Synchronously creates the file. | ||
/// | ||
/// If recursive is false, the default, the file is created only if all | ||
/// directories in its path already exist. If recursive is true, all | ||
/// non-existing parent paths are created first. | ||
/// | ||
/// If exclusive is true and to-be-created file already exists, a | ||
/// PathExistsException is thrown. | ||
/// | ||
/// If exclusive is false, existing files are left untouched by createSync. | ||
/// Calling createSync on an existing file still might fail if there are | ||
/// restrictive permissions on the file. | ||
/// | ||
/// Throws a FileSystemException if the operation fails. | ||
/// | ||
/// @description Checks that if `exclusive` is `false`, existing files are left | ||
/// untouched by create. Test [Link] pointing to a not existing entity | ||
/// @author [email protected] | ||
import "dart:io"; | ||
import "../../../Utils/expect.dart"; | ||
import "../file_utils.dart"; | ||
|
||
main() async { | ||
await inSandbox(_main); | ||
} | ||
|
||
_test(Directory sandbox, {bool recursive = false}) { | ||
File target = File(getTempFilePath(parent: sandbox)); | ||
Expect.isFalse(target.existsSync()); | ||
Link link = getTempLinkSync(parent: sandbox, target: target.path); | ||
File file = File(link.path); | ||
file.createSync(recursive: recursive); | ||
Expect.isTrue(file.existsSync()); | ||
Expect.isTrue(target.existsSync()); | ||
Expect.equals(file.path, link.path); | ||
// Now check that all read/write operations are performed on link's target | ||
file.writeAsStringSync("Lily was here"); | ||
Expect.equals("Lily was here", target.readAsStringSync()); | ||
// Delete doesn't delete the target of the link but the link itself | ||
file.deleteSync(); | ||
Expect.isFalse(file.existsSync()); | ||
Expect.isTrue(target.existsSync()); | ||
Expect.isFalse(link.existsSync()); | ||
} | ||
|
||
_main(Directory sandbox) { | ||
_test(sandbox, recursive: false); | ||
_test(sandbox, recursive: true); | ||
} |
Oops, something went wrong.