Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: mojo/dart/packages/mojom/test/generate_test.dart

Issue 1658763002: mojom.dart: Allow package name != directory name (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/dart/packages/mojom/pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:mojom/src/command_runner.dart'; 8 import 'package:mojom/src/command_runner.dart';
9 import 'package:mojom/src/utils.dart'; 9 import 'package:mojom/src/utils.dart';
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 final singlePacakgeMojomContents = ''' 13 final String singlePacakgeMojomContents = '''
14 [DartPackage="single_package"] 14 [DartPackage="single_package"]
15 module single_package; 15 module single_package;
16 struct SinglePackage { 16 struct SinglePackage {
17 int32 thingo; 17 int32 thingo;
18 }; 18 };
19 '''; 19 ''';
20 20
21 final String singlePackagePubspecContents = '''
22 name: single_package
23 ''';
24
21 Future runCommand(List<String> args) { 25 Future runCommand(List<String> args) {
22 return new MojomCommandRunner().run(args); 26 return new MojomCommandRunner().run(args);
23 } 27 }
24 28
29 Future<String> setupPackage(
30 String basePath, String dirName, String packageName, String pubspec) async {
31 // //dirName
32 String packagePath = path.join(basePath, dirName);
33 // //dirName/lib
34 String packageLibPath = path.join(packagePath, 'lib');
35 // //dirName/packages
36 String packagePackagesPath = path.join(packagePath, 'packages');
37 // //dirName/packages/packageName
38 String packagePackagePath =
39 path.join(packagePackagesPath, packageName);
40 // //dirName/pubspec.yaml
41 String pubspecPath = path.join(packagePath, 'pubspec.yaml');
42
43 // Create the directory structure
44 await new Directory(packageLibPath).create(recursive: true);
45 await new Directory(packagePackagesPath).create(recursive: true);
46 await new Link(packagePackagePath).create(packageLibPath);
47
48 // Write the pubspec.yaml
49 File pubspecFile = new File(pubspecPath);
50 await pubspecFile.create(recursive: true);
51 await pubspecFile.writeAsString(pubspec);
52
53 return packagePath;
54 }
55
56 Future destroyPackage(String basePath, String dirName) async {
57 await new Directory(path.join(basePath, dirName)).delete(recursive: true);
58 }
59
25 main() async { 60 main() async {
26 String mojoSdk; 61 String mojoSdk;
27 if (Platform.environment['MOJO_SDK'] != null) { 62 if (Platform.environment['MOJO_SDK'] != null) {
28 mojoSdk = Platform.environment['MOJO_SDK']; 63 mojoSdk = Platform.environment['MOJO_SDK'];
29 } else { 64 } else {
30 mojoSdk = path.normalize(path.join( 65 mojoSdk = path.normalize(path.join(
31 path.dirname(Platform.script.path), '..', '..', '..', '..', 'public')); 66 path.dirname(Platform.script.path), '..', '..', '..', '..', 'public'));
32 } 67 }
33 if (!await new Directory(mojoSdk).exists()) { 68 if (!await new Directory(mojoSdk).exists()) {
34 fail("Could not find the Mojo SDK"); 69 fail("Could not find the Mojo SDK");
35 } 70 }
36 71
37 final scriptPath = path.dirname(Platform.script.path); 72 final scriptPath = path.dirname(Platform.script.path);
38 73
39 // //test_mojoms/mojom 74 // //test_mojoms/mojom
40 final testMojomPath = path.join(scriptPath, 'test_mojoms'); 75 final testMojomPath = path.join(scriptPath, 'test_mojoms');
41 76
42 setUp(() async { 77 setUp(() async {
43 await new Directory(testMojomPath).create(recursive: true); 78 await new Directory(testMojomPath).create(recursive: true);
79
80 // //test_mojoms/single_package/public/interfaces/single_package.mojom
81 final singlePackageMojomFile = new File(path.join(testMojomPath,
82 'single_package', 'public', 'interfaces', 'single_package.mojom'));
83 await singlePackageMojomFile.create(recursive: true);
84 await singlePackageMojomFile.writeAsString(singlePacakgeMojomContents);
44 }); 85 });
45 86
46 tearDown(() async { 87 tearDown(() async {
47 await new Directory(testMojomPath).delete(recursive: true); 88 await new Directory(testMojomPath).delete(recursive: true);
48 }); 89 });
49 90
50 group('Commands', () { 91 group('Commands', () {
51 // //single_package 92 test('single', () async {
52 final singlePackagePath = path.join(scriptPath, 'single_package'); 93 String packagePath = await setupPackage(
53 // //single_package/.mojoms 94 scriptPath, 'single_package', 'single_package',
54 final singlePackageMojomsPath = path.join(singlePackagePath, '.mojoms'); 95 singlePackagePubspecContents);
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 96
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([ 97 await runCommand([
81 'single', 98 'single',
82 '-m', 99 '-m',
83 mojoSdk, 100 mojoSdk,
84 '-r', 101 '-r',
85 testMojomPath, 102 testMojomPath,
86 '-p', 103 '-p',
87 singlePackagePath 104 packagePath
88 ]); 105 ]);
89 106
90 // Should have: 107 // Should have:
91 // //single_package/lib/single_package/single_package.mojom.dart 108 // //single_package/lib/single_package/single_package.mojom.dart
92 final resultPath = path.join( 109 final resultPath = path.join(
93 singlePackageLibPath, 'single_package', 'single_package.mojom.dart'); 110 packagePath, 'lib', 'single_package', 'single_package.mojom.dart');
94 final resultFile = new File(resultPath); 111 final resultFile = new File(resultPath);
95 expect(await resultFile.exists(), isTrue); 112 expect(await resultFile.exists(), isTrue);
96 113
97 // There should be no stray .mojoms file haning around. 114 await destroyPackage(scriptPath, 'single_package');
98 final mojomsFile = new File(singlePackageMojomsPath);
99 expect(await mojomsFile.exists(), isFalse);
100 }); 115 });
101 116
102 test('gen', () async { 117 test('gen', () async {
118 String packagePath = await setupPackage(
119 scriptPath, 'single_package', 'single_package',
120 singlePackagePubspecContents);
121
103 await runCommand( 122 await runCommand(
104 ['gen', '-m', mojoSdk, '-r', testMojomPath, '-o', scriptPath]); 123 ['gen', '-m', mojoSdk, '-r', testMojomPath, '-o', scriptPath]);
105 124
106 // Should have: 125 // Should have:
107 // //single_package/lib/single_package/single_package.mojom.dart 126 // //single_package/lib/single_package/single_package.mojom.dart
108 final resultPath = path.join( 127 final resultPath = path.join(
109 singlePackageLibPath, 'single_package', 'single_package.mojom.dart'); 128 packagePath, 'lib', 'single_package', 'single_package.mojom.dart');
110 final resultFile = new File(resultPath); 129 final resultFile = new File(resultPath);
111 expect(await resultFile.exists(), isTrue); 130 expect(await resultFile.exists(), isTrue);
112 131
113 // There should be no stray .mojoms file haning around. 132 await destroyPackage(scriptPath, 'single_package');
114 final mojomsFile = new File(singlePackageMojomsPath); 133 });
115 expect(await mojomsFile.exists(), isFalse); 134
135 test('gen wrong name', () async {
136 String packagePath = await setupPackage(
137 scriptPath, 'wrong_name', 'single_package',
138 singlePackagePubspecContents);
139
140 await runCommand(
141 ['gen', '-m', mojoSdk, '-r', testMojomPath, '-o', scriptPath]);
142
143 final resultPath = path.join(
144 packagePath, 'lib', 'single_package', 'single_package.mojom.dart');
145 final resultFile = new File(resultPath);
146 expect(await resultFile.exists(), isTrue);
147
148 await destroyPackage(scriptPath, 'wrong_name');
116 }); 149 });
117 }); 150 });
118 } 151 }
OLDNEW
« no previous file with comments | « mojo/dart/packages/mojom/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698