Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare to publish v3 Fixes #12
- Loading branch information
Showing
11 changed files
with
150 additions
and
70 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
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 |
---|---|---|
@@ -1,70 +1,105 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:io/ansi.dart' as ansi; | ||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
|
||
import 'utils.dart'; | ||
|
||
const pubPlaceHolder = 'PUB'; | ||
const dartPlaceHolder = 'DART'; | ||
|
||
void expectBuildCleanImpl( | ||
Future<void> expectBuildCleanImpl( | ||
String workingDir, | ||
List<String> command, { | ||
String? packageRelativeDirectory, | ||
}) { | ||
}) async { | ||
if (command.isEmpty) { | ||
throw ArgumentError.value(command, 'customCommand', 'Cannot be empty'); | ||
} | ||
|
||
final repoRoot = | ||
_runProc('git', ['rev-parse', '--show-toplevel'], workingDir); | ||
await _runProc('git', ['rev-parse', '--show-toplevel'], workingDir); | ||
final pkgDir = p.join(repoRoot, packageRelativeDirectory); | ||
if (!p.equals(pkgDir, workingDir)) { | ||
throw StateError('Expected the git root ($repoRoot) ' | ||
'to match the current directory ($workingDir).'); | ||
throw StateError( | ||
'Expected the git root ($repoRoot) ' | ||
'to match the current directory ($workingDir).', | ||
); | ||
} | ||
|
||
// 1 - get a list of modified files files - should be empty | ||
expect( | ||
_changedGeneratedFiles(workingDir), | ||
await _changedGeneratedFiles(workingDir), | ||
isEmpty, | ||
reason: 'The working directory should be clean before running build.', | ||
); | ||
|
||
var executable = command.first; | ||
if (executable == pubPlaceHolder) { | ||
executable = pubPath; | ||
} else if (executable == 'DART') { | ||
if (executable == 'DART') { | ||
executable = dartPath; | ||
} | ||
|
||
final arguments = command.skip(1).toList(); | ||
|
||
// 2 - run build - should be no output, since nothing should change | ||
final result = _runProc(executable, arguments, workingDir); | ||
final result = await _runProc(executable, arguments, workingDir); | ||
|
||
expectResultOutputSucceeds(result); | ||
|
||
// 3 - get a list of modified files after the build - should still be empty | ||
expect(_changedGeneratedFiles(workingDir), isEmpty); | ||
expect(await _changedGeneratedFiles(workingDir), isEmpty); | ||
} | ||
|
||
void expectResultOutputSucceeds(String result) { | ||
expect(result, | ||
contains(RegExp(r'\[INFO\] Succeeded after .+ with \d+ outputs'))); | ||
expect( | ||
result, | ||
contains(RegExp(r'\[INFO\] Succeeded after .+ with \d+ outputs')), | ||
); | ||
} | ||
|
||
String _changedGeneratedFiles(String workingDir) => | ||
Future<String> _changedGeneratedFiles(String workingDir) => | ||
_runProc('git', ['diff'], workingDir); | ||
|
||
String _runProc(String proc, List<String> args, String workingDir) { | ||
final result = Process.runSync(proc, args, workingDirectory: workingDir); | ||
Future<String> _runProc( | ||
String proc, | ||
List<String> args, | ||
String workingDir, | ||
) async { | ||
print( | ||
'Running: `${ansi.cyan.wrap( | ||
[proc, ...args].join(' '), | ||
)}` in `${ansi.cyan.wrap(workingDir)}`', | ||
); | ||
|
||
if (result.exitCode != 0) { | ||
print(result.stdout); | ||
print(result.stderr); | ||
throw ProcessException(proc, args, 'Process failed', result.exitCode); | ||
final process = await Process.start(proc, args, workingDirectory: workingDir); | ||
|
||
Future<void> transform( | ||
Stream<List<int>> standardChannel, | ||
List<String> lines, | ||
) => | ||
standardChannel | ||
.transform(const SystemEncoding().decoder) | ||
.transform(const LineSplitter()) | ||
.forEach((element) { | ||
print(element); | ||
lines.add(element); | ||
}); | ||
|
||
final stdoutContent = <String>[]; | ||
final stderrContent = <String>[]; | ||
|
||
final result = await Future.wait([ | ||
process.exitCode, | ||
transform(process.stderr, stderrContent), | ||
transform(process.stdout, stdoutContent), | ||
]); | ||
|
||
final exitCode = result.first as int; | ||
|
||
if (exitCode != 0) { | ||
throw ProcessException(proc, args, 'Process failed', exitCode); | ||
} | ||
|
||
return (result.stdout as String).trim(); | ||
return stdoutContent.join('\n').trim(); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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