| // Copyright 2024 The Flutter Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd. |
| |
| import 'dart:io'; |
| |
| import 'package:path/path.dart' as p; |
| import 'package:test/test.dart'; |
| |
| void main() { |
| final examplesWithExtensions = [ |
| ( |
| relativePublishLocation: p.join('..', 'dart_foo'), |
| sourceCodeLocation: p.join( |
| 'example', |
| 'packages_with_extensions', |
| 'dart_foo', |
| 'packages', |
| 'dart_foo_devtools_extension', |
| ), |
| ), |
| ( |
| relativePublishLocation: p.join('..', 'foo'), |
| sourceCodeLocation: p.join( |
| 'example', |
| 'packages_with_extensions', |
| 'foo', |
| 'packages', |
| 'foo_devtools_extension', |
| ), |
| ), |
| ( |
| relativePublishLocation: '.', |
| sourceCodeLocation: p.join( |
| 'example', |
| 'packages_with_extensions', |
| 'standalone_extension', |
| ), |
| ), |
| ]; |
| |
| group('devtools_extensions validate command succeeds', () { |
| for (final example in examplesWithExtensions) { |
| test(example.relativePublishLocation, () async { |
| final p = await Process.run('dart', [ |
| 'run', |
| 'devtools_extensions', |
| 'validate', |
| '-p', |
| example.relativePublishLocation, |
| ], workingDirectory: example.sourceCodeLocation); |
| expect(p.stderr, isEmpty); |
| }); |
| } |
| }); |
| |
| group('devtools_extensions validate command fails', () { |
| test('when config.yaml name contains invalid characters', () async { |
| final tempDir = Directory.systemTemp.createTempSync(); |
| try { |
| final extDir = Directory(p.join(tempDir.path, 'extension', 'devtools')) |
| ..createSync(recursive: true); |
| Directory(p.join(extDir.path, 'build')).createSync(recursive: true); |
| File(p.join(extDir.path, 'build', 'index.html')).writeAsStringSync(''); |
| File(p.join(extDir.path, 'config.yaml')).writeAsStringSync(''' |
| name: invalid-name-with-hyphens |
| issueTracker: https://www.google.com/ |
| version: 1.0.0 |
| materialIconCodePoint: "0xe50a" |
| '''); |
| File(p.join(tempDir.path, 'pubspec.yaml')).writeAsStringSync(''' |
| name: actual_package_name |
| environment: |
| sdk: ^3.2.0 |
| '''); |
| |
| final process = await Process.run('dart', [ |
| 'run', |
| 'devtools_extensions', |
| 'validate', |
| '-p', |
| tempDir.path, |
| ]); |
| expect( |
| process.stderr, |
| contains( |
| 'Validation error: The "name" field in config.yaml should only ' |
| 'contain lowercase letters, numbers, and underscores', |
| ), |
| ); |
| } finally { |
| tempDir.deleteSync(recursive: true); |
| } |
| }); |
| }); |
| } |