From 7b9c5d938b60ecdec19e03f8cd057d31f403c6b8 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Mon, 3 Feb 2025 00:37:19 -0800 Subject: [PATCH] [ddc,frontend_server] Remove macro tests Change-Id: I1227eaed501e0175859e3c7759d88a8b19e8f4d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406964 Reviewed-by: Nicholas Shahan Commit-Queue: Johnni Winther Reviewed-by: Jens Johansen Reviewed-by: Jake Macdonald --- pkg/dev_compiler/pubspec.yaml | 2 - pkg/dev_compiler/test/macros/macros_test.dart | 247 ------------------ pkg/frontend_server/test/macros_test.dart | 141 ---------- tests/modular/macro/add_function.dart | 20 -- tests/modular/macro/analysis_options.yaml | 3 - tests/modular/macro/main.dart | 12 - tests/modular/macro/modules.yaml | 19 -- 7 files changed, 444 deletions(-) delete mode 100644 pkg/dev_compiler/test/macros/macros_test.dart delete mode 100644 pkg/frontend_server/test/macros_test.dart delete mode 100644 tests/modular/macro/add_function.dart delete mode 100644 tests/modular/macro/analysis_options.yaml delete mode 100644 tests/modular/macro/main.dart delete mode 100644 tests/modular/macro/modules.yaml diff --git a/pkg/dev_compiler/pubspec.yaml b/pkg/dev_compiler/pubspec.yaml index 70a81964150..89a624050ff 100644 --- a/pkg/dev_compiler/pubspec.yaml +++ b/pkg/dev_compiler/pubspec.yaml @@ -25,11 +25,9 @@ dependencies: dev_dependencies: browser_launcher: any expect: any - frontend_server: any http_multi_server: any js: any lints: any - macros: any modular_test: any reload_test: any shelf: any diff --git a/pkg/dev_compiler/test/macros/macros_test.dart b/pkg/dev_compiler/test/macros/macros_test.dart deleted file mode 100644 index 3b3e2b3ddcb..00000000000 --- a/pkg/dev_compiler/test/macros/macros_test.dart +++ /dev/null @@ -1,247 +0,0 @@ -// 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. - -import 'dart:io'; - -import 'package:bazel_worker/bazel_worker.dart'; -import 'package:dev_compiler/ddc.dart' as ddc; -import 'package:frontend_server/compute_kernel.dart'; -import 'package:macros/src/bootstrap.dart'; -import 'package:macros/src/executor/serialization.dart'; -import 'package:path/path.dart' as p; -import 'package:test/test.dart'; - -Directory tmp = Directory.systemTemp.createTempSync('ddc_worker_test'); -File file(String path) => File.fromUri(tmp.uri.resolve(path)); -String _resolvePath(String executableRelativePath) { - return Uri.file(Platform.resolvedExecutable) - .resolve(executableRelativePath) - .toFilePath(); -} - -void main() { - group('DDC: Macros', timeout: Timeout(Duration(minutes: 2)), () { - late File testMacroDart; - late String bootstrapDillPathVm; - late String bootstrapAotPathVm; - late File bootstrapDillFileDdc; - late Uri testMacroUri; - late File packageConfig; - late List ddcArgs; - late List executableArgs; - late String dartAot; - - final applyTestMacroDart = file('apply_test_macro.dart'); - final testMacroJS = file('test_macro.js'); - final testMacroSummary = file('test_macro.dill'); - final applyTestMacroJS = file('apply_test_macro.js'); - - setUp(() async { - // Write a simple test macro and supporting package config. - testMacroDart = file('lib/test_macro.dart') - ..createSync(recursive: true) - ..writeAsStringSync(''' -import 'package:macros/macros.dart'; - -macro class TestMacro implements ClassDeclarationsMacro { - const TestMacro(); - - @override - Future buildDeclarationsForClass( - ClassDeclaration clazz, MemberDeclarationBuilder builder) async { - builder.declareInType(DeclarationCode.fromString('int get x => 0;')); - } -} -'''); - packageConfig = file('.dart_tool/package_config.json') - ..createSync(recursive: true) - ..writeAsStringSync(''' - { - "configVersion": 2, - "packages": [ - { - "name": "test_macro", - "rootUri": "../", - "packageUri": "lib/" - }, - { - "name": "_macros", - "rootUri": "${Platform.script.resolve('../../../_macros')}", - "packageUri": "lib/" - }, - { - "name": "macros", - "rootUri": "${Platform.script.resolve('../../../macros')}", - "packageUri": "lib/" - }, - { - "name": "meta", - "rootUri": "${Platform.script.resolve('../../../meta')}", - "packageUri": "lib/" - } - ] - } - '''); - - // Write the macro entrypoint, the "bootstrap" file. - testMacroUri = Uri.parse('package:test_macro/test_macro.dart'); - var bootstrapContent = bootstrapMacroIsolate( - { - testMacroUri.toString(): { - 'TestMacro': [''], - }, - }, - SerializationMode.byteData, - ); - var bootstrapFile = file('bootstrap.dart') - ..writeAsStringSync(bootstrapContent); - - // Compile the macro to vm dill to be run by the CFE. - var productPlatformDill = File(_resolvePath('../' - 'lib/_internal/vm_platform_strong_product.dill')); - var ddcPlatformDill = File(_resolvePath('../' - 'lib/_internal/ddc_outline.dill')); - bootstrapDillPathVm = 'bootstrap.dart.dill'; - var bootstrapResult = await computeKernel([ - '--enable-experiment=macros', - '--no-summary', - '--no-summary-only', - '--target=vm', - '--dart-sdk-summary=${productPlatformDill.uri}', - '--output=$bootstrapDillPathVm', - '--source=${bootstrapFile.uri}', - '--source=${testMacroDart.uri}', - '--packages-file=${packageConfig.uri}', - ]); - expect(bootstrapResult.succeeded, true); - - // Compile the macro to vm AOT executable to be run by the CFE. - bootstrapAotPathVm = 'bootstrap.dart.exe'; - var bootstrapAotResult = Process.runSync(Platform.resolvedExecutable, [ - 'compile', - 'exe', - '--enable-experiment=macros', - '-o', - bootstrapAotPathVm, - bootstrapFile.path, - ]); - expect(bootstrapAotResult.exitCode, EXIT_CODE_OK); - - // Compile the macro to ddc dill for the ddc build. - bootstrapDillFileDdc = file('bootstrap_ddc.dart.dill'); - var bootstrapResultDdc = await computeKernel([ - '--enable-experiment=macros', - '--target=ddc', - '--dart-sdk-summary=${ddcPlatformDill.uri}', - '--output=${bootstrapDillFileDdc.path}', - '--source=${bootstrapFile.uri}', - '--source=${testMacroDart.uri}', - '--packages-file=${packageConfig.uri}', - ]); - expect(bootstrapResultDdc.succeeded, true); - - // Write source that applies the macro. - applyTestMacroDart.writeAsStringSync(''' -import 'package:test_macro/test_macro.dart'; - -@TestMacro() -class TestClass{} - -void main() { - // Use the declaration created by the macro, so the compile will fail if the - // macro application fails. - print(TestClass().x); -} -'''); - ddcArgs = [ - '--enable-experiment=macros', - '--dart-sdk-summary', - _resolvePath('../../ddc_outline.dill'), - '--packages=${packageConfig.uri}', - ]; - }); - - tearDown(() { - if (tmp.existsSync()) tmp.deleteSync(recursive: true); - }); - - test('compile using dartdevc source code', () async { - await ddc.internalMain([ - ...ddcArgs, - '--no-source-map', - '-o', - testMacroJS.path, - testMacroDart.path, - ]); - // TODO(johnniwinther): Is there a way to verify that no errors/warnings - // were reported? - expect(exitCode, EXIT_CODE_OK); - - expect(testMacroJS.existsSync(), isTrue); - expect(testMacroSummary.existsSync(), isTrue); - - await ddc.internalMain([ - ...ddcArgs, - '--precompiled-macro', - '$bootstrapDillPathVm;$testMacroUri', - '--no-source-map', - '--no-summarize', - '-s', - testMacroSummary.path, - '-s', - bootstrapDillFileDdc.path, - '-o', - applyTestMacroJS.path, - applyTestMacroDart.path, - ]); - // TODO(johnniwinther): Is there a way to verify that no errors/warnings - // were reported? - expect(exitCode, EXIT_CODE_OK); - expect(applyTestMacroJS.existsSync(), isTrue); - }); - - test('compile using dartdevc snapshot', () { - executableArgs = [ - _resolvePath('snapshots/dartdevc_aot.dart.snapshot'), - ...ddcArgs - ]; - - dartAot = p.absolute(p.dirname(Platform.resolvedExecutable), - Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime'); - - var result = Process.runSync(dartAot, [ - ...executableArgs, - '--no-source-map', - '-o', - testMacroJS.path, - testMacroDart.path, - ]); - expect(result.stdout, isEmpty); - expect(result.stderr, isEmpty); - expect(result.exitCode, EXIT_CODE_OK); - - expect(testMacroJS.existsSync(), isTrue); - expect(testMacroSummary.existsSync(), isTrue); - - result = Process.runSync(dartAot, [ - ...executableArgs, - '--precompiled-macro', - '$bootstrapAotPathVm;$testMacroUri', - '--no-source-map', - '--no-summarize', - '-s', - testMacroSummary.path, - '-s', - bootstrapDillFileDdc.path, - '-o', - applyTestMacroJS.path, - applyTestMacroDart.path, - ]); - expect(result.stdout, isEmpty); - expect(result.stderr, isEmpty); - expect(result.exitCode, EXIT_CODE_OK); - expect(applyTestMacroJS.existsSync(), isTrue); - }); - }); -} diff --git a/pkg/frontend_server/test/macros_test.dart b/pkg/frontend_server/test/macros_test.dart deleted file mode 100644 index 7c61700dfbb..00000000000 --- a/pkg/frontend_server/test/macros_test.dart +++ /dev/null @@ -1,141 +0,0 @@ -// 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. - -import 'dart:io'; - -import 'package:frontend_server/compute_kernel.dart'; -import 'package:macros/src/bootstrap.dart'; -import 'package:macros/src/executor/serialization.dart'; -import 'package:test/test.dart'; - -void main() async { - group('basic macro', timeout: new Timeout(new Duration(minutes: 2)), () { - late File productPlatformDill; - late Directory tempDir; - late Uri testMacroUri; - late File packageConfig; - late File bootstrapDillFile; - - setUp(() async { - productPlatformDill = new File('${Platform.resolvedExecutable}/../../' - 'lib/_internal/vm_platform_strong_product.dill'); - Directory systemTempDir = Directory.systemTemp; - tempDir = systemTempDir.createTempSync('frontendServerTest'); - testMacroUri = Uri.parse('package:test_macro/test_macro.dart'); - String bootstrapContent = bootstrapMacroIsolate( - { - testMacroUri.toString(): { - 'TestMacro': [''], - }, - }, - SerializationMode.byteData, - ); - File bootstrapFile = new File('${tempDir.path}/bootstrap.dart') - ..writeAsStringSync(bootstrapContent); - packageConfig = new File('${tempDir.path}/.dart_tool/package_config.json') - ..createSync(recursive: true) - ..writeAsStringSync(''' - { - "configVersion": 2, - "packages": [ - { - "name": "test_macro", - "rootUri": "../", - "packageUri": "lib/" - }, - { - "name": "macros", - "rootUri": "${Platform.script.resolve('../../macros')}", - "packageUri": "lib/" - }, - { - "name": "_macros", - "rootUri": "${Platform.script.resolve('../../_macros')}", - "packageUri": "lib/" - }, - { - "name": "meta", - "rootUri": "${Platform.script.resolve('../../meta')}", - "packageUri": "lib/" - } - ] - } - '''); - File testMacroFile = new File('${tempDir.path}/lib/test_macro.dart') - ..createSync(recursive: true) - ..writeAsStringSync(''' -import 'package:macros/macros.dart'; - -macro class TestMacro implements ClassDeclarationsMacro { - const TestMacro(); - - @override - Future buildDeclarationsForClass( - ClassDeclaration clazz, MemberDeclarationBuilder builder) async { - builder.declareInType(DeclarationCode.fromString('int get x => 0;')); - } -} -'''); - - bootstrapDillFile = new File('${tempDir.path}/bootstrap.dart.dill'); - ComputeKernelResult bootstrapResult = await computeKernel([ - '--enable-experiment=macros', - '--no-summary', - '--no-summary-only', - '--target=vm', - '--dart-sdk-summary=${productPlatformDill.uri}', - '--output=${bootstrapDillFile.path}', - '--source=${bootstrapFile.uri}', - '--source=${testMacroFile.uri}', - '--packages-file=${packageConfig.uri}', - ]); - expect(bootstrapResult.succeeded, true); - }); - - tearDown(() { - tempDir.deleteSync(recursive: true); - }); - - for (bool useIncrementalCompiler in [true, false]) { - test( - 'can be compiled and applied' - '${useIncrementalCompiler ? ' with incremental compiler' : ''}', - () async { - File applyTestMacroFile = - new File('${tempDir.path}/lib/apply_test_macro.dart') - ..createSync(recursive: true) - ..writeAsStringSync(''' -import 'package:test_macro/test_macro.dart'; - -@TestMacro() -class TestClass{} - -void main() { - // Use the declaration created by the macro, so the compile will fail if the - // macro application fails. - print(TestClass().x); -} -'''); - File applyTestMacroDill = - new File('${tempDir.path}/apply_test_macro.dart.dill'); - ComputeKernelResult applyTestMacroResult = await computeKernel([ - if (useIncrementalCompiler) '--use-incremental-compiler', - '--enable-experiment=macros', - '--no-summary', - '--no-summary-only', - '--target=vm', - '--dart-sdk-summary=${productPlatformDill.uri}', - '--output=${applyTestMacroDill.path}', - '--source=${applyTestMacroFile.uri}', - '--packages-file=${packageConfig.uri}', - '--enable-experiment=macros', - '--precompiled-macro', - '${bootstrapDillFile.uri};$testMacroUri', - '--macro-serialization-mode=bytedata', - ]); - expect(applyTestMacroResult.succeeded, true); - }); - } - }); -} diff --git a/tests/modular/macro/add_function.dart b/tests/modular/macro/add_function.dart deleted file mode 100644 index b474cd75983..00000000000 --- a/tests/modular/macro/add_function.dart +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2024, 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. - -import 'package:macros/macros.dart'; - -/// Adds a function with a specified name to a class, with no body and a void -/// return type. -macro class AddFunction implements ClassDeclarationsMacro { - /// The name of the function to add. - final String name; - - const AddFunction(this.name); - - @override - void buildDeclarationsForClass( - ClassDeclaration clazz, MemberDeclarationBuilder builder) { - builder.declareInType(DeclarationCode.fromString('void $name() {}')); - } -} diff --git a/tests/modular/macro/analysis_options.yaml b/tests/modular/macro/analysis_options.yaml deleted file mode 100644 index c38912d5d74..00000000000 --- a/tests/modular/macro/analysis_options.yaml +++ /dev/null @@ -1,3 +0,0 @@ -analyzer: - enable-experiment: - - macros diff --git a/tests/modular/macro/main.dart b/tests/modular/macro/main.dart deleted file mode 100644 index 5c2b19be970..00000000000 --- a/tests/modular/macro/main.dart +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2019, 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. - -import 'add_function.dart'; - -void main() { - A().myFunc(); -} - -@AddFunction('myFunc') -class A {} diff --git a/tests/modular/macro/modules.yaml b/tests/modular/macro/modules.yaml deleted file mode 100644 index fabd6521bad..00000000000 --- a/tests/modular/macro/modules.yaml +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2024, 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. -# -# Tests running precompiled macros from dependent modules. -dependencies: - main: [add_function] - add_function: [macros] - macros: [_macros] -macros: - add_function: - dev-dart-app:/add_function.dart: - AddFunction: - - "" -flags: - - macros -packages: - macros: ../../../pkg/macros/lib - _macros: ../../../pkg/_macros/lib