-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dart_cli): stub process.run in unit tests (#440)
- Loading branch information
Showing
3 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:universal_io/io.dart'; | ||
import 'package:very_good_cli/src/cli/cli.dart'; | ||
|
||
class _FakeProcess { | ||
Future<ProcessResult> run( | ||
String command, | ||
List<String> args, { | ||
bool runInShell = false, | ||
String? workingDirectory, | ||
}) { | ||
throw UnimplementedError(); | ||
} | ||
} | ||
|
||
void main() { | ||
group('ProcessOverrides', () { | ||
group('runZoned', () { | ||
test('uses default Process.run when not specified', () { | ||
ProcessOverrides.runZoned(() { | ||
final overrides = ProcessOverrides.current; | ||
expect(overrides!.runProcess, isA<Function>()); | ||
}); | ||
}); | ||
|
||
test('uses custom Process.run when specified', () { | ||
final process = _FakeProcess(); | ||
ProcessOverrides.runZoned( | ||
() { | ||
final overrides = ProcessOverrides.current; | ||
expect(overrides!.runProcess, equals(process.run)); | ||
}, | ||
runProcess: process.run, | ||
); | ||
}); | ||
|
||
test( | ||
'uses current Process.run when not specified ' | ||
'and zone already contains a Process.run', () { | ||
final process = _FakeProcess(); | ||
ProcessOverrides.runZoned( | ||
() { | ||
ProcessOverrides.runZoned(() { | ||
final overrides = ProcessOverrides.current; | ||
expect(overrides!.runProcess, equals(process.run)); | ||
}); | ||
}, | ||
runProcess: process.run, | ||
); | ||
}); | ||
|
||
test( | ||
'uses nested Process.run when specified ' | ||
'and zone already contains a Process.run', () { | ||
final rootProcess = _FakeProcess(); | ||
ProcessOverrides.runZoned( | ||
() { | ||
final nestedProcess = _FakeProcess(); | ||
final overrides = ProcessOverrides.current; | ||
expect(overrides!.runProcess, equals(rootProcess.run)); | ||
ProcessOverrides.runZoned( | ||
() { | ||
final overrides = ProcessOverrides.current; | ||
expect(overrides!.runProcess, equals(nestedProcess.run)); | ||
}, | ||
runProcess: nestedProcess.run, | ||
); | ||
}, | ||
runProcess: rootProcess.run, | ||
); | ||
}); | ||
}); | ||
}); | ||
} |