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
4 changes: 4 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ jobs:
- test/commands/create/flutter_package/flutter_pkg_test.dart
- test/commands/create/flutter_plugin/flutter_plugin_test.dart

# E2E tests for the `packages check licenses` command
- test/commands/packages/check/licenses/licenses_allowed_test.dart
- test/commands/packages/check/licenses/licenses_forbidden_test.dart

steps:
- name: 📚 Git Checkout
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'dart:io';

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../../../../../helpers/helpers.dart';

/// Objectives:
///
/// * Generate a new Dart project using (`dart create`)
/// * Add dependencies to `pubspec.yaml` with an MIT license
/// * Run `very_good packages check licenses --allowed="MIT"` and expect success
void main() {
test(
'packages check licenses --allowed="MIT"',
timeout: const Timeout(Duration(minutes: 2)),
withRunner((commandRunner, logger, updater, logs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

const projectName = 'my_dart_project';
await expectSuccessfulProcessResult(
'dart',
['create', 'my_dart_project', '--no-pub'],
workingDirectory: tempDirectory.path,
);
final projectPath = path.join(tempDirectory.path, projectName);
await expectSuccessfulProcessResult(
'dart',
['pub', 'add', 'formz'],
workingDirectory: projectPath,
);
await expectSuccessfulProcessResult(
'dart',
['pub', 'get'],
workingDirectory: projectPath,
);

final relativeProjectPath = path.relative(
projectPath,
from: Directory.current.path,
);
final resultAllowed = await commandRunner.run(
[
'packages',
'check',
'licenses',
'--allowed=MIT',
relativeProjectPath,
],
);
expect(
resultAllowed,
equals(ExitCode.success.code),
reason: 'Should succeed when allowed licenses are used',
);
}),
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'dart:io';

import 'package:mason/mason.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../../../../../helpers/helpers.dart';

/// Objectives:
///
/// * Generate a new Dart project using (`dart create`)
/// * Add dependencies to `pubspec.yaml` with an MIT license
/// * Run `very_good packages check licenses --forbidden="MIT"` and expect
/// failure
void main() {
test(
'packages check licenses --forbidden="MIT"',
timeout: const Timeout(Duration(minutes: 2)),
withRunner((commandRunner, logger, updater, logs) async {
final tempDirectory = Directory.systemTemp.createTempSync();
addTearDown(() => tempDirectory.deleteSync(recursive: true));

const projectName = 'my_dart_project';
await expectSuccessfulProcessResult(
'dart',
['create', 'my_dart_project', '--no-pub'],
workingDirectory: tempDirectory.path,
);
final projectPath = path.join(tempDirectory.path, projectName);
await expectSuccessfulProcessResult(
'dart',
['pub', 'add', 'formz'],
workingDirectory: projectPath,
);
await expectSuccessfulProcessResult(
'dart',
['pub', 'get'],
workingDirectory: projectPath,
);

final relativeProjectPath = path.relative(
projectPath,
from: Directory.current.path,
);

final resultForbidden = await commandRunner.run(
[
'packages',
'check',
'licenses',
'--forbidden=MIT',
relativeProjectPath,
],
);
expect(
resultForbidden,
equals(ExitCode.config.code),
reason: 'Should fail when forbidden licenses are used',
);
}),
);
}