Skip to content

#2291. Add more Link.createSync() tests. Part 2 #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions LibTest/io/Link/createSync_A04_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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(
/// String target,
/// {bool recursive = false}
/// )
/// Synchronously create the link. Calling createSync on an existing link will
/// throw an exception.
///
/// If recursive is false, the default, the link is created only if all
/// directories in its path exist. If recursive is true, all non-existing parent
/// paths are created first. The directories in the path of target are not
/// affected, unless they are also in path.
///
/// On the Windows platform, this call will create a true symbolic link instead
/// of a junction. The link represents a file or directory and does not change
/// its type after creation. If [target] exists then the type of the link will
/// match the type [target], otherwise a file symlink is created.
///
/// In order to create a symbolic link on Windows, Dart must be run in
/// Administrator mode or the system must have Developer Mode enabled,
/// otherwise a [FileSystemException] will be raised with
/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made.
///
/// On other platforms, the POSIX symlink() call is used to make a symbolic link
/// containing the string target. If target is a relative path, it will be
/// interpreted relative to the directory containing the link.
///
/// @description Checks that if `target` exists then the type of the link will
/// match the type `target`. Test [Link] pointing to a not existing entity as a
/// target (expect `file` on Windows and `notFound` on other platforms).
/// @author [email protected]

import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() {
inSandbox(_main);
}

_main(Directory sandbox) {
Link target = getTempLinkSync(
parent: sandbox, target: getTempFilePath(parent: sandbox));
Link link = Link(getTempFilePath(parent: sandbox));
link.createSync(target.path);
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
File file = File(link.targetSync());
file.createSync();
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path));
}
}
57 changes: 57 additions & 0 deletions LibTest/io/Link/createSync_A04_t06.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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(
/// String target,
/// {bool recursive = false}
/// )
/// Synchronously create the link. Calling createSync on an existing link will
/// throw an exception.
///
/// If recursive is false, the default, the link is created only if all
/// directories in its path exist. If recursive is true, all non-existing parent
/// paths are created first. The directories in the path of target are not
/// affected, unless they are also in path.
///
/// On the Windows platform, this call will create a true symbolic link instead
/// of a junction. The link represents a file or directory and does not change
/// its type after creation. If [target] exists then the type of the link will
/// match the type [target], otherwise a file symlink is created.
///
/// In order to create a symbolic link on Windows, Dart must be run in
/// Administrator mode or the system must have Developer Mode enabled,
/// otherwise a [FileSystemException] will be raised with
/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made.
///
/// On other platforms, the POSIX symlink() call is used to make a symbolic link
/// containing the string target. If target is a relative path, it will be
/// interpreted relative to the directory containing the link.
///
/// @description Checks that if `target` does not exist then the type of the link
/// will be `file` on Windows and `notFound` on other platforms.
/// @author [email protected]

import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() {
inSandbox(_main);
}

_main(Directory sandbox) {
Link link = Link(getTempFilePath(parent: sandbox));
link.createSync(getTempFilePath(parent: sandbox));
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
File file = File(link.targetSync());
file.createSync();
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path));
}
}
68 changes: 68 additions & 0 deletions LibTest/io/Link/createSync_A04_t07.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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(
/// String target,
/// {bool recursive = false}
/// )
/// Synchronously create the link. Calling createSync on an existing link will
/// throw an exception.
///
/// If recursive is false, the default, the link is created only if all
/// directories in its path exist. If recursive is true, all non-existing parent
/// paths are created first. The directories in the path of target are not
/// affected, unless they are also in path.
///
/// On the Windows platform, this call will create a true symbolic link instead
/// of a junction. The link represents a file or directory and does not change
/// its type after creation. If [target] exists then the type of the link will
/// match the type [target], otherwise a file symlink is created.
///
/// In order to create a symbolic link on Windows, Dart must be run in
/// Administrator mode or the system must have Developer Mode enabled,
/// otherwise a [FileSystemException] will be raised with
/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made.
///
/// On other platforms, the POSIX symlink() call is used to make a symbolic link
/// containing the string target. If target is a relative path, it will be
/// interpreted relative to the directory containing the link.
///
/// @description Checks that if a link with the target directory was created and
/// then this directory was deleted and created again, then the link stays valid
/// @author [email protected]

import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() {
inSandbox(_main);
}

_main(Directory sandbox) {
Directory target1 = getTempDirectorySync(parent: sandbox);
Link link = Link(getTempFilePath(parent: sandbox));
link.createSync(target1.path);
Expect.equals(
FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path));
target1.deleteSync();
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path));
}
Directory target2 = Directory(target1.path);
target2.createSync();
Expect.equals(
FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path));
target2.deleteSync();

Link target3 = Link(target1.path);
Directory linkTarget = getTempDirectorySync();
target3.createSync(linkTarget.path);
Expect.equals(
FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path));
}
79 changes: 79 additions & 0 deletions LibTest/io/Link/createSync_A04_t08.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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(
/// String target,
/// {bool recursive = false}
/// )
/// Synchronously create the link. Calling createSync on an existing link will
/// throw an exception.
///
/// If recursive is false, the default, the link is created only if all
/// directories in its path exist. If recursive is true, all non-existing parent
/// paths are created first. The directories in the path of target are not
/// affected, unless they are also in path.
///
/// On the Windows platform, this call will create a true symbolic link instead
/// of a junction. The link represents a file or directory and does not change
/// its type after creation. If [target] exists then the type of the link will
/// match the type [target], otherwise a file symlink is created.
///
/// In order to create a symbolic link on Windows, Dart must be run in
/// Administrator mode or the system must have Developer Mode enabled,
/// otherwise a [FileSystemException] will be raised with
/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made.
///
/// On other platforms, the POSIX symlink() call is used to make a symbolic link
/// containing the string target. If target is a relative path, it will be
/// interpreted relative to the directory containing the link.
///
/// @description Checks that if a link with the target directory was created and
/// then this directory was deleted and a file with the same name created, then
/// on Windows the link became invalid on other platforms it changes its type
/// @author [email protected]

import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() {
inSandbox(_main);
}

_main(Directory sandbox) {
Directory target1 = getTempDirectorySync(parent: sandbox);
Link link = Link(getTempFilePath(parent: sandbox));
link.createSync(target1.path);
Expect.equals(
FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path));
target1.deleteSync();
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path));
}
File target2 = File(target1.path);
target2.createSync();
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
}
target2.deleteSync();

Link target3 = Link(target1.path);
File linkTarget = getTempFileSync();
target3.createSync(linkTarget.path);
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
}
}
68 changes: 68 additions & 0 deletions LibTest/io/Link/createSync_A04_t09.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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(
/// String target,
/// {bool recursive = false}
/// )
/// Synchronously create the link. Calling createSync on an existing link will
/// throw an exception.
///
/// If recursive is false, the default, the link is created only if all
/// directories in its path exist. If recursive is true, all non-existing parent
/// paths are created first. The directories in the path of target are not
/// affected, unless they are also in path.
///
/// On the Windows platform, this call will create a true symbolic link instead
/// of a junction. The link represents a file or directory and does not change
/// its type after creation. If [target] exists then the type of the link will
/// match the type [target], otherwise a file symlink is created.
///
/// In order to create a symbolic link on Windows, Dart must be run in
/// Administrator mode or the system must have Developer Mode enabled,
/// otherwise a [FileSystemException] will be raised with
/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made.
///
/// On other platforms, the POSIX symlink() call is used to make a symbolic link
/// containing the string target. If target is a relative path, it will be
/// interpreted relative to the directory containing the link.
///
/// @description Checks that if a link with the target file was created and
/// then this file was deleted and created again, then the link stays valid
/// @author [email protected]

import "dart:io";
import "../../../Utils/expect.dart";
import "../file_utils.dart";

main() {
inSandbox(_main);
}

_main(Directory sandbox) {
File target1 = getTempFileSync(parent: sandbox);
Link link = Link(getTempFilePath(parent: sandbox));
link.createSync(target1.path);
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
target1.deleteSync();
if (Platform.isWindows) {
Expect.equals(
FileSystemEntityType.link, FileSystemEntity.typeSync(link.path));
} else {
Expect.equals(
FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path));
}
File target2 = File(target1.path);
target2.createSync();
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
target2.deleteSync();

Link target3 = Link(target1.path);
File linkTarget = getTempFileSync();
target3.createSync(linkTarget.path);
Expect.equals(
FileSystemEntityType.file, FileSystemEntity.typeSync(link.path));
}
Loading