Skip to content

Commit

Permalink
test: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dickermoshe committed Sep 19, 2024
1 parent cb97d93 commit dfd3317
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 51 deletions.
19 changes: 13 additions & 6 deletions packages/custom_lint/lib/src/workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,22 @@ publish_to: 'none'

void _writePubspecDependencies(StringBuffer buffer) {
final uniqueDependencyNames = projects.expand((e) sync* {
yield* e.pubspec.dependencies.keys;
yield* e.pubspec.devDependencies.keys;
yield* e.pubspec.dependencyOverrides.keys;
}).toSet();

final dependenciesByName = {
for (final name in uniqueDependencyNames)
name: (
dependencies: projects
.map((project) {
final dependency = project.pubspec.dependencies[name];
if (dependency == null) return null;
return (project: project, dependency: dependency);
})
.nonNulls
.toList(),
devDependencies: projects
.map((project) {
final dependency = project.pubspec.devDependencies[name];
Expand Down Expand Up @@ -674,7 +683,10 @@ publish_to: 'none'
? ' any'
: _buildDependencyConstraint(
name,
allDependencies.devDependencies,
[
...allDependencies.devDependencies,
...allDependencies.dependencies
],
workingDirectory: workingDirectory,
fileName: 'pubspec.yaml',
);
Expand Down Expand Up @@ -943,11 +955,6 @@ class CustomLintProject {
errorStackTrace: stack,
);
});
projectPubspec.devDependencies.entries
.followedBy(projectPubspec.dependencies.entries)
.groupListsBy((element) => element.key)
.entries
.map((e) => e.value);

final dependencyMap = <String, Dependency>{
...projectPubspec.dependencies,
Expand Down
95 changes: 50 additions & 45 deletions packages/custom_lint/test/cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,63 +164,68 @@ No issues found!
expect(process.exitCode, 0);
});

test('CLI lists warnings from all plugins and set exit code', () async {
final plugin =
createPlugin(name: 'test_lint', main: helloWordPluginSource);
final plugin2 =
createPlugin(name: 'test_lint2', main: oyPluginSource);

final app = createLintUsage(
source: {
'lib/main.dart': 'void fn() {}',
'lib/another.dart': 'void fail() {}',
},
plugins: {'test_lint': plugin.uri, 'test_lint2': plugin2.uri},
name: 'test_app',
);
for (final installAsDevDependency in [false, true]) {
test(
'CLI lists warnings from all plugins and set exit code installAsDevDependency: $installAsDevDependency',
() async {
final plugin =
createPlugin(name: 'test_lint', main: helloWordPluginSource);
final plugin2 =
createPlugin(name: 'test_lint2', main: oyPluginSource);

final app = createLintUsage(
source: {
'lib/main.dart': 'void fn() {}',
'lib/another.dart': 'void fail() {}',
},
plugins: {'test_lint': plugin.uri, 'test_lint2': plugin2.uri},
name: 'test_app',
installAsDevDependency: installAsDevDependency,
);

final process = await Process.start(
'dart',
[
customLintBinPath,
'--format',
format,
],
workingDirectory: app.path,
);
final process = await Process.start(
'dart',
[
customLintBinPath,
'--format',
format,
],
workingDirectory: app.path,
);

final out = process.stdout.map(utf8.decode);
final err = process.stderr.map(utf8.decode);
final out = process.stdout.map(utf8.decode);
final err = process.stderr.map(utf8.decode);

expect(err, emitsDone);
expect(err, emitsDone);

if (format == 'json') {
expect(
out.join(),
completion(
equals('${jsonLints(app.resolveSymbolicLinksSync())}\n'),
),
);
} else {
expect(
out.join(),
completion(
allOf(
startsWith('Analyzing...'),
endsWith('''
if (format == 'json') {
expect(
out.join(),
completion(
equals('${jsonLints(app.resolveSymbolicLinksSync())}\n'),
),
);
} else {
expect(
out.join(),
completion(
allOf(
startsWith('Analyzing...'),
endsWith('''
lib/another.dart:1:6 • Hello world • hello_world • INFO
lib/another.dart:1:6 • Oy • oy • INFO
lib/main.dart:1:6 • Hello world • hello_world • INFO
lib/main.dart:1:6 • Oy • oy • INFO
4 issues found.
'''),
),
),
),
);
}
expect(await process.exitCode, 1);
});
);
}
expect(await process.exitCode, 1);
});
}
});
}
}
Expand Down

0 comments on commit dfd3317

Please sign in to comment.