Skip to content

Commit

Permalink
Fix watch mode not quitting (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhnroyal authored Sep 4, 2023
1 parent 6589559 commit c4026f3
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/custom_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased patch

- Sort lints by severity in the command line (thanks to @kuhnroyal)
- Fix watch mode not quitting with `q` (thanks to @kuhnroyal)

## 0.5.3 - 2023-08-29

Expand Down
3 changes: 2 additions & 1 deletion packages/custom_lint/lib/custom_lint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ Future<void> _startWatchMode(
);
break;
case 'q':
// Let's quit the command line
// Let's quit the command line
return;
default:
// Unknown command. Nothing to do
}
Expand Down
1 change: 1 addition & 0 deletions packages/custom_lint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dev_dependencies:
freezed: ^2.3.2
json_serializable: ^6.5.4
test: ^1.20.2
test_process: ^2.1.0

executables:
custom_lint: custom_lint
150 changes: 150 additions & 0 deletions packages/custom_lint/test/cli_process_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';

import 'package:custom_lint/src/package_utils.dart';
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';

import 'cli_test.dart';
import 'create_project.dart';
Expand Down Expand Up @@ -269,4 +270,153 @@ So, because custom_lint_client depends on test_lint from path, version solving f
},
);
});

group('Watch mode', () {
group('[q] quits', () {
test('with exit code 0 when no lints', () async {
final workspace = createTemporaryDirectory();

final process = await TestProcess.start(
'dart',
[
customLintBinPath,
'--watch',
],
workingDirectory: workspace.path,
);

// Ignore first lines
await process.stdout.skip(4);
expect(await process.stdout.next, 'q: Quit');

process.stdin.write('q');

await expectLater(process.stdout.rest, emitsThrough(emitsDone));
await process.shouldExit(0);
});

test('with exit code 1 when there are lints', () async {
final workspace = createTemporaryDirectory();

final plugin = createPlugin(
name: 'test_lint',
main: createPluginSource([
TestLintRule(
code: 'hello_world',
message: 'Hello world',
),
]),
);

createLintUsage(
parent: workspace,
source: {'lib/main.dart': 'void fn() {}'},
plugins: {'test_lint': plugin.uri},
name: 'test_app',
);

final process = await TestProcess.start(
'dart',
[
customLintBinPath,
'--watch',
],
workingDirectory: workspace.path,
);

// Ignore first lines
await process.stdout.skip(6);
expect(await process.stdout.next, 'q: Quit');

process.stdin.write('q');

await expectLater(process.stdout.rest, emitsThrough(emitsDone));
await process.shouldExit(1);
});
});

group('[r] reloads', () {
test('with no lints', () async {
final workspace = createTemporaryDirectory();

final process = await TestProcess.start(
'dart',
[
customLintBinPath,
'--watch',
],
workingDirectory: workspace.path,
);

// Ignore first lines
expect(await process.stdout.next, 'No issues found!');
await process.stdout.skip(3);
expect(await process.stdout.next, 'q: Quit');

process.stdin.write('r');

// Skip empty lines
await process.stdout.skip(2);
expect(await process.stdout.next, 'Manual Reload...');
expect(await process.stdout.next, 'No issues found!');

process.stdin.write('q');

await process.shouldExit(0);
});

test('with lints', () async {
final workspace = createTemporaryDirectory();

final plugin = createPlugin(
name: 'test_lint',
main: createPluginSource([
TestLintRule(
code: 'hello_world',
message: 'Hello world',
),
]),
);

createLintUsage(
parent: workspace,
source: {'lib/main.dart': 'void fn() {}'},
plugins: {'test_lint': plugin.uri},
name: 'test_app',
);

final process = await TestProcess.start(
'dart',
[
customLintBinPath,
'--watch',
],
workingDirectory: workspace.path,
);

// Ignore first lines
await process.stdout.skip(2);
expect(
await process.stdout.next,
' test_app/lib/main.dart:1:6 • Hello world • hello_world • INFO',
);
await process.stdout.skip(3);
expect(await process.stdout.next, 'q: Quit');

process.stdin.write('r');

// Skip empty lines
await process.stdout.skip(2);
expect(await process.stdout.next, 'Manual Reload...');
expect(
await process.stdout.next,
' test_app/lib/main.dart:1:6 • Hello world • hello_world • INFO',
);

process.stdin.write('q');

await process.shouldExit(1);
});
});
});
}

1 comment on commit c4026f3

@vercel
Copy link

@vercel vercel bot commented on c4026f3 Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.