| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 import 'dart:io'; | |
| 7 | |
| 8 import 'package:mojom/src/command_runner.dart'; | |
| 9 import 'package:mojom/src/utils.dart'; | |
| 10 import 'package:path/path.dart' as path; | |
| 11 import 'package:unittest/unittest.dart'; | |
| 12 | |
| 13 final singlePacakgeMojomContents = ''' | |
| 14 [DartPackage="single_package"] | |
| 15 module single_package; | |
| 16 struct SinglePackage { | |
| 17 int32 thingo; | |
| 18 }; | |
| 19 '''; | |
| 20 | |
| 21 Future runCommand(List<String> args) { | |
| 22 return new MojomCommandRunner().run(args); | |
| 23 } | |
| 24 | |
| 25 main() async { | |
| 26 String mojoSdk; | |
| 27 if (Platform.environment['MOJO_SDK'] != null) { | |
| 28 mojoSdk = Platform.environment['MOJO_SDK']; | |
| 29 } else { | |
| 30 mojoSdk = path.normalize( | |
| 31 path.join(path.dirname(Platform.script.path), '..', '..', '..')); | |
| 32 } | |
| 33 if (!await new Directory(mojoSdk).exists()) { | |
| 34 fail("Could not find the Mojo SDK"); | |
| 35 } | |
| 36 | |
| 37 final scriptPath = path.dirname(Platform.script.path); | |
| 38 | |
| 39 // //test_mojoms/mojom | |
| 40 final testMojomPath = path.join(scriptPath, 'test_mojoms'); | |
| 41 | |
| 42 setUp(() async { | |
| 43 await new Directory(testMojomPath).create(recursive: true); | |
| 44 }); | |
| 45 | |
| 46 tearDown(() async { | |
| 47 await new Directory(testMojomPath).delete(recursive: true); | |
| 48 }); | |
| 49 | |
| 50 group('Commands', () { | |
| 51 // //single_package | |
| 52 final singlePackagePath = path.join(scriptPath, 'single_package'); | |
| 53 // //single_package/.mojoms | |
| 54 final singlePackageMojomsPath = path.join(singlePackagePath, '.mojoms'); | |
| 55 // //single_package/lib | |
| 56 final singlePackageLibPath = path.join(singlePackagePath, 'lib'); | |
| 57 // //single_package/packages | |
| 58 final singlePackagePackagesPath = path.join(singlePackagePath, 'packages'); | |
| 59 // //single_package/packages/single_package | |
| 60 final singlePackagePackagePath = | |
| 61 path.join(singlePackagePackagesPath, 'single_package'); | |
| 62 | |
| 63 setUp(() async { | |
| 64 await new Directory(singlePackageLibPath).create(recursive: true); | |
| 65 await new Directory(singlePackagePackagesPath).create(recursive: true); | |
| 66 await new Link(singlePackagePackagePath).create(singlePackageLibPath); | |
| 67 | |
| 68 // //test_mojoms/single_package/public/interfaces/single_package.mojom | |
| 69 final singlePackageMojomFile = new File(path.join(testMojomPath, | |
| 70 'single_package', 'public', 'interfaces', 'single_package.mojom')); | |
| 71 await singlePackageMojomFile.create(recursive: true); | |
| 72 await singlePackageMojomFile.writeAsString(singlePacakgeMojomContents); | |
| 73 }); | |
| 74 | |
| 75 tearDown(() async { | |
| 76 await new Directory(singlePackagePath).delete(recursive: true); | |
| 77 }); | |
| 78 | |
| 79 test('single', () async { | |
| 80 await runCommand([ | |
| 81 'single', | |
| 82 '-m', | |
| 83 mojoSdk, | |
| 84 '-r', | |
| 85 testMojomPath, | |
| 86 '-p', | |
| 87 singlePackagePath | |
| 88 ]); | |
| 89 | |
| 90 // Should have: | |
| 91 // //single_package/lib/single_package/single_package.mojom.dart | |
| 92 final resultPath = path.join( | |
| 93 singlePackageLibPath, 'single_package', 'single_package.mojom.dart'); | |
| 94 final resultFile = new File(resultPath); | |
| 95 expect(await resultFile.exists(), isTrue); | |
| 96 | |
| 97 // There should be no stray .mojoms file haning around. | |
| 98 final mojomsFile = new File(singlePackageMojomsPath); | |
| 99 expect(await mojomsFile.exists(), isFalse); | |
| 100 }); | |
| 101 | |
| 102 test('gen', () async { | |
| 103 await runCommand( | |
| 104 ['gen', '-m', mojoSdk, '-r', testMojomPath, '-o', scriptPath]); | |
| 105 | |
| 106 // Should have: | |
| 107 // //single_package/lib/single_package/single_package.mojom.dart | |
| 108 final resultPath = path.join( | |
| 109 singlePackageLibPath, 'single_package', 'single_package.mojom.dart'); | |
| 110 final resultFile = new File(resultPath); | |
| 111 expect(await resultFile.exists(), isTrue); | |
| 112 | |
| 113 // There should be no stray .mojoms file haning around. | |
| 114 final mojomsFile = new File(singlePackageMojomsPath); | |
| 115 expect(await mojomsFile.exists(), isFalse); | |
| 116 }); | |
| 117 }); | |
| 118 } | |
| OLD | NEW |