From b5294b97538cc8d4f221d1306874dfc259c435bc Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 10 Jun 2026 15:30:26 -0700 Subject: [PATCH] [test_runner] Invoke tests with relative paths. This makes tests more reproducible, and makes it easier to copy commands between workspaces, or between a failing bot and a local workspace. Change-Id: Ic8dd10a3540f314a406e5c5b0a23d97032e5d01d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508364 Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- pkg/test_runner/lib/src/command_output.dart | 4 +--- .../lib/src/compiler_configuration.dart | 14 ++++++-------- pkg/test_runner/lib/src/configuration.dart | 7 +------ pkg/test_runner/lib/src/multitest.dart | 2 +- pkg/test_runner/lib/src/test_file.dart | 2 +- pkg/test_runner/lib/src/test_suite.dart | 14 ++++++-------- pkg/test_runner/lib/src/testing_servers.dart | 2 +- tests/standalone/io/process_non_ascii_test.dart | 1 + tests/standalone/io/regress_7679_test.dart | 1 + 9 files changed, 19 insertions(+), 28 deletions(-) diff --git a/pkg/test_runner/lib/src/command_output.dart b/pkg/test_runner/lib/src/command_output.dart index 7f16e867cb2..0843b4d7a08 100644 --- a/pkg/test_runner/lib/src/command_output.dart +++ b/pkg/test_runner/lib/src/command_output.dart @@ -737,9 +737,7 @@ class AnalysisCommandOutput extends CommandOutput with _StaticErrorOutput { files.sort(); for (var file in files) { - var path = Path( - file!, - ).relativeTo(testCase.testFile.path.directoryPath).toString(); + var path = Path(file!).toString(); output.subsection("unexpected analysis errors in $path"); var errors = errorsByFile[file]!; diff --git a/pkg/test_runner/lib/src/compiler_configuration.dart b/pkg/test_runner/lib/src/compiler_configuration.dart index c0481c32b4d..59b0ad95be2 100644 --- a/pkg/test_runner/lib/src/compiler_configuration.dart +++ b/pkg/test_runner/lib/src/compiler_configuration.dart @@ -1124,8 +1124,7 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration List arguments, Map environmentOverrides, ) { - var pkgVmDir = Platform.script.resolve('../../../pkg/vm').toFilePath(); - var compareIl = '$pkgVmDir/tool/compare_il$shellScriptExtension'; + var compareIl = 'pkg/vm/tool/compare_il$shellScriptExtension'; var args = [ arguments.firstWhere((arg) => arg.endsWith('_il_test.dart')), @@ -1653,8 +1652,7 @@ abstract mixin class VMKernelCompilerMixin { List arguments, Map environmentOverrides, ) { - var pkgVmDir = Platform.script.resolve('../../../pkg/vm').toFilePath(); - var genKernel = '$pkgVmDir/tool/gen_kernel$shellScriptExtension'; + var genKernel = 'pkg/vm/tool/gen_kernel$shellScriptExtension'; var kernelBinariesFolder = _configuration.buildDirectory; if (_useSdk) { @@ -1684,10 +1682,10 @@ abstract mixin class VMKernelCompilerMixin { name.startsWith('--enable-experiment=') || name.startsWith('--keep-class-names-implementing='), ), - '-Ddart.vm.product=$isProductMode', - '-Ddart.vm.asan=$isAsan', - '-Ddart.vm.msan=$isMsan', - '-Ddart.vm.tsan=$isTsan', + if (isProductMode) '-Ddart.vm.product=true', + if (isAsan) '-Ddart.vm.asan=true', + if (isMsan) '-Ddart.vm.msan=true', + if (isTsan) '-Ddart.vm.tsan=true', if (_enableAsserts || arguments.contains('--enable-asserts') || arguments.contains('--enable_asserts')) diff --git a/pkg/test_runner/lib/src/configuration.dart b/pkg/test_runner/lib/src/configuration.dart index c014a83325d..eb1f89e2e30 100644 --- a/pkg/test_runner/lib/src/configuration.dart +++ b/pkg/test_runner/lib/src/configuration.dart @@ -14,7 +14,6 @@ import 'compiler_configuration.dart'; import 'deflake_info.dart'; import 'feature.dart'; import 'path.dart'; -import 'repository.dart'; import 'runtime_configuration.dart'; import 'testing_servers.dart'; @@ -73,11 +72,7 @@ class TestConfiguration { required this.reproducingArguments, this.fastTestsOnly = false, this.printPassingStdout = false, - }) : packages = - packages ?? - Repository.uri - .resolve('.dart_tool/package_config.json') - .toFilePath(); + }) : packages = packages ?? '.dart_tool/package_config.json'; final Map selectors; final Progress progress; diff --git a/pkg/test_runner/lib/src/multitest.dart b/pkg/test_runner/lib/src/multitest.dart index f01a7a81fa6..25548235910 100644 --- a/pkg/test_runner/lib/src/multitest.dart +++ b/pkg/test_runner/lib/src/multitest.dart @@ -360,5 +360,5 @@ Path _createMultitestDirectory( .append(_suiteNameFromPath(suiteDir)) .join(relative); TestUtils.mkdirRecursive(Path.workingDirectory, path); - return Path(File(path.toNativePath()).absolute.path); + return path; } diff --git a/pkg/test_runner/lib/src/test_file.dart b/pkg/test_runner/lib/src/test_file.dart index 47a4e5a99a0..a03c0296eeb 100644 --- a/pkg/test_runner/lib/src/test_file.dart +++ b/pkg/test_runner/lib/src/test_file.dart @@ -349,7 +349,7 @@ class TestFile extends _TestFileBase { // The analyzer package also uses a similar syntax for expectations, but // we don't want the test_runner to inadvertently think files containing // those are static error tests. - if (!filePath.replaceAll('\\', '/').contains('/pkg/analyzer/')) { + if (!filePath.replaceAll('\\', '/').contains('pkg/analyzer/')) { try { errorExpectations.addAll(_parseExpectations(filePath)); } on FormatException catch (error) { diff --git a/pkg/test_runner/lib/src/test_suite.dart b/pkg/test_runner/lib/src/test_suite.dart index b5b95889fe9..a2ff85cadb3 100644 --- a/pkg/test_runner/lib/src/test_suite.dart +++ b/pkg/test_runner/lib/src/test_suite.dart @@ -246,7 +246,7 @@ abstract class TestSuite { String dirname, Path testPath, ) { - var relative = testPath.relativeTo(Repository.dir); + var relative = testPath; relative = relative.directoryPath.append(relative.filenameWithoutExtension); var testUniqueName = TestUtils.getShortName(relative.toString()); @@ -257,7 +257,7 @@ abstract class TestSuite { TestUtils.mkdirRecursive(Path('.'), generatedTestPath); return File( generatedTestPath.toNativePath(), - ).absolute.path.replaceAll('\\', '/'); + ).path.replaceAll('\\', '/'); } /// Create a directories for generated assets (tests, html files, @@ -393,7 +393,7 @@ class VMTestSuite extends TestSuite { configuration.architecture == Architecture.x64c ? '$buildDir/gen/kernel-service.dart.snapshot' : '$buildDir/gen/kernel_service.dill'; - var dfePath = Path(filename).absolute.toNativePath(); + var dfePath = Path(filename).toNativePath(); final experiments = [...configuration.experiments]; var args = [ ...initialTargetArguments, @@ -619,7 +619,7 @@ class StandardTestSuite extends TestSuite { bool recursive = false, }) : dartDir = Repository.dir, listRecursively = recursive, - suiteDir = Repository.dir.join(suiteDirectory), + suiteDir = suiteDirectory, extraVmOptions = configuration.vmOptions, super(configuration, suiteName, statusFilePaths) { // Initialize _dart2JsBootstrapDependencies. @@ -1097,12 +1097,10 @@ class StandardTestSuite extends TestSuite { } else if (configuration.compiler == Compiler.ddc) { var ddcConfig = configuration.compilerConfiguration as DevCompilerConfiguration; - var nameFromModuleRoot = testFile.path.relativeTo(Repository.dir); + var nameFromModuleRoot = testFile.path; var nameFromModuleRootNoExt = "${nameFromModuleRoot.directoryPath}/$nameNoExt"; - var jsDir = Path( - compilationTempDir, - ).relativeTo(Repository.dir).toString(); + var jsDir = Path(compilationTempDir).toString(); var nativeNonNullAsserts = testFile.ddcOptions.contains( '--native-null-assertions', ); diff --git a/pkg/test_runner/lib/src/testing_servers.dart b/pkg/test_runner/lib/src/testing_servers.dart index 99ab706908d..1998b640223 100644 --- a/pkg/test_runner/lib/src/testing_servers.dart +++ b/pkg/test_runner/lib/src/testing_servers.dart @@ -133,7 +133,7 @@ class TestingServers { int port = 0, int crossOriginPort = 0, }) async { - _packageConfig = await loadPackageConfigUri(_packages); + _packageConfig = await loadPackageConfigUri(Uri.base.resolveUri(_packages)); _server = await _startHttpServer(host, port: port); await _startHttpServer( diff --git a/tests/standalone/io/process_non_ascii_test.dart b/tests/standalone/io/process_non_ascii_test.dart index 72972a76d4c..f77896b62e8 100644 --- a/tests/standalone/io/process_non_ascii_test.dart +++ b/tests/standalone/io/process_non_ascii_test.dart @@ -32,6 +32,7 @@ main() { executable, [] ..addAll(Platform.executableArguments) + ..add("--packages=" + Platform.packageConfig!) ..add(script), workingDirectory: nonAsciiDir.path, environment: {'DART_CRASHPAD_HANDLER': ''}, diff --git a/tests/standalone/io/regress_7679_test.dart b/tests/standalone/io/regress_7679_test.dart index 964336e65b9..35b961d7533 100644 --- a/tests/standalone/io/regress_7679_test.dart +++ b/tests/standalone/io/regress_7679_test.dart @@ -41,6 +41,7 @@ main() { executable, [] ..addAll(Platform.executableArguments) + ..add("--packages=" + Platform.packageConfig!) ..add('script.dart'), workingDirectory: temp.path, environment: {'DART_CRASHPAD_HANDLER': ''},