Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ jobs:
run: dart run dependency_validator
- name: Analysis
run: dart run dart_dev analyze
# Format check disabled for the Dart 3 upgrade. Dart 3.7+ uses a new
# formatter style; uncomment after a dedicated format PR.
# - name: Formatting
# if: ${{ matrix.sdk == 'stable' && matrix.os == 'ubuntu' }}
# run: dart run dart_dev format --check
- name: Formatting
if: ${{ matrix.sdk == 'stable' && matrix.os == 'ubuntu' }}
run: dart run dart_dev format --check
- name: Tests
run: dart run dart_dev test
10 changes: 3 additions & 7 deletions lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ Future<void> handleFastFormat(List<String> args) async {
final configFile = File(_paths.config);
if (configFile.existsSync()) {
final toolBuilder = FormatToolBuilder();
parseString(
content: configFile.readAsStringSync(),
).unit.accept(toolBuilder);
parseString(content: configFile.readAsStringSync()).unit
.accept(toolBuilder);
formatTool = toolBuilder
.formatDevTool; // could be null if no custom `format` entry found

Expand Down Expand Up @@ -274,10 +273,7 @@ void main(List<String> args) async {
''';
}

Future<void> runWithConfig(
List<String> args,
ConfigGetter configGetter,
) async {
Future<void> runWithConfig(List<String> args, ConfigGetter configGetter) async {
attachLoggerToStdio(args);

try {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/utils/organize_directives/organize_directives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import 'namespace_collector.dart';
///
/// Throws an ArgumentError if [sourceFileContents] cannot be parsed.
String organizeDirectives(String sourceFileContents) {
final directives = parseString(
content: sourceFileContents,
).unit.accept(NamespaceCollector())!;
final directives = parseString(content: sourceFileContents).unit
.accept(NamespaceCollector())!;

if (directives.isEmpty) {
return sourceFileContents;
Expand Down
1 change: 1 addition & 0 deletions test/functional/analyze_tool_functional_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@TestOn('vm')
@Timeout(Duration(seconds: 20))
library;

import 'package:test/test.dart';

import '../functional.dart';
Expand Down
44 changes: 21 additions & 23 deletions test/functional/format_tool_functional_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@TestOn('vm')
@Timeout(Duration(seconds: 20))
library;

import 'dart:io';

import 'package:test/test.dart';
Expand Down Expand Up @@ -38,29 +39,26 @@ void main() {
);
});

test(
'passes configured languageVersion to dart format when supported',
() async {
const projectPath =
'test/functional/fixtures/format/language_version/dart_format_configured/';

final process = await runDevToolFunctionalTest('format', projectPath);
final stdoutFuture = process.stdoutStream().toList();

await process.shouldExit(0);

final stdout = (await stdoutFuture).join('\n');
final expectedCommandPattern = RegExp(
[
RegExp.escape('dart format'),
RegExp.escape('--language-version=3.0'),
r'lib[\\/]main\.dart',
].join(r'\s+'),
);

expect(stdout, contains(expectedCommandPattern));
},
);
test('passes configured languageVersion to dart format when supported', () async {
const projectPath =
'test/functional/fixtures/format/language_version/dart_format_configured/';

final process = await runDevToolFunctionalTest('format', projectPath);
final stdoutFuture = process.stdoutStream().toList();

await process.shouldExit(0);

final stdout = (await stdoutFuture).join('\n');
final expectedCommandPattern = RegExp(
[
RegExp.escape('dart format'),
RegExp.escape('--language-version=3.0'),
r'lib[\\/]main\.dart',
].join(r'\s+'),
);

expect(stdout, contains(expectedCommandPattern));
});
});
}

Expand Down
1 change: 1 addition & 0 deletions test/functional/null_safety_functional_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@TestOn('vm')
@Timeout(Duration(seconds: 20))
library;

import 'package:test/test.dart';

import '../functional.dart';
Expand Down
1 change: 1 addition & 0 deletions test/tools/analyze_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/src/dart_dev_tool.dart';
Expand Down
1 change: 1 addition & 0 deletions test/tools/compound_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:dart_dev/dart_dev.dart';
import 'package:dart_dev/src/tools/compound_tool.dart';
Expand Down
65 changes: 27 additions & 38 deletions test/tools/format_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'dart:io';

import 'package:args/args.dart';
Expand Down Expand Up @@ -442,11 +443,7 @@ void main() {
expect(execution.formatProcess!.executable, exe.dart);
expect(
execution.formatProcess!.args,
orderedEquals([
'format',
'--language-version=latest',
'.',
]),
orderedEquals(['format', '--language-version=latest', '.']),
);
expect(execution.formatProcess!.mode, ProcessStartMode.inheritStdio);
});
Expand Down Expand Up @@ -545,31 +542,28 @@ void main() {
},
);

test(
'dart_style:format uses configured language version for dart_style >=3.0.0',
() {
final context = DevToolExecutionContext();
final execution = buildExecution(
context,
formatter: Formatter.dartStyle,
languageVersion: '3.0',
defaultMode: FormatMode.overwrite,
path: 'test/tools/fixtures/format/has_dart_style_v3',
);
expect(execution.exitCode, isNull);
expect(execution.formatProcess!.executable, exe.dart);
expect(
execution.formatProcess!.args,
orderedEquals([
'run',
'dart_style:format',
'--language-version=3.0',
'.',
]),
);
expect(execution.formatProcess!.mode, ProcessStartMode.inheritStdio);
},
);
test('dart_style:format uses configured language version for dart_style >=3.0.0', () {
final context = DevToolExecutionContext();
final execution = buildExecution(
context,
formatter: Formatter.dartStyle,
languageVersion: '3.0',
defaultMode: FormatMode.overwrite,
path: 'test/tools/fixtures/format/has_dart_style_v3',
);
expect(execution.exitCode, isNull);
expect(execution.formatProcess!.executable, exe.dart);
expect(
execution.formatProcess!.args,
orderedEquals([
'run',
'dart_style:format',
'--language-version=3.0',
'.',
]),
);
expect(execution.formatProcess!.mode, ProcessStartMode.inheritStdio);
});

test('dartFormat with args', () {
final argParser = FormatTool().toCommand('t').argParser;
Expand Down Expand Up @@ -608,11 +602,7 @@ void main() {
expect(execution.formatProcess!.executable, exe.dart);
expect(
execution.formatProcess!.args,
orderedEquals([
'format',
'--language-version=3.0',
'.',
]),
orderedEquals(['format', '--language-version=3.0', '.']),
);
expect(execution.formatProcess!.mode, ProcessStartMode.inheritStdio);
});
Expand Down Expand Up @@ -741,9 +731,8 @@ void main() {

setUp(() {
argParser = FormatTool().toCommand('test_format').argParser;
usageException = DevToolExecutionContext(
commandName: 'test_format',
).usageException;
usageException = DevToolExecutionContext(commandName: 'test_format')
.usageException;
});

test('--check and --dry-run and --overwrite throws UsageException', () {
Expand Down
1 change: 1 addition & 0 deletions test/tools/function_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/dart_dev.dart';
Expand Down
9 changes: 6 additions & 3 deletions test/tools/process_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'dart:async';
import 'dart:convert';

Expand All @@ -22,9 +23,11 @@ void main() {
});

test('can run from a custom working directory', () async {
final tool =
DevTool.fromProcess('pwd', [], workingDirectory: 'lib')
as ProcessTool;
final tool = DevTool.fromProcess(
'pwd',
[],
workingDirectory: 'lib',
) as ProcessTool;
expect(await tool.run(), isZero);
final stdout =
(await tool.process!.stdout.transform(utf8.decoder).join('')).trim();
Expand Down
1 change: 1 addition & 0 deletions test/tools/test_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/src/dart_dev_tool.dart';
Expand Down
46 changes: 22 additions & 24 deletions test/tools/webdev_serve_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/src/dart_dev_tool.dart';
Expand Down Expand Up @@ -215,34 +216,31 @@ void main() {
);
});

test(
'returns config exit code and logs if webdev is not globally activate',
() {
overrideAnsiOutput(false, () {
expect(
Logger.root.onRecord,
emitsThrough(
severeLogOf(
allOf(
contains('webdev serve could not run'),
contains(
"dart pub global activate webdev '$webdevVersionConstraint'",
),
test('returns config exit code and logs if webdev is not globally activate', () {
overrideAnsiOutput(false, () {
expect(
Logger.root.onRecord,
emitsThrough(
severeLogOf(
allOf(
contains('webdev serve could not run'),
contains(
"dart pub global activate webdev '$webdevVersionConstraint'",
),
),
),
);
),
);

expect(
buildExecution(
DevToolExecutionContext(),
environment: pubCacheWithoutWebdev.envOverride,
).exitCode,
ExitCode.config.code,
);
});
},
);
expect(
buildExecution(
DevToolExecutionContext(),
environment: pubCacheWithoutWebdev.envOverride,
).exitCode,
ExitCode.config.code,
);
});
});

group('returns a WebdevServeExecution', () {
test('(default)', () {
Expand Down
1 change: 1 addition & 0 deletions test/utils/arg_results_utils_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:dart_dev/src/utils/arg_results_utils.dart';
import 'package:test/test.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@TestOn('vm')
library;

import 'package:args/args.dart';
import 'package:dart_dev/src/utils/assert_no_positional_args_before_separator.dart';
import 'package:test/test.dart';
Expand Down
Loading
Loading