@@ -45,6 +45,8 @@ const expectedUsage = [
4545const responseBody =
4646 '{"name": "very_good_cli", "versions": ["0.4.0", "0.3.3"]}' ;
4747
48+ const latestVersion = '9999.0.0' ;
49+
4850void main () {
4951 group ('VeryGoodCommandRunner' , () {
5052 late List <String > printLogs;
@@ -70,14 +72,9 @@ void main() {
7072
7173 when (() => analytics.firstRun).thenReturn (false );
7274 when (() => analytics.enabled).thenReturn (false );
73-
7475 when (
75- () => pubUpdater.isUpToDate (
76- packageName: any (named: 'packageName' ),
77- currentVersion: any (named: 'currentVersion' ),
78- ),
79- ).thenAnswer ((_) => Future .value (true ));
80-
76+ () => pubUpdater.getLatestVersion (any ()),
77+ ).thenAnswer ((_) async => packageVersion);
8178 when (
8279 () => pubUpdater.update (
8380 packageName: any (named: 'packageName' ),
@@ -101,18 +98,17 @@ void main() {
10198
10299 group ('run' , () {
103100 test ('prompts for update when newer version exists' , () async {
104- when (() => pubUpdater.isUpToDate (
105- packageName: any (named: 'packageName' ),
106- currentVersion: any (named: 'currentVersion' ),
107- )).thenAnswer ((_) => Future .value (false ));
101+ when (
102+ () => pubUpdater.getLatestVersion (any ()),
103+ ).thenAnswer ((_) async => latestVersion);
108104
109105 when (() => logger.prompt (any ())).thenReturn ('n' );
110106
111107 final result = await commandRunner.run (['--version' ]);
112108 expect (result, equals (ExitCode .success.code));
113109 verify (
114110 () => logger.info (
115- lightYellow.wrap ('A new release of $packageName is available.' ) ,
111+ '''${ lightYellow .wrap ('A new version of $packageName is available:' )} ${ lightCyan . wrap ( packageVersion )} -> ${ lightCyan . wrap ( latestVersion )}''' ,
116112 ),
117113 ).called (1 );
118114 verify (
@@ -122,10 +118,7 @@ void main() {
122118
123119 test ('handles pub update errors gracefully' , () async {
124120 when (
125- () => pubUpdater.isUpToDate (
126- packageName: any (named: 'packageName' ),
127- currentVersion: any (named: 'currentVersion' ),
128- ),
121+ () => pubUpdater.getLatestVersion (any ()),
129122 ).thenThrow (Exception ('oops' ));
130123
131124 final result = await commandRunner.run (['--version' ]);
@@ -138,17 +131,16 @@ void main() {
138131 });
139132
140133 test ('updates on "y" response when newer version exists' , () async {
141- when (() => pubUpdater.isUpToDate (
142- packageName: any (named: 'packageName' ),
143- currentVersion: any (named: 'currentVersion' ),
144- )).thenAnswer ((_) => Future .value (false ));
134+ when (
135+ () => pubUpdater.getLatestVersion (any ()),
136+ ).thenAnswer ((_) async => latestVersion);
145137
146138 when (() => logger.prompt (any ())).thenReturn ('y' );
147139 when (() => logger.progress (any ())).thenReturn (([String ? message]) {});
148140
149141 final result = await commandRunner.run (['--version' ]);
150142 expect (result, equals (ExitCode .success.code));
151- verify (() => logger.progress ('Updating' )).called (1 );
143+ verify (() => logger.progress ('Updating to $ latestVersion ' )).called (1 );
152144 });
153145
154146 test ('prompts for analytics collection on first run (y)' , () async {
0 commit comments