Skip to content

Commit

Permalink
removes Colorize from VersionCheckResult.explanation
Browse files Browse the repository at this point in the history
adds empty VersionCheckResult to console_diff_reporter_test
  • Loading branch information
devmil committed Dec 19, 2023
1 parent 5949ccf commit 8f87784
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
12 changes: 5 additions & 7 deletions lib/src/cli/commands/version_check.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:io';

import 'package:colorize/colorize.dart';
import 'package:pub_semver/pub_semver.dart';

import '../../../api_tool.dart';
Expand Down Expand Up @@ -104,17 +103,16 @@ abstract class VersionCheck {
newVersion: newVersion,
neededVersion: null,
explanation:
'$prefix Got "${Colorize(newVersion.toString()).bold()}" expected > "${Colorize(oldVersion.toString()).bold()}" (pre-release but changes)',
'$prefix Got "$newVersion" expected > "$oldVersion" (pre-release but changes)',
);
}
final explanation = containsAnyChanges
? 'which is > "${Colorize(oldVersion.toString()).bold()}" (pre-release but changes)'
? 'which is > "$oldVersion" (pre-release but changes)'
: 'and no changes';
return VersionCheckResult.success(
oldVersion: oldVersion,
newVersion: newVersion,
explanation:
'$prefix Got "${Colorize(newVersion.toString()).bold()}" $explanation');
explanation: '$prefix Got "$newVersion" $explanation');
}

Version expectedMinVersion =
Expand All @@ -141,15 +139,15 @@ abstract class VersionCheck {
newVersion: newVersion,
neededVersion: expectedMinVersion,
explanation:
'Got "${Colorize(newVersion.toString()).bold()}" expected >= "${Colorize(expectedMinVersion.toString()).bold()}" ($versionExplanation)',
'Got "$newVersion" expected >= "$expectedMinVersion" ($versionExplanation)',
);
} else {
return VersionCheckResult.success(
oldVersion: oldVersion,
newVersion: newVersion,
neededVersion: expectedMinVersion,
explanation:
'Got "${Colorize(newVersion.toString()).bold()}" which is >= "${Colorize(expectedMinVersion.toString()).bold()}" ($versionExplanation)',
'Got "$newVersion" which is >= "$expectedMinVersion" ($versionExplanation)',
);
}
}
Expand Down
25 changes: 19 additions & 6 deletions test/unit_tests/diff/report/console_diff_reporter_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import 'package:dart_apitool/api_tool.dart';
import 'package:dart_apitool/src/cli/commands/version_check.dart';
import 'package:dart_apitool/src/diff/report/console_diff_reporter.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:test/test.dart';

void main() {
group('ConsoleDiffReporter', () {
late ConsoleDiffReporter reporter;
final anyVersionCheckResult = VersionCheckResult.success(
oldVersion: Version(0, 0, 0),
newVersion: Version(0, 0, 0),
explanation: '',
);

setUp(() {
reporter = ConsoleDiffReporter();
Expand Down Expand Up @@ -47,37 +54,43 @@ void main() {

test('Can handle empty diff report', () {
final diffResult = createEmptyDiffResult();
expect(() => reporter.generateReport(diffResult), returnsNormally);
expect(() => reporter.generateReport(diffResult, anyVersionCheckResult),
returnsNormally);
});
test('Can handle diff report with only one breaking change', () {
final diffResult = createEmptyDiffResult();
addBreakingChange(diffResult, changeCode: ApiChangeCode.ci01);
expect(() => reporter.generateReport(diffResult), returnsNormally);
expect(() => reporter.generateReport(diffResult, anyVersionCheckResult),
returnsNormally);
});
test('Can handle diff report with multiple breaking changes', () {
final diffResult = createEmptyDiffResult();
addBreakingChange(diffResult, changeCode: ApiChangeCode.ci01);
addBreakingChange(diffResult, changeCode: ApiChangeCode.ci04);
expect(() => reporter.generateReport(diffResult), returnsNormally);
expect(() => reporter.generateReport(diffResult, anyVersionCheckResult),
returnsNormally);
});
test('Can handle diff report with only one non-breaking change', () {
final diffResult = createEmptyDiffResult();
addNonBreakingChange(diffResult, changeCode: ApiChangeCode.ci02);
expect(() => reporter.generateReport(diffResult), returnsNormally);
expect(() => reporter.generateReport(diffResult, anyVersionCheckResult),
returnsNormally);
});
test('Can handle diff report with multiple non-breaking changes', () {
final diffResult = createEmptyDiffResult();
addNonBreakingChange(diffResult, changeCode: ApiChangeCode.ci02);
addNonBreakingChange(diffResult, changeCode: ApiChangeCode.ci05);
expect(() => reporter.generateReport(diffResult), returnsNormally);
expect(() => reporter.generateReport(diffResult, anyVersionCheckResult),
returnsNormally);
});
test('Can handle diff report with breaking and non-breaking changes', () {
final diffResult = createEmptyDiffResult();
addBreakingChange(diffResult, changeCode: ApiChangeCode.ci01);
addNonBreakingChange(diffResult, changeCode: ApiChangeCode.ci02);
addBreakingChange(diffResult, changeCode: ApiChangeCode.ci04);
addNonBreakingChange(diffResult, changeCode: ApiChangeCode.ci05);
expect(() => reporter.generateReport(diffResult), returnsNormally);
expect(() => reporter.generateReport(diffResult, anyVersionCheckResult),
returnsNormally);
});
});
}

0 comments on commit 8f87784

Please sign in to comment.