[ddc,frontend_server] Remove macro tests
Change-Id: I1227eaed501e0175859e3c7759d88a8b19e8f4d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406964
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
diff --git a/pkg/dev_compiler/pubspec.yaml b/pkg/dev_compiler/pubspec.yaml
index 70a8196..89a6240 100644
--- a/pkg/dev_compiler/pubspec.yaml
+++ b/pkg/dev_compiler/pubspec.yaml
@@ -25,11 +25,9 @@
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 3b3e2b3..0000000
--- 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<String> ddcArgs;
- late List<String> 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<void> 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 7c61700..0000000
--- 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<void> 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 b474cd7..0000000
--- 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 c38912d..0000000
--- 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 5c2b19b..0000000
--- 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 fabd652..0000000
--- 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