diff --git a/integration_tests/regression/lib/issue_2142/test.dart b/integration_tests/regression/lib/issue_2142/test.dart index f510c09ea..92efa4c8a 100644 --- a/integration_tests/regression/lib/issue_2142/test.dart +++ b/integration_tests/regression/lib/issue_2142/test.dart @@ -1,3 +1,4 @@ +@Skip('https://github.com/dart-lang/test/issues/2142') library; import 'package:test/test.dart'; diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index 07fe2e006..b5cb03e3d 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md @@ -1,8 +1,6 @@ ## 1.24.10-wip * Handle paths with leading `/` when spawning test isolates. -* Fix running of tests defined under `lib/` with relative imports to other - libraries in the package. ## 1.24.9 diff --git a/pkgs/test/lib/src/runner/browser/platform.dart b/pkgs/test/lib/src/runner/browser/platform.dart index a29fbbc79..dc28f65fc 100644 --- a/pkgs/test/lib/src/runner/browser/platform.dart +++ b/pkgs/test/lib/src/runner/browser/platform.dart @@ -362,9 +362,9 @@ class BrowserPlatform extends PlatformPlugin var jsPath = p.join(dir, '${p.basename(dartPath)}.browser_test.dart.js'); var bootstrapContent = ''' ${suiteConfig.metadata.languageVersionComment ?? await rootPackageLanguageVersionComment} - import 'package:test/src/bootstrap/browser.dart'; + import "package:test/src/bootstrap/browser.dart"; - import '${await absoluteUri(dartPath)}' as test; + import "${p.toUri(p.absolute(dartPath))}" as test; void main() { internalBootstrapBrowserTest(() => test.main); diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md index 8f111d065..808ff03fc 100644 --- a/pkgs/test_core/CHANGELOG.md +++ b/pkgs/test_core/CHANGELOG.md @@ -1,8 +1,6 @@ ## 0.5.10-wip * Handle paths with leading `/` when spawning test isolates. -* Fix running of tests defined under `lib/` with relative imports to other - libraries in the package. ## 0.5.9 diff --git a/pkgs/test_core/lib/src/runner/vm/platform.dart b/pkgs/test_core/lib/src/runner/vm/platform.dart index 436cd775d..6a57c3176 100644 --- a/pkgs/test_core/lib/src/runner/vm/platform.dart +++ b/pkgs/test_core/lib/src/runner/vm/platform.dart @@ -121,7 +121,7 @@ class VMPlatform extends PlatformPlugin { // ignore: deprecated_member_use, Remove when SDK constraint is at 3.2.0 var isolateID = Service.getIsolateID(isolate!)!; - var libraryPath = (await absoluteUri(path)).toString(); + var libraryPath = _absolute(path).toString(); var serverUri = info.serverUri!; client = await vmServiceConnectUri(_wsUriFor(serverUri).toString()); var isolateNumber = int.parse(isolateID.split('/').last); @@ -164,6 +164,12 @@ class VMPlatform extends PlatformPlugin { _tempDir.deleteWithRetry(), ])); + Uri _absolute(String path) { + final uri = p.toUri(path); + if (uri.isAbsolute) return uri; + return _workingDirectory.resolveUri(uri); + } + /// Compiles [path] to a native executable and spawns it as a process. /// /// Sets up a communication channel as well by passing command line arguments @@ -185,11 +191,11 @@ class VMPlatform extends PlatformPlugin { path, suiteMetadata.languageVersionComment ?? await rootPackageLanguageVersionComment); - var output = File(p.setExtension(await bootstrapPath, '.exe')); + var output = File(p.setExtension(bootstrapPath, '.exe')); var processResult = await Process.run(Platform.resolvedExecutable, [ 'compile', 'exe', - await bootstrapPath, + bootstrapPath, '--output', output.path, '--packages', @@ -225,7 +231,7 @@ stderr: ${processResult.stderr}'''); Compiler.kernel => _spawnIsolateWithUri( await _compileToKernel(path, suiteMetadata), message), Compiler.source => _spawnIsolateWithUri( - await _bootstrapIsolateTestFile( + _bootstrapIsolateTestFile( path, suiteMetadata.languageVersionComment ?? await rootPackageLanguageVersionComment), @@ -241,13 +247,12 @@ stderr: ${processResult.stderr}'''); /// Compiles [path] to kernel and returns the uri to the compiled dill. Future _compileToKernel(String path, Metadata suiteMetadata) async { - final response = - await _compiler.compile(await absoluteUri(path), suiteMetadata); + final response = await _compiler.compile(_absolute(path), suiteMetadata); var compiledDill = response.kernelOutputUri?.toFilePath(); if (compiledDill == null || response.errorCount > 0) { throw LoadException(path, response.compilerOutput ?? 'unknown error'); } - return absoluteUri(compiledDill); + return _absolute(compiledDill); } /// Runs [uri] in an isolate, passing [message]. @@ -258,10 +263,9 @@ stderr: ${processResult.stderr}'''); Future _spawnPrecompiledIsolate(String testPath, SendPort message, String precompiledPath, Compiler compiler) async { - testPath = - (await absoluteUri('${p.join(precompiledPath, testPath)}.vm_test.dart')) - .path - .stripDriveLetterLeadingSlash; + testPath = _absolute('${p.join(precompiledPath, testPath)}.vm_test.dart') + .path + .stripDriveLetterLeadingSlash; switch (compiler) { case Compiler.kernel: var dillTestpath = @@ -296,15 +300,15 @@ stderr: ${processResult.stderr}'''); /// file. /// /// Returns the [Uri] to the created file. - Future _bootstrapIsolateTestFile( - String testPath, String languageVersionComment) async { + Uri _bootstrapIsolateTestFile( + String testPath, String languageVersionComment) { var file = File(p.join( _tempDir.path, p.setExtension(testPath, '.bootstrap.isolate.dart'))); if (!file.existsSync()) { file ..createSync(recursive: true) ..writeAsStringSync(_bootstrapIsolateTestContents( - await absoluteUri(testPath), languageVersionComment)); + _absolute(testPath), languageVersionComment)); } return file.uri; } @@ -313,15 +317,15 @@ stderr: ${processResult.stderr}'''); /// contents to a temporary file. /// /// Returns the path to the created file. - Future _bootstrapNativeTestFile( - String testPath, String languageVersionComment) async { + String _bootstrapNativeTestFile( + String testPath, String languageVersionComment) { var file = File(p.join( _tempDir.path, p.setExtension(testPath, '.bootstrap.native.dart'))); if (!file.existsSync()) { file ..createSync(recursive: true) ..writeAsStringSync(_bootstrapNativeTestContents( - await absoluteUri(testPath), languageVersionComment)); + _absolute(testPath), languageVersionComment)); } return file.path; } diff --git a/pkgs/test_core/lib/src/util/package_config.dart b/pkgs/test_core/lib/src/util/package_config.dart index 8e2593f3a..d6067f3ca 100644 --- a/pkgs/test_core/lib/src/util/package_config.dart +++ b/pkgs/test_core/lib/src/util/package_config.dart @@ -2,11 +2,9 @@ // 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. -import 'dart:io'; import 'dart:isolate'; import 'package:package_config/package_config.dart'; -import 'package:path/path.dart' as p; /// The [PackageConfig] parsed from the current isolates package config file. final Future currentPackageConfig = () async { @@ -20,13 +18,3 @@ final Future packageConfigUri = () async { } return uri; }(); - -/// Returns an `package:` URI for [path] if it is in a package, otherwise -/// returns an absolute file URI. -Future absoluteUri(String path) async { - final uri = p.toUri(path); - final absoluteUri = - uri.isAbsolute ? uri : Directory.current.uri.resolveUri(uri); - final packageConfig = await currentPackageConfig; - return packageConfig.toPackageUri(absoluteUri) ?? absoluteUri; -}