Files
sdk/pkg/dartdev/test/core_test.dart
T
Sam Rawlins 539840f91c dartdev: Simplify some JSON-parsing code; remove dead code
* In `_handleServerResponse`, use if-case with map patterns to avoid
  casts and null checks and repeatedly fetching map values.
* Remove the castStringKeyedMap utility. After some other changes,
  most call-sites passed in a Map, so then half of the utility is not
  used. In the others, it seemed simplest to use `as Map` and `.cast()`
  inline.
* Change some `dynamic` local variables to be `Object?` instead.
* Replace `DartdevCommand.project` getter and `_project` field with a
  single final field.
* Remove unused properties from `Project` and unused `PackageConfig`
  class.
* Remove associated tests.

Change-Id: I1f626ecc0e6e4d27ef24f65959fd4cb54fb5fc92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412980
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-02-28 14:54:14 -08:00

127 lines
3.5 KiB
Dart

// Copyright (c) 2020, 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:dartdev/src/commands/analyze.dart';
import 'package:dartdev/src/commands/compile.dart';
import 'package:dartdev/src/commands/create.dart';
import 'package:dartdev/src/commands/fix.dart';
import 'package:dartdev/src/commands/run.dart';
import 'package:dartdev/src/commands/test.dart';
import 'package:dartdev/src/core.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'utils.dart';
void main() {
initGlobalState();
group('DartdevCommand', _dartdevCommand);
group('Project', _project);
}
void _dartdevCommand() {
void assertDartdevCommandProperties(
DartdevCommand command, String name, String expectedUsagePath,
[int subcommandCount = 0]) {
expect(command, isNotNull);
expect(command.name, name);
expect(command.description, isNotEmpty);
expect(command.project, isNotNull);
expect(command.argParser, isNotNull);
expect(command.subcommands.length, subcommandCount);
}
test('analyze', () {
assertDartdevCommandProperties(AnalyzeCommand(), 'analyze', 'analyze');
});
test('compile', () {
assertDartdevCommandProperties(CompileCommand(), 'compile', 'compile', 7);
});
test('compile/js', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['js'] as DartdevCommand,
'js',
'compile/js');
});
test('compile/js-dev', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['js-dev'] as DartdevCommand,
'js-dev',
'compile/js-dev');
});
test('compile/jit-snapshot', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['jit-snapshot'] as DartdevCommand,
'jit-snapshot',
'compile/jit-snapshot');
});
test('compile/kernel', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['kernel'] as DartdevCommand,
'kernel',
'compile/kernel');
});
test('compile/exe', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['exe'] as DartdevCommand,
'exe',
'compile/exe');
});
test('compile/aot-snapshot', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['aot-snapshot'] as DartdevCommand,
'aot-snapshot',
'compile/aot-snapshot');
});
test('compile/wasm', () {
assertDartdevCommandProperties(
CompileCommand().subcommands['wasm'] as DartdevCommand,
'wasm',
'compile/wasm');
});
test('create', () {
assertDartdevCommandProperties(CreateCommand(), 'create', 'create');
});
test('fix', () {
assertDartdevCommandProperties(FixCommand(), 'fix', 'fix');
});
test('run', () {
assertDartdevCommandProperties(RunCommand(verbose: false), 'run', 'run');
});
test('test', () {
assertDartdevCommandProperties(TestCommand(), 'test', 'test');
});
}
void _project() {
test('hasPubspecFile positive', () {
final p = project();
Project coreProj = Project.fromDirectory(p.dir);
expect(coreProj.hasPubspecFile, isTrue);
});
test('hasPubspecFile negative', () {
final p = project();
var pubspec = File(path.join(p.dirPath, 'pubspec.yaml'));
pubspec.deleteSync();
Project coreProj = Project.fromDirectory(p.dir);
expect(coreProj.hasPubspecFile, isFalse);
});
}