@@ -337,6 +337,58 @@ void main() {
337337 expect (processResult.stdout, startsWith ('goodbye world' ));
338338 expect (processResult.exitCode, 0 );
339339 });
340+
341+ test ('can support custom librariesSpec' , () async {
342+ final defaultLibrariesJson = File (p.join (sdkDir, 'lib' , 'libraries.json' ));
343+ final libraries =
344+ jsonDecode (defaultLibrariesJson.readAsStringSync ())
345+ as Map <String , Object ?>;
346+
347+ // Create the custom library file
348+ final customLibFile = File (p.join (packageRoot, 'bin' , 'custom_lib.dart' ));
349+ await customLibFile.writeAsString ('void hello() => print("custom!");' );
350+
351+ if (libraries['vm_common' ] case {
352+ 'libraries' : final Map <String , Object ?> libs,
353+ }) {
354+ libs['custom_lib' ] = {'uri' : customLibFile.absolute.uri.toString ()};
355+ }
356+
357+ final customLibrariesJsonFile = File (p.join (packageRoot, 'libraries.json' ));
358+ await customLibrariesJsonFile.writeAsString (jsonEncode (libraries));
359+
360+ final entrypoint = p.join (packageRoot, 'bin' , 'main_custom.dart' );
361+ await File (entrypoint).writeAsString ('''
362+ import 'dart:custom_lib';
363+ void main() {
364+ hello();
365+ }
366+ ''' );
367+
368+ client = await FrontendServerClient .start (
369+ entrypoint,
370+ p.join (packageRoot, 'out_custom.dill' ),
371+ vmPlatformDill,
372+ packagesJson: packagesJsonPath,
373+ librariesSpec: customLibrariesJsonFile.uri.toString (),
374+ );
375+ var result = await client! .compile ();
376+ client! .accept ();
377+ expect (result.errorCount, 0 );
378+ expect (result.dillOutput, isNotNull);
379+ await client! .shutdown ();
380+
381+ // Without librariesSpec, compiling the same entrypoint should fail
382+ client = await FrontendServerClient .start (
383+ entrypoint,
384+ p.join (packageRoot, 'out_custom_fail.dill' ),
385+ vmPlatformDill,
386+ packagesJson: packagesJsonPath,
387+ );
388+ result = await client! .compile ();
389+ client! .accept ();
390+ expect (result.errorCount, greaterThan (0 ));
391+ });
340392}
341393
342394Future <Isolate > waitForIsolatesAndResume (VmService vmService) async {
0 commit comments