[cfe] Add Windows work-around for git diff in expectation testing

Change-Id: I126fb328181fc225177486e01a98e83060539b9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114502
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
This commit is contained in:
Johnni Winther
2019-08-27 09:56:53 +00:00
committed by commit-bot@chromium.org
parent 7dbf8eed3b
commit e7614adedb
2 changed files with 29 additions and 4 deletions
@@ -1928,6 +1928,7 @@ physical
pick
picked
pipeline
piping
pivot
place
placed
@@ -2396,6 +2397,7 @@ should
shouldn't
show
shown
shows
shrink
side
sign
+27 -4
View File
@@ -7,6 +7,7 @@ library fasta.testing.kernel_chain;
import 'dart:async' show Future;
import 'dart:io' show Directory, File, IOSink;
import 'dart:io';
import 'dart:typed_data' show Uint8List;
@@ -402,10 +403,32 @@ class BytesCollector implements Sink<List<int>> {
}
Future<String> runDiff(Uri expected, String actual) async {
StdioProcess process = await StdioProcess.run(
"git", <String>["diff", "--no-index", "-u", expected.toFilePath(), "-"],
input: actual, runInShell: true);
return process.output;
if (Platform.isWindows) {
// TODO(johnniwinther): Work-around for Windows. For some reason piping
// the actual result through stdin doesn't work; it shows a diff as if the
// actual result is the empty string.
Directory tempDirectory = Directory.systemTemp.createTempSync();
Uri uri = tempDirectory.uri.resolve('actual');
File file = new File.fromUri(uri)..writeAsStringSync(actual);
StdioProcess process = await StdioProcess.run(
"git",
<String>[
"diff",
"--no-index",
"-u",
expected.toFilePath(),
uri.toFilePath()
],
runInShell: true);
file.deleteSync();
tempDirectory.deleteSync();
return process.output;
} else {
StdioProcess process = await StdioProcess.run(
"git", <String>["diff", "--no-index", "-u", expected.toFilePath(), "-"],
input: actual, runInShell: true);
return process.output;
}
}
Future<void> openWrite(Uri uri, f(IOSink sink)) async {