c850242ef9
Bug: https://github.com/dart-lang/sdk/issues/61548 Change-Id: I7a4d562a88d5d2f4ca2245e924411042ec463c37 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452544 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Brian Quinlan <bquinlan@google.com>
72 lines
2.2 KiB
Dart
72 lines
2.2 KiB
Dart
// Copyright (c) 2025, 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.
|
|
|
|
// This test was generated by Gemini.
|
|
|
|
import "dart:io";
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
// The simple script to be run in a child process.
|
|
// It prints both executable paths to standard output.
|
|
const String _testScriptContent = """
|
|
import "dart:io";
|
|
|
|
void main() {
|
|
print(Platform.executable);
|
|
print(Platform.resolvedExecutable);
|
|
}
|
|
""";
|
|
|
|
void main() {
|
|
if (!Platform.isLinux && !Platform.isMacOS) return;
|
|
|
|
// 1. Get the absolute path to the current Dart executable.
|
|
final dartExecutablePath = Platform.resolvedExecutable;
|
|
|
|
// 2. Create a temporary directory and the necessary files.
|
|
final tempDir = Directory.systemTemp.createTempSync("dart_symlink_test_");
|
|
final symlinkPath = "${tempDir.path}${Platform.pathSeparator}dart_symlink";
|
|
final childScriptPath =
|
|
"${tempDir.path}${Platform.pathSeparator}child_script.dart";
|
|
|
|
try {
|
|
// Create the symbolic link.
|
|
Link(symlinkPath).createSync(dartExecutablePath, recursive: true);
|
|
|
|
// Write the child script to a file.
|
|
File(childScriptPath).writeAsStringSync(_testScriptContent);
|
|
|
|
// 3. Execute the child script using the symlink.
|
|
final result = Process.runSync(
|
|
symlinkPath, // This is the key: use the symlink path
|
|
[childScriptPath],
|
|
runInShell: true,
|
|
);
|
|
|
|
// Verify the child process exited successfully.
|
|
print("stdout:");
|
|
print(result.stdout);
|
|
print("stderr:");
|
|
print(result.stderr);
|
|
|
|
Expect.equals(0, result.exitCode);
|
|
|
|
// 4. Parse the output.
|
|
final output = result.stdout.toString().trim().split("\n");
|
|
final executablePath = output[0];
|
|
final resolvedExecutablePath = output[1];
|
|
|
|
// 5. Assert the paths are different.
|
|
print("Executable: $executablePath");
|
|
print("Resolved Executable: $resolvedExecutablePath");
|
|
Expect.notEquals(executablePath, resolvedExecutablePath);
|
|
} finally {
|
|
// Clean up the temporary directory.
|
|
if (tempDir.existsSync()) {
|
|
tempDir.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
}
|